All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 43s
Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
106 lines
4.1 KiB
Bash
106 lines
4.1 KiB
Bash
#!/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
|
|
|
|
#######################################
|
|
# Reading and extracting variables from "${PRESEED}".
|
|
# Globals:
|
|
# HMP_RECIPE_DEV_PARTITIONS
|
|
# VAR_ARCHITECTURE
|
|
# VAR_NUKE
|
|
# VAR_PRESEED
|
|
# VAR_RECIPE_FIRMWARE
|
|
# VAR_RECIPE_HIGHEST_DEVICE
|
|
# VAR_RECIPE_STRING
|
|
# VAR_RECIPE_TABLE
|
|
# architecture
|
|
# Arguments:
|
|
# None
|
|
# Returns:
|
|
# 0: on success
|
|
# ERR_NO_VALID_RECIPE
|
|
#######################################
|
|
yaml_reader() {
|
|
### Declare Arrays, HashMaps, and Variables.
|
|
declare -Ag HMP_RECIPE_DEV_PARTITIONS=()
|
|
declare -gx VAR_RECIPE_STRING="" VAR_RECIPE_HIGHEST_DEVICE="" VAR_ARCHITECTURE="" VAR_RECIPE_FIRMWARE="" VAR_NUKE="" \
|
|
VAR_RECIPE_TABLE=""
|
|
|
|
### Declare and substitute input files.
|
|
declare -r var_if="${VAR_PRESEED}"
|
|
### Search pattern for variables (recipe_<string>_active='true')
|
|
declare -r var_search_pattern="^recipe_.*_active='true'"
|
|
declare var_line="" var_middle_part="" var_highest_dev="" var_device="" var_fields="" var_partition="" \
|
|
recipe_firmware_var="" recipe_nuke_var="" recipe_table_var=""
|
|
|
|
### Read "${var_if}" line by line
|
|
while IFS= read -r var_line; do
|
|
### Check, if line matches the search pattern
|
|
if [[ "${var_line}" =~ ^recipe_([^_]+)_active=\'true\' ]]; then
|
|
var_middle_part="${BASH_REMATCH[1]}"
|
|
VAR_RECIPE_STRING="${var_middle_part}"
|
|
break
|
|
fi
|
|
#if [[ "${var_line}" =~ ${var_search_pattern} ]]; then
|
|
# ### Extract the middle part or second position
|
|
# var_middle_part=$(echo "${var_line}" | sed -E "s/^recipe_([^_]+)_active='true'/\1/")
|
|
# VAR_RECIPE_STRING="${var_middle_part}"
|
|
# ### Exit after first occurrence
|
|
# break
|
|
#fi
|
|
done < "${var_if}"
|
|
|
|
if [[ -n "${VAR_RECIPE_STRING}" ]]; then
|
|
do_log "info" "file_only" "1251() Found active recipe string: '${VAR_RECIPE_STRING}'."
|
|
else
|
|
do_log "fatal" "file_only" "1251() Found NO active recipe string: '${VAR_RECIPE_STRING}'."
|
|
exit "${ERR_NO_VALID_RECIPE}"
|
|
fi
|
|
|
|
### Extract architecture.
|
|
VAR_ARCHITECTURE="${architecture}"
|
|
|
|
### Extract chosen firmware.
|
|
recipe_firmware_var="recipe_${VAR_RECIPE_STRING}_control_firmware"
|
|
VAR_RECIPE_FIRMWARE="${!recipe_firmware_var}"
|
|
|
|
### Extract the chosen Nuke mechanism.
|
|
recipe_nuke_var="recipe_${VAR_RECIPE_STRING}_control_nuke"
|
|
VAR_NUKE="${!recipe_nuke_var}"
|
|
|
|
### Extract chosen partition table.
|
|
recipe_table_var="recipe_${VAR_RECIPE_STRING}_control_table"
|
|
VAR_RECIPE_TABLE="${!recipe_table_var}"
|
|
|
|
if [[ "${VAR_RECIPE_TABLE,,}" == "gpt" && "${VAR_RECIPE_FIRMWARE,,}" == "uefi" ]]; then
|
|
|
|
do_log "info" "file_only" "1251() 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" "file_only" "1251() 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" "file_only" "1251() 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" "file_only" "1251() Partition table: '${VAR_RECIPE_TABLE}' and firmware: '${VAR_RECIPE_FIRMWARE}' > No special firmware partition necessary."
|
|
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh
|