]>
Commit | Line | Data |
---|---|---|
ef9b54cf HH |
1 | #!/bin/sh |
2 | >/dev/watchdog | |
781f1971 HH |
3 | getcmdline() { |
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 | ||
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 | } | |
ef9b54cf | 98 | export PATH=/sbin:/bin:/usr/sbin:/usr/bin |
9cf339ad | 99 | strstr() { [ "${1##*"$2"*}" != "$1" ]; } |
6d58fa27 | 100 | CMDLINE=$(while read line || [ -n "$line" ]; do echo $line;done < /proc/cmdline) |
ef9b54cf HH |
101 | plymouth --quit |
102 | exec </dev/console >/dev/console 2>&1 | |
103 | ||
104 | ismounted() { | |
6d58fa27 | 105 | while read a m a || [ -n "$m" ]; do |
ef9b54cf HH |
106 | [ "$m" = "$1" ] && return 0 |
107 | done < /proc/mounts | |
108 | return 1 | |
109 | } | |
110 | ||
111 | if ismounted /usr; then | |
9ca53063 | 112 | echo "dracut-root-block-success" | dd oflag=direct,dsync of=/dev/sdc |
ef9b54cf HH |
113 | fi |
114 | export TERM=linux | |
115 | export PS1='initramfs-test:\w\$ ' | |
116 | [ -f /etc/mtab ] || ln -sfn /proc/mounts /etc/mtab | |
117 | [ -f /etc/fstab ] || ln -sfn /proc/mounts /etc/fstab | |
118 | stty sane | |
119 | echo "made it to the rootfs!" | |
781f1971 | 120 | if getargbool 0 rd.shell; then |
ef9b54cf HH |
121 | strstr "$(setsid --help)" "control" && CTTY="-c" |
122 | setsid $CTTY sh -i | |
123 | fi | |
124 | echo "Powering down." | |
125 | mount -n -o remount,ro / | |
126 | poweroff -f |