#!/bin/bash # SPDX-Version: 3.0 # SPDX-CreationInfo: 2025-02-13; WEIDNER, Marc S.; # 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.; # 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.7.9. Functions - installation - setup hostname # ########################################################################################### ########################################################################################### # Generate files: '/etc/hostname' | '/etc/hosts' | '/etc/mailname' # Globals: # FINAL_FQDN # FINAL_IPV4_ADDRESS # FINAL_IPV6 # FINAL_IPV6_ADDRESS # MODULE_ERR # MODULE_TXT # TARGET # network_hostname # network_ipv6 # Arguments: # None ########################################################################################### 3_7_9_functions_installation_setup_hostname() { declare -g -x MODULE_ERR="3_7_9_functions_installation_setup_hostname" declare -g -x MODULE_TXT="Setup hostname '${network_hostname}'" do_show_header "${MODULE_TXT}" # Create '${TARGET}/etc/hostname' file. if [[ -f "${TARGET}"/etc/hostname ]]; then rm "${TARGET}"/etc/hostname do_log "info" "false" "Existing '${TARGET}/etc/hostname' removed." fi touch "${TARGET}"/etc/hostname chmod 0644 "${TARGET}"/etc/hostname cat << EOF >> "${TARGET}"/etc/hostname "${FINAL_FQDN}" EOF do_log "info" "false" "File generated: '${TARGET}/etc/hostname' | hostname '${network_hostname}'." # Create '${TARGET}/etc/mailname' file. if [[ -f "${TARGET}"/etc/mailname ]]; then rm "${TARGET}"/etc/mailname do_log "info" "false" "Existing '${TARGET}/etc/mailname' removed." fi touch "${TARGET}"/etc/mailname chmod 0644 "${TARGET}"/etc/mailname cat << EOF >> "${TARGET}"/etc/mailname "${FINAL_FQDN}" EOF do_log "info" "false" "File generated: '${TARGET}/etc/mailname' | mailname '${network_hostname}'." # Generate '${TARGET}/etc/hosts' basic IPv4 entries if [[ -f "${TARGET}"/etc/hosts ]]; then rm "${TARGET}"/etc/hosts do_log "info" "false" "Existing '${TARGET}/etc/hosts' removed." fi touch "${TARGET}"/etc/hosts chmod 0644 "${TARGET}"/etc/hosts cat << EOF >> "${TARGET}"/etc/hosts 127.0.0.1 localhost "${FINAL_IPV4_ADDRESS}" "${FINAL_FQDN}" EOF do_log "info" "false" "File generated: '${TARGET}/etc/hosts' with basic IPv4 entries." # Generate '${TARGET}/etc/hosts' basic IPv6 entries if [[ ${FINAL_IPV6,,} == "true" || ${network_ipv6,,} == "true" ]]; then cat << EOF >> "${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 "${FINAL_IPV6_ADDRESS}" "${FINAL_FQDN}" EOF do_log "info" "false" "File updated: '${TARGET}/etc/hosts' with basic IPv6 entries." fi do_show_footer "${MODULE_TXT}" } # vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh: