V8.00.000.2025.06.17
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 1m43s

Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
2025-07-07 09:14:48 +02:00
parent f88d6fc090
commit e5fba1ad03
3 changed files with 50 additions and 54 deletions

View File

@@ -84,10 +84,8 @@ do_log() {
declare var_log_only="$2"; shift
declare ary_message=("$@")
declare var_msg_string="${ary_message[*]}"
# shellcheck disable=SC2155
declare var_color=$(do_get_log_color "${var_log_level}")
# shellcheck disable=SC2155
declare var_ts="$(date -u '+%Y-%m-%dT%H:%M:%S.%4N%z')"
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

View File

@@ -12,6 +12,26 @@
guard_sourcing
#######################################
# /etc/fstab entry writer and logger.
# Globals:
# TARGET
# Arguments:
# 1: UUID
# 2: Mount Path
# 3: Filesystem
# 4: Mount Options
# 5: Dump and Pass Value combined by one <space>, e.g., "0 1"
# Returns:
# 0: Successfully executed commands.
#######################################
write_fstab() {
declare _uuid="$1" _path="$2" _fs="$3" _opts="$4" _dp="$5"
printf "UUID=%s %s %s %s %s\n" "${_uuid}" "${_path}" "${_fs}" "${_opts}" "${_dp}" >> "${TARGET}/etc/fstab"
do_log "info" "true" "fstab entry generated: 'UUID=${_uuid} ${_path} ${_fs} ${_opts} ${_dp}'."
return 0
}
#######################################
# Generate target '/etc/fstab' entries.
# Globals:
@@ -23,10 +43,12 @@ guard_sourcing
# VAR_SETUP_PART
# Arguments:
# None
# Returns:
# 0: Successfully executed commands.
#######################################
generate_fstab() {
### Generate '${TARGET}/etc/fstab' header
touch "${TARGET}/etc/fstab"
### Generate '${TARGET}/etc/fstab' header.
: >| "${TARGET}/etc/fstab"
chmod 0644 "${TARGET}/etc/fstab"
cat << 'EOF' >> "${TARGET}/etc/fstab"
@@ -71,7 +93,7 @@ EOF
fi
var_part=$(echo "${var_entry}" | yq e 'path | .[-2]' -)
var_dev=$(yq e '.recipe.*.dev | keys[0]' "${VAR_SETUP_PART}")
var_dev=$(echo "${var_entry}" | yq e 'path | .[-3]' -)
var_key="UUID_${var_path}"
var_uuid="${HMP_PATH_FSUUID[${var_key}]}"
var_fs_btrfs_compress=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.filesystem.btrfs.compress" "${VAR_SETUP_PART}")
@@ -83,53 +105,44 @@ EOF
if [[ "${var_fs_version,,}" == btrfs ]]; then
if [[ "${var_fs_btrfs_level}" -eq 0 ]]; then
if [[ "${var_fs_btrfs_level:-0}" == 0 ]]; then
var_btrfs_compression="compress=no"
else
var_btrfs_compression="compress=${var_fs_btrfs_compress}:${var_fs_btrfs_level}"
fi
echo "UUID=${var_uuid} ${var_path} ${var_fs_version} ${var_mount_options},${var_btrfs_compression} 0 1" >> "${TARGET}/etc/fstab"
do_log "info" "false" "fstab entry generated: 'UUID=${var_uuid} ${var_path} ${var_fs_version} ${var_mount_options},${var_btrfs_compression} 0 1'."
write_fstab "${var_uuid}" "${var_path}" "${var_fs_version}" "${var_mount_options},${var_btrfs_compression}" "0 1"
if [[ -n "${var_fs_btrfs_subvolume}" ]]; then
if [[ "${var_path}" == "/" ]]; then
echo "UUID=${var_uuid} /.snapshots ${var_fs_version} ${var_mount_optsnap} 0 0" >> "${TARGET}/etc/fstab"
do_log "info" "false" "fstab entry generated: 'UUID=${var_uuid} /.snapshots ${var_fs_version} ${var_mount_optsnap} 0 0'."
write_fstab "${var_uuid}" "/.snapshots" "${var_fs_version}" "${var_mount_optsnap}" "0 0"
else
echo "UUID=${var_uuid} ${var_path}/.snapshots ${var_fs_version} ${var_mount_optsnap} 0 0" >> "${TARGET}/etc/fstab"
do_log "info" "false" "fstab entry generated: 'UUID=${var_uuid} ${var_path}/.snapshots ${var_fs_version} ${var_mount_optsnap} 0 0'."
write_fstab "${var_uuid}" "${var_path}/.snapshots" "${var_fs_version}" "${var_mount_optsnap}" "0 0"
fi
fi
echo "" >> "${TARGET}/etc/fstab"
continue
elif [[ "${var_fs_version,,}" == ext4 ]]; then
echo "UUID=${var_uuid} ${var_path} ${var_fs_version} ${var_mount_options} 0 1" >> "${TARGET}/etc/fstab"
do_log "info" "false" "fstab entry generated: 'UUID=${var_uuid} ${var_path} ${var_fs_version} ${var_mount_options} 0 1'."
echo "" >> "${TARGET}/etc/fstab"
write_fstab "${var_uuid}" "${var_path}" "${var_fs_version}" "${var_mount_options}" "0 1"
continue
elif [[ "${var_fs_version,,}" == fat32 ]]; then
echo "UUID=${var_uuid} ${var_path} vfat ${var_mount_options} 0 2" >> "${TARGET}"/etc/fstab
do_log "info" "false" "fstab entry generated: 'UUID=${var_uuid} ${var_path} vfat ${var_mount_options} 0 2'."
echo "" >> "${TARGET}"/etc/fstab
write_fstab "${var_uuid}" "${var_path}" "vfat" "${var_mount_options}" "0 2"
continue
fi
done
### Generate '${TARGET}/etc/fstab' remaining entries
### Generate '${TARGET}/etc/fstab' remaining entries.
for var_path in "${!MAP_MOUNTPATH_DEV[@]}"; do
if validation_array "${var_path}" "${ary_skip[@]}"; then
@@ -143,7 +156,7 @@ EOF
fi
var_part=$(echo "${var_entry}" | yq e 'path | .[-2]' -)
var_dev=$(yq e '.recipe.*.dev | keys[0]' "${VAR_SETUP_PART}")
var_dev=$(echo "${var_entry}" | yq e 'path | .[-3]' -)
var_key="UUID_${var_path}"
var_uuid="${HMP_PATH_FSUUID[${var_key}]}"
var_fs_btrfs_compress=$(yq_val ".recipe.${VAR_RECIPE_STRING}.dev.${var_dev}.${var_part}.filesystem.btrfs.compress" "${VAR_SETUP_PART}")
@@ -155,37 +168,27 @@ EOF
if [[ "${var_fs_version,,}" == btrfs ]]; then
if [[ "${var_fs_btrfs_level}" -eq 0 ]]; then
if [[ "${var_fs_btrfs_level:-0}" == 0 ]]; then
var_btrfs_compression="compress=no"
else
var_btrfs_compression="compress=${var_fs_btrfs_compress}:${var_fs_btrfs_level}"
fi
echo "UUID=${var_uuid} ${var_path} ${var_fs_version} ${var_mount_options},${var_btrfs_compression} 0 2" >> "${TARGET}/etc/fstab"
do_log "info" "false" "fstab entry generated: 'UUID=${var_uuid} ${var_path} ${var_fs_version} ${var_mount_options},${var_btrfs_compression} 0 2'."
write_fstab "${var_uuid}" "${var_path}" "${var_fs_version}" "${var_mount_options},${var_btrfs_compression}" "0 2"
if [[ -n "${var_fs_btrfs_subvolume}" ]]; then
echo "UUID=${var_uuid} ${var_path}/.snapshots ${var_fs_version} ${var_mount_optsnap} 0 0" >> "${TARGET}/etc/fstab"
do_log "info" "false" "fstab entry generated: 'UUID=${var_uuid} ${var_path}/.snapshots ${var_fs_version} ${var_mount_optsnap} 0 0'."
write_fstab "${var_uuid}" "${var_path}/.snapshots" "${var_fs_version}" "${var_mount_optsnap}" "0 0"
fi
echo "" >> "${TARGET}/etc/fstab"
continue
elif [[ "${var_fs_version,,}" == ext4 ]]; then
echo "UUID=${var_uuid} ${var_path} ${var_fs_version} ${var_mount_options} 0 2" >> "${TARGET}/etc/fstab"
do_log "info" "false" "fstab entry generated: 'UUID=${var_uuid} ${var_path} ${var_fs_version} ${var_mount_options} 0 2'."
echo "" >> "${TARGET}/etc/fstab"
write_fstab "${var_uuid}" "${var_path}" "${var_fs_version}" "${var_mount_options}" "0 2"
continue
elif [[ "${var_fs_version,,}" == fat32 ]]; then
echo "UUID=${var_uuid} ${var_path} vfat ${var_mount_options} 0 2" >> "${TARGET}"/etc/fstab
do_log "info" "false" "fstab entry generated: 'UUID=${var_uuid} ${var_path} vfat ${var_mount_options} 0 2'."
echo "" >> "${TARGET}"/etc/fstab
write_fstab "${var_uuid}" "${var_path}" "vfat" "${var_mount_options}" "0 2"
continue
fi
@@ -193,22 +196,19 @@ EOF
done
cat << 'EOF' >> "${TARGET}/etc/fstab"
/dev/sr0 /media/cdrom0 udf,iso9660 user,noauto 0 0
EOF
do_log "info" "false" "fstab entry generated: '/dev/sr0 /media/cdrom0 udf,iso9660 user,noauto 0 0'."
do_log "info" "true" "fstab entry generated: '/dev/sr0 /media/cdrom0 udf,iso9660 user,noauto 0 0'."
### Add entry for 'SWAP' device.
var_path="SWAP"
echo "/dev/mapper/${HMP_EPHEMERAL_ENCLABEL["${var_path}"]} none swap defaults 0 0" >> "${TARGET}/etc/fstab"
echo "" >> "${TARGET}/etc/fstab"
do_log "info" "false" "fstab entry generated: '/dev/mapper/${HMP_EPHEMERAL_ENCLABEL["${var_path}"]} none swap defaults 0 0'."
write_fstab "/dev/mapper/${HMP_EPHEMERAL_ENCLABEL["${var_path}"]}" "none" "swap" "defaults" "0 0"
### Add entry for '/tmp' device.
var_path="/tmp"
echo "/dev/mapper/${HMP_EPHEMERAL_ENCLABEL["${var_path}"]} /tmp ext4 defaults,rw,nodev,nosuid,relatime 0 0" >> "${TARGET}/etc/fstab"
echo "" >> "${TARGET}/etc/fstab"
do_log "info" "false" "fstab entry generated: '/dev/mapper/${HMP_EPHEMERAL_ENCLABEL["${var_path}"]} /tmp ext4 defaults,rw,nodev,nosuid,relatime 0 0'."
write_fstab "/dev/mapper/${HMP_EPHEMERAL_ENCLABEL["${var_path}"]}" "/tmp" "ext4" "defaults,rw,nodev,nosuid,relatime" "0 0"
return 0
}

View File

@@ -1,18 +1,16 @@
#!/bin/bash
# SPDX-Version: 3.0
# SPDX-CreationInfo: 2025-02-13; WEIDNER, Marc S.; <cendev@coresecret.eu>
# SPDX-ExternalRef: GIT https://cendev.eu/marc.weidner/CISS.2025.debian.installer.git
# 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.; <cendev@coresecret.eu>
# 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.2025.hardened.installer framework.
# SPDX-PackageName: CISS.2025.hardened.installer
# SPDX-LicenseComment: This file is part of the CISS.debian.installer.secure framework.
# SPDX-PackageName: CISS.debian.installer
# SPDX-Security-Contact: security@coresecret.eu
###########################################################################################
# 3.7.3. Functions - installation - generate crypttab #
###########################################################################################
guard_sourcing
###########################################################################################
# Generate "${TARGET}" /etc/crypttab entries.