#!/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-FileContributor: WEIDNER, Marc S.; Centurion Intelligence Consulting Agency
# SPDX-FileCopyrightText: 2024-2025; WEIDNER, Marc S.; <cendev@coresecret.eu>
# 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-Security-Contact: security@coresecret.eu

###########################################################################################
# 3.9.1. Functions - installation - generate files recovery                               #
###########################################################################################

###########################################################################################
# Generates '${RECOVERY}/etc/crypttab' and '${RECOVERY}/etc/fstab' files for recovery partition.
# Globals:
#   tba
# Arguments:
#   None
###########################################################################################
3_9_1_functions_installation_generate_files_recovery() {
  declare -g -x MODULE_ERR="3_9_1_functions_installation_generate_files_recovery"
  declare -g -x MODULE_TXT="Generate 'fstab' and 'crypttab' for recovery partition"
  do_show_header "${MODULE_TXT}"

  ### BLOCK '${RECOVERY}/etc/crypttab'

  # Generate '${RECOVERY}/etc/crypttab'
  touch "${RECOVERY}"/etc/crypttab
  chmod 0644 "${RECOVERY}"/etc/crypttab

  # Generate '${RECOVERY}/etc/crypttab' header
  # shellcheck disable=SC2129
  cat << EOF >> "${RECOVERY}"/etc/crypttab
# <name>  <device>  <password-file-or-none>  <options>

EOF

  ### Reminder ###
  # MAP_MOUNTPATH_DEV["${MOUNT_PATH}"]="/dev/mapper/${ENCRYPTION_LABEL}"
  # MAP_UUID_CRYPT["${ENCRYPTION_LABEL}"]="${UUID}"
  # MAP_PATH_CRYPT["${MOUNT_PATH}"]="${ENCRYPTION_LABEL}"

  # Extract the key from HashMap MAP_PATH_CRYPT["${MOUNT_PATH}"]="${ENCRYPTION_LABEL}"
  declare KEY=""
  declare VAR=""

  for VAR in "${!MAP_PATH_CRYPT[@]}"; do
    if [[ ${MAP_PATH_CRYPT[$VAR]} == "crypt_rescue" ]]; then
      KEY="${VAR}"
      break
    fi
  done

  declare ENCRYPTION_LABEL
  ENCRYPTION_LABEL="${MAP_PATH_CRYPT["${KEY}"]}"

  # shellcheck disable=2129
  echo "# ${KEY} was on /dev/mapper/${MAP_PATH_CRYPT["${KEY}"]} during installation" >> "${RECOVERY}"/etc/crypttab
  echo "${MAP_PATH_CRYPT["${KEY}"]} UUID=${MAP_UUID_CRYPT["${ENCRYPTION_LABEL}"]} none luks,discard" >> "${RECOVERY}"/etc/crypttab
  echo "" >> "${RECOVERY}"/etc/crypttab
  do_log "info" "false" "crypttab entry generated: '${MAP_PATH_CRYPT["${KEY}"]} UUID=${MAP_UUID_CRYPT["${ENCRYPTION_LABEL}"]} none luks,discard'."

  # TODO: Update loop to iterate thru dynamic number of ephemeral drives.
  # Generate '${RECOVERY}/etc/crypttab' special ephemeral entries.
  declare -a EPHEMERAL_MOUNT_PATH=("SWAP" "/tmp")
  declare KEY=""

  # MAP_EPHEMERAL_DEV["${MOUNT_PATH}"]="/dev/${DEV}${PARTITION}"
  # MAP_EPHEMERAL_ENCLABEL["${MOUNT_PATH}"]="${ENCRYPTION_LABEL}"
  for KEY in "${EPHEMERAL_MOUNT_PATH[@]}"; do

    if [[ ${KEY} == "SWAP" ]]; then

      # shellcheck disable=2129
      echo "# ${KEY} was on ${MAP_EPHEMERAL_DEV[${KEY}]} during installation" >> "${RECOVERY}"/etc/crypttab
      # TODO: Change static 'LABEL=' to dynamic extraction of partitioning.yaml 'recipe_..._filesystem_label' recipe string.
      echo "${MAP_EPHEMERAL_ENCLABEL[${KEY}]}  LABEL=SWAP  /dev/random  swap,offset=2048,cipher=aes-xts-plain64,size=512,sector-size=4096" >> "${RECOVERY}"/etc/crypttab
      echo "" >> "${RECOVERY}"/etc/crypttab
      do_log "info" "false" "'${RECOVERY}/etc/crypttab' entry generated: '${MAP_EPHEMERAL_ENCLABEL[${KEY}]}  LABEL=SWAP  /dev/random  swap,offset=2048,cipher=aes-xts-plain64,size=512,sector-size=4096'."

    elif [[ ${KEY} == "/tmp" ]]; then

      # shellcheck disable=2129
      echo "# ${KEY} was on ${MAP_EPHEMERAL_DEV[${KEY}]} during installation" >> "${RECOVERY}"/etc/crypttab
      # TODO: Change static 'LABEL=' to dynamic extraction of partitioning.yaml 'recipe_..._filesystem_label' recipe string.
      echo "${MAP_EPHEMERAL_ENCLABEL[${KEY}]}  LABEL=ext4_tmp  /dev/random  offset=2048,cipher=aes-xts-plain64,size=512,sector-size=4096,tmp=ext4" >> "${RECOVERY}"/etc/crypttab
      echo "" >> "${RECOVERY}"/etc/crypttab
      do_log "info" "false" "'${RECOVERY}/etc/crypttab' entry generated: '${MAP_EPHEMERAL_ENCLABEL[${KEY}]}  LABEL=ext4_tmp  /dev/random  offset=2048,cipher=aes-xts-plain64,size=512,sector-size=4096,tmp=ext4'."

    else

      do_log "info" "true" "${RECOVERY}/etc/crypttab (This message should never get printed.)"

    fi

  done

  ### BLOCK '${RECOVERY}/etc/fstab'

  # Generate '${RECOVERY}/etc/fstab'
  touch "${RECOVERY}"/etc/fstab
  chmod 0644 "${RECOVERY}"/etc/fstab

  # Generate '${RECOVERY}/etc/fstab' header
  # shellcheck disable=SC2129
  cat << EOF >> "${RECOVERY}"/etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# systemd generates mount units based on this file, see systemd.mount(5).
# Please run 'systemctl daemon-reload' after making changes here.
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>

EOF

  ### Reminder ###
  # MAP_MOUNTPATH_DEV["${MOUNT_PATH}"]="/dev/mapper/${ENCRYPTION_LABEL}"
  # MAP_UUID_CRYPT["${ENCRYPTION_LABEL}"]="${UUID}"
  # MAP_PATH_CRYPT["${MOUNT_PATH}"]="${ENCRYPTION_LABEL}"

  # TODO: BEGIN: BLOCK "${RECOVERY}"/etc/fstab
  # TODO: complete this block

  # Generate '${TARGET}/etc/fstab' special entries '/' '/boot' '/boot/efi'.
  # Define the order of the special keys.
  declare -a KEY_ORDER
  KEY_ORDER=("/RECOVERY")

  declare DEVICE_PATH
  declare DEVICE_UUID
  declare ENCRYPTION_LABEL
  declare KEY
  declare MATCHING_VAR
  declare TRANSFORMED_STRING

  for KEY in "${KEY_ORDER[@]}"; do
    # Initialize variables
    DEVICE_PATH="${MAP_MOUNTPATH_DEV[${KEY}]}"
    DEVICE_UUID=$(blkid -s UUID -o value "${DEVICE_PATH}")

    # if KEY:VALUE equals "/dev/${DEV}${PARTITION}"
    if [[ ${DEVICE_PATH} =~ ^/dev/[a-zA-Z]+[0-9]+$ ]]; then

      TRANSFORMED_STRING=$(echo "${DEVICE_PATH}" | sed 's|/dev/|dev_|; s|\([a-zA-Z]\)\([0-9]\)|\1_\2|')

    # if KEY:VALUE equals "/dev/mapper/${ENCRYPTION_LABEL}"
    elif [[ ${DEVICE_PATH} =~ ^/dev/mapper/ ]]; then

      # Extract ENCRYPTION_LABEL
      ENCRYPTION_LABEL="${DEVICE_PATH#/dev/mapper/}"

      # Search matching variable of the sourced "${PRESEED}" variable file
      MATCHING_VAR=$(declare -p | grep -oP "recipe_[^ ]+_encryption_label=${ENCRYPTION_LABEL}")

      if [[ -n ${MATCHING_VAR} ]]; then

        # Extract third, fourth and fifth part of the respective variable
        TRANSFORMED_STRING=$(echo "${MATCHING_VAR}" | sed -E 's|recipe_[^_]+_(dev_[^_]+_[^_]+)_.*|\1|')

      else

        do_log "error" "false" "No matching variable found for ENCRYPTION_LABEL='${ENCRYPTION_LABEL}'."
        exit "${ERR_NO_ENCR_LABEL}"

      fi

    else

      do_log "error" "false" "Unknown DEVICE_PATH-Format: '${DEVICE_PATH}'."
      exit "${ERR_NO_DEVIC_PATH}"

    fi

    declare BTRFS_COMPR_VAR="recipe_${RECIPE_STRING}_${TRANSFORMED_STRING}_filesystem_btrfs_compress"
    declare BTRFS_LEVEL_VAR="recipe_${RECIPE_STRING}_${TRANSFORMED_STRING}_filesystem_btrfs_level"
    declare FILESYSTEM_LABEL_VAR="recipe_${RECIPE_STRING}_${TRANSFORMED_STRING}_filesystem_label"
    declare FILESYSTEM_VERSION_VAR="recipe_${RECIPE_STRING}_${TRANSFORMED_STRING}_filesystem_version"
    declare MOUNT_OPTIONS_VAR="recipe_${RECIPE_STRING}_${TRANSFORMED_STRING}_mount_options"
    declare MOUNT_SUBVOLUME_VAR="recipe_${RECIPE_STRING}_${TRANSFORMED_STRING}_mount_subvolume"

    declare BTRFS_COMPR=${!BTRFS_COMPR_VAR}
    declare BTRFS_LEVEL=${!BTRFS_LEVEL_VAR}
    declare FILESYSTEM_LABEL=${!FILESYSTEM_LABEL_VAR}
    declare FILESYSTEM_VERSION=${!FILESYSTEM_VERSION_VAR}
    declare MOUNT_OPTIONS=${!MOUNT_OPTIONS_VAR}
    declare MOUNT_SUBVOLUME=${!MOUNT_SUBVOLUME_VAR}

    if [[ ${KEY} == "/" ]]; then

      if [[ ${FILESYSTEM_VERSION} == "btrfs" ]]; then

        declare BTRFS_OPTIONS="compress=${BTRFS_COMPR}:${BTRFS_LEVEL}"
        # shellcheck disable=2129
        echo "# ${KEY} was on ${MAP_MOUNTPATH_DEV[${KEY}]} during installation" >> "${TARGET}"/etc/fstab
        echo "# ${KEY} was on ${DEVICE_UUID} during installation" >> "${TARGET}"/etc/fstab
        echo "${MAP_MOUNTPATH_DEV[${KEY}]}  ${KEY}  ${FILESYSTEM_VERSION}  ${MOUNT_OPTIONS},${BTRFS_OPTIONS},subvol=${MOUNT_SUBVOLUME}  0  1" >> "${TARGET}"/etc/fstab
        echo "" >> "${TARGET}"/etc/fstab
        do_log "info" "false" "fstab entry generated: '${MAP_MOUNTPATH_DEV[${KEY}]}  ${KEY}  ${FILESYSTEM_VERSION}  ${MOUNT_OPTIONS},${BTRFS_OPTIONS},subvol=${MOUNT_SUBVOLUME}  0  1'."

      elif [[ ${FILESYSTEM_VERSION} == "ext4" ]]; then

        # shellcheck disable=2129
        echo "# ${KEY} was on ${MAP_MOUNTPATH_DEV[${KEY}]} during installation" >> "${TARGET}"/etc/fstab
        echo "# ${KEY} was on ${DEVICE_UUID} during installation" >> "${TARGET}"/etc/fstab
        echo "${MAP_MOUNTPATH_DEV[${KEY}]}  ${KEY}  ${FILESYSTEM_VERSION}  ${MOUNT_OPTIONS}  0  1" >> "${TARGET}"/etc/fstab
        echo "" >> "${TARGET}"/etc/fstab
        do_log "info" "false" "fstab entry generated: '${MAP_MOUNTPATH_DEV[${KEY}]}  ${KEY} ${FILESYSTEM_VERSION}  ${MOUNT_OPTIONS}  0  1'."

      else

        do_log "error" "false" "fstab entry - no valid filesystem: '${FILESYSTEM_VERSION}' found for '${KEY}'."

      fi

    elif [[ ${KEY} == "/boot" ]]; then

      if [[ ${FILESYSTEM_VERSION} == "btrfs" ]]; then

        declare BTRFS_OPTIONS="compress=${BTRFS_COMPR}:${BTRFS_LEVEL}"
        # shellcheck disable=2129
        echo "# ${KEY} was on ${MAP_MOUNTPATH_DEV[${KEY}]} during installation" >> "${TARGET}"/etc/fstab
        echo "# ${KEY} was on ${DEVICE_UUID} during installation" >> "${TARGET}"/etc/fstab
        echo "UUID=${DEVICE_UUID}  ${KEY}  ${FILESYSTEM_VERSION}  ${MOUNT_OPTIONS},${BTRFS_OPTIONS},subvol=${MOUNT_SUBVOLUME}  0  2" >> "${TARGET}"/etc/fstab
        echo "" >> "${TARGET}"/etc/fstab
        do_log "info" "false" "fstab entry generated: 'UUID=${DEVICE_UUID}  ${KEY}  ${FILESYSTEM_VERSION}  ${MOUNT_OPTIONS},${BTRFS_OPTIONS},subvol=${MOUNT_SUBVOLUME}  0  2'."

      elif [[ ${FILESYSTEM_VERSION} == "ext4" ]]; then

        # shellcheck disable=2129
        echo "# ${KEY} was on ${MAP_MOUNTPATH_DEV[${KEY}]} during installation" >> "${TARGET}"/etc/fstab
        echo "# ${KEY} was on ${DEVICE_UUID} during installation" >> "${TARGET}"/etc/fstab
        echo "UUID=${DEVICE_UUID}  ${KEY}  ${FILESYSTEM_VERSION}  ${MOUNT_OPTIONS}  0  2" >> "${TARGET}"/etc/fstab
        echo "" >> "${TARGET}"/etc/fstab
        do_log "info" "false" "fstab entry generated: 'UUID=${DEVICE_UUID}  ${KEY}  ${FILESYSTEM_VERSION}  ${MOUNT_OPTIONS}  0  2'."

      else

        do_log "error" "false" "fstab entry - no valid filesystem: '${FILESYSTEM_VERSION}' found for '${KEY}'."

      fi

    elif [[ ${KEY} == "/boot/efi" ]]; then

      if [[ ${FILESYSTEM_VERSION} == "fat32" ]]; then

        # shellcheck disable=2129
        echo "# ${KEY} was on ${MAP_MOUNTPATH_DEV[${KEY}]} during installation" >> "${TARGET}"/etc/fstab
        echo "# ${KEY} was on ${DEVICE_UUID} during installation" >> "${TARGET}"/etc/fstab
        echo "UUID=${DEVICE_UUID}  ${KEY}  vfat  umask=0077  0  2" >> "${TARGET}"/etc/fstab
        echo "" >> "${TARGET}"/etc/fstab
        do_log "info" "false" "fstab entry generated: 'UUID=${DEVICE_UUID}  ${KEY}  vfat umask=0077  0  2'."

      else

        do_log "error" "false" "fstab entry - no valid filesystem: '${FILESYSTEM_VERSION}' found for '${KEY}'."

      fi

    else

      do_log "error" "false" "fstab entry - no valid '${KEY}' for '/', '/boot', '/boot/efi' found."

    fi

  done

  # Generate '${TARGET}/etc/fstab' remaining entries
  for KEY in "${!MAP_MOUNTPATH_DEV[@]}"; do

    # Initialize variables
    DEVICE_PATH="${MAP_MOUNTPATH_DEV[${KEY}]}"
    DEVICE_UUID=$(blkid -s UUID -o value "${DEVICE_PATH}")

    # if KEY:VALUE equals "/dev/${DEV}${PARTITION}"
    if [[ ${DEVICE_PATH} =~ ^/dev/[a-zA-Z]+[0-9]+$ ]]; then

      TRANSFORMED_STRING=$(echo "${DEVICE_PATH}" | sed 's|/dev/|dev_|; s|\([a-zA-Z]\)\([0-9]\)|\1_\2|')

    # if KEY:VALUE equals "/dev/mapper/${ENCRYPTION_LABEL}"
    elif [[ ${DEVICE_PATH} =~ ^/dev/mapper/ ]]; then

      # Extract ENCRYPTION_LABEL
      ENCRYPTION_LABEL="${DEVICE_PATH#/dev/mapper/}"

      # Search matching variable of the sourced "${PRESEED}" variable file
      MATCHING_VAR=$(declare -p | grep -oP "recipe_[^ ]+_encryption_label=${ENCRYPTION_LABEL}")

      if [[ -n ${MATCHING_VAR} ]]; then

        # Extract third, fourth and fifth part of the respective variable
        TRANSFORMED_STRING=$(echo "${MATCHING_VAR}" | sed -E 's|recipe_[^_]+_(dev_[^_]+_[^_]+)_.*|\1|')

      else

        do_log "error" "false" "No matching variable found for ENCRYPTION_LABEL='${ENCRYPTION_LABEL}'."
        exit "${ERR_NO_ENCR_LABEL}"

      fi

    else

      do_log "error" "false" "Unknown DEVICE_PATH-Format: '${DEVICE_PATH}'."
      exit "${ERR_NO_DEVIC_PATH}"

    fi

    declare BTRFS_COMPR_VAR="recipe_${RECIPE_STRING}_${TRANSFORMED_STRING}_filesystem_btrfs_compress"
    declare BTRFS_LEVEL_VAR="recipe_${RECIPE_STRING}_${TRANSFORMED_STRING}_filesystem_btrfs_level"
    declare FILESYSTEM_LABEL_VAR="recipe_${RECIPE_STRING}_${TRANSFORMED_STRING}_filesystem_label"
    declare FILESYSTEM_VERSION_VAR="recipe_${RECIPE_STRING}_${TRANSFORMED_STRING}_filesystem_version"
    declare MOUNT_OPTIONS_VAR="recipe_${RECIPE_STRING}_${TRANSFORMED_STRING}_mount_options"
    declare MOUNT_SUBVOLUME_VAR="recipe_${RECIPE_STRING}_${TRANSFORMED_STRING}_mount_subvolume"

    declare BTRFS_COMPR=${!BTRFS_COMPR_VAR}
    declare BTRFS_LEVEL=${!BTRFS_LEVEL_VAR}
    declare FILESYSTEM_LABEL=${!FILESYSTEM_LABEL_VAR}
    declare FILESYSTEM_VERSION=${!FILESYSTEM_VERSION_VAR}
    declare MOUNT_OPTIONS=${!MOUNT_OPTIONS_VAR}
    declare MOUNT_SUBVOLUME=${!MOUNT_SUBVOLUME_VAR}

    # Skip already mounted paths ("/", "/boot", "/boot/efi")
    if [[ " ${KEY_ORDER[*]} " == *" ${KEY} "* ]]; then
      continue
    fi

    if [[ ${FILESYSTEM_VERSION} == "btrfs" ]]; then

      declare BTRFS_OPTIONS="compress=${BTRFS_COMPR}:${BTRFS_LEVEL}"
      # shellcheck disable=2129
      echo "# ${KEY} was on ${MAP_MOUNTPATH_DEV[${KEY}]} during installation" >> "${TARGET}"/etc/fstab
      echo "# ${KEY} was on ${DEVICE_UUID} during installation" >> "${TARGET}"/etc/fstab
      echo "UUID=${DEVICE_UUID}  ${KEY}  ${FILESYSTEM_VERSION}  ${MOUNT_OPTIONS},${BTRFS_OPTIONS},subvol=${MOUNT_SUBVOLUME}  0  2" >> "${TARGET}"/etc/fstab
      echo "" >> "${TARGET}"/etc/fstab
      do_log "info" "false" "fstab entry generated: 'UUID=${DEVICE_UUID}  ${KEY}  ${FILESYSTEM_VERSION}  ${MOUNT_OPTIONS},${BTRFS_OPTIONS},subvol=${MOUNT_SUBVOLUME}  0  2'."

    elif [[ ${FILESYSTEM_VERSION} == "ext4" ]]; then

      # shellcheck disable=2129
      echo "# ${KEY} was on ${MAP_MOUNTPATH_DEV[${KEY}]} during installation" >> "${TARGET}"/etc/fstab
      echo "# ${KEY} was on ${DEVICE_UUID} during installation" >> "${TARGET}"/etc/fstab
      echo "UUID=${DEVICE_UUID}  ${KEY}  ${FILESYSTEM_VERSION}  ${MOUNT_OPTIONS}  0  2" >> "${TARGET}"/etc/fstab
      echo "" >> "${TARGET}"/etc/fstab
      do_log "info" "false" "fstab entry generated: 'UUID=${DEVICE_UUID}  ${KEY}  ${FILESYSTEM_VERSION}  ${MOUNT_OPTIONS}  0  2'."

    else

      do_log "error" "false" "fstab entry - no valid filesystem: '${FILESYSTEM_VERSION}' found for '${KEY}'."

    fi

  done

  # TODO: flexible entries for more than one CD-ROM drives.
  # Add entry for CD-ROM device
  # shellcheck disable=2129
  echo "# /media/cdrom0 was on /dev/sr0 during installation" >> "${TARGET}"/etc/fstab
  echo "/dev/sr0  /media/cdrom0  udf,iso9660  user,noauto  0  0" >> "${TARGET}"/etc/fstab
  echo "" >> "${TARGET}"/etc/fstab
  do_log "info" "false" "fstab entry generated: '/dev/sr0  /media/cdrom0  udf,iso9660  user,noauto  0  0'."

  # Add entry for proc and tmpfs device
  # shellcheck disable=2129
  echo "##### Added by CISS.2025.debian.installer" >> "${TARGET}"/etc/fstab
  echo "proc  /proc  proc  nodev,nosuid,noexec,hidepid=2  0  0" >> "${TARGET}"/etc/fstab
  echo "tmpfs  /dev/shm  tmpfs  rw,nodev,nosuid,noexec,relatime,size=1G  0  0" >> "${TARGET}"/etc/fstab
  echo "" >> "${TARGET}"/etc/fstab
  do_log "info" "false" "fstab entry generated: 'proc  /proc  proc  nodev,nosuid,noexec,hidepid=2  0  0'."
  do_log "info" "false" "fstab entry generated: 'tmpfs  /dev/shm  tmpfs  rw,nodev,nosuid,noexec,relatime,size=1G  0  0'."

  # TODO: flexible 'SWAP' entry, not only ephemeral SWAP.
  # Add entry for SWAP device
  declare MOUNT_PATH="SWAP"
  # shellcheck disable=2129
  echo "##### Added by CISS.2025.debian.installer" >> "${TARGET}"/etc/fstab
  echo "${MAP_EPHEMERAL_ENCLABEL["${MOUNT_PATH}"]}  none  swap  defaults  0  0" >> "${TARGET}"/etc/fstab
  echo "" >> "${TARGET}"/etc/fstab
  do_log "info" "false" "fstab entry generated: '${MAP_EPHEMERAL_ENCLABEL["${MOUNT_PATH}"]}  none  swap  defaults  0  0'."

  # TODO: flexible '/tmp' entry, not only ephemeral SWAP.
  # Add entry for '/tmp' device
  declare MOUNT_PATH="/tmp"
  # shellcheck disable=2129
  echo "##### Added by CISS.2025.debian.installer" >> "${TARGET}"/etc/fstab
  echo "${MAP_EPHEMERAL_ENCLABEL["${MOUNT_PATH}"]}  /tmp  ext4  defaults,rw,nodev,nosuid,relatime  0  0" >> "${TARGET}"/etc/fstab
  echo "" >> "${TARGET}"/etc/fstab
  do_log "info" "false" "fstab entry generated: '${MAP_EPHEMERAL_ENCLABEL["${MOUNT_PATH}"]}  /tmp  ext4  defaults,rw,nodev,nosuid,relatime  0  0'."

  # TODO: END: BLOCK "${RECOVERY}"/etc/fstab
  # TODO: complete this block

  do_show_footer "${MODULE_TXT}"
}
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh:
