summaryrefslogtreecommitdiff
path: root/configs/profile/root-image/root/.session/session-common.sh.inc
diff options
context:
space:
mode:
Diffstat (limited to 'configs/profile/root-image/root/.session/session-common.sh.inc')
-rw-r--r--configs/profile/root-image/root/.session/session-common.sh.inc112
1 files changed, 0 insertions, 112 deletions
diff --git a/configs/profile/root-image/root/.session/session-common.sh.inc b/configs/profile/root-image/root/.session/session-common.sh.inc
deleted file mode 100644
index fc665f1..0000000
--- a/configs/profile/root-image/root/.session/session-common.sh.inc
+++ /dev/null
@@ -1,112 +0,0 @@
-readonly SESSION_DIR="$(cd $(dirname ${BASH_SOURCE[0]}) ; pwd)"
-readonly WIZARD_DIR="${SESSION_DIR}"/install
-readonly SESSION_INCLUDE_FILENAME=session-common.sh.inc # this file
-readonly SESSION_STATE_FILENAME=.session_state
-readonly TRANSLATIONS_FILENAME=translations.sh.inc
-readonly CHROOT_ENVIRONMENT_FILENAME=chroot-environment.sh
-readonly CHROOT_LOGIN_FILENAME=chroot-login.sh
-readonly CHROOT_SERVICES_FILENAME=chroot-services.sh
-readonly SESSION_INCLUDE_FILE="${SESSION_DIR}"/${SESSION_INCLUDE_FILENAME} # this file
-readonly SESSION_STATE_FILE="${SESSION_DIR}"/${SESSION_STATE_FILENAME}
-readonly TRANSLATIONS_FILE="${SESSION_DIR}"/${TRANSLATIONS_FILENAME}
-readonly CHROOT_ENVIRONMENT_FILE="${WIZARD_DIR}"/${CHROOT_ENVIRONMENT_FILENAME}
-readonly CHROOT_LOGIN_FILE="${WIZARD_DIR}"/${CHROOT_LOGIN_FILENAME}
-readonly CHROOT_SERVICES_FILE="${WIZARD_DIR}"/${CHROOT_SERVICES_FILENAME}
-
-
-## sanity checks ##
-
-! which dialog &> /dev/null && echo "can not find the \`dialog\` program" && exit
-(( $EUID )) && echo "this program requires superuser privilege" && exit
-
-
-## state helpers ##
-
-SetStateVar() # (var_name value*)
-{
- local var_name=$1 ; shift ;
- local value=$*
-
- sed -i "/^${var_name}=.*/d" "${SESSION_STATE_FILE}"
- echo "${var_name}=${value}" >> "${SESSION_STATE_FILE}"
-}
-
-GetStateVar() # (var_name [def_value])
-{
- local var_name=$1
- local def_value=$2
- local stored_value=$(grep "${var_name}=" "${SESSION_STATE_FILE}" | cut -d '=' -f 2)
-
- if [[ -n "${stored_value}" ]] && [[ "${stored_value}" != '_UNDEFINED_' ]]
- then echo ${stored_value}
- else echo ${def_value}
- fi
-}
-
-
-## dialog prompt helpers ##
-
-InitDlg() # (title prompt default_option options*)
-{
- declare -l title="$1"
- declare -l prompt="$2"
- declare -l default_option="$3"
- declare -l options=("${@:4}")
-
- dialog --stdout --sleep 1 --timeout 30 --no-tags --no-cancel \
- --backtitle "$title" \
- --default-item "${default_option}" \
- --menu "$prompt" $H $W $N_ITEMS "${options[@]}"
-}
-
-WizardDlg() # (title dialog_args*)
-{
- declare -l title="$1"
- declare -l options=("${@:2}")
-
- # when the "Cancel" button or <ESC> key is pressed, in a '--msgbox',
- # dialog exits with status 1; but nothing is printed to STDOUT
- # install.sh runs under `set -e`; so we can not propogate the non-zero status,
- # otherwise, callers would need to supress it
- # callers should instead, exit upon the empty result, when a selection is mandatory
- #
- # the exception is '--yesno' dialogs, which exits with status 1 for the 'No' button
- # the non-zero status is propogated for '--yesno' dialogs; and callers must handle it
- # ASSERT: '--yesno' dialogs should pass '--yesno' as positional parameter #2 (options[0])
- dialog --stdout --sleep 1 \
- --backtitle "${TR[wizard-${TR_KEY}]}" \
- --title "${title}" "${options[@]}" || \
- ( (( $? == 1 )) && [[ "${options[0]}" != '--yesno' ]] )
- clear >&2
-}
-
-
-## error logging helpers ##
-
-LogError() # (source_file func_name line_n)
-{
- local SOURCE_FILE="$1"
- local FUNC_NAME="$( [[ -n "$2" ]] && echo "$2" || echo "${SOURCE_FILE}" )"
- local LINE_N=$3
- local N_CONTEXT_LINES=3
- local N_LINES=$(( 1 + (2 * N_CONTEXT_LINES) ))
- local BEGIN_LINE_N=$(( LINE_N - N_CONTEXT_LINES ))
- local END_LINE_N=$(( LINE_N + N_CONTEXT_LINES ))
- local marker line
-
- echo "ERROR: in ${FUNC_NAME}::${LINE_N}" >&2
- sed 's|\\$||' "${SOURCE_FILE}" | pr -tn | \
- tail -n +${BEGIN_LINE_N} | head -n ${N_LINES} | tr '\n' '\n' | \
- while read line
- do line_n=$(sed -E 's|([0-9]+).*|\1|' <<<${line})
- (( line_n == LINE_N )) && marker='==>' || marker=' '
- printf "%s %s\n" "${marker}" "${line}" >&2
- done
-}
-
-
-## translations for user-facing strings ##
-
-readonly TRANSLATIONS=" en es gl pt " # pending translations 'eo' 'fr' 'it' 'pl'
-readonly TR_KEY=$(GetStateVar 'TR_KEY' 'en')
-source "${TRANSLATIONS_FILE}"