009f92aea1
🛡️ Retrieve DNSSEC status of coresecret.dev. / 🛡️ Retrieve DNSSEC status of coresecret.dev. (push) Has been cancelled
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Has been cancelled
💙 Generating a PUBLIC Live ISO. / 💙 Generating a PUBLIC Live ISO. (push) Has been cancelled
🔐 Generating a Private Live ISO TRIXIE. / 🔐 Generating a Private Live ISO TRIXIE. (push) Has been cancelled
Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
710 lines
21 KiB
Bash
710 lines
21 KiB
Bash
#!/bin/bash
|
|
# SPDX-Version: 3.0
|
|
# SPDX-CreationInfo: 2025-10-06; WEIDNER, Marc S.; <msw@coresecret.dev>
|
|
# SPDX-ExternalRef: GIT https://git.coresecret.dev/msw/CISS.debian.live.builder.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: LicenseRef-CNCL-1.1 OR LicenseRef-CCLA-1.1
|
|
# SPDX-LicenseComment: This file is part of the CISS.debian.installer.secure framework.
|
|
# SPDX-PackageName: CISS.debian.live.builder
|
|
# SPDX-Security-Contact: security@coresecret.eu
|
|
|
|
set -Ceuo pipefail
|
|
umask 0077
|
|
|
|
declare -gx VAR_RDNS_DOMAIN="" # Forward-confirmed reverse DNS domain.
|
|
declare -gx VAR_RDNS_IPV4="" # IPv4 address used for RDNS verification.
|
|
declare -gx VAR_RDNS_NORMALIZED="" # RDNS domain normalized for Primordial branch names.
|
|
declare -gx VAR_PRIMORDIAL_KEY="" # Primordial SSH identity filename.
|
|
declare -gx VAR_PRIMORDIAL_SSH_PORT="" # Primordial SSH port.
|
|
declare -gx VAR_PRIMORDIAL_URL="" # Primordial HTTPS Git URL.
|
|
declare -grx VAR_SEMAPHORE="/root/cdi.ciss" # Semaphore to appear.
|
|
declare -girx VAR_TIMEOUT=3600 # Semaphore timer in seconds.
|
|
|
|
install -d -m 0755 /run/lock
|
|
exec 9> /run/lock/9999_cdi_starter.lock
|
|
flock -n 9 || { echo "9999_cdi_starter already running. Exiting."; exit 0; }
|
|
|
|
#######################################
|
|
# Call into the CISS.debian.installer once the semaphore file is present.
|
|
# Globals:
|
|
# None
|
|
# Arguments:
|
|
# None
|
|
# Returns:
|
|
# 0: on success
|
|
#######################################
|
|
cdi() {
|
|
### Declare Arrays, HashMaps, and Variables.
|
|
declare -i rc=""
|
|
|
|
./ciss_debian_installer.sh \
|
|
--autoinstall \
|
|
--debug XTRACE \
|
|
--log debug \
|
|
--reionice-priority 1 0 \
|
|
--renice-priority "-19" \
|
|
|
|
rc="$?"
|
|
|
|
if [[ "${rc}" -eq 0 ]]; then
|
|
|
|
### In autoinstall mode this command should never be reached due to the reboot command inside ciss_debian_installer.sh.
|
|
logger -t cdi-watcher "cdi(): ciss_debian_installer.sh completed SUCCESSFULLY [${rc}]."
|
|
exit 0
|
|
|
|
else
|
|
|
|
logger -t cdi-watcher "cdi(): ciss_debian_installer.sh FAILED [${rc}]."
|
|
exit "${rc}"
|
|
|
|
fi
|
|
}
|
|
### Prevents accidental 'unset -f'.
|
|
# shellcheck disable=SC2034
|
|
readonly -f cdi
|
|
|
|
#######################################
|
|
# Wait for network connectivity by looping.
|
|
# Globals:
|
|
# None
|
|
# Arguments:
|
|
# None
|
|
# Returns:
|
|
# 0: on success
|
|
#######################################
|
|
net_wait() {
|
|
### Declare Arrays, HashMaps, and Variables.
|
|
declare -i i
|
|
|
|
for ((i=1; i<=60; i++)); do
|
|
|
|
if getent hosts git.coresecret.dev >/dev/null 2>&1; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
return 1
|
|
}
|
|
### Prevents accidental 'unset -f'.
|
|
# shellcheck disable=SC2034
|
|
readonly -f net_wait
|
|
|
|
#######################################
|
|
# Validate an IPv4 address.
|
|
# Globals:
|
|
# None
|
|
# Arguments:
|
|
# $1: IPv4 address
|
|
# Returns:
|
|
# 0: valid IPv4 address
|
|
# 1: invalid IPv4 address
|
|
#######################################
|
|
is_ipv4() {
|
|
### Declare Arrays, HashMaps, and Variables.
|
|
declare -r var_ip="${1:-}"
|
|
declare -a ary_octets=()
|
|
declare var_octet=""
|
|
|
|
[[ "${var_ip}" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]] || return 1
|
|
|
|
IFS='.' read -r -a ary_octets <<< "${var_ip}"
|
|
|
|
for var_octet in "${ary_octets[@]}"; do
|
|
|
|
if ! ((10#${var_octet} <= 255)); then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
return 0
|
|
}
|
|
### Prevents accidental 'unset -f'.
|
|
# shellcheck disable=SC2034
|
|
readonly -f is_ipv4
|
|
|
|
#######################################
|
|
# Validate a DNS domain name returned by RDNS.
|
|
# Globals:
|
|
# None
|
|
# Arguments:
|
|
# $1: domain name
|
|
# Returns:
|
|
# 0: valid domain name
|
|
# 1: invalid domain name
|
|
#######################################
|
|
is_dns_name() {
|
|
### Declare Arrays, HashMaps, and Variables.
|
|
declare -r var_name="${1:-}"
|
|
|
|
[[ "${#var_name}" -le 253 ]] || return 1
|
|
[[ "${var_name}" =~ ^[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+$ ]] \
|
|
|| return 1
|
|
|
|
return 0
|
|
}
|
|
### Prevents accidental 'unset -f'.
|
|
# shellcheck disable=SC2034
|
|
readonly -f is_dns_name
|
|
|
|
#######################################
|
|
# Retrieve and forward-confirm reverse DNS for the active IPv4 route.
|
|
# Globals:
|
|
# VAR_RDNS_DOMAIN
|
|
# VAR_RDNS_IPV4
|
|
# Arguments:
|
|
# $1: module log file
|
|
# Returns:
|
|
# 0: on confirmed RDNS
|
|
# 1: on missing or unconfirmed RDNS
|
|
#######################################
|
|
# retrieve_rdns() intentionally probes optional resolver tools and validation helpers inside conditionals.
|
|
# shellcheck disable=SC2310,SC2312
|
|
retrieve_rdns() {
|
|
### Declare Arrays, HashMaps, and Variables.
|
|
declare -r var_log="${1:-}"
|
|
declare -a ary_a=()
|
|
declare -a ary_rdns=()
|
|
declare -a ary_targets=()
|
|
declare var_a="" var_ipv4="" var_rdns="" var_target=""
|
|
|
|
VAR_RDNS_DOMAIN=""
|
|
VAR_RDNS_IPV4=""
|
|
|
|
mapfile -t ary_targets < <(
|
|
getent ahostsv4 git.coresecret.dev 2>/dev/null \
|
|
| awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}[[:space:]]/ && !seen[$1]++ { print $1 }'
|
|
)
|
|
ary_targets+=( "1.1.1.1" "9.9.9.9" "8.8.8.8" )
|
|
|
|
if command -v ip >/dev/null 2>&1; then
|
|
|
|
for var_target in "${ary_targets[@]}"; do
|
|
|
|
if var_ipv4="$(
|
|
ip -o -4 route get "${var_target}" 2>/dev/null \
|
|
| awk '{ for (i = 1; i <= NF; i++) { if ($i == "src") { print $(i + 1); exit } } }'
|
|
)" && is_ipv4 "${var_ipv4}"; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
var_ipv4=""
|
|
|
|
done
|
|
|
|
if [[ -z "${var_ipv4}" ]]; then
|
|
|
|
mapfile -t ary_targets < <(
|
|
ip -o -4 addr show scope global up 2>/dev/null \
|
|
| awk '{ split($4, addr, "/"); if (!seen[addr[1]]++) { print addr[1] } }'
|
|
)
|
|
|
|
for var_target in "${ary_targets[@]}"; do
|
|
|
|
if is_ipv4 "${var_target}"; then
|
|
|
|
var_ipv4="${var_target}"
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [[ -z "${var_ipv4}" ]]; then
|
|
|
|
logger -t cdi-watcher "retrieve_rdns(): no active IPv4 address found; continuing without RDNS."
|
|
printf "Command: [retrieve_rdns] no active IPv4 address found; continuing without RDNS.\n" >> "${var_log}"
|
|
return 1
|
|
|
|
fi
|
|
|
|
if command -v dig >/dev/null 2>&1; then
|
|
|
|
mapfile -t ary_rdns < <(
|
|
dig +time=3 +tries=1 +short -x "${var_ipv4}" 2>/dev/null \
|
|
| sed 's/[.]$//' \
|
|
| awk 'NF && !seen[$0]++ { print $0 }'
|
|
)
|
|
|
|
fi
|
|
|
|
if ((${#ary_rdns[@]} == 0)) && command -v host >/dev/null 2>&1; then
|
|
|
|
mapfile -t ary_rdns < <(
|
|
host "${var_ipv4}" 2>/dev/null \
|
|
| awk '/domain name pointer/ { sub(/[.]$/, "", $NF); if (!seen[$NF]++) { print $NF } }'
|
|
)
|
|
|
|
fi
|
|
|
|
if ((${#ary_rdns[@]} == 0)); then
|
|
|
|
mapfile -t ary_rdns < <(
|
|
getent hosts "${var_ipv4}" 2>/dev/null \
|
|
| awk '{ for (i = 2; i <= NF; i++) { sub(/[.]$/, "", $i); if (!seen[$i]++) { print $i } } }'
|
|
)
|
|
|
|
fi
|
|
|
|
for var_rdns in "${ary_rdns[@]}"; do
|
|
|
|
var_rdns="${var_rdns%.}"
|
|
var_rdns="${var_rdns,,}"
|
|
|
|
if ! is_dns_name "${var_rdns}"; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
ary_a=()
|
|
|
|
if command -v dig >/dev/null 2>&1; then
|
|
|
|
mapfile -t ary_a < <(
|
|
dig +time=3 +tries=1 +short A "${var_rdns}" 2>/dev/null \
|
|
| awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/ && !seen[$0]++ { print $0 }'
|
|
)
|
|
|
|
fi
|
|
|
|
if ((${#ary_a[@]} == 0)) && command -v host >/dev/null 2>&1; then
|
|
|
|
mapfile -t ary_a < <(
|
|
host -t A "${var_rdns}" 2>/dev/null \
|
|
| awk '/ has address / && !seen[$NF]++ { print $NF }'
|
|
)
|
|
|
|
fi
|
|
|
|
if ((${#ary_a[@]} == 0)); then
|
|
|
|
mapfile -t ary_a < <(
|
|
getent ahostsv4 "${var_rdns}" 2>/dev/null \
|
|
| awk '!seen[$1]++ { print $1 }'
|
|
)
|
|
|
|
fi
|
|
|
|
for var_a in "${ary_a[@]}"; do
|
|
|
|
if is_ipv4 "${var_a}" && [[ "${var_a}" == "${var_ipv4}" ]]; then
|
|
|
|
VAR_RDNS_IPV4="${var_ipv4}"
|
|
VAR_RDNS_DOMAIN="${var_rdns}"
|
|
logger -t cdi-watcher "retrieve_rdns(): confirmed IPv4 ${VAR_RDNS_IPV4} RDNS ${VAR_RDNS_DOMAIN}."
|
|
printf "Command: [retrieve_rdns] confirmed IPv4 [%s] RDNS [%s].\n" \
|
|
"${VAR_RDNS_IPV4}" "${VAR_RDNS_DOMAIN}" >> "${var_log}"
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
logger -t cdi-watcher "retrieve_rdns(): no forward-confirmed RDNS for IPv4 ${var_ipv4}; continuing without RDNS."
|
|
printf "Command: [retrieve_rdns] no forward-confirmed RDNS for IPv4 [%s]; continuing without RDNS.\n" \
|
|
"${var_ipv4}" >> "${var_log}"
|
|
|
|
return 1
|
|
}
|
|
### Prevents accidental 'unset -f'.
|
|
# shellcheck disable=SC2034
|
|
readonly -f retrieve_rdns
|
|
|
|
#######################################
|
|
# Normalize a DNS domain into a Primordial branch name.
|
|
# Globals:
|
|
# None
|
|
# Arguments:
|
|
# $1: DNS domain name
|
|
# Returns:
|
|
# 0: on success
|
|
# 1: on invalid DNS domain
|
|
#######################################
|
|
normalize_rdns_domain() {
|
|
### Declare Arrays, HashMaps, and Variables.
|
|
declare var_domain="${1:-}"
|
|
|
|
var_domain="${var_domain%.}"
|
|
var_domain="${var_domain,,}"
|
|
|
|
# shellcheck disable=SC2310
|
|
is_dns_name "${var_domain}" || return 1
|
|
|
|
printf '%s\n' "${var_domain//./_}"
|
|
|
|
return 0
|
|
}
|
|
### Prevents accidental 'unset -f'.
|
|
# shellcheck disable=SC2034
|
|
readonly -f normalize_rdns_domain
|
|
|
|
#######################################
|
|
# Convert an HTTPS Git URL into the SSH URL used for Primordial clone.
|
|
# Globals:
|
|
# None
|
|
# Arguments:
|
|
# $1: HTTPS Git URL
|
|
# $2: SSH port
|
|
# Returns:
|
|
# 0: on success
|
|
# 1: on invalid URL or port
|
|
#######################################
|
|
derive_ssh_git_url() {
|
|
### Declare Arrays, HashMaps, and Variables.
|
|
declare -r var_https_url="${1:-}"
|
|
declare -r var_ssh_port="${2:-}"
|
|
declare var_host="" var_path=""
|
|
|
|
if [[ ! "${var_https_url}" =~ ^https://([A-Za-z0-9.-]+)/([A-Za-z0-9._~/%+=:@,-]+\.git)$ ]]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
var_host="${BASH_REMATCH[1]}"
|
|
var_path="${BASH_REMATCH[2]}"
|
|
|
|
if [[ -z "${var_host}" || -z "${var_path}" || ! "${var_ssh_port}" =~ ^[0-9]+$ ]] \
|
|
|| ((10#${var_ssh_port} < 1 || 10#${var_ssh_port} > 65535)); then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
printf 'ssh://git@%s:%s/%s\n' "${var_host}" "${var_ssh_port}" "${var_path}"
|
|
|
|
return 0
|
|
}
|
|
### Prevents accidental 'unset -f'.
|
|
# shellcheck disable=SC2034
|
|
readonly -f derive_ssh_git_url
|
|
|
|
#######################################
|
|
# Apply the Primordial overlay and create the CDI semaphore only on success.
|
|
# Globals:
|
|
# VAR_PRIMORDIAL_KEY
|
|
# VAR_PRIMORDIAL_SSH_PORT
|
|
# VAR_PRIMORDIAL_URL
|
|
# VAR_RDNS_DOMAIN
|
|
# VAR_RDNS_NORMALIZED
|
|
# VAR_SEMAPHORE
|
|
# Arguments:
|
|
# $1: module log file
|
|
# $2: CISS.debian.installer directory
|
|
# Returns:
|
|
# 0: on success or optional skip
|
|
# 1: on failed configured Primordial overlay
|
|
#######################################
|
|
apply_primordial_overlay() {
|
|
### Declare Arrays, HashMaps, and Variables.
|
|
declare -r var_log="${1:-}"
|
|
declare -r var_repo_dir="${2:-}"
|
|
declare -r var_overlay_dir="/root/git/overlay"
|
|
declare var_identity="" var_ssh_url="" var_rdns_normalized=""
|
|
|
|
if [[ -z "${VAR_PRIMORDIAL_URL}" && -z "${VAR_PRIMORDIAL_KEY}" && -z "${VAR_PRIMORDIAL_SSH_PORT}" ]]; then
|
|
|
|
logger -t cdi-watcher "Primordial overlay not configured; continuing with existing semaphore polling."
|
|
printf "Command: [apply_primordial_overlay] skipped; Primordial overlay not configured.\n" >> "${var_log}"
|
|
return 0
|
|
|
|
fi
|
|
|
|
if ! rm -f -- "${VAR_SEMAPHORE}"; then
|
|
|
|
logger -t cdi-watcher "Failed to remove existing CDI semaphore; aborting CDI autostart."
|
|
printf "Command: [rm -f -- %s] failed; aborting CDI autostart.\n" "${VAR_SEMAPHORE}" >> "${var_log}"
|
|
return 1
|
|
|
|
fi
|
|
|
|
if [[ -z "${VAR_PRIMORDIAL_URL}" || -z "${VAR_PRIMORDIAL_KEY}" || -z "${VAR_PRIMORDIAL_SSH_PORT}" || -z "${VAR_RDNS_DOMAIN}" ]]; then
|
|
|
|
logger -t cdi-watcher "Primordial overlay configuration incomplete; aborting CDI autostart."
|
|
printf "Command: [apply_primordial_overlay] failed; Primordial URL, key, SSH port, and RDNS domain are required.\n" >> "${var_log}"
|
|
return 1
|
|
|
|
fi
|
|
|
|
# shellcheck disable=SC2310
|
|
if ! var_rdns_normalized="$(normalize_rdns_domain "${VAR_RDNS_DOMAIN}")"; then
|
|
|
|
logger -t cdi-watcher "Primordial overlay RDNS branch derivation failed; aborting CDI autostart."
|
|
printf "Command: [normalize_rdns_domain %s] failed; aborting CDI autostart.\n" "${VAR_RDNS_DOMAIN}" >> "${var_log}"
|
|
return 1
|
|
|
|
fi
|
|
|
|
declare -gx VAR_RDNS_NORMALIZED="${var_rdns_normalized}"
|
|
|
|
# shellcheck disable=SC2310
|
|
if ! var_ssh_url="$(derive_ssh_git_url "${VAR_PRIMORDIAL_URL}" "${VAR_PRIMORDIAL_SSH_PORT}")"; then
|
|
|
|
logger -t cdi-watcher "Primordial HTTPS Git URL conversion failed; aborting CDI autostart."
|
|
printf "Command: [derive_ssh_git_url] failed for configured Primordial URL; aborting CDI autostart.\n" >> "${var_log}"
|
|
return 1
|
|
|
|
fi
|
|
|
|
var_identity="/root/.ssh/${VAR_PRIMORDIAL_KEY}"
|
|
|
|
if [[ ! -e "${var_identity}" ]]; then
|
|
|
|
logger -t cdi-watcher "Primordial SSH identity file is missing; aborting CDI autostart."
|
|
printf "Command: [test -e /root/.ssh/<primordial-key>] failed; aborting CDI autostart.\n" >> "${var_log}"
|
|
return 1
|
|
|
|
fi
|
|
|
|
if [[ ! -f "${var_identity}" ]]; then
|
|
|
|
logger -t cdi-watcher "Primordial SSH identity path is not a regular file; aborting CDI autostart."
|
|
printf "Command: [test -f /root/.ssh/<primordial-key>] failed; aborting CDI autostart.\n" >> "${var_log}"
|
|
return 1
|
|
|
|
fi
|
|
|
|
if [[ ! -r "${var_identity}" ]]; then
|
|
|
|
logger -t cdi-watcher "Primordial SSH identity file is not readable by root; aborting CDI autostart."
|
|
printf "Command: [test -r /root/.ssh/<primordial-key>] failed; aborting CDI autostart.\n" >> "${var_log}"
|
|
return 1
|
|
|
|
fi
|
|
|
|
if ! rm -rf -- "${var_overlay_dir}"; then
|
|
|
|
logger -t cdi-watcher "Failed to remove existing Primordial overlay directory; aborting CDI autostart."
|
|
printf "Command: [rm -rf -- %s] failed; aborting CDI autostart.\n" "${var_overlay_dir}" >> "${var_log}"
|
|
return 1
|
|
|
|
fi
|
|
|
|
if ! GIT_SSH_COMMAND="ssh -i ${var_identity} -p ${VAR_PRIMORDIAL_SSH_PORT}" \
|
|
git clone --branch "${VAR_RDNS_NORMALIZED}" "${var_ssh_url}" "${var_overlay_dir}"; then
|
|
|
|
logger -t cdi-watcher "Primordial overlay clone failed; aborting CDI autostart."
|
|
printf "Command: [git clone --branch %s <primordial-ssh-url> %s] failed; aborting CDI autostart.\n" \
|
|
"${VAR_RDNS_NORMALIZED}" "${var_overlay_dir}" >> "${var_log}"
|
|
rm -rf -- "${var_overlay_dir}" || true
|
|
return 1
|
|
|
|
fi
|
|
|
|
if [[ ! -d "${var_overlay_dir}/.preseed" ]]; then
|
|
|
|
logger -t cdi-watcher "Primordial overlay .preseed directory is missing; aborting CDI autostart."
|
|
printf "Command: [test -d %s/.preseed] failed; aborting CDI autostart.\n" "${var_overlay_dir}" >> "${var_log}"
|
|
return 1
|
|
|
|
fi
|
|
|
|
if [[ ! -d "${var_overlay_dir}/includes" ]]; then
|
|
|
|
logger -t cdi-watcher "Primordial overlay includes directory is missing; aborting CDI autostart."
|
|
printf "Command: [test -d %s/includes] failed; aborting CDI autostart.\n" "${var_overlay_dir}" >> "${var_log}"
|
|
return 1
|
|
|
|
fi
|
|
|
|
install -d -m 0700 "${var_repo_dir}/.preseed" "${var_repo_dir}/includes"
|
|
|
|
if ! rsync -av "${var_overlay_dir}/.preseed/" "${var_repo_dir}/.preseed/"; then
|
|
|
|
logger -t cdi-watcher "Primordial overlay .preseed rsync failed; aborting CDI autostart."
|
|
printf "Command: [rsync -av %s/.preseed/ %s/.preseed/] failed; aborting CDI autostart.\n" \
|
|
"${var_overlay_dir}" "${var_repo_dir}" >> "${var_log}"
|
|
return 1
|
|
|
|
fi
|
|
|
|
if ! rsync -av "${var_overlay_dir}/includes/" "${var_repo_dir}/includes"; then
|
|
|
|
logger -t cdi-watcher "Primordial overlay includes rsync failed; aborting CDI autostart."
|
|
printf "Command: [rsync -av %s/includes/ %s/includes] failed; aborting CDI autostart.\n" \
|
|
"${var_overlay_dir}" "${var_repo_dir}" >> "${var_log}"
|
|
return 1
|
|
|
|
fi
|
|
|
|
if ! install -m 0600 /dev/null "${VAR_SEMAPHORE}"; then
|
|
|
|
logger -t cdi-watcher "Primordial overlay applied but semaphore creation failed; aborting CDI autostart."
|
|
printf "Command: [install -m 0600 /dev/null %s] failed; aborting CDI autostart.\n" "${VAR_SEMAPHORE}" >> "${var_log}"
|
|
return 1
|
|
|
|
fi
|
|
|
|
logger -t cdi-watcher "Primordial overlay applied for branch ${VAR_RDNS_NORMALIZED}; CDI semaphore created."
|
|
printf "Command: [apply_primordial_overlay] executed for branch [%s].\n" "${VAR_RDNS_NORMALIZED}" >> "${var_log}"
|
|
|
|
return 0
|
|
}
|
|
### Prevents accidental 'unset -f'.
|
|
# shellcheck disable=SC2034
|
|
readonly -f apply_primordial_overlay
|
|
|
|
#######################################
|
|
# Wrapper for loading CISS hardened Kernel Parameters.
|
|
# Globals:
|
|
# None
|
|
# Arguments:
|
|
# None
|
|
# Returns:
|
|
# 0: on success
|
|
#######################################
|
|
sysp() {
|
|
sysctl -p /etc/sysctl.d/90-ciss-local.hardened
|
|
|
|
# shellcheck disable=SC2312
|
|
sysctl -a | grep -E '^(kernel|vm|net)\.' >| "/var/log/sysctl_check_$(date +'%Y-%m-%d_%H-%M-%S').log"
|
|
|
|
return 0
|
|
}
|
|
### Prevents accidental 'unset -f'.
|
|
# shellcheck disable=SC2034
|
|
readonly -f sysp
|
|
|
|
#######################################
|
|
# Main autostart function.
|
|
# Arguments:
|
|
# None
|
|
#######################################
|
|
main() {
|
|
### Declare Arrays, HashMaps, and Variables.
|
|
declare -r var_repo_url="https://git.coresecret.dev/msw/CISS.debian.installer.git"
|
|
declare -r var_repo_dir="/root/git/CISS.debian.installer"
|
|
declare -i i=""
|
|
declare var_log="" var_mode=""
|
|
|
|
### Prepare logging.
|
|
install -d -m 0700 /root/.ciss/cdi
|
|
install -d -m 0700 /root/.ciss/cdi/log
|
|
var_log="/root/.ciss/cdi/log/9999-cdi-starter_$(date +"%Y-%m-%d_%H-%M-%S").log"
|
|
touch "${var_log}"
|
|
|
|
printf "CISS.debian.live.builder V9.14.026.2026.06.17 calling CISS.debian.installer ... \n" >> "${var_log}"
|
|
|
|
### Sleep a moment to settle boot artifacts.
|
|
sleep 8
|
|
|
|
### Harden Kernel parameters.
|
|
printf "Command: [sysp] to be executed ... \n" >> "${var_log}"
|
|
sysp
|
|
printf "Command: [sysp] executed.\n" >> "${var_log}"
|
|
|
|
### Wait for network connectivity.
|
|
printf "Command: [net_wait] to be executed ... \n" >> "${var_log}"
|
|
# shellcheck disable=SC2310
|
|
if ! net_wait; then
|
|
|
|
logger -t cdi-watcher "Network/DNS not available after 60s; skipping online bootstrap."
|
|
printf "Command: [net_wait] no DNS/network after 60s; skipping apt/git bootstrap.\n" >> "${var_log}"
|
|
### Do not mark the service as failed when the system is simply offline.
|
|
exit 0
|
|
|
|
fi
|
|
printf "Command: [net_wait] executed.\n" >> "${var_log}"
|
|
|
|
### Retrieve forward-confirmed reverse DNS.
|
|
printf "Command: [retrieve_rdns] to be executed ... \n" >> "${var_log}"
|
|
# shellcheck disable=SC2310
|
|
retrieve_rdns "${var_log}" || true
|
|
printf "Command: [retrieve_rdns] executed.\n" >> "${var_log}"
|
|
|
|
### apt update.
|
|
if ! apt-get update >> "${var_log}"; then
|
|
|
|
logger -t cdi-watcher "apt-get update failed; continuing without package refresh."
|
|
printf "Command: [apt-get update] failed; continuing without package refresh.\n" >> "${var_log}"
|
|
|
|
fi
|
|
|
|
### Download CISS.debian.installer.
|
|
install -d -m 0700 /root/git
|
|
cd /root/git
|
|
|
|
[[ -d "${var_repo_dir}" ]] && rm -rf "${var_repo_dir}"
|
|
|
|
if ! git clone "${var_repo_url}" "${var_repo_dir}"; then
|
|
|
|
logger -t cdi-watcher "git clone of ${var_repo_url} failed; aborting CDI autostart."
|
|
printf "Command: [git clone %s %s] failed; aborting CDI autostart.\n" "${var_repo_url}" "${var_repo_dir}" >> "${var_log}"
|
|
exit 0
|
|
|
|
fi
|
|
|
|
chmod 0700 "${var_repo_dir}/ciss_debian_installer.sh"
|
|
cd "${var_repo_dir}"
|
|
printf "Command: [git clone %s %s] executed.\n" "${var_repo_url}" "${var_repo_dir}" >> "${var_log}"
|
|
|
|
### Apply Primordial overlay before allowing CDI autostart.
|
|
# shellcheck disable=SC2310
|
|
if ! apply_primordial_overlay "${var_log}" "${var_repo_dir}"; then
|
|
|
|
logger -t cdi-watcher "Primordial overlay failed; CDI autostart aborted before semaphore polling."
|
|
printf "Command: [apply_primordial_overlay] failed; CDI autostart aborted before semaphore polling.\n" >> "${var_log}"
|
|
exit 0
|
|
|
|
fi
|
|
|
|
### Poll up to VAR_TIMEOUT seconds for the semaphore to appear and be mode 0600.
|
|
for ((i=0; i<VAR_TIMEOUT; i++)); do
|
|
|
|
if [[ -e "${VAR_SEMAPHORE}" && ! -s "${VAR_SEMAPHORE}" ]]; then
|
|
|
|
var_mode="$(stat -c '%a' -- "${VAR_SEMAPHORE}" 2>/dev/null || echo '?')"
|
|
|
|
if [[ "${var_mode}" == "600" ]]; then
|
|
|
|
logger -t cdi-watcher "Semaphore found (${VAR_SEMAPHORE}, mode 0600) after ${i}s -> invoking cdi()"
|
|
printf "Command: [cdi] to be executed.\n" >> "${var_log}"
|
|
|
|
cdi
|
|
### cdi() never returns (it exits the script), so no code below this point in the 'then'-block will run.
|
|
|
|
else
|
|
|
|
logger -t cdi-watcher "Semaphore ${VAR_SEMAPHORE} present but wrong mode ${var_mode} (expected 600); ignoring"
|
|
printf "INFO: [Semaphore %s present but wrong mode %s (expected 600); ignoring] executed.\n" "${VAR_SEMAPHORE}" "${var_mode}" >> "${var_log}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
### Timeout reached without acceptable semaphore.
|
|
logger -t cdi-watcher "No valid semaphore ${VAR_SEMAPHORE} (mode 0600) within ${VAR_TIMEOUT}s; exiting idle."
|
|
printf "CISS.debian.live.builder V9.14.026.2026.06.17: No valid semaphore [%s] within [%s]s.\n" "${VAR_SEMAPHORE}" "${VAR_TIMEOUT}" >> "${var_log}"
|
|
|
|
exit 0
|
|
}
|
|
### Prevents accidental 'unset -f'.
|
|
# shellcheck disable=SC2034
|
|
readonly -f main
|
|
|
|
main "$@"
|
|
|
|
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh
|