V8.00.000.2025.06.17
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 1m44s
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 1m44s
Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
@@ -21,11 +21,12 @@ guard_sourcing
|
|||||||
# 1: MOUNT_PATH
|
# 1: MOUNT_PATH
|
||||||
# 2: MOUNT_DEVICE
|
# 2: MOUNT_DEVICE
|
||||||
# 3: MOUNT_OPTIONS
|
# 3: MOUNT_OPTIONS
|
||||||
|
# 4: MOUNT_FILESYSTEM
|
||||||
# Returns:
|
# Returns:
|
||||||
# 0: on success
|
# 0: on success
|
||||||
#######################################
|
#######################################
|
||||||
mount_with_dir() {
|
mount_with_dir() {
|
||||||
declare var_mount_path="$1" var_mount_device="$2" var_mount_options="${3:-}"
|
declare var_mount_path="${1}" var_mount_device="${2}" var_mount_options="${3:-}" var_mount_fs="${4:-}"
|
||||||
declare -a ary_cmd=( mount )
|
declare -a ary_cmd=( mount )
|
||||||
|
|
||||||
if [[ "${var_mount_device}" =~ ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}$ ]] || [[ "${var_mount_device}" =~ ^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$ ]]; then
|
if [[ "${var_mount_device}" =~ ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}$ ]] || [[ "${var_mount_device}" =~ ^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$ ]]; then
|
||||||
@@ -43,15 +44,27 @@ mount_with_dir() {
|
|||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${var_mount_fs:-}" ]]; then
|
||||||
|
|
||||||
|
var_mount_fs=$(blkid -o value -s TYPE "${var_mount_device}" 2>/dev/null || true)
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
[[ "${var_mount_path}" != "/" ]] && mkdir -p "${TARGET}${var_mount_path}"
|
[[ "${var_mount_path}" != "/" ]] && mkdir -p "${TARGET}${var_mount_path}"
|
||||||
|
|
||||||
### Build the command in an array to keep word boundaries intact.
|
### Build the command in an array to keep word boundaries intact.
|
||||||
|
|
||||||
|
[[ -n "${var_fstype}" ]] && ary_cmd+=( "-t" "${var_fstype}" )
|
||||||
[[ -n "${var_mount_options}" ]] && ary_cmd+=( "-o" "${var_mount_options}" )
|
[[ -n "${var_mount_options}" ]] && ary_cmd+=( "-o" "${var_mount_options}" )
|
||||||
ary_cmd+=("${var_mount_device}" "${TARGET}${var_mount_path}")
|
|
||||||
|
ary_cmd+=( "${var_mount_device}" "${TARGET%/}${var_mount_path}" )
|
||||||
|
|
||||||
safe_exec "${ary_cmd[@]}" "${ERR_MOUNTING_DEV}" || return
|
safe_exec "${ary_cmd[@]}" "${ERR_MOUNTING_DEV}" || return
|
||||||
|
|
||||||
do_log "debug" "file_only" "3280() [safe_exec ${ary_cmd[*]} ${ERR_MOUNTING_DEV}]."
|
do_log "debug" "file_only" "3280() [safe_exec ${ary_cmd[*]} ${ERR_MOUNTING_DEV}]."
|
||||||
do_log "info" "file_only" "3280() Mounted: '${var_mount_device}' on: '${TARGET}${var_mount_path}' (Options='${var_mount_options}')."
|
|
||||||
|
do_log "info" "file_only" "3280() Mounted: '${var_mount_device}' on: '${TARGET}${var_mount_path}' Options='${var_mount_options}'."
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@@ -68,27 +81,38 @@ mount_with_dir() {
|
|||||||
#######################################
|
#######################################
|
||||||
resolve_device() {
|
resolve_device() {
|
||||||
declare local_var_dev="$1" local_var_partition="$2" local_var_enc_boolean="$3" local_var_enc_label="$4"
|
declare local_var_dev="$1" local_var_partition="$2" local_var_enc_boolean="$3" local_var_enc_label="$4"
|
||||||
|
|
||||||
if [[ "${local_var_enc_boolean,,}" == "true" ]]; then
|
if [[ "${local_var_enc_boolean,,}" == "true" ]]; then
|
||||||
|
|
||||||
printf '/dev/mapper/%s' "${local_var_enc_label}"
|
printf '/dev/mapper/%s' "${local_var_enc_label}"
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
printf '/dev/%s%s' "${local_var_dev}" "${local_var_partition}"
|
printf '/dev/%s%s' "${local_var_dev}" "${local_var_partition}"
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
# Validates btrfs compression algo and level.
|
# Validates btrfs compression algo and level.
|
||||||
# Arguments:
|
# Arguments:
|
||||||
# 1 var_fs_btrfs_compress
|
# 1: var_fs_btrfs_compress
|
||||||
# 2 var_fs_btrfs_level
|
# 2: var_fs_btrfs_level
|
||||||
# Returns:
|
# Returns:
|
||||||
# 0: Valid combination.
|
# 0: Valid combination.
|
||||||
# 1: Invalid combination.
|
# 1: Invalid combination.
|
||||||
#######################################
|
#######################################
|
||||||
validate_btrfs_compression() {
|
validate_btrfs_compression() {
|
||||||
declare var_algo="$1" var_level="$2"
|
declare var_algo="$1" var_level="$2"
|
||||||
|
|
||||||
case "${var_algo}:${var_level}" in
|
case "${var_algo}:${var_level}" in
|
||||||
|
|
||||||
zstd:|zstd:[0-9]|zstd:1[0-9]|zstd:2[0-2]|lzo:) return 0 ;;
|
zstd:|zstd:[0-9]|zstd:1[0-9]|zstd:2[0-2]|lzo:) return 0 ;;
|
||||||
|
|
||||||
*) do_log "error" "file_only" "3280() Invalid btrfs compression: '${var_algo}:${var_level}'"; return "${ERR_BTRFS_OPTION}" ;;
|
*) do_log "error" "file_only" "3280() Invalid btrfs compression: '${var_algo}:${var_level}'"; return "${ERR_BTRFS_OPTION}" ;;
|
||||||
|
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,8 +223,6 @@ mount_partition() {
|
|||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p "${TARGET}${var_mount_path}"
|
|
||||||
|
|
||||||
if [[ "${var_fs_version,,}" == "btrfs" ]]; then
|
if [[ "${var_fs_version,,}" == "btrfs" ]]; then
|
||||||
|
|
||||||
var_fs_btrfs_subvolume=$(get_label "${var_mount_path}" "${var_fs_version}" "sub")
|
var_fs_btrfs_subvolume=$(get_label "${var_mount_path}" "${var_fs_version}" "sub")
|
||||||
@@ -244,7 +266,7 @@ mount_partition() {
|
|||||||
HMP_FSTAB_MOUNT_OPTS["${var_mount_path}"]="${var_btrfs_options}"
|
HMP_FSTAB_MOUNT_OPTS["${var_mount_path}"]="${var_btrfs_options}"
|
||||||
do_log "debug" "file_only" "3280() [HMP_FSTAB_MOUNT_OPTS] : '${var_mount_path}' -> '${HMP_FSTAB_MOUNT_OPTS["${var_mount_path}"]}'."
|
do_log "debug" "file_only" "3280() [HMP_FSTAB_MOUNT_OPTS] : '${var_mount_path}' -> '${HMP_FSTAB_MOUNT_OPTS["${var_mount_path}"]}'."
|
||||||
|
|
||||||
mount_with_dir "${var_mount_path}" "${var_fs_uuid}" "${var_btrfs_options}" || return "${ERR_MOUNTING_DEV}"
|
mount_with_dir "${var_mount_path}" "${var_fs_uuid}" "${var_btrfs_options}" "btrfs" || return "${ERR_MOUNTING_DEV}"
|
||||||
do_log "info" "file_only" "3280() Mounted: '${var_fs_uuid}' on: '${TARGET}${var_mount_path}' (Options='${var_btrfs_options}')."
|
do_log "info" "file_only" "3280() Mounted: '${var_fs_uuid}' on: '${TARGET}${var_mount_path}' (Options='${var_btrfs_options}')."
|
||||||
|
|
||||||
if [[ "${var_fs_btrfs_snapshot}" == "true" ]]; then
|
if [[ "${var_fs_btrfs_snapshot}" == "true" ]]; then
|
||||||
@@ -263,7 +285,7 @@ mount_partition() {
|
|||||||
HMP_FSTAB_MOUNT_OPTS["${var_mount_path}/.snapshots"]="${var_mount_optsnap}"
|
HMP_FSTAB_MOUNT_OPTS["${var_mount_path}/.snapshots"]="${var_mount_optsnap}"
|
||||||
do_log "debug" "file_only" "3280() [HMP_FSTAB_MOUNT_OPTS] : '${var_mount_path}/.snapshots' -> '${HMP_FSTAB_MOUNT_OPTS["${var_mount_path}/.snapshots"]}'."
|
do_log "debug" "file_only" "3280() [HMP_FSTAB_MOUNT_OPTS] : '${var_mount_path}/.snapshots' -> '${HMP_FSTAB_MOUNT_OPTS["${var_mount_path}/.snapshots"]}'."
|
||||||
|
|
||||||
mount_with_dir "${var_mount_path}/.snapshots" "${var_fs_uuid}" "${var_mount_optsnap}"
|
mount_with_dir "${var_mount_path}/.snapshots" "${var_fs_uuid}" "${var_mount_optsnap}" "btrfs"
|
||||||
do_log "info" "file_only" "3280() Mounted: '${var_fs_uuid}' on: '${TARGET}${var_mount_path}/.snapshots' (Options='${var_mount_optsnap}')."
|
do_log "info" "file_only" "3280() Mounted: '${var_fs_uuid}' on: '${TARGET}${var_mount_path}/.snapshots' (Options='${var_mount_optsnap}')."
|
||||||
|
|
||||||
fi
|
fi
|
||||||
@@ -275,7 +297,7 @@ mount_partition() {
|
|||||||
HMP_FSTAB_MOUNT_OPTS["${var_mount_path}"]="${var_mount_options}"
|
HMP_FSTAB_MOUNT_OPTS["${var_mount_path}"]="${var_mount_options}"
|
||||||
do_log "debug" "file_only" "3280() [HMP_FSTAB_MOUNT_OPTS] : '${var_mount_path}' -> '${HMP_FSTAB_MOUNT_OPTS["${var_mount_path}"]}'."
|
do_log "debug" "file_only" "3280() [HMP_FSTAB_MOUNT_OPTS] : '${var_mount_path}' -> '${HMP_FSTAB_MOUNT_OPTS["${var_mount_path}"]}'."
|
||||||
|
|
||||||
mount_with_dir "${var_mount_path}" "${var_fs_uuid}" "${var_mount_options}" || return "${ERR_MOUNTING_DEV}"
|
mount_with_dir "${var_mount_path}" "${var_fs_uuid}" "${var_mount_options}" "ext4" || return "${ERR_MOUNTING_DEV}"
|
||||||
do_log "info" "file_only" "3280() Mounted: '${var_fs_uuid}' on: '${TARGET}${var_mount_path}' (Options='${var_mount_options}')."
|
do_log "info" "file_only" "3280() Mounted: '${var_fs_uuid}' on: '${TARGET}${var_mount_path}' (Options='${var_mount_options}')."
|
||||||
;;
|
;;
|
||||||
|
|
||||||
@@ -285,7 +307,7 @@ mount_partition() {
|
|||||||
HMP_FSTAB_MOUNT_OPTS["${var_mount_path}"]="${var_mount_options}"
|
HMP_FSTAB_MOUNT_OPTS["${var_mount_path}"]="${var_mount_options}"
|
||||||
do_log "debug" "file_only" "3280() [HMP_FSTAB_MOUNT_OPTS] : '${var_mount_path}' -> '${HMP_FSTAB_MOUNT_OPTS["${var_mount_path}"]}'."
|
do_log "debug" "file_only" "3280() [HMP_FSTAB_MOUNT_OPTS] : '${var_mount_path}' -> '${HMP_FSTAB_MOUNT_OPTS["${var_mount_path}"]}'."
|
||||||
|
|
||||||
mount_with_dir "${var_mount_path}" "${var_fs_uuid}" "${var_mount_options}" || return "${ERR_MOUNTING_DEV}"
|
mount_with_dir "${var_mount_path}" "${var_fs_uuid}" "${var_mount_options}" "vfat" || return "${ERR_MOUNTING_DEV}"
|
||||||
do_log "info" "file_only" "3280() Mounted: '${var_fs_uuid}' on: '${TARGET}${var_mount_path}' (Options='${var_mount_options}')."
|
do_log "info" "file_only" "3280() Mounted: '${var_fs_uuid}' on: '${TARGET}${var_mount_path}' (Options='${var_mount_options}')."
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ safe_exec() {
|
|||||||
declare -a ary_cmd=("${@:1:$#-1}") # All but last arg.
|
declare -a ary_cmd=("${@:1:$#-1}") # All but last arg.
|
||||||
declare var_errcode="${!#}" # Last arg.
|
declare var_errcode="${!#}" # Last arg.
|
||||||
"${ary_cmd[@]}" && return 0
|
"${ary_cmd[@]}" && return 0
|
||||||
do_log "error" "file_only" "Command '${ary_cmd[*]}' failed."
|
do_log "error" "file_only" "0011() Command '${ary_cmd[*]}' failed."
|
||||||
return "${var_errcode}"
|
return "${var_errcode}"
|
||||||
}
|
}
|
||||||
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh
|
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ guard_sourcing
|
|||||||
set -o errexit # Exit script when a command exits with non-zero status, the same as "set -e".
|
set -o errexit # Exit script when a command exits with non-zero status, the same as "set -e".
|
||||||
set -o errtrace # Any traps on ERR are inherited in a subshell environment, the same as "set -E".
|
set -o errtrace # Any traps on ERR are inherited in a subshell environment, the same as "set -E".
|
||||||
set -o functrace # Any traps on DEBUG and RETURN are inherited in a subshell environment, the same as "set -T".
|
set -o functrace # Any traps on DEBUG and RETURN are inherited in a subshell environment, the same as "set -T".
|
||||||
|
set -o ignoreeof # An interactive shell will not exit upon reading EOF.
|
||||||
set -o nounset # Exit script on use of an undefined variable, the same as "set -u".
|
set -o nounset # Exit script on use of an undefined variable, the same as "set -u".
|
||||||
set -o pipefail # Makes pipelines return the exit status of the last command in the pipe that failed.
|
set -o pipefail # Makes pipelines return the exit status of the last command in the pipe that failed.
|
||||||
set -o noclobber # Prevent overwriting, the same as "set -C".
|
set -o noclobber # Prevent overwriting, the same as "set -C".
|
||||||
|
|||||||
Reference in New Issue
Block a user