]> git.ipfire.org Git - thirdparty/dracut.git/blob - test/TEST-50-MULTINIC/client-init.sh
529379f0e57f86dcc2a0e3d8973487567da7d73b
[thirdparty/dracut.git] / test / TEST-50-MULTINIC / client-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
98 exec >/dev/console 2>&1
99 set -x
100 export PATH=/sbin:/bin:/usr/sbin:/usr/bin
101 strstr() { [ "${1##*"$2"*}" != "$1" ]; }
102 strglobin() { [ -n "$1" -a -z "${1##*$2*}" ]; }
103 CMDLINE=$(while read line || [ -n "$line" ]; do echo $line;done < /proc/cmdline)
104 export TERM=linux
105 export PS1='initramfs-test:\w\$ '
106 stty sane
107 echo "made it to the rootfs! Powering down."
108 for i in /run/initramfs/net.*.did-setup; do
109 [ -f "$i" ] || continue
110 strglobin "$i" ":*:*:*:*:" && continue
111 i=${i%.did-setup}
112 IFACES+="${i##*/net.} "
113 done
114 {
115 echo "OK"
116 echo "$IFACES"
117 } > /dev/sda
118
119 getargbool 0 rd.shell && sh -i
120 poweroff -f