]> git.ipfire.org Git - thirdparty/dracut.git/blame - test/TEST-20-NFS/client-init.sh
test: use dd to write status to marker disk
[thirdparty/dracut.git] / test / TEST-20-NFS / client-init.sh
CommitLineData
528277f3 1#!/bin/sh
781f1971
HH
2getcmdline() {
3 while read -r _line || [ -n "$_line" ]; do
b039b20e 4 printf "%s" "$_line"
781f1971
HH
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
44getarg() {
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
83getargbool() {
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}
387bf82e 97export PATH=/sbin:/bin:/usr/sbin:/usr/bin
528277f3
DD
98exec >/dev/console 2>&1
99export TERM=linux
100export PS1='initramfs-test:\w\$ '
6d58fa27 101CMDLINE=$(while read line || [ -n "$line" ]; do echo $line;done < /proc/cmdline)
9cf339ad 102strstr() { [ "${1##*"$2"*}" != "$1" ]; }
fc871190 103
528277f3 104stty sane
781f1971 105if getargbool 0 rd.shell; then
5899f2f5 106 [ -c /dev/watchdog ] && printf 'V' > /dev/watchdog
28d03673
HH
107 strstr "$(setsid --help)" "control" && CTTY="-c"
108 setsid $CTTY sh -i
109fi
110
528277f3 111echo "made it to the rootfs! Powering down."
28d03673 112
6d58fa27 113while read dev fs fstype opts rest || [ -n "$dev" ]; do
574f2965 114 [ "$fstype" != "nfs" -a "$fstype" != "nfs4" ] && continue
9ca53063 115 echo "nfs-OK $dev $fstype $opts" | dd oflag=direct,dsync of=/dev/sda
574f2965
DD
116 break
117done < /proc/mounts
f71145d2 118>/dev/watchdog
528277f3 119poweroff -f