V8.00.000.2025.06.17
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 1m3s
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:
@@ -36,11 +36,13 @@ guard_sourcing
|
||||
# ERR_CHRT_COMMAND: on failure
|
||||
#######################################
|
||||
chroot_exec() {
|
||||
### Declare Arrays, HashMaps, and Variables.
|
||||
declare var_chroot_target="$1"; shift
|
||||
declare -a ary_chroot_command=("$@")
|
||||
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%%_*}()"
|
||||
|
||||
### Basic sanitation.
|
||||
if (( ${#ary_chroot_command[@]} == 0 )); then
|
||||
|
||||
do_log "emergency" "file_only" "1080() Empty command passed to 'chroot_exec()'."
|
||||
@@ -56,6 +58,7 @@ chroot_exec() {
|
||||
|
||||
fi
|
||||
|
||||
### Main wrapper.
|
||||
if ! chroot "${var_chroot_target}" /usr/bin/env -i \
|
||||
HOME="/root" \
|
||||
PATH="${var_default_path}" \
|
||||
@@ -97,12 +100,14 @@ chroot_exec() {
|
||||
# ERR_CHRT_COMMAND: on failure
|
||||
#######################################
|
||||
chroot_script() {
|
||||
### Declare Arrays, HashMaps, and Variables.
|
||||
declare var_chroot_target="$1"
|
||||
declare var_chroot_script="$2"
|
||||
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 var_mod="${BASH_SOURCE[1]##*/}"; var_mod="${var_mod%%_*}()"
|
||||
|
||||
### Basic sanitation.
|
||||
if [[ -z "${var_chroot_script}" ]]; then
|
||||
|
||||
do_log "emergency" "file_only" "1080() Empty command passed to 'chroot_script()'."
|
||||
@@ -110,6 +115,7 @@ chroot_script() {
|
||||
|
||||
fi
|
||||
|
||||
### Main wrapper.
|
||||
if ! chroot "${var_chroot_target}" /usr/bin/env -i \
|
||||
HOME="/root" \
|
||||
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:
|
||||
# BASH_SOURCE
|
||||
# TERM
|
||||
@@ -171,19 +177,35 @@ chroot_script() {
|
||||
# ERR_CHRT_COMMAND: on failure
|
||||
#######################################
|
||||
chroot_stdin() {
|
||||
declare var_chroot_target="$1"
|
||||
declare var_chroot_script="$2"
|
||||
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 var_mod="${BASH_SOURCE[1]##*/}"; var_mod="${var_mod%%_*}()"
|
||||
### Declare Arrays, HashMaps, and Variables.
|
||||
declare var_chroot_target="$1"; shift # consume TARGET
|
||||
declare payload_marker="$1"; shift # consume marker (e.g. "__payload__")
|
||||
declare var_log_level_on_error="emergency" # default
|
||||
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()'."
|
||||
return "${ERR_CHRT_COMMAND}"
|
||||
|
||||
fi
|
||||
|
||||
### Main wrapper.
|
||||
if ! chroot "${var_chroot_target}" /usr/bin/env -i \
|
||||
HOME="/root" \
|
||||
PATH="${var_default_path}" \
|
||||
@@ -221,7 +243,7 @@ chroot_stdin() {
|
||||
|
||||
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
|
||||
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user