V8.00.000.2025.06.17
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 39s
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 39s
Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
@@ -22,6 +22,7 @@ guard_sourcing
|
||||
# 0: on success
|
||||
#######################################
|
||||
check_nic() {
|
||||
# shellcheck disable=SC2312
|
||||
ip -o link show | awk -F': ' '{print $2}' | sed 's!lo!!' | sed '/^$/d' | awk '{$1=$1};1' >| "${DIR_TMP}nic.tmp"
|
||||
declare var_counter=1
|
||||
declare var_line=""
|
||||
@@ -37,7 +38,7 @@ check_nic() {
|
||||
var_nic=$(dialog --ascii-lines --clear --backtitle "Specify the NIC for setup" --radiolist "NIC available" 0 0 ${var_counter} ${var_radiolist} 3>&1 1>&2 2>&3)
|
||||
clear
|
||||
|
||||
do_log "info" "true" "You have selected: '${var_nic}' - proceeding with setup."
|
||||
do_log "info" "file_only" "You have selected: '${var_nic}' - proceeding with setup."
|
||||
return 0
|
||||
}
|
||||
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh
|
||||
|
||||
@@ -37,7 +37,7 @@ do_in_target() {
|
||||
declare -a ary_chroot_command=("$@")
|
||||
|
||||
if (( ${#ary_chroot_command[@]} == 0 )); then
|
||||
do_log "emergency" "true" "Empty command passed to 'do_in_target()'."
|
||||
do_log "emergency" "file_only" "Empty command passed to 'do_in_target()'."
|
||||
return "${ERR_CHRT_COMMAND}"
|
||||
fi
|
||||
|
||||
@@ -49,10 +49,10 @@ do_in_target() {
|
||||
LC_ALL=C.UTF-8 \
|
||||
"${ary_chroot_command[@]}"
|
||||
then
|
||||
do_log "info" "true" "Success: chroot '${var_chroot_target}': '${ary_chroot_command[*]}'."
|
||||
do_log "info" "file_only" "Success: chroot '${var_chroot_target}': '${ary_chroot_command[*]}'."
|
||||
return 0
|
||||
else
|
||||
do_log "emergency" "true" "Failed: chroot '${var_chroot_target}': '${ary_chroot_command[*]}'."
|
||||
do_log "emergency" "file_only" "Failed: chroot '${var_chroot_target}': '${ary_chroot_command[*]}'."
|
||||
return "${ERR_CHRT_COMMAND}"
|
||||
fi
|
||||
}
|
||||
@@ -77,11 +77,11 @@ do_in_target_script() {
|
||||
declare var_chroot_script="$1"
|
||||
|
||||
if [[ -z "${var_chroot_script}" ]]; then
|
||||
do_log "emergency" "true" "Empty command passed to 'do_in_target_script()'."
|
||||
do_log "emergency" "file_only" "Empty command passed to 'do_in_target_script()'."
|
||||
return "${ERR_CHRT_COMMAND}"
|
||||
fi
|
||||
|
||||
do_log "debug" "true" "Evaluating chroot script in '${var_chroot_target}': '${var_chroot_script}'."
|
||||
# do_log "debug" "file_only" "Evaluating chroot script in '${var_chroot_target}': '${var_chroot_script}'."
|
||||
|
||||
if chroot "${var_chroot_target}" /usr/bin/env -i \
|
||||
HOME=/root \
|
||||
@@ -93,14 +93,14 @@ do_in_target_script() {
|
||||
|
||||
then
|
||||
|
||||
do_log "info" "true" "Success: chroot '${var_chroot_target}': '${var_chroot_script}'."
|
||||
do_log "info" "file_only" "Success: chroot '${var_chroot_target}': '${var_chroot_script}'."
|
||||
return 0
|
||||
|
||||
else
|
||||
|
||||
declare -i var_chroot_rc="${?}"
|
||||
do_log "emergency" "true" "Failure: chroot '${var_chroot_target}': '${var_chroot_script}'."
|
||||
do_log "debug" "true" "Return code: '${var_chroot_rc}'."
|
||||
do_log "emergency" "file_only" "Failure: chroot '${var_chroot_target}': '${var_chroot_script}'."
|
||||
do_log "debug" "file_only" "Return code: '${var_chroot_rc}'."
|
||||
|
||||
# TODO: Test with Dialog Wrapper in interactive mode.
|
||||
#if [[ "${DEBUG_INTERACTIVE}" == "true" ]]; then
|
||||
|
||||
@@ -36,6 +36,7 @@ do_print_fold() {
|
||||
declare var_color="$1"; shift
|
||||
declare var_msg_string="$*"
|
||||
declare var_formatted_string="${var_color}${var_msg_string}${RES}"
|
||||
# shellcheck disable=SC2312
|
||||
printf "%b\n" "${var_formatted_string}" | fold -s -w 76 | sed '1! s/^/ /'
|
||||
}
|
||||
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
#!/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
|
||||
|
||||
#######################################
|
||||
# Log level values for comparison.
|
||||
# Arguments:
|
||||
# 1: "${LOG_LEVEL}" one of: "debug" | "info" | "notice" | "warn" | "error" | "critical" | "fatal" | "emergency"
|
||||
#######################################
|
||||
log_level_value() {
|
||||
case "${1,,}" in
|
||||
debug) printf '%d' 7 ;;
|
||||
info) printf '%d' 6 ;;
|
||||
notice) printf '%d' 5 ;;
|
||||
warn) printf '%d' 4 ;;
|
||||
error) printf '%d' 3 ;;
|
||||
critical) printf '%d' 2 ;;
|
||||
fatal) printf '%d' 1 ;;
|
||||
emergency) printf '%d' 0 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
#######################################
|
||||
# Filter and compare log levels.
|
||||
# Globals:
|
||||
# VAR_DEFAULT_LOG_LEVEL
|
||||
# Arguments:
|
||||
# 1: "${LOG_LEVEL}" one of: "debug" | "info" | "notice" | "warn" | "error" | "critical" | "fatal" | "emergency"
|
||||
#######################################
|
||||
do_should_log() {
|
||||
# shellcheck disable=SC2155
|
||||
declare -i var_desired_log_value=$(log_level_value "$1") # Desired log level
|
||||
# shellcheck disable=SC2155
|
||||
declare -i var_default_log_value=$(log_level_value "${VAR_DEFAULT_LOG_LEVEL}") # Current threshold
|
||||
### Return true if a message should be logged.
|
||||
[[ ${var_desired_log_value} -le ${var_default_log_value} ]]
|
||||
}
|
||||
|
||||
#######################################
|
||||
# Log level color retriever.
|
||||
# Globals:
|
||||
# BLU
|
||||
# GRE
|
||||
# MAG
|
||||
# RED
|
||||
# WHI
|
||||
# YEL
|
||||
# Arguments:
|
||||
# 1: "${LOG_LEVEL}" one of: "debug" | "info" | "notice" | "warn" | "error" | "critical" | "fatal" | "emergency"
|
||||
#######################################
|
||||
do_get_log_color() {
|
||||
case "${1,,}" in
|
||||
debug) echo "${WHI}" ;;
|
||||
info) echo "${GRE}" ;;
|
||||
notice) echo "${YEL}" ;;
|
||||
warn | error | critical) echo "${RED}" ;;
|
||||
fatal | emergency) echo "${MAG}" ;;
|
||||
*) echo "${BLU}" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
#######################################
|
||||
# Main logger wrapper.
|
||||
# Globals:
|
||||
# LOG_ERR
|
||||
# LOG_INS
|
||||
# Arguments:
|
||||
# 1: "${LOG_LEVEL}" one of: "debug" | "info" | "notice" | "warn" | "error" | "critical" | "fatal" | "emergency"
|
||||
# 2: "${LOG_ONLY}" boolean "true" | "false"
|
||||
# @: "${MESSAGE[*]}" arbitrary text string to log.
|
||||
#######################################
|
||||
do_log() {
|
||||
declare var_log_level="$1"; shift
|
||||
declare var_log_only="$2"; shift
|
||||
declare ary_message=("$@")
|
||||
declare var_msg_string="${ary_message[*]}"
|
||||
declare var_color; var_color=$(do_get_log_color "${var_log_level}")
|
||||
declare var_ts; var_ts="$(date -u '+%Y-%m-%dT%H:%M:%S.%4N%z')"
|
||||
declare var_log_entry=("${var_ts} [${var_log_level}]: ${ary_message[*]}")
|
||||
|
||||
if do_should_log "${var_log_level}"; then
|
||||
if [[ "${var_log_only,,}" == "true" ]]; then
|
||||
case "${var_log_level,,}" in
|
||||
debug | info | notice) do_print_log "${var_log_entry[*]}" >> "${LOG_INS}" ;;
|
||||
warn | error | critical | fatal | emergency ) do_print_log "${var_log_entry[*]}" >> "${LOG_ERR}" ;;
|
||||
esac
|
||||
elif [[ "${var_log_only,,}" == "false" ]]; then
|
||||
case "${var_log_level,,}" in
|
||||
debug | info | notice)
|
||||
if [[ ${#var_msg_string} -le 76 ]]; then
|
||||
do_print_color "${var_color}" "${var_log_entry[*]}"
|
||||
do_print_log "${var_log_entry[*]}" >> "${LOG_INS}"
|
||||
else
|
||||
do_print_fold "${var_color}" "${var_log_entry[*]}"
|
||||
do_print_log "${var_log_entry[*]}" >> "${LOG_INS}"
|
||||
fi
|
||||
;;
|
||||
warn | error | critical | fatal | emergency)
|
||||
if [[ ${#var_msg_string} -le 76 ]]; then
|
||||
do_print_color "${var_color}" "${var_log_entry[*]}"
|
||||
do_print_log "${var_log_entry[*]}" >> "${LOG_ERR}"
|
||||
else
|
||||
do_print_fold "${var_color}" "${var_log_entry[*]}"
|
||||
do_print_log "${var_log_entry[*]}" >> "${LOG_ERR}"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
if [[ ${#var_msg_string} -le 76 ]]; then
|
||||
do_print_color "${var_color}" "${var_log_entry[*]}"
|
||||
do_print_log "${var_log_entry[*]}" >> "${LOG_INS}"
|
||||
else
|
||||
do_print_fold "${var_color}" "${var_log_entry[*]}"
|
||||
do_print_log "${var_log_entry[*]}" >> "${LOG_INS}"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
}
|
||||
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh
|
||||
@@ -25,7 +25,7 @@ validation_ipv4() {
|
||||
declare var_ip="$1"
|
||||
### Single-pass check: 4 octets, each 0-255, no leading zeros (unless the octet is exactly "0")
|
||||
if [[ "${var_ip}" =~ ^((25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})$ ]]; then
|
||||
do_log "info" "true" "'${var_ip}' seems to be a valid IPv4."
|
||||
do_log "info" "file_only" "'${var_ip}' seems to be a valid IPv4."
|
||||
else
|
||||
return "${ERR_INVALID_IPV4}"
|
||||
fi
|
||||
@@ -86,7 +86,7 @@ validation_ipv6() {
|
||||
fi
|
||||
|
||||
### Success
|
||||
do_log "info" "true" "'${var_ip}' seems to be a valid IPv6."
|
||||
do_log "info" "file_only" "'${var_ip}' seems to be a valid IPv6."
|
||||
}
|
||||
|
||||
#######################################
|
||||
@@ -101,9 +101,9 @@ validation_ipv6() {
|
||||
validation_port() {
|
||||
declare var_port="$1"
|
||||
if [[ "${var_port}" =~ ^[0-9]+$ ]] && (( var_port >= 1 && var_port <= 65535 )); then
|
||||
do_log "info" "true" "'${var_port}' seems to be a valid port."
|
||||
do_log "info" "file_only" "'${var_port}' seems to be a valid port."
|
||||
else
|
||||
do_log "error" "false" "'${var_port}' seems to be NOT a valid port."
|
||||
do_log "error" "file_only" "'${var_port}' seems to be NOT a valid port."
|
||||
return "${ERR_INVALID_PORT}"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ validation_preseed() {
|
||||
if [[ -n "${value}" ]]; then
|
||||
validation_ipv4 "${value}"
|
||||
else
|
||||
do_log "info" "true" "'${var}' is not set."
|
||||
do_log "info" "file_only" "'${var}' is not set."
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -54,7 +54,7 @@ validation_preseed() {
|
||||
if [[ -n "${value}" ]]; then
|
||||
validation_ipv6 "${value}"
|
||||
else
|
||||
do_log "info" "false" "'${var}' is not set."
|
||||
do_log "info" "file_only" "'${var}' is not set."
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
@@ -48,9 +48,9 @@ yaml_reader() {
|
||||
done < "${var_if}"
|
||||
|
||||
if [[ -n "${VAR_RECIPE_STRING}" ]]; then
|
||||
do_log "info" "true" "Found active recipe string: '${VAR_RECIPE_STRING}'."
|
||||
do_log "info" "file_only" "Found active recipe string: '${VAR_RECIPE_STRING}'."
|
||||
else
|
||||
do_log "fatal" "true" "Found NO active recipe string: '${VAR_RECIPE_STRING}'." >&2
|
||||
do_log "fatal" "file_only" "Found NO active recipe string: '${VAR_RECIPE_STRING}'." >&2
|
||||
exit "${ERR_NO_VALID_RECIPE}"
|
||||
fi
|
||||
|
||||
@@ -80,9 +80,9 @@ END { print max }
|
||||
declare -gx VAR_RECIPE_DEV_COUNTER="${var_highest_dev}"
|
||||
|
||||
if [[ -n "${VAR_RECIPE_DEV_COUNTER}" ]]; then
|
||||
do_log "info" "true" "Found highest recipe device: '${VAR_RECIPE_DEV_COUNTER}'."
|
||||
do_log "info" "file_only" "Found highest recipe device: '${VAR_RECIPE_DEV_COUNTER}'."
|
||||
else
|
||||
do_log "fatal" "true" "Found NO highest recipe device: '${VAR_RECIPE_DEV_COUNTER}'." >&2
|
||||
do_log "fatal" "file_only" "Found NO highest recipe device: '${VAR_RECIPE_DEV_COUNTER}'." >&2
|
||||
exit "${ERR_NO_VALID_RECIPE}"
|
||||
fi
|
||||
|
||||
@@ -114,7 +114,7 @@ END { print max }
|
||||
done < <(grep -E "^recipe_${VAR_RECIPE_STRING}_dev_" "${var_if}")
|
||||
|
||||
for var_device in "${!HMP_RECIPE_DEV_PARTITIONS[@]}"; do
|
||||
do_log "info" "false" "Highest number of partitions for ${var_device}: ${HMP_RECIPE_DEV_PARTITIONS[${var_device}]}"
|
||||
do_log "info" "file_only" "Highest number of partitions for ${var_device}: ${HMP_RECIPE_DEV_PARTITIONS[${var_device}]}"
|
||||
done
|
||||
|
||||
### Extract architecture
|
||||
@@ -134,19 +134,19 @@ END { print max }
|
||||
|
||||
if [[ "${VAR_RECIPE_TABLE,,}" == "gpt" && "${VAR_RECIPE_FIRMWARE,,}" == "uefi" ]]; then
|
||||
|
||||
do_log "info" "true" "Partition table: '${VAR_RECIPE_TABLE}' and firmware: '${VAR_RECIPE_FIRMWARE}' > ESP 'EF00' necessary."
|
||||
do_log "info" "file_only" "Partition table: '${VAR_RECIPE_TABLE}' and firmware: '${VAR_RECIPE_FIRMWARE}' > ESP 'EF00' necessary."
|
||||
|
||||
elif [[ "${VAR_RECIPE_TABLE,,}" == "gpt" && "${VAR_RECIPE_FIRMWARE,,}" == "bios" ]]; then
|
||||
|
||||
do_log "info" "true" "Partition table: '${VAR_RECIPE_TABLE}' and firmware: '${VAR_RECIPE_FIRMWARE}' > BIOS Boot Partition 'EF02' necessary."
|
||||
do_log "info" "file_only" "Partition table: '${VAR_RECIPE_TABLE}' and firmware: '${VAR_RECIPE_FIRMWARE}' > BIOS Boot Partition 'EF02' necessary."
|
||||
|
||||
elif [[ "${VAR_RECIPE_TABLE,,}" == "msdos" && "${VAR_RECIPE_FIRMWARE,,}" == "uefi" ]]; then
|
||||
|
||||
do_log "info" "true" "Partition table: '${VAR_RECIPE_TABLE}' and firmware: '${VAR_RECIPE_FIRMWARE}' > ESP on MBR needs partition type '0xEF'."
|
||||
do_log "info" "file_only" "Partition table: '${VAR_RECIPE_TABLE}' and firmware: '${VAR_RECIPE_FIRMWARE}' > ESP on MBR needs partition type '0xEF'."
|
||||
|
||||
elif [[ "${VAR_RECIPE_TABLE,,}" == "msdos" && "${VAR_RECIPE_FIRMWARE,,}" == "bios" ]]; then
|
||||
|
||||
do_log "info" "true" "Partition table: '${VAR_RECIPE_TABLE}' and firmware: '${VAR_RECIPE_FIRMWARE}' > No special firmware partition necessary."
|
||||
do_log "info" "file_only" "Partition table: '${VAR_RECIPE_TABLE}' and firmware: '${VAR_RECIPE_FIRMWARE}' > No special firmware partition necessary."
|
||||
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user