diff options
author | bill-auger <mr.j.spam.me@gmail.com> | 2022-08-15 07:45:40 -0400 |
---|---|---|
committer | bill-auger <mr.j.spam.me@gmail.com> | 2022-08-17 06:37:01 -0400 |
commit | 03f73ce81a566d312ad78dca1ea9938f17110477 (patch) | |
tree | 2717310c4a55c3e0e9d881b9f57136c9bd6d4a59 | |
parent | afdaca93dd3237490b9d621e669f82ac204728fa (diff) |
guard common include against missing `dialog` and translations in-chroot
-rw-r--r-- | session-common.sh.inc | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/session-common.sh.inc b/session-common.sh.inc index c9106f1..4a732a7 100644 --- a/session-common.sh.inc +++ b/session-common.sh.inc @@ -71,9 +71,13 @@ readonly STATEVARS_PRESET readonly DIALOG_ERR_MSG="ERROR: can not find the \`dialog\` program" readonly PRIVILEGE_ERR_MSG="ERROR: this program requires superuser privilege" readonly STATEFILE_ERR_MSG="ERROR: can not write to state file" -which dialog &> /dev/null || ! echo "${DIALOG_ERR_MSG}" || exit -(( ! $EUID )) || ! echo "${PRIVILEGE_ERR_MSG}" || exit -[[ -w "${THIS_DIR}"/.session_state ]] || ! echo "${STATEFILE_ERR_MSG}" || exit +readonly IN_CHROOT=$( main_script="${BASH_SOURCE[$(( ${#BASH_SOURCE[@]} - 1 ))]}" \ + [[ "${main_script}" =~ ^/root/chroot-.*\.sh$ ]] ; echo $((!$?)) ) +if (( ! IN_CHROOT )) +then which dialog &> /dev/null || ! echo "${DIALOG_ERR_MSG}" || exit + (( ! $EUID )) || ! echo "${PRIVILEGE_ERR_MSG}" || exit + [[ -w "${THIS_DIR}"/.session_state ]] || ! echo "${STATEFILE_ERR_MSG}" || exit +fi ## state helpers ## @@ -470,9 +474,11 @@ readonly SWAP_SED_RX='/(\[part_auto-[a-z][a-z]\]=".*) [^ ]+ ([^ ]+\)")/{s//\1 '$ readonly SWAP_SED_ERR_MSG="SWAP_SED_RX failed on translations.sh.inc" readonly TRANSLATIONS_ERR_MSG="failed to source translations.sh.inc" -# inject size of automatic swap partition into translations, then load the translations -sed -i -E "${SWAP_SED_RX}" translations.sh.inc || ! echo "${SWAP_SED_ERR_MSG}" || exit 1 -source "${THIS_DIR}"/translations.sh.inc || ! echo "${TRANSLATIONS_ERR_MSG}" || exit 1 +if (( ! IN_CHROOT )) +then # inject size of automatic swap partition into translations, then load the translations + sed -i -E "${SWAP_SED_RX}" translations.sh.inc || ! echo "${SWAP_SED_ERR_MSG}" || exit 1 + source translations.sh.inc || ! echo "${TRANSLATIONS_ERR_MSG}" || exit 1 +fi # helper for install.sh |