V8.00.000.2025.06.17
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 1m3s

Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
2025-09-14 16:57:27 +02:00
parent 1d7b736e78
commit 828c2cbbd7

View File

@@ -36,11 +36,13 @@ guard_sourcing
# ERR_CHRT_COMMAND: on failure # ERR_CHRT_COMMAND: on failure
####################################### #######################################
chroot_exec() { chroot_exec() {
### Declare Arrays, HashMaps, and Variables.
declare var_chroot_target="$1"; shift declare var_chroot_target="$1"; shift
declare -a ary_chroot_command=("$@") declare -a ary_chroot_command=("$@")
declare -r var_default_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" declare -r var_default_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
declare var_mod="${BASH_SOURCE[1]##*/}"; var_mod="${var_mod%%_*}()" declare var_mod="${BASH_SOURCE[1]##*/}"; var_mod="${var_mod%%_*}()"
### Basic sanitation.
if (( ${#ary_chroot_command[@]} == 0 )); then if (( ${#ary_chroot_command[@]} == 0 )); then
do_log "emergency" "file_only" "1080() Empty command passed to 'chroot_exec()'." do_log "emergency" "file_only" "1080() Empty command passed to 'chroot_exec()'."
@@ -56,6 +58,7 @@ chroot_exec() {
fi fi
### Main wrapper.
if ! chroot "${var_chroot_target}" /usr/bin/env -i \ if ! chroot "${var_chroot_target}" /usr/bin/env -i \
HOME="/root" \ HOME="/root" \
PATH="${var_default_path}" \ PATH="${var_default_path}" \
@@ -97,12 +100,14 @@ chroot_exec() {
# ERR_CHRT_COMMAND: on failure # ERR_CHRT_COMMAND: on failure
####################################### #######################################
chroot_script() { chroot_script() {
### Declare Arrays, HashMaps, and Variables.
declare var_chroot_target="$1" declare var_chroot_target="$1"
declare var_chroot_script="$2" declare var_chroot_script="$2"
declare var_log_level_on_error="${3:-emergency}" declare var_log_level_on_error="${3:-emergency}"
declare -r var_default_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" declare -r var_default_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
declare var_mod="${BASH_SOURCE[1]##*/}"; var_mod="${var_mod%%_*}()" declare var_mod="${BASH_SOURCE[1]##*/}"; var_mod="${var_mod%%_*}()"
### Basic sanitation.
if [[ -z "${var_chroot_script}" ]]; then if [[ -z "${var_chroot_script}" ]]; then
do_log "emergency" "file_only" "1080() Empty command passed to 'chroot_script()'." do_log "emergency" "file_only" "1080() Empty command passed to 'chroot_script()'."
@@ -110,6 +115,7 @@ chroot_script() {
fi fi
### Main wrapper.
if ! chroot "${var_chroot_target}" /usr/bin/env -i \ if ! chroot "${var_chroot_target}" /usr/bin/env -i \
HOME="/root" \ HOME="/root" \
PATH="${var_default_path}" \ PATH="${var_default_path}" \
@@ -154,7 +160,7 @@ chroot_script() {
} }
####################################### #######################################
# Run the installer-desired code incl. positional arguments via stdin (HEREDEC) inside the chroot with bash -s. # Run the installer-desired code incl. positional arguments via stdin (HEREDOC) inside the chroot with bash -s.
# Globals: # Globals:
# BASH_SOURCE # BASH_SOURCE
# TERM # TERM
@@ -171,19 +177,35 @@ chroot_script() {
# ERR_CHRT_COMMAND: on failure # ERR_CHRT_COMMAND: on failure
####################################### #######################################
chroot_stdin() { chroot_stdin() {
declare var_chroot_target="$1" ### Declare Arrays, HashMaps, and Variables.
declare var_chroot_script="$2" declare var_chroot_target="$1"; shift # consume TARGET
declare var_log_level_on_error="${3:-emergency}" declare payload_marker="$1"; shift # consume marker (e.g. "__payload__")
declare -r var_default_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" declare var_log_level_on_error="emergency" # default
declare var_mod="${BASH_SOURCE[1]##*/}"; var_mod="${var_mod%%_*}()" declare var_default_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
declare var_mod="${BASH_SOURCE[1]##*/}"; var_mod="${var_mod%%_*}()"
if [[ -z "${var_chroot_script}" ]]; then ### Optional third parameter as log level, else we expect a '--' sentinel next.
if [[ "${1-}" != "--" && -n "${1-}" ]]; then
var_log_level_on_error="$1"
shift
fi
### If a '--' sentinel is present, drop it; the rest are payload args.
if [[ "${1-}" == "--" ]]; then
shift
fi
### Now: "$@" are exactly the arguments for the chroot payload ($1,$2,... inside bash -s)
### Basic sanitation
if [[ -z "${payload_marker}" ]]; then
do_log "emergency" "file_only" "1080() Empty command passed to 'chroot_script()'." do_log "emergency" "file_only" "1080() Empty command passed to 'chroot_script()'."
return "${ERR_CHRT_COMMAND}" return "${ERR_CHRT_COMMAND}"
fi fi
### Main wrapper.
if ! chroot "${var_chroot_target}" /usr/bin/env -i \ if ! chroot "${var_chroot_target}" /usr/bin/env -i \
HOME="/root" \ HOME="/root" \
PATH="${var_default_path}" \ PATH="${var_default_path}" \
@@ -221,7 +243,7 @@ chroot_stdin() {
else else
do_log "info" "file_only" "1080() Command of ${var_mod} [chroot ${var_chroot_target} /usr/bin/env -i HOME=/root PATH=${var_default_path} TERM=${TERM} LANG=C.UTF-8 LC_ALL=C.UTF-8 DEBIAN_FRONTEND=noninteractive APT_LISTCHANGES_FRONTEND=none /bin/bash -c ${var_chroot_script}] successful." do_log "info" "file_only" "1080() Command of ${var_mod} [chroot ${var_chroot_target} /usr/bin/env -i HOME=/root PATH=${var_default_path} TERM=${TERM} LANG=C.UTF-8 LC_ALL=C.UTF-8 DEBIAN_FRONTEND=noninteractive APT_LISTCHANGES_FRONTEND=none /bin/bash -s] successful."
return 0 return 0
fi fi