commit:     1a68a5349bb423ddff5ec56ea733631621eba862
Author:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 16 18:22:57 2020 +0000
Commit:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
CommitDate: Thu Jul 16 18:34:28 2020 +0000
URL:        https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=1a68a534

linuxrc: Add gk.userinteraction.disabled

When this option is set and enabled, genkernel initramfs will not prompt
on errors, i.e. this will disable any user interaction, e.g. for a kiosk system.

Bug: https://bugs.gentoo.org/730966
Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>

 defaults/initrd.defaults |  1 +
 defaults/initrd.scripts  | 52 ++++++++++++++++++++++++++++++++++++++++++++++++
 defaults/linuxrc         |  8 ++++++++
 doc/genkernel.8.txt      |  8 ++++++++
 4 files changed, 69 insertions(+)

diff --git a/defaults/initrd.defaults b/defaults/initrd.defaults
index 15326dd..79d7322 100644
--- a/defaults/initrd.defaults
+++ b/defaults/initrd.defaults
@@ -96,6 +96,7 @@ GK_SSHD_LOCKFILE='/tmp/remote-rescueshell.lock'
 GK_SSHD_PIDFILE='/var/run/dropbear.pid'
 GK_SSHD_PORT=22
 GK_SSHD_WAIT=
+GK_USERINTERACTION_DISABLED_STATEFILE='/tmp/user-interaction.disabled'
 
 CRYPT_ENV_FILE='/etc/CRYPT_ENV.conf'
 CRYPT_KEYFILE_ROOT='/tmp/root.key'

diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts
index d5378b7..6dc588f 100644
--- a/defaults/initrd.scripts
+++ b/defaults/initrd.scripts
@@ -959,6 +959,12 @@ run() {
 }
 
 run_shell() {
+       if [ -f "${GK_USERINTERACTION_DISABLED_STATEFILE}" ]
+       then
+               bad_msg "gk.userinteraction.disabled is set; Spawning a shell 
is disabled!"
+               return
+       fi
+
        [ -x /bin/sh ] && SH=/bin/sh || SH=/bin/ash
 
        run touch "${GK_SHELL_LOCKFILE}"
@@ -1114,6 +1120,15 @@ warn_msg() {
        [ "$2" != '1' ] && printf "%b\n" "${WARN}**${NORMAL}${BOLD} 
${msg_string} ${NORMAL}"
 }
 
+warn_msg_n() {
+       local msg_string=${1}
+       msg_string="${msg_string:-...}"
+
+       log_msg "[**] ${msg_string}"
+
+       [ "$2" != '1' ] && printf "%b" "${WARN}**${NORMAL}${BOLD} ${msg_string}"
+}
+
 write_env_file() {
        local env_file=${1}
        shift
@@ -1233,6 +1248,43 @@ prompt_user() {
        [ -n "${3}" ] && local explnt=" or : ${3}" || local explnt="."
 
        bad_msg "Could not find the ${2} in ${oldvalue}${explnt}"
+
+       if [ -f "${GK_USERINTERACTION_DISABLED_STATEFILE}" ]
+       then
+               bad_msg "gk.userinteraction.disabled is set; No user 
interaction allowed!"
+
+               wait_sshd
+
+               if [ -f "${GK_SSHD_LOCKFILE}" ]
+               then
+                       warn_msg "The lockfile at '${GK_SSHD_LOCKFILE}' exists."
+                       warn_msg "The boot process will be paused until the 
lock is removed."
+                       while true
+                       do
+                               if [ -f "${GK_SSHD_LOCKFILE}" ]
+                               then
+                                       sleep 1
+                               else
+                                       break
+                               fi
+                       done
+               fi
+
+               local timeout=${GK_PROMPT_TIMEOUT}
+               [ ${timeout} -eq 0 ] && timeout=10
+
+               warn_msg_n "System will automatically reboot in ${timeout} 
seconds ..."
+               while [ ${timeout} -gt 0 ]
+               do
+                       let timeout=${timeout}-1
+                       sleep 1
+                       printf "."
+               done
+               echo
+
+               reboot -f
+       fi
+
        bad_msg "Please specify another value or:"
        bad_msg "- press Enter for the same"
        bad_msg '- type "shell" for a shell'

diff --git a/defaults/linuxrc b/defaults/linuxrc
index 682f647..5354d09 100644
--- a/defaults/linuxrc
+++ b/defaults/linuxrc
@@ -356,6 +356,14 @@ do
                        fi
                        unset tmp_wait
                ;;
+               gk.userinteraction.disabled=*)
+                       tmp_disabled=${x#*=}
+                       if is_true "${tmp_disabled}"
+                       then
+                               touch "${GK_USERINTERACTION_DISABLED_STATEFILE}"
+                       fi
+                       unset tmp_disabled
+               ;;
                gk.prompt.timeout=*)
                        tmp_timeout=${x#*=}
                        if is_int "${tmp_timeout}"

diff --git a/doc/genkernel.8.txt b/doc/genkernel.8.txt
index 5b15a02..f84892c 100644
--- a/doc/genkernel.8.txt
+++ b/doc/genkernel.8.txt
@@ -835,6 +835,14 @@ genkernel's initramfs will only mount root filesystem by 
default. If you
 want to store the log file in '/var/log/genkernel-boot.log' for example
 make sure that this mountpoint is accessible, see *initramfs.mounts*.
 
+*gk.userinteraction.disabled*=<...>::
+By default, genkernel will prompt on errors. In case this is not wanted
+or desired, e.g. for a kiosk system, this boolean option will disable
+any prompting, including the rescue shell.
+
+NOTE: Because no user interaction is possible when this option is set,
+system will automatically reboot on error after a timeout.
+
 *noload*=<...>::
     List of modules to skip loading.
     Separate using commas or spaces.

Reply via email to