From 9e18b08b629c69e49417fd778fafc3f0217b4cc9 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Fri, 21 Feb 2020 09:39:33 +0100 Subject: update-me: -c and -s new --- update-me.in | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/update-me.in b/update-me.in index 46db7f7..903c30d 100644 --- a/update-me.in +++ b/update-me.in @@ -1,5 +1,40 @@ #!/bin/bash +usage() { + >&2 echo 'usage: update-me [-s|-c]' + >&2 echo ' -s: play it save' + >&2 echo ' -c: clear for exit' + exit $1 +} + +play_it_safe=false +safety_file='/tmp/update-me.do-not-exit' + +case $# in + 0) + ;; + 1) + case "x$1" in + 'x-s') + play_it_safe=true + ;; + 'x-c') + if [ -f "${safety_file}" ] && kill -0 $(cat "${safety_file}"); then + rm "${safety_file}" + exit 0 + fi + exit 1 + ;; + *) + usage + ;; + esac + ;; + *) + usage 1 + ;; +esac + preCmds=('hostname') cmds=() postCmds=('sync') @@ -21,6 +56,18 @@ if command -v check-kernel >/dev/null; then fi exit_or_rescue_shell() { + if "${play_it_safe}"; then + printf '%s' "$$" >"${safety_file}" + >&2 printf '%s: waiting for clearance ...' "$(hostname)" + while [ -f "${safety_file}" ] && [ "$(cat "${safety_file}")" = "$$" ]; do + if read -t 1; then + >&2 printf ' rescue shell!\n' + bash + break + fi + done + >&2 printf ' clear.\n' + fi if [ "$1" -eq 0 ]; then >&2 printf '%s: Erfolg\n' "$(hostname)" else -- cgit v1.2.3-70-g09d2