1 |
commit: 1d79338fa7391f8bc41bb74411c9a955e24d81cd |
2 |
Author: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Aug 6 18:04:20 2019 +0000 |
4 |
Commit: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Aug 7 15:03:44 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=1d79338f |
7 |
|
8 |
initrd.scripts: prompt_user(): Read answer from $GK_PROMPT_FILE on timeout |
9 |
|
10 |
This commit will bring back read timeout which was removed in |
11 |
Commit a280829. Read timeout is still disabled by default but |
12 |
can now be controlled via gk.prompt.timeout kernel command-line |
13 |
argument. |
14 |
|
15 |
When gk.prompt.timeout is != 0, the current prompt will be written |
16 |
to $GK_PROMPT_FILE. This will allow remote user to notice that |
17 |
there's a prompt. |
18 |
|
19 |
In addition, on timeout, $GK_PROMPT_FILE will be read allowing |
20 |
remote user to answer prompt and hopefully to fix the problem |
21 |
and resume booting. |
22 |
|
23 |
To make this work, gk.prompt.timeout will be set to 30 seconds |
24 |
by default when SSH usage is enabled. |
25 |
|
26 |
Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org> |
27 |
|
28 |
defaults/initrd.defaults | 2 ++ |
29 |
defaults/initrd.scripts | 36 ++++++++++++++++++++++++++++++------ |
30 |
defaults/linuxrc | 10 ++++++++++ |
31 |
doc/genkernel.8.txt | 9 +++++++++ |
32 |
4 files changed, 51 insertions(+), 6 deletions(-) |
33 |
|
34 |
diff --git a/defaults/initrd.defaults b/defaults/initrd.defaults |
35 |
index 553600d..06057d7 100644 |
36 |
--- a/defaults/initrd.defaults |
37 |
+++ b/defaults/initrd.defaults |
38 |
@@ -85,6 +85,8 @@ GK_NET_TIMEOUT_DAD=10 |
39 |
GK_NET_TIMEOUT_DECONFIGURATION=10 |
40 |
GK_NET_TIMEOUT_DHCP=10 |
41 |
GK_NET_TIMEOUT_INTERFACE=10 |
42 |
+GK_PROMPT_FILE='/tmp/current_prompt' |
43 |
+GK_PROMPT_TIMEOUT=0 |
44 |
GK_SHELL_LOCKFILE='/tmp/rescueshell.lock' |
45 |
GK_SSHD_LOCKFILE='/tmp/remote-rescueshell.lock' |
46 |
GK_SSHD_PIDFILE='/var/run/dropbear.pid' |
47 |
|
48 |
diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts |
49 |
index 68adfb9..88046b4 100644 |
50 |
--- a/defaults/initrd.scripts |
51 |
+++ b/defaults/initrd.scripts |
52 |
@@ -1108,12 +1108,30 @@ prompt_user() { |
53 |
bad_msg '- type "shell" for a shell' |
54 |
bad_msg '- type "q" to skip ...' |
55 |
printf "%s" "${2}(${oldvalue}) :: " |
56 |
- read ${1} |
57 |
- #if [ $? -gt 0 ] |
58 |
- #then |
59 |
- # # prompt timed out |
60 |
- # printf "\n" |
61 |
- #fi |
62 |
+ |
63 |
+ if [ "${GK_PROMPT_TIMEOUT}" = '0' ] |
64 |
+ then |
65 |
+ read ${1} |
66 |
+ else |
67 |
+ local read_timeout_timestamp |
68 |
+ let read_timeout_timestamp=$(date +%s)+${GK_PROMPT_TIMEOUT} |
69 |
+ |
70 |
+ echo "# Could not find the ${2} in ${oldvalue}${explnt}" > "${GK_PROMPT_FILE}" |
71 |
+ echo "# Please specify another value (file will be processed at $(date -d @${read_timeout_timestamp}):" >> "${GK_PROMPT_FILE}" |
72 |
+ echo "${1}=${oldvalue}" >> "${GK_PROMPT_FILE}" |
73 |
+ read -t ${GK_PROMPT_TIMEOUT} ${1} |
74 |
+ if [ $? -gt 0 ] |
75 |
+ then |
76 |
+ # prompt timed out |
77 |
+ printf "\n" |
78 |
+ |
79 |
+ if [ -f "${GK_PROMPT_FILE}" ] |
80 |
+ then |
81 |
+ warn_msg "Timeout! Trying to read answer from '${GK_PROMPT_FILE}' ..." |
82 |
+ . "${GK_PROMPT_FILE}" && run rm "${GK_PROMPT_FILE}" |
83 |
+ fi |
84 |
+ fi |
85 |
+ fi |
86 |
|
87 |
case $(eval echo '$'${1}) in |
88 |
'q') |
89 |
@@ -2145,6 +2163,12 @@ start_sshd() { |
90 |
return |
91 |
fi |
92 |
|
93 |
+ if [ "${GK_PROMPT_TIMEOUT}" = '0' ] |
94 |
+ then |
95 |
+ warn_msg "Changing gk.prompt.timeout=0 to 30 ..." |
96 |
+ GK_PROMPT_TIMEOUT=30 |
97 |
+ fi |
98 |
+ |
99 |
if [ ! -x "/usr/sbin/dropbear" ] |
100 |
then |
101 |
bad_msg "/usr/sbin/dropbear not found! Did you call genkernel with --ssh parameter?" |
102 |
|
103 |
diff --git a/defaults/linuxrc b/defaults/linuxrc |
104 |
index b2ac54e..a57de1c 100644 |
105 |
--- a/defaults/linuxrc |
106 |
+++ b/defaults/linuxrc |
107 |
@@ -336,6 +336,16 @@ do |
108 |
fi |
109 |
unset tmp_wait |
110 |
;; |
111 |
+ gk.prompt.timeout=*) |
112 |
+ tmp_timeout=${x#*=} |
113 |
+ if is_int "${tmp_timeout}" |
114 |
+ then |
115 |
+ GK_PROMPT_TIMEOUT=${tmp_timeout} |
116 |
+ else |
117 |
+ warn_msg "'${x}' does not look like a valid time (second) value -- ignored!" |
118 |
+ fi |
119 |
+ unset tmp_timeout |
120 |
+ ;; |
121 |
real_rootflags=*) |
122 |
REAL_ROOTFLAGS=${x#*=} |
123 |
;; |
124 |
|
125 |
diff --git a/doc/genkernel.8.txt b/doc/genkernel.8.txt |
126 |
index 3ab28ce..3ebd320 100644 |
127 |
--- a/doc/genkernel.8.txt |
128 |
+++ b/doc/genkernel.8.txt |
129 |
@@ -687,6 +687,15 @@ recognized by the kernel itself. |
130 |
*gk.net.timeout.interface*=<...>:: |
131 |
By default we will wait up to 10 seconds for interface to show up. |
132 |
|
133 |
+*gk.prompt.timeout*=<...>:: |
134 |
+By default a prompt within genkernel initramfs like shown when set |
135 |
+*root* could not be found will never timeout. Use this option to set |
136 |
+a timeout. |
137 |
+ |
138 |
+NOTE: When *dosshd* is used, *gk.prompt.timeout* will be set to 30 seconds |
139 |
+when not set. This will allow remote user to provide answer through |
140 |
+*GK_PROMPT_FILE* which is set to '/tmp/current_prompt' by default. |
141 |
+ |
142 |
*dosshd*:: |
143 |
Will bring up an interface and start a SSH daemon within initramfs |
144 |
allowing to remotely unlock encrypted devices or just for debugging |