]> git.ipfire.org Git - thirdparty/dracut.git/blob - test/TEST-04-FULL-SYSTEMD/test-init.sh
TEST-04-FULL-SYSTEMD: change error reporting
[thirdparty/dracut.git] / test / TEST-04-FULL-SYSTEMD / test-init.sh
1 #!/bin/sh
2 >/dev/watchdog
3 getcmdline() {
4 while read -r _line || [ -n "$_line" ]; do
5 printf "%s" "$_line"
6 done </proc/cmdline;
7 }
8
9 _dogetarg() {
10 local _o _val _doecho
11 unset _val
12 unset _o
13 unset _doecho
14 CMDLINE=$(getcmdline)
15
16 for _o in $CMDLINE; do
17 if [ "${_o%%=*}" = "${1%%=*}" ]; then
18 if [ -n "${1#*=}" -a "${1#*=*}" != "${1}" ]; then
19 # if $1 has a "=<value>", we want the exact match
20 if [ "$_o" = "$1" ]; then
21 _val="1";
22 unset _doecho
23 fi
24 continue
25 fi
26
27 if [ "${_o#*=}" = "$_o" ]; then
28 # if cmdline argument has no "=<value>", we assume "=1"
29 _val="1";
30 unset _doecho
31 continue
32 fi
33
34 _val="${_o#*=}"
35 _doecho=1
36 fi
37 done
38 if [ -n "$_val" ]; then
39 [ "x$_doecho" != "x" ] && echo "$_val";
40 return 0;
41 fi
42 return 1;
43 }
44
45 getarg() {
46 local _deprecated _newoption
47 while [ $# -gt 0 ]; do
48 case $1 in
49 -d) _deprecated=1; shift;;
50 -y) if _dogetarg $2 >/dev/null; then
51 if [ "$_deprecated" = "1" ]; then
52 [ -n "$_newoption" ] && warn "Kernel command line option '$2' is deprecated, use '$_newoption' instead." || warn "Option '$2' is deprecated."
53 fi
54 echo 1
55 return 0
56 fi
57 _deprecated=0
58 shift 2;;
59 -n) if _dogetarg $2 >/dev/null; then
60 echo 0;
61 if [ "$_deprecated" = "1" ]; then
62 [ -n "$_newoption" ] && warn "Kernel command line option '$2' is deprecated, use '$_newoption=0' instead." || warn "Option '$2' is deprecated."
63 fi
64 return 1
65 fi
66 _deprecated=0
67 shift 2;;
68 *) if [ -z "$_newoption" ]; then
69 _newoption="$1"
70 fi
71 if _dogetarg $1; then
72 if [ "$_deprecated" = "1" ]; then
73 [ -n "$_newoption" ] && warn "Kernel command line option '$1' is deprecated, use '$_newoption' instead." || warn "Option '$1' is deprecated."
74 fi
75 return 0;
76 fi
77 _deprecated=0
78 shift;;
79 esac
80 done
81 return 1
82 }
83
84 getargbool() {
85 local _b
86 unset _b
87 local _default
88 _default="$1"; shift
89 _b=$(getarg "$@")
90 [ $? -ne 0 -a -z "$_b" ] && _b="$_default"
91 if [ -n "$_b" ]; then
92 [ $_b = "0" ] && return 1
93 [ $_b = "no" ] && return 1
94 [ $_b = "off" ] && return 1
95 fi
96 return 0
97 }
98 export PATH=/sbin:/bin:/usr/sbin:/usr/bin
99 strstr() { [ "${1##*"$2"*}" != "$1" ]; }
100 CMDLINE=$(while read line || [ -n "$line" ]; do echo $line;done < /proc/cmdline)
101 plymouth --quit
102 exec </dev/console >/dev/console 2>&1
103
104 ismounted() {
105 while read a m a || [ -n "$a" ]; do
106 [ "$m" = "$1" ] && return 0
107 done < /proc/mounts
108 return 1
109 }
110
111 systemctl --failed --no-legend --no-pager > /failed
112
113 if ! ismounted /usr; then
114 echo "**************************FAILED**************************"
115 echo "/usr not mounted!!"
116 cat /proc/mounts
117 echo "**************************FAILED**************************"
118 else
119 if [ -s /failed ]; then
120 echo "**************************FAILED**************************"
121 cat /failed
122 echo "**************************FAILED**************************"
123
124 else
125 echo "dracut-root-block-success" | dd oflag=direct,dsync of=/dev/sdc
126 echo "All OK"
127 fi
128 fi
129
130 export TERM=linux
131 export PS1='initramfs-test:\w\$ '
132 [ -f /etc/mtab ] || ln -sfn /proc/mounts /etc/mtab
133 [ -f /etc/fstab ] || ln -sfn /proc/mounts /etc/fstab
134 stty sane
135 echo "made it to the rootfs!"
136 if getargbool 0 rd.shell; then
137 # while sleep 1; do sleep 1;done
138 strstr "$(setsid --help)" "control" && CTTY="-c"
139 setsid $CTTY sh -i
140 fi
141 set -x
142 /usr/bin/systemctl poweroff
143 echo "Powering down."