]> git.ipfire.org Git - thirdparty/dracut.git/blob - test/TEST-14-IMSM/test-init.sh
test: use dd to write status to marker disk
[thirdparty/dracut.git] / test / TEST-14-IMSM / test-init.sh
1 #!/bin/sh
2 getcmdline() {
3 while read -r _line || [ -n "$_line" ]; do
4 printf "%s" "$_line"
5 done </proc/cmdline;
6 }
7
8 _dogetarg() {
9 local _o _val _doecho
10 unset _val
11 unset _o
12 unset _doecho
13 CMDLINE=$(getcmdline)
14
15 for _o in $CMDLINE; do
16 if [ "${_o%%=*}" = "${1%%=*}" ]; then
17 if [ -n "${1#*=}" -a "${1#*=*}" != "${1}" ]; then
18 # if $1 has a "=<value>", we want the exact match
19 if [ "$_o" = "$1" ]; then
20 _val="1";
21 unset _doecho
22 fi
23 continue
24 fi
25
26 if [ "${_o#*=}" = "$_o" ]; then
27 # if cmdline argument has no "=<value>", we assume "=1"
28 _val="1";
29 unset _doecho
30 continue
31 fi
32
33 _val="${_o#*=}"
34 _doecho=1
35 fi
36 done
37 if [ -n "$_val" ]; then
38 [ "x$_doecho" != "x" ] && echo "$_val";
39 return 0;
40 fi
41 return 1;
42 }
43
44 getarg() {
45 local _deprecated _newoption
46 while [ $# -gt 0 ]; do
47 case $1 in
48 -d) _deprecated=1; shift;;
49 -y) if _dogetarg $2 >/dev/null; then
50 if [ "$_deprecated" = "1" ]; then
51 [ -n "$_newoption" ] && warn "Kernel command line option '$2' is deprecated, use '$_newoption' instead." || warn "Option '$2' is deprecated."
52 fi
53 echo 1
54 return 0
55 fi
56 _deprecated=0
57 shift 2;;
58 -n) if _dogetarg $2 >/dev/null; then
59 echo 0;
60 if [ "$_deprecated" = "1" ]; then
61 [ -n "$_newoption" ] && warn "Kernel command line option '$2' is deprecated, use '$_newoption=0' instead." || warn "Option '$2' is deprecated."
62 fi
63 return 1
64 fi
65 _deprecated=0
66 shift 2;;
67 *) if [ -z "$_newoption" ]; then
68 _newoption="$1"
69 fi
70 if _dogetarg $1; then
71 if [ "$_deprecated" = "1" ]; then
72 [ -n "$_newoption" ] && warn "Kernel command line option '$1' is deprecated, use '$_newoption' instead." || warn "Option '$1' is deprecated."
73 fi
74 return 0;
75 fi
76 _deprecated=0
77 shift;;
78 esac
79 done
80 return 1
81 }
82
83 getargbool() {
84 local _b
85 unset _b
86 local _default
87 _default="$1"; shift
88 _b=$(getarg "$@")
89 [ $? -ne 0 -a -z "$_b" ] && _b="$_default"
90 if [ -n "$_b" ]; then
91 [ $_b = "0" ] && return 1
92 [ $_b = "no" ] && return 1
93 [ $_b = "off" ] && return 1
94 fi
95 return 0
96 }
97 export PATH=/sbin:/bin:/usr/sbin:/usr/bin
98 strstr() { [ "${1##*"$2"*}" != "$1" ]; }
99 CMDLINE=$(while read line || [ -n "$line" ]; do echo $line;done < /proc/cmdline)
100 plymouth --quit
101 exec >/dev/console 2>&1
102 echo "dracut-root-block-success" | dd oflag=direct,dsync of=/dev/sda
103 export TERM=linux
104 export PS1='initramfs-test:\w\$ '
105 cat /proc/mdstat
106 [ -f /etc/fstab ] || ln -s /proc/mounts /etc/fstab
107 stty sane
108 echo "made it to the rootfs!"
109 getargbool 0 rd.shell && sh -i
110 echo "Powering down."
111 mount -n -o remount,ro /
112 poweroff -f