]> git.ipfire.org Git - thirdparty/dracut.git/blame - test/TEST-01-BASIC/test-init.sh
test: use dd to write status to marker disk
[thirdparty/dracut.git] / test / TEST-01-BASIC / test-init.sh
CommitLineData
dd26a551 1#!/bin/sh
c8f3a1c0 2>/dev/watchdog
781f1971
HH
3getcmdline() {
4 while read -r _line || [ -n "$_line" ]; do
b039b20e 5 printf "%s" "$_line"
781f1971
HH
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
45getarg() {
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
84getargbool() {
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}
dd26a551 98export PATH=/sbin:/bin:/usr/sbin:/usr/bin
9cf339ad 99strstr() { [ "${1##*"$2"*}" != "$1" ]; }
6d58fa27 100CMDLINE=$(while read line || [ -n "$line" ]; do echo $line;done < /proc/cmdline)
dd26a551
HH
101plymouth --quit
102exec >/dev/console 2>&1
9ca53063 103echo "dracut-root-block-success" | dd oflag=direct,dsync of=/dev/sdb
dd26a551
HH
104export TERM=linux
105export PS1='initramfs-test:\w\$ '
106[ -f /etc/mtab ] || ln -sfn /proc/mounts /etc/mtab
486ec657 107[ -f /etc/fstab ] || ln -sfn /proc/mounts /etc/fstab
dd26a551
HH
108stty sane
109echo "made it to the rootfs!"
781f1971 110if getargbool 0 rd.shell; then
d8eb522e
HH
111 strstr "$(setsid --help)" "control" && CTTY="-c"
112 setsid $CTTY sh -i
113fi
dd26a551
HH
114echo "Powering down."
115mount -n -o remount,ro /
116poweroff -f