All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 1m53s
Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
89 lines
2.7 KiB
Bash
89 lines
2.7 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 || return "${ERR_GUARD_SOURCE}"
|
|
|
|
#######################################
|
|
# Configure the '/etc/hostname' | '/etc/hosts' | '/etc/mailname' files.
|
|
# Globals:
|
|
# RECOVERY
|
|
# TARGET
|
|
# VAR_FINAL_FQDN
|
|
# VAR_FINAL_IPV4
|
|
# VAR_FINAL_IPV6
|
|
# VAR_LINK_IPV6
|
|
# VAR_RUN_RECOVERY
|
|
# network_ipv6
|
|
# Arguments:
|
|
# None
|
|
# Returns:
|
|
# 0: on success
|
|
#######################################
|
|
setup_hostname() {
|
|
### Declare Arrays, HashMaps, and Variables.
|
|
declare var_target="${TARGET}"
|
|
|
|
### Check for TARGET / RECOVERY.
|
|
[[ "${VAR_RUN_RECOVERY}" == "true" ]] && var_target="${RECOVERY}"
|
|
|
|
### Create the '${var_target}/etc/hostname' file.
|
|
cat << EOF >| "${var_target}/etc/hostname"
|
|
${VAR_FINAL_FQDN}
|
|
EOF
|
|
chmod 0644 "${var_target}/etc/hostname"
|
|
do_log "info" "file_only" "4030() File generated: '${var_target}/etc/hostname' | hostname '${VAR_FINAL_FQDN}'."
|
|
|
|
|
|
### Create the '${var_target}/etc/mailname' file.
|
|
cat << EOF >| "${var_target}/etc/mailname"
|
|
${VAR_FINAL_FQDN}
|
|
EOF
|
|
chmod 0644 "${var_target}/etc/mailname"
|
|
do_log "info" "file_only" "4030() File generated: '${var_target}/etc/mailname' | mailname '${VAR_FINAL_FQDN}'."
|
|
|
|
|
|
### Generate '${var_target}/etc/hosts' basic IPv4 entries
|
|
cat << EOF >| "${var_target}/etc/hosts"
|
|
127.0.0.1 localhost
|
|
${VAR_FINAL_IPV4} ${VAR_FINAL_FQDN}
|
|
|
|
EOF
|
|
chmod 0644 "${var_target}/etc/hosts"
|
|
do_log "info" "file_only" "4030() File generated: '${var_target}/etc/hosts' with basic IPv4 entries."
|
|
|
|
|
|
### Generate '${var_target}/etc/hosts' basic IPv6 entries
|
|
if [[ "${VAR_LINK_IPV6,,}" == "true" || "${network_ipv6,,}" == "true" ]]; then
|
|
|
|
cat << EOF >> "${var_target}/etc/hosts"
|
|
# The following lines are desirable for IPv6 capable hosts
|
|
::1 localhost ip6-localhost ip6-loopback
|
|
fe00::0 ip6-localnet
|
|
ff00::0 ip6-mcastprefix
|
|
ff02::1 ip6-allnodes
|
|
ff02::2 ip6-allrouters
|
|
ff02::3 ip6-allhosts
|
|
${VAR_FINAL_IPV6} ${VAR_FINAL_FQDN}
|
|
|
|
EOF
|
|
|
|
do_log "info" "file_only" "4030() File updated: '${var_target}/etc/hosts' with basic IPv6 entries."
|
|
|
|
fi
|
|
|
|
guard_dir; return 0
|
|
}
|
|
### Prevents accidental 'unset -f'.
|
|
# shellcheck disable=SC2034
|
|
readonly -f setup_hostname
|
|
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh
|