Debian Codegraph @

dracut/modules.d/59kiwi-lib/kiwi-dialog-lib.sh

raw
1 #!/bin/bash
2
3 type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
4
5 function run_dialog {
6 # """
7 # Run the dialog program via the systemd service either in a
8 # framebuffer terminal or on the console. The return code of
9 # the function is the return code of the dialog call. The
10 # output of the dialog call is stored in a file and can be
11 # one time read via the get_dialog_result function
12 # """
13 stop_plymouth
14 local dialog_result=/tmp/dialog_result
15 local dialog_exit_code=/tmp/dialog_code
16 {
17 echo "dialog $* 2>$dialog_result"
18 echo "echo -n \$? >$dialog_exit_code"
19 } >/run/dracut-interactive
20 _run_interactive
21 return "$(cat $dialog_exit_code)"
22 }
23
24 function setup_progress_fifo {
25 local fifo=$1
26 export current_progress_fifo="${fifo}"
27 [ -e "${fifo}" ] || mkfifo "${fifo}"
28 }
29
30 function stop_dialog {
31 _stop_interactive
32 }
33
34 function run_progress_dialog {
35 # """
36 # Run the gauge dialog via systemd reading progress
37 # status information from stdin
38 # """
39 stop_plymouth
40 declare fifo=${current_progress_fifo}
41 local title=$1
42 local backtitle=$2
43 local progress_at="${fifo}"
44 if [ ! -e "${progress_at}" ];then
45 return
46 fi
47 {
48 echo -n "cat ${fifo} | dialog --backtitle \"${backtitle}\" "
49 echo -n "--gauge \"${title}\"" 7 65 0
50 echo
51 } >/run/dracut-interactive
52 _run_interactive
53 }
54
55 function get_dialog_result {
56 local dialog_result=/tmp/dialog_result
57 [ -e "${dialog_result}" ] && cat ${dialog_result}; rm -f ${dialog_result}
58 }
59
60 function stop_plymouth {
61 if ! getargbool 0 rd.kiwi.allow_plymouth; then
62 if command -v plymouth &>/dev/null;then
63 plymouth --quit --wait
64 fi
65 fi
66 }
67
68 #=========================================
69 # Methods considered private
70 #-----------------------------------------
71 function _setup_interactive_service {
72 local service=/run/systemd/system/dracut-run-interactive.service
73 local script=/run/dracut-interactive
74 mkdir -p /run/systemd/system
75 [ -e ${service} ] && return
76 {
77 echo "[Unit]"
78 echo "Description=Dracut Run Interactive"
79 echo "DefaultDependencies=no"
80 echo "After=systemd-vconsole-setup.service"
81 echo "Wants=systemd-vconsole-setup.service"
82 echo "Conflicts=emergency.service emergency.target"
83 echo "[Service]"
84 echo "EnvironmentFile=/dialog_profile"
85 echo "Environment=HOME=/"
86 echo "Environment=DRACUT_SYSTEMD=1"
87 echo "Environment=NEWROOT=/sysroot"
88 echo "WorkingDirectory=/"
89 if _fbiterm_ok; then
90 echo "ExecStart=fbiterm -- /bin/bash ${script} "
91 else
92 echo "ExecStart=/bin/bash ${script}"
93 fi
94 echo "Type=oneshot"
95 echo "StandardInput=tty-force"
96 echo "StandardOutput=inherit"
97 echo "StandardError=inherit"
98 echo "KillMode=process"
99 echo "IgnoreSIGPIPE=no"
100 echo "KillSignal=SIGHUP"
101 } > ${service}
102 }
103
104 function _run_interactive {
105 _setup_interactive_service
106 systemctl start dracut-run-interactive.service
107 }
108
109 function _stop_interactive {
110 systemctl stop dracut-run-interactive.service
111 }
112
113 function _fbiterm_ok {
114 if [ ! -e /dev/fb0 ];then
115 # no framebuffer device found
116 return 1
117 fi
118 if ! command -v fbiterm &>/dev/null;then
119 # no framebuffer terminal program found
120 return 1
121 fi
122 if ! fbiterm echo &>/dev/null;then
123 # fbiterm can't be called with echo test cmd
124 return 1
125 fi
126 return 0
127 }
128
129 function dialog_timeout {
130 local timeout=60
131 custom_timeout=$(getarg "rd.kiwi.dialog.timeout=")
132 [ -n "${custom_timeout}" ] && timeout="${custom_timeout}"
133 echo "${timeout}"
134 }
135
136 function show_log_and_quit {
137 local text_message="$1"
138 local log_file="$2"
139 local timeout
140 timeout=$(dialog_timeout)
141 if [ "${timeout}" = "off" ];then
142 run_dialog --backtitle "\"${text_message}\"" \
143 --textbox "${log_file}" 15 80
144 else
145 run_dialog --timeout "${timeout}" --backtitle "\"${text_message}\"" \
146 --textbox "${log_file}" 15 80
147 fi
148 if getargbool 0 rd.debug; then
149 die "${text_message}"
150 else
151 reboot -f
152 fi
153 }
154
155 function report_and_quit {
156 local text_message="$1"
157 local timeout
158 timeout=$(dialog_timeout)
159 if [ "${timeout}" = "off" ];then
160 run_dialog --msgbox "\"${text_message}\"" 5 80
161 else
162 run_dialog --timeout "${timeout}" --msgbox "\"${text_message}\"" 5 80
163 fi
164 if getargbool 0 rd.debug; then
165 die "${text_message}"
166 else
167 reboot -f
168 fi
169 }
170
171 function ask_and_reboot {
172 local text_message="$1"
173 if ! run_dialog --yesno "\"${text_message}\"" 7 80; then
174 die "${text_message}"
175 else
176 reboot -f
177 fi
178 }
179
180 function ask_and_shutdown {
181 local text_message="$1"
182 if ! run_dialog --yesno "\"${text_message}\"" 7 80; then
183 die "${text_message}"
184 else
185 systemctl poweroff
186 fi
187 }
188
189 function ask_for_credentials {
190 local text_message="$1"
191 run_dialog --insecure --passwordbox "\"${text_message}\"" 7 60
192 }