V8.00.000.2025.06.17
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 1m29s
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 1m29s
Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
@@ -43,23 +43,55 @@ create_btrfs_subvolume() {
|
||||
# $3: MOUNT_OPTIONS
|
||||
#######################################
|
||||
mount_with_dir() {
|
||||
declare var_mount_path="$1"
|
||||
declare var_mount_device="$2"
|
||||
declare var_mount_options="$3"
|
||||
declare var_mount_path="$1" var_mount_device="$2" var_mount_options="$3"
|
||||
|
||||
if [[ "${var_mount_path}" == "/" ]]; then
|
||||
var_mount_path=""
|
||||
:
|
||||
else
|
||||
mkdir -p "${TARGET}${var_mount_path}"
|
||||
fi
|
||||
|
||||
mkdir -p "${TARGET}${var_mount_path}"
|
||||
### Build the command in an array to keep word boundaries intact
|
||||
declare -a ary_cmd=(mount)
|
||||
ary_cmd+=("${var_mount_device}" "${TARGET}${var_mount_path}")
|
||||
[[ -n "${var_mount_options}" ]] && ary_cmd+=("-o" "${var_mount_options}")
|
||||
|
||||
mount "${var_mount_options:+-o $var_mount_options}" "${var_mount_device}" "${TARGET}${var_mount_path}" || {
|
||||
do_log "error" "false" "Error occurred at mounting '${var_mount_device}' on: '${TARGET}${var_mount_path}'."
|
||||
"${ary_cmd[@]}" || {
|
||||
do_log "error" "false" "Mounting '${var_mount_device}' on '${TARGET}${var_mount_path}' failed."
|
||||
exit "${ERR_MOUNTING_DEV}"
|
||||
}
|
||||
do_log "info" "false" "Mounted: '${var_mount_device}' on: '${TARGET}${var_mount_path}' incl. options: '${var_mount_options}'."
|
||||
}
|
||||
|
||||
do_log "info" "false" "Mounted: '${var_mount_device}' on: '${TARGET}${var_mount_path}' (Options='${var_mount_options}')."
|
||||
}
|
||||
|
||||
#######################################
|
||||
# Device Path Resolver
|
||||
# Arguments:
|
||||
# $1: Device
|
||||
# $2: Partition
|
||||
# $3: Boolean Encryption
|
||||
# $4: Encryption Label
|
||||
#######################################
|
||||
resolve_device() {
|
||||
declare local_var_dev="$1" local_var_partition="$2" encryption_boolean="$3" local_var_enc_label="$4"
|
||||
[[ "${encryption_boolean}" == true ]] && printf '/dev/mapper/%s' "${local_var_enc_label}" \
|
||||
|| printf '/dev/%s%s' "${local_var_dev}" "${local_var_partition}"
|
||||
}
|
||||
|
||||
#######################################
|
||||
# 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}"
|
||||
}
|
||||
|
||||
|
||||
#######################################
|
||||
# Function for mounting all partitions for debootstrap, including the generation of btrfs subvolumes.
|
||||
# Globals:
|
||||
@@ -106,23 +138,26 @@ mount_partition() {
|
||||
|
||||
declare var_dev var_part var_fs_btrfs_compress var_fs_btrfs_level var_encryption_enable var_encryption_label \
|
||||
var_fs_label var_fs_version var_mount_path var_mount_options var_mount_subvolume
|
||||
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
|
||||
|
||||
### 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_fs_btrfs_compress=$(yq e ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.filesystem.btrfs.compress" "${VAR_SETUP_PART}")
|
||||
var_fs_btrfs_level=$(yq e ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.filesystem.btrfs.level" "${VAR_SETUP_PART}")
|
||||
var_encryption_enable=$(yq e ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.encryption.enable" "${VAR_SETUP_PART}")
|
||||
var_encryption_label=$(yq e ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.encryption.label" "${VAR_SETUP_PART}")
|
||||
var_fs_label=$(yq e ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.filesystem.label" "${VAR_SETUP_PART}")
|
||||
var_fs_version=$(yq e ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.filesystem.version" "${VAR_SETUP_PART}")
|
||||
var_mount_path=$(yq e ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.mount.path" "${VAR_SETUP_PART}")
|
||||
var_mount_options=$(yq e ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.mount.options" "${VAR_SETUP_PART}")
|
||||
var_mount_subvolume=$(yq e ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.mount.subvolume" "${VAR_SETUP_PART}")
|
||||
var_fs_btrfs_compress=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.filesystem.btrfs.compress" "${VAR_SETUP_PART}")
|
||||
var_fs_btrfs_level=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.filesystem.btrfs.level" "${VAR_SETUP_PART}")
|
||||
var_encryption_enable=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.encryption.enable" "${VAR_SETUP_PART}")
|
||||
var_encryption_label=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.encryption.label" "${VAR_SETUP_PART}")
|
||||
var_fs_label=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.filesystem.label" "${VAR_SETUP_PART}")
|
||||
var_fs_version=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.filesystem.version" "${VAR_SETUP_PART}")
|
||||
var_mount_path=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.mount.path" "${VAR_SETUP_PART}")
|
||||
var_mount_options=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.mount.options" "${VAR_SETUP_PART}")
|
||||
var_mount_subvolume=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.mount.subvolume" "${VAR_SETUP_PART}")
|
||||
|
||||
### Skip already mounted paths ("/", "/boot", "/boot/efi") and skip ("/recovery")
|
||||
if [[ "${var_mount_path}" == "/" || "${var_mount_path}" == "/boot" || "${var_mount_path}" == "/boot/efi" || "${var_mount_path}" == "/recovery" ]]; then
|
||||
@@ -150,6 +185,19 @@ mount_partition() {
|
||||
|
||||
fi
|
||||
|
||||
|
||||
device=$(resolve_device "$var_dev" "$var_part" "$var_encryption_enable" "$var_encryption_label")
|
||||
mount_with_dir "$var_mount_path" "$device" "$var_btrfs_compression_options"
|
||||
|
||||
case "${var_fs_version,,}:${var_encryption_enable}" in
|
||||
btrfs:true) … ;;
|
||||
btrfs:false) … ;;
|
||||
ext4:true) … ;;
|
||||
ext4:false) … ;;
|
||||
*) do_log error false "Unsupported fs/encryption combination."
|
||||
exit "$ERR_MOUNTING_DEV" ;;
|
||||
esac
|
||||
|
||||
if [[ "${var_fs_version,,}" == "btrfs" && "${var_encryption_enable}" == "true" ]]; then
|
||||
|
||||
declare var_btrfs_compression_options="compress=${var_fs_btrfs_compress}:${var_fs_btrfs_level}"
|
||||
|
||||
Reference in New Issue
Block a user