V8.00.000.2025.06.17
Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
26
func/2019_helper_yaml.sh
Normal file
26
func/2019_helper_yaml.sh
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/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
|
||||
|
||||
#######################################
|
||||
# yq_val <YQ expression> <file> – Returns value, converts null to ""
|
||||
# Arguments:
|
||||
# $1: Key String to evaluate
|
||||
# $2: YAML File
|
||||
#######################################
|
||||
yq_val() {
|
||||
declare var_h; var_h=$(yq e "$1" "$2")
|
||||
[[ "${var_h}" == null ]] && var_h=""
|
||||
printf '%s' "${var_h}"
|
||||
}
|
||||
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh
|
||||
@@ -27,60 +27,62 @@ guard_sourcing
|
||||
partitioning() {
|
||||
### Declare Arrays and Variables.
|
||||
declare -Ag HMP_UUID_PARTITION
|
||||
declare var_dev var_part var_begin var_end var_fs var_boot var_pri var_uuid
|
||||
declare var_dev var_part var_end_arg var_begin var_end var_fs var_boot var_pri var_uuid
|
||||
declare -a ary_devs ary_parts
|
||||
|
||||
### Iterate over all devices in the recipe.
|
||||
for var_dev in $(yq e ".recipe.${VAR_RECIPE_STRING}.dev | keys | .[]" "${VAR_SETUP_PART}"); do
|
||||
readarray -t ary_devs < <(yq e ".recipe.${VAR_RECIPE_STRING}.dev | keys | .[]" "${VAR_SETUP_PART}")
|
||||
for var_dev in "${ary_devs[@]}"; do
|
||||
|
||||
### All current data for the respective device will be deleted.
|
||||
blkdiscard "/dev/${var_dev}" \
|
||||
|| { do_log "fatal" "false" "Partition table deletion '/dev/${var_dev}' failed."; exit "${ERR_READ_PARTTBL}"; }
|
||||
do_log "info" "false" "Partition table of '/dev/${var_dev}' discarded."
|
||||
|
||||
if [[ "${VAR_RECIPE_TABLE}" == "gpt" ]]; then
|
||||
|
||||
parted -s "/dev/${var_dev}" mklabel gpt \
|
||||
|| { do_log "fatal" "false" "Partition table creation '/dev/${var_dev}' failed."; exit "${ERR_READ_PARTTBL}"; }
|
||||
do_log "info" "false" "Partition table '${VAR_RECIPE_TABLE}' of '/dev/${var_dev}' generated."
|
||||
|
||||
elif [[ "${VAR_RECIPE_TABLE}" == "mbr" ]]; then
|
||||
|
||||
parted -s "/dev/${var_dev}" mklabel mbr \
|
||||
|| { do_log "fatal" "false" "Partition table creation '/dev/${var_dev}' failed."; exit "${ERR_READ_PARTTBL}"; }
|
||||
do_log "info" "false" "Partition table '${VAR_RECIPE_TABLE}' of '/dev/${var_dev}' generated."
|
||||
|
||||
else
|
||||
|
||||
do_log "fatal" "false" "No valid partition table chosen. String was '${VAR_RECIPE_TABLE}'."
|
||||
exit "${ERR_PARTITIONTBL}"
|
||||
|
||||
if ! blkdiscard "/dev/${var_dev}"; then
|
||||
do_log "fatal" "false" "Partition table deletion '/dev/${var_dev}' failed."
|
||||
return "${ERR_TABLE_DELETE}"
|
||||
fi
|
||||
|
||||
do_log "info" "false" "Partition table of '/dev/${var_dev}' discarded."
|
||||
|
||||
case "${VAR_RECIPE_TABLE,,}" in
|
||||
|
||||
gpt|mbr)
|
||||
if ! parted -s "/dev/${var_dev}" mklabel "${VAR_RECIPE_TABLE,,}"; then
|
||||
do_log "fatal" "false" "Partition table creation '/dev/${var_dev}' failed."
|
||||
return "${ERR_TABLE_CREATE}"
|
||||
fi
|
||||
do_log "info" "false" "Partition table '${VAR_RECIPE_TABLE}' of '/dev/${var_dev}' generated."
|
||||
;;
|
||||
*)
|
||||
do_log "fatal" "false" "No valid partition table chosen. String was '${VAR_RECIPE_TABLE}'."
|
||||
return "${ERR_PARTITIONTBL}"
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
### Iterate over all partitions for this device.
|
||||
for var_part in $(yq e ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev} | keys | .[]" "${VAR_SETUP_PART}"); do
|
||||
readarray -t ary_parts < <(yq e ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev} | keys | .[]" "${VAR_SETUP_PART}")
|
||||
for var_part in "${ary_parts[@]}"; do
|
||||
|
||||
### Extract parameters from YAML.
|
||||
var_begin=$(yq e ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.begin" "${VAR_SETUP_PART}")
|
||||
var_end=$(yq e ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.end" "${VAR_SETUP_PART}")
|
||||
var_fs=$(yq e ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.filesystem.version" "${VAR_SETUP_PART}")
|
||||
var_boot=$(yq e ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.bootable" "${VAR_SETUP_PART}")
|
||||
var_pri=$(yq e ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.primary" "${VAR_SETUP_PART}")
|
||||
var_begin=$(yq_val e ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.begin" "${VAR_SETUP_PART}")
|
||||
var_end=$(yq_val e ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.end" "${VAR_SETUP_PART}")
|
||||
var_fs=$(yq_val e ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.filesystem.version" "${VAR_SETUP_PART}")
|
||||
var_boot=$(yq_val e ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.bootable" "${VAR_SETUP_PART}")
|
||||
var_pri=$(yq_val e ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.primary" "${VAR_SETUP_PART}")
|
||||
|
||||
### Generate partition.
|
||||
if [[ "${var_end}" == "-1" ]]; then
|
||||
|
||||
parted -s /dev/"${var_dev}" mkpart "${var_pri}" "${var_fs}" "${var_begin}" "100%" \
|
||||
|| { do_log "fatal" "false" "Partition creation '/dev/${var_dev}${var_part}' failed."; exit "${ERR_READ_PARTTBL}"; }
|
||||
do_log "info" "false" "Partition generated: '${var_part}' | on device '/dev/${var_dev}' | begin: '${var_begin}' | end: 100 % of remaining disk."
|
||||
|
||||
var_end_arg="100%"
|
||||
else
|
||||
|
||||
parted -s /dev/"${var_dev}" mkpart "${var_pri}" "${var_fs}" "${var_begin}" "${var_end}" \
|
||||
|| { do_log "fatal" "false" "Partition creation '/dev/${var_dev}${var_part}' failed."; exit "${ERR_READ_PARTTBL}"; }
|
||||
do_log "info" "false" "Partition generated: '${var_part}' | on device '/dev/${var_dev}' | begin: '${var_begin}' | end: '${var_end}'."
|
||||
|
||||
var_end_arg="${var_end}"
|
||||
fi
|
||||
|
||||
if ! parted -s "/dev/${var_dev}" mkpart "${var_pri}" "${var_fs}" "${var_begin}" "${var_end_arg}"; then
|
||||
do_log "fatal" "false" "Partition creation '/dev/${var_dev}${var_part}' failed."
|
||||
return "${ERR_PART_CREATE}"
|
||||
fi
|
||||
|
||||
do_log "info" "false" "Partition generated: '${var_part}' | on device '/dev/${var_dev}' | begin: '${var_begin}' | end: '${var_end_arg}'."
|
||||
|
||||
### Set the bootable flag if necessary.
|
||||
if [[ "${var_boot,,}" == "true" ]]; then
|
||||
parted -s "/dev/${var_dev}" set "${var_part}" boot on
|
||||
@@ -91,7 +93,7 @@ partitioning() {
|
||||
var_uuid=$(blkid -s UUID -o value "/dev/${var_dev}${var_part}")
|
||||
if [[ -z "${var_uuid}" ]]; then
|
||||
do_log "fatal" "false" "WARNING: could not read UUID for '/dev/${var_dev}${var_part}'."
|
||||
exit "${ERR_READ_PARTTBL}"
|
||||
return "${ERR_PART_READ}"
|
||||
else
|
||||
### Store UUID in an associative array.
|
||||
HMP_UUID_PARTITION["UUID_${var_dev}${var_part}"]="${var_uuid}"
|
||||
|
||||
@@ -12,9 +12,6 @@
|
||||
|
||||
guard_sourcing
|
||||
|
||||
declare -grx VAR_SAFE_MNT_BASE="/run/ciss/bootstrap"
|
||||
mkdir -p "${VAR_SAFE_MNT_BASE}"
|
||||
|
||||
#######################################
|
||||
# Validates var_mount_path to be processed.
|
||||
# Arguments:
|
||||
@@ -71,19 +68,6 @@ resolve_device() {
|
||||
fi
|
||||
}
|
||||
|
||||
#######################################
|
||||
# YAML Parser Null String exception Handler.
|
||||
# Arguments:
|
||||
# $1: Key String to evaluate
|
||||
# $2: YAML File
|
||||
#######################################
|
||||
yq_val() {
|
||||
# shellcheck disable=SC2155
|
||||
declare var_helper=$(yq e "$1" "$2")
|
||||
[[ "${var_helper}" == null ]] && var_helper=""
|
||||
printf '%s' "${var_helper}"
|
||||
}
|
||||
|
||||
#######################################
|
||||
# Validates btrfs compression algo and level.
|
||||
# Arguments:
|
||||
|
||||
@@ -26,8 +26,9 @@ guard_sourcing
|
||||
gen_dir_files() {
|
||||
### MAKE DIRS
|
||||
mkdir -p /tmp/.ciss/{backup,log,tmp} && chmod -R 0700 /tmp/.ciss
|
||||
mkdir -p /target
|
||||
mkdir -p /recovery
|
||||
mkdir -p "${TARGET}"
|
||||
mkdir -p "${RECOVERY}"
|
||||
mkdir -p "${VAR_SAFE_MNT_BASE}"
|
||||
|
||||
### TOUCH FILES
|
||||
touch "${LOG_ERR}" && chmod 0600 "${LOG_ERR}"
|
||||
|
||||
@@ -26,14 +26,17 @@ declare -girx ERR_INVALID_IPV6=244 # IPv6 validation failure.
|
||||
declare -girx ERR_INVALID_PORT=243 # Port validation failure.
|
||||
declare -girx ERR_ARG_MISMATCH=242 # The wrong number of optional arguments has been provided.
|
||||
declare -girx ERR_PARTITIONTBL=241 # The partition table is not allowed.
|
||||
declare -girx ERR_READ_PARTTBL=240 # The partition could not be deleted, created, or the UUID of the partition could not be read.
|
||||
declare -girx ERR_BTRFS_INITPH=239 # The btrfs subvolume could not be initialized.
|
||||
declare -girx ERR_BTRFS_SUBVOL=238 # The btrfs subvolume could not be created.
|
||||
declare -girx ERR_BTRFS_OPTION=237 # Compression options algo:level not valid btrfs pairs.
|
||||
declare -girx ERR_MOUNTING_DEV=236 # The Device could not be mounted.
|
||||
declare -girx ERR_MOUNTING_ROOT=235 # The / Volume could not be mounted.
|
||||
declare -girx ERR_MOUNTING_LUKS=234 # The LUKS Volume could not be mounted.
|
||||
declare -girx ERR_UNKNOWN_DEV=233 # Unknown Device Path.
|
||||
declare -girx ERR_TABLE_CREATE=240 # The partition table could not be created.
|
||||
declare -girx ERR_TABLE_DELETE=239 # The partition table could not be deleted.
|
||||
declare -girx ERR_PART_CREATE=238 # The partition could not be created.
|
||||
declare -girx ERR_PART_READ=237 # The partition UUID could not be read.
|
||||
declare -girx ERR_BTRFS_INITPH=236 # The btrfs subvolume could not be initialized.
|
||||
declare -girx ERR_BTRFS_SUBVOL=235 # The btrfs subvolume could not be created.
|
||||
declare -girx ERR_BTRFS_OPTION=234 # Compression options algo:level not valid btrfs pairs.
|
||||
declare -girx ERR_MOUNTING_DEV=233 # The Device could not be mounted.
|
||||
declare -girx ERR_MOUNTING_ROOT=232 # The / Volume could not be mounted.
|
||||
declare -girx ERR_MOUNTING_LUKS=231 # The LUKS Volume could not be mounted.
|
||||
declare -girx ERR_UNKNOWN_DEV=230 # Unknown Device Path.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ declare -grx VAR_PRESEED="${DIR_TMP}/combined.var"
|
||||
### Base mount paths for debootstrap.
|
||||
declare -grx TARGET="/target"
|
||||
declare -grx RECOVERY="/recovery"
|
||||
declare -grx VAR_SAFE_MNT_BASE="/run/ciss/bootstrap"
|
||||
|
||||
### Default log level.
|
||||
declare -gx DEFAULT_LOG_LEVEL="info"
|
||||
|
||||
Reference in New Issue
Block a user