All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 2m6s
Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
137 lines
3.5 KiB
Bash
137 lines
3.5 KiB
Bash
#!/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
|
|
|
|
#######################################
|
|
# Finalize the chroot system before exiting.
|
|
# Globals:
|
|
# RECOVERY
|
|
# TARGET
|
|
# VAR_RUN_RECOVERY
|
|
# Arguments:
|
|
# None
|
|
# Returns:
|
|
# 0: on success
|
|
#######################################
|
|
final_commands() {
|
|
### Declare Arrays, HashMaps, and Variables.
|
|
declare -r var_logfile="/root/.ciss/cdi/log/4900_final_command.log"
|
|
declare var_target="${TARGET}"
|
|
|
|
### Check for TARGET / RECOVERY.
|
|
[[ "${VAR_RUN_RECOVERY}" == "true" ]] && var_target="${RECOVERY}"
|
|
|
|
chroot_logger "${var_target}${var_logfile}"
|
|
|
|
chroot_script "${var_target}" "
|
|
updatedb | tee -a ${var_logfile}
|
|
"
|
|
|
|
ciss_enforce_multi_user_target
|
|
|
|
rm -f "${var_target}/root/ciss_xdg_tmp.sh"
|
|
|
|
guard_dir && return 0
|
|
}
|
|
### Prevents accidental 'unset -f'.
|
|
# shellcheck disable=SC2034
|
|
readonly -f final_commands
|
|
|
|
#######################################
|
|
# description
|
|
# Globals:
|
|
# RECOVERY
|
|
# TARGET
|
|
# VAR_RUN_RECOVERY
|
|
# Arguments:
|
|
# None
|
|
# Returns:
|
|
# 0: on success
|
|
#######################################
|
|
ciss_enforce_multi_user_target() {
|
|
### Declare Arrays, HashMaps, and Variables.
|
|
declare var_target="${TARGET}"
|
|
|
|
### Check for TARGET / RECOVERY.
|
|
[[ "${VAR_RUN_RECOVERY}" == "true" ]] && var_target="${RECOVERY}"
|
|
|
|
# shellcheck disable=SC2016
|
|
chroot_script "${var_target}" '
|
|
declare var_dm="" var_unit_dir="" var_link="/etc/systemd/system/default.target"
|
|
|
|
### Determine the canonical systemd unit dir inside TARGET.
|
|
if [[ -d /lib/systemd/system ]]; then
|
|
|
|
var_unit_dir=/lib/systemd/system
|
|
|
|
elif [[ -d /usr/lib/systemd/system ]]; then
|
|
|
|
var_unit_dir=/usr/lib/systemd/system
|
|
|
|
fi
|
|
|
|
### Enforce default.target -> multi-user.target as a symlink.
|
|
if [[ -e "${var_link}" ]] && [[ ! -L "${var_link}" ]]; then
|
|
|
|
### A regular file here is wrong; we remove it to avoid vendor fallback to graphical.
|
|
rm -f -- "${var_link}"
|
|
|
|
fi
|
|
|
|
if [[ ! -L "${var_link}" ]]; then
|
|
|
|
ln -s "${var_unit_dir}/multi-user.target" "${var_link}"
|
|
|
|
else
|
|
|
|
### Ensure it points to multi-user.
|
|
|
|
if [[ "$(readlink -f "${var_link}")" != "${var_unit_dir}/multi-user.target" ]]; then
|
|
|
|
rm -f -- "${var_link}"
|
|
ln -s "${var_unit_dir}/multi-user.target" "${var_link}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
### Hard-block any display manager (mask via /dev/null symlink). Include common DMs, and the generic alias:
|
|
ary_dm_units=(
|
|
"display-manager.service"
|
|
"gdm.service"
|
|
"gdm3.service"
|
|
"sddm.service"
|
|
"lightdm.service"
|
|
"xdm.service"
|
|
"lxdm.service"
|
|
"slim.service"
|
|
)
|
|
|
|
for var_dm in "${ary_dm_units[@]}"; do
|
|
|
|
if [[ ! -L "/etc/systemd/system/${var_dm}" ]]; then
|
|
|
|
ln -s /dev/null "/etc/systemd/system/${var_dm}"
|
|
|
|
fi
|
|
|
|
done
|
|
'
|
|
|
|
return 0
|
|
}
|
|
### Prevents accidental 'unset -f'.
|
|
# shellcheck disable=SC2034
|
|
readonly -f ciss_enforce_multi_user_target
|
|
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh
|