armbian-next: split prepare_host(), fix .tmp reset trap

- `prepare_host()`: split; do checks earlier and allow them to be interactive
- introduce `exit_if_countdown_not_aborted()` for "Low Disk Space" and other critical conditions
- split `prepare_host()` into interactive & non-interactive parts
- split off `clean_deprecated_mountpoints()` from prepare into `cleaning.sh`
- introduce and use `reset_uid_owner_non_recursive()` for `.tmp` reset in trap, to avoid disasters
- add more logging sections to default-build.sh, avoid unlogged parts
This commit is contained in:
Ricardo Pardini
2023-01-16 23:49:20 +01:00
parent 2d9f9216eb
commit bf891d54d9
6 changed files with 115 additions and 60 deletions

View File

@@ -165,3 +165,35 @@ function exit_with_error() {
exit 43
}
# This exits, unless user presses ENTER. If not interactive, user will be unable to comply and the script will exit.
function exit_if_countdown_not_aborted() {
# parse
declare -i loops="${1}"
declare reason="${2}"
# validate
[[ -z "${loops}" ]] && exit_with_error "countdown_to_exit_or_just_exit_if_noninteractive() called without a number of loops"
[[ -z "${reason}" ]] && exit_with_error "countdown_to_exit_or_just_exit_if_noninteractive() called without a reason"
# If not interactive, just exit.
if [[ ! -t 1 ]]; then
exit_with_error "Exiting due to '${reason}' - not interactive, exiting immediately."
fi
display_alert "Problem detected" "${reason}" "err"
display_alert "Exiting in ${loops} seconds" "Press \e[0;33m<Ctrl-C>\x1B[0m to abort, \e[0;33m<Enter>\x1B[0m to ignore and continue" "err"
echo -n "Counting down: "
for i in $(seq 1 "${loops}"); do
declare stop_waiting=0
declare keep_waiting=0
timeout --foreground 1 bash -c "read -n1; echo \$REPLY" && stop_waiting=1 || keep_waiting=1
if [[ "$stop_waiting" == "1" ]]; then
display_alert "User pressed ENTER, continuing, albeit" "${reason}" "wrn"
return 0
fi
echo -n "$i... " >&2
done
# Countdown finished, exit.
exit_with_error "Exiting due to '${reason}'"
}