system-image: implement auto confirm / reject feature

This is intended for use in server environments, in the installer, and any
situation where you don't want a prompt on the TTY at shutdown/reboot.
master
BodgeMaster 2026-07-16 16:20:17 +02:00
parent fac6679f4e
commit a575eafb66
1 changed files with 37 additions and 18 deletions

View File

@ -16,7 +16,15 @@ function echo_tty {
fi fi
} }
AUTO_CONFIRM="false"
AUTO_REJECT="false"
function yesno { function yesno {
if "$AUTO_CONFIRM"; then
return 0
fi
if "$AUTO_REJECT"; then
return 1
fi
unset DISCARD_ME unset DISCARD_ME
while [ -z "$DISCARD_ME" ]; do while [ -z "$DISCARD_ME" ]; do
echo_tty -n "[y/n] " echo_tty -n "[y/n] "
@ -43,27 +51,36 @@ function yesno {
#TODO: refuse to run if system is running #TODO: refuse to run if system is running
if [ "$1" = "--yes" ]; then if [ "$1" = "--yes" ]; then
DONT_ASK="true" AUTO_CONFIRM="true"
else else
DONT_ASK="false" if [ -e "/run/void-usb/system-image-auto-confirm-marker" ]; then
AUTO_CONFIRM="true"
#TODO: use a bright color for ==== and the question else
echo_tty "==========================" if [ -e "/run/void-usb/system-image-auto-reject-marker" ]; then
echo_tty "Create a new system image?" AUTO_REJECT="true"
echo_tty "==========================" else
echo_tty #TODO: use a bright color for ==== and the question
echo_tty "This will replace the existing system image with a snapshot of the currently" echo_tty "=========================="
echo_tty "running system. Choosing no here will discard any newly installed programs," echo_tty "Create a new system image?"
echo_tty "updates, system configuration changes, etc." echo_tty "=========================="
echo_tty echo_tty
echo_tty "This should not affect your files in /home as they are stored to disk directly." echo_tty "This will replace the existing system image with a snapshot of the currently"
echo_tty "Check /TODO/README.txt for more information." echo_tty "running system. Choosing no here will discard any newly installed programs,"
echo_tty echo_tty "updates, system configuration changes, etc."
echo_tty "Creating a new system image will take some time." echo_tty
echo_tty echo_tty "This should not affect your files in /home as they are stored to disk directly."
echo_tty "Check /TODO/README.txt for more information."
echo_tty
echo_tty "Creating a new system image will take some time."
echo_tty
fi
fi
fi fi
if $DONT_ASK || yesno; then if yesno; then
echo_tty "=========================="
echo_tty "Building new system image."
echo_tty "=========================="
echo_tty -n "Generating exclusion list... " echo_tty -n "Generating exclusion list... "
# cutting off the leading slash allows us to just ignore empty lines below # cutting off the leading slash allows us to just ignore empty lines below
readarray -t MOUNT_LIST <<< "$(findmnt --output TARGET --noheadings --raw | sed -e 's|^/||' | sort)" readarray -t MOUNT_LIST <<< "$(findmnt --output TARGET --noheadings --raw | sed -e 's|^/||' | sort)"
@ -107,7 +124,9 @@ if $DONT_ASK || yesno; then
echo_tty "done" echo_tty "done"
fi fi
else else
echo_tty "=========================="
echo_tty "Discarding system changes." echo_tty "Discarding system changes."
echo_tty "=========================="
fi fi
echo_tty -n "Syncing... " echo_tty -n "Syncing... "