Files
CISS.debian.installer/lib/0080_trap_int.sh
2025-07-25 10:05:36 +02:00

88 lines
2.9 KiB
Bash

#!/bin/bash
# SPDX-Version: 3.0
# SPDX-CreationInfo: 2025-06-17; WEIDNER, Marc S.; <msw@coresecret.dev>
# SPDX-ExternalRef: GIT https://git.coresecret.dev/msw/CISS.debian.installer.git
# SPDX-FileContributor: WEIDNER, Marc S.; Centurion Intelligence Consulting Agency
# SPDX-FileCopyrightText: 2024-2025; WEIDNER, Marc S.; <msw@coresecret.dev>
# SPDX-FileType: SOURCE
# SPDX-License-Identifier: EUPL-1.2 OR LicenseRef-CCLA-1.0
# SPDX-LicenseComment: This file is part of the CISS.debian.installer.secure framework.
# SPDX-PackageName: CISS.debian.installer
# SPDX-Security-Contact: security@coresecret.eu
guard_sourcing
#######################################
# Restart Dialog Wrapper in case of unintentional SIGINT.
# Globals:
# VAR_DEBUG_TRAP
# Arguments:
# 1: var_helper_dialog
#######################################
restart_dialog() {
[[ "${VAR_DEBUG_TRAP}" == "true" ]] && trap 'debug_trap' DEBUG
trap 'trap_int' INT TERM
trap 'trap_err "$?" "${BASH_SOURCE[0]}" "${LINENO}" "${FUNCNAME[0]:-main}" "${BASH_COMMAND}"' ERR
case "$1" in
box ) dialog_box ;;
gauge ) dialog_gauge ;;
* ) ;;
esac
}
#######################################
# Trap function to be called on 'SIGINT'.
# Globals:
# ERR_TRAPPED_SIG_INT
# VAR_IN_DIALOG_WR
# Arguments:
# None
# Returns:
# 0: In case of unintentional SIGINT.
#######################################
trap_int() {
case "${VAR_IN_DIALOG_WR}" in
box ) dialog_box_cleaner; declare var_helper_dialog="box" ;;
gauge ) dialog_gauge_cleaner; declare var_helper_dialog="gauge" ;;
* ) declare var_helper_dialog="false" ;;
esac
trap - DEBUG ERR INT TERM
declare answer
if ! read -r -t 16 -p $'\n\e[93mCISS.debian.installer caught an INT.\e[0m \e[92mDo you want to abort the Installer? (y/N) \e[0m' answer; then
printf "\e[92mCISS.debian.installer caught an INT. No User confirmation after 16 seconds. Proceeding with Installer. \e[0m\n" >&2
if [[ "${var_helper_dialog}" == box ]]; then
restart_dialog "${var_helper_dialog}"
return 0
elif [[ "${var_helper_dialog}" == gauge ]]; then
restart_dialog "${var_helper_dialog}"
return 0
else
restart_dialog "${var_helper_dialog}"
return 0
fi
fi
case "${answer,,}" in
y|yes)
printf "\e[91mCISS.debian.installer caught an INT. SIGINT confirmed by User, exiting Installer. \e[0m\n" >&2
exit "${ERR_TRAPPED_SIG_INT}"
;;
*)
printf "\e[92mCISS.debian.installer caught an INT. SIGINT NOT confirmed by User, proceeding with Installer. \e[0m\n" >&2
if [[ "${var_helper_dialog}" == box ]]; then
restart_dialog "${var_helper_dialog}"
return 0
elif [[ "${var_helper_dialog}" == gauge ]]; then
restart_dialog "${var_helper_dialog}"
return 0
else
restart_dialog "${var_helper_dialog}"
return 0
fi
;;
esac
}
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh