V8.00.000.2025.06.17
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 1m41s

Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
2025-08-28 17:40:06 +02:00
parent 44b3d1fb60
commit d43638d262
10 changed files with 159 additions and 189 deletions

View File

@@ -18,8 +18,6 @@ guard_sourcing
# ARY_IPV4_NS
# ARY_IPV6_NS
# TARGET
# VAR_ARCHITECTURE
# VAR_CODENAME
# VAR_FINAL_IPV4
# VAR_FINAL_IPV4_GW
# VAR_FINAL_IPV4_SUBNET
@@ -28,22 +26,42 @@ guard_sourcing
# VAR_FINAL_IPV6_SUBNET
# VAR_FINAL_NIC
# VAR_LINK_IPV6
# VAR_VERSION
# network_autoconfig_enable
# network_choose_interface_auto
# network_static_ipv4nameserver_0
# network_static_ipv6address
# network_static_ipv6nameserver_0
# Arguments:
# None
# None
# Returns:
# 0: on success
#######################################
installation_network() {
### Declare Arrays, HashMaps, and Variables.
declare var_supersede="" var_supersede_ipv6=""
declare -r var_logfile="/root/.ciss/cdi/log/4300_installation_network.log"
chroot_exec "${TARGET}" apt-get install -y dhcpcd-base
chroot_logger "${TARGET}${var_logfile}"
chroot_script "${TARGET}" "
export INITRD=No
apt-get purge -y dhcpcd isc-dhcp-client 2>&1 | tee -a ${var_logfile}
echo ExitCode: \$? >> ${var_logfile}
"
chroot_script "${TARGET}" "
export INITRD=No
apt-get install -y --no-install-suggests ifupdown dhcpcd-base 2>&1 | tee -a ${var_logfile}
echo ExitCode: \$? >> ${var_logfile}
"
chroot_script "${TARGET}" "
systemctl disable systemd-networkd NetworkManager 2>/dev/null | tee -a ${var_logfile} || true
systemctl disable dhcpcd.service 2>/dev/null | tee -a ${var_logfile} || true
echo ExitCode: \$? >> ${var_logfile}
"
chroot_exec "${TARGET}"
mkdir -p "${TARGET}/etc/network/interfaces.d"
### Create a network configuration file header.
@@ -55,67 +73,41 @@ installation_network() {
fi
cat << EOF >| "${TARGET}/etc/network/interfaces"
# SPDX-Version: 3.0
# SPDX-CreationInfo: ${VAR_DATE}; 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
# Static file system information: /etc/network/interfaces
# Generated by CISS.debian.installer ${VAR_VERSION}
# Architecture: ${VAR_ARCHITECTURE}
# Distribution: ${VAR_CODENAME}
### Reminder ###
# auto:
# For servers or systems with static interfaces that should always be available (e.g., eth0 on a server).
# For configurations where the interface should be active regardless of the cable status.
# allow-hotplug:
# For systems with dynamic or removable network devices (e.g., laptops or USB adapters).
# To avoid boot delays when interfaces are unavailable.
insert_header "${TARGET}/etc/network/interfaces"
insert_comments "${TARGET}/etc/network/interfaces"
cat << EOF >> "${TARGET}/etc/network/interfaces"
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
source-directory /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
auto ${VAR_FINAL_NIC}
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh
EOF
chmod 0644 "${TARGET}/etc/network/interfaces"
do_log "info" "file_only" "4300() Header '${TARGET}/etc/network/interfaces' created."
### Configure network interfaces based on 'preseed.yaml' and create network configuration files for IPv4.
if [[ "${network_autoconfig_enable}" == "true" && "${network_choose_interface_auto}" == "true" ]]; then
### Reminder ###
# auto:
# For servers or systems with static interfaces that should always be available (e.g., eth0 on a server).
# For configurations where the interface should be active regardless of the cable status.
# allow-hotplug:
# For systems with dynamic or removable network devices (e.g., laptops or USB adapters).
# To avoid boot delays when interfaces are unavailable.
cat << EOF >| "${TARGET}/etc/network/interfaces.d/10-ipv4-dhcp"
# SPDX-Version: 3.0
# SPDX-CreationInfo: ${VAR_DATE}; 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
# Static file system information: /etc/network/interfaces.d/10-ipv4-dhcp
# Generated by CISS.debian.installer ${VAR_VERSION}
# Architecture: ${VAR_ARCHITECTURE}
# Distribution: ${VAR_CODENAME}
# The primary network interface IPv4
auto ${VAR_FINAL_NIC}
insert_header "${TARGET}/etc/network/interfaces.d/10-ipv4-dhcp"
insert_comments "${TARGET}/etc/network/interfaces.d/10-ipv4-dhcp"
cat << EOF >> "${TARGET}/etc/network/interfaces.d/10-ipv4-dhcp"
# The primary network interface: IPv4 via DHCP
iface ${VAR_FINAL_NIC} inet dhcp
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh
@@ -125,25 +117,10 @@ EOF
elif [[ "${network_autoconfig_enable}" == "true" && "${network_choose_interface_auto}" == "false" ]]; then
cat << EOF >| "${TARGET}/etc/network/interfaces.d/10-ipv4-dhcp"
# SPDX-Version: 3.0
# SPDX-CreationInfo: ${VAR_DATE}; 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
# Static file system information: /etc/network/interfaces.d/10-ipv4-dhcp
# Generated by CISS.debian.installer ${VAR_VERSION}
# Architecture: ${VAR_ARCHITECTURE}
# Distribution: ${VAR_CODENAME}
# The primary network interface IPv4
auto ${VAR_FINAL_NIC}
insert_header "${TARGET}/etc/network/interfaces.d/10-ipv4-dhcp"
insert_comments "${TARGET}/etc/network/interfaces.d/10-ipv4-dhcp"
cat << EOF >> "${TARGET}/etc/network/interfaces.d/10-ipv4-dhcp"
# The primary network interface: IPv4 via DHCP
iface ${VAR_FINAL_NIC} inet dhcp
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh
@@ -156,25 +133,10 @@ EOF
if [[ "${network_autoconfig_enable}" == "false" ]]; then
# shellcheck disable=SC2153
cat << EOF >| "${TARGET}/etc/network/interfaces.d/10-ipv4-static"
# SPDX-Version: 3.0
# SPDX-CreationInfo: ${VAR_DATE}; 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
# Static file system information: /etc/network/interfaces.d/10-ipv4-static
# Generated by CISS.debian.installer ${VAR_VERSION}
# Architecture: ${VAR_ARCHITECTURE}
# Distribution: ${VAR_CODENAME}
# The primary network interface IPv4
auto ${VAR_FINAL_NIC}
insert_header "${TARGET}/etc/network/interfaces.d/10-ipv4-static"
insert_comments "${TARGET}/etc/network/interfaces.d/10-ipv4-static"
cat << EOF >> "${TARGET}/etc/network/interfaces.d/10-ipv4-static"
# The primary network interface: IPv4 via static IP
iface ${VAR_FINAL_NIC} inet static
address ${VAR_FINAL_IPV4}
netmask ${VAR_FINAL_IPV4_SUBNET}
@@ -188,59 +150,29 @@ EOF
fi
### Configure network interfaces based on 'preseed.yaml' and create network configuration files for IPv6.
if [[ "${network_autoconfig_enable}" == "true" && "${VAR_LINK_IPV6}" == "true" ]]; then
if [[ "${network_autoconfig_enable}" == "true" && "${VAR_LINK_IPV6}" == "true" && -z "${network_static_ipv6address}" ]]; then
cat << EOF >| "${TARGET}/etc/network/interfaces.d/10-ipv6-dhcp"
# SPDX-Version: 3.0
# SPDX-CreationInfo: ${VAR_DATE}; 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
# Static file system information: /etc/network/interfaces.d/10-ipv6-dhcp
# Generated by CISS.debian.installer ${VAR_VERSION}
# Architecture: ${VAR_ARCHITECTURE}
# Distribution: ${VAR_CODENAME}
# The primary network interface IPv6
auto ${VAR_FINAL_NIC}
iface ${VAR_FINAL_NIC} inet6 dhcp
insert_header "${TARGET}/etc/network/interfaces.d/10-ipv6-dhcp"
insert_comments "${TARGET}/etc/network/interfaces.d/10-ipv6-dhcp"
cat << EOF >> "${TARGET}/etc/network/interfaces.d/10-ipv6-dhcp"
# The primary network interface: IPv6 via SLAAC (+ stateless DHCPv6 for DNS)
iface ${VAR_FINAL_NIC} inet6 auto
accept_ra 2
dhcp 1
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh
EOF
chmod 0644 "${TARGET}/etc/network/interfaces.d/10-ipv6-dhcp"
do_log "info" "file_only" "4300() IPv6 on the primary NIC: '${VAR_FINAL_NIC}' configured with DHCP."
fi
elif [[ "${VAR_LINK_IPV6}" == "true" && -n "${network_static_ipv6address}" ]]; then
if [[ "${network_autoconfig_enable}" == "false" && -n "${network_static_ipv6address}" ]]; then
# shellcheck disable=SC2153
cat << EOF >| "${TARGET}/etc/network/interfaces.d/10-ipv6-static"
# SPDX-Version: 3.0
# SPDX-CreationInfo: ${VAR_DATE}; 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
# Static file system information: /etc/network/interfaces.d/10-ipv6-static
# Generated by CISS.debian.installer ${VAR_VERSION}
# Architecture: ${VAR_ARCHITECTURE}
# Distribution: ${VAR_CODENAME}
# The primary network interface IPv6
auto ${VAR_FINAL_NIC}
insert_header "${TARGET}/etc/network/interfaces.d/10-ipv6-static"
insert_comments "${TARGET}/etc/network/interfaces.d/10-ipv6-static"
cat << EOF >> "${TARGET}/etc/network/interfaces.d/10-ipv6-static"
# The primary network interface: IPv6 via static IP
iface ${VAR_FINAL_NIC} inet6 static
address ${VAR_FINAL_IPV6}/${VAR_FINAL_IPV6_SUBNET}
gateway ${VAR_FINAL_IPV6_GW}
@@ -255,60 +187,73 @@ EOF
### Ensure 'dhcpcd-base' DHCP Client is not overwriting the static nameserver settings.
if [[ "${network_autoconfig_enable}" == "true" && -n "${network_static_ipv4nameserver_0}" ]]; then
if [[ -f "${TARGET}/etc/dhcpcd.conf" ]]; then
if [[ -f "${TARGET}/etc/dhcpcd.conf" ]]; then
mkdir -p "${TARGET}/root/.ciss/cdi/backup/etc"
mv "${TARGET}/etc/dhcpcd.conf" "${TARGET}/root/.ciss/cdi/backup/etc/dhcpcd.conf.bak"
do_log "info" "file_only" "4300() Existing '${TARGET}/etc/dhcpcd.conf' moved."
mkdir -p "${TARGET}/root/.ciss/cdi/backup/etc"
mv "${TARGET}/etc/dhcpcd.conf" "${TARGET}/root/.ciss/cdi/backup/etc/dhcpcd.conf.bak"
do_log "info" "file_only" "4300() Existing '${TARGET}/etc/dhcpcd.con' copied."
fi
fi
insert_header "${TARGET}/etc/dhcpcd.conf"
insert_comments "${TARGET}/etc/dhcpcd.conf"
cat << 'EOF' >> "${TARGET}/etc/dhcpcd.conf"
### A ServerID is required by RFC2131.
require dhcp_server_identifier
insert_header "${TARGET}/etc/dhcpcd.conf"
insert_comments "${TARGET}/etc/dhcpcd.conf"
cat << EOF >> "${TARGET}/etc/dhcpcd.conf"
### Global defaults for all interfaces.
### Respect the network MTU. This is applied to DHCP routes.
option interface_mtu
### A list of options to request from the DHCP server.
option host_name
option domain_name
option domain_search
option domain_name_servers
### Most distributions have NTP support.
option ntp_servers
### Ask server to update both A and PTR via FQDN (RFC 4702 semantics).
fqdn both
### Enforce static DNS and prevent dhcpcd from writing 'resolv.conf'.
EOF
if [[ -n "${network_static_ipv4nameserver_0}" ]]; then
cat << EOF >> "${TARGET}/etc/dhcpcd.conf"
### Enforce static DNS
nooption domain_name_servers
nohook resolv.conf rdnssd
nohook rdnssd
### Static resolvers (IPv4).
### (This does NOT write '/etc/resolv.conf' because of nohook above.)
interface ${VAR_FINAL_NIC}
EOF
var_supersede=$(printf "%s " "${ARY_IPV4_NS[@]}")
echo "static domain_name_servers=${var_supersede}" >> "${TARGET}/etc/dhcpcd.conf"
echo " static domain_name_servers=${var_supersede}" >> "${TARGET}/etc/dhcpcd.conf"
do_log "info" "file_only" "4300() DHCP client configuration for IPv4: '${TARGET}/etc/dhcpcd.conf' configured."
fi
if [[ -n "${network_static_ipv6nameserver_0}" ]]; then
if [[ "${network_autoconfig_enable}" == "false" && -n "${network_static_ipv6nameserver_0}" ]]; then
cat << EOF >> "${TARGET}/etc/dhcpcd.conf"
### Static resolvers (IPv6).
EOF
var_supersede_ipv6=$(printf "%s " "${ARY_IPV6_NS[@]}")
echo "static domain_name_servers=${var_supersede_ipv6}" >> "${TARGET}/etc/dhcpcd.conf"
echo " static domain_name_servers=${var_supersede_ipv6}" >> "${TARGET}/etc/dhcpcd.conf"
do_log "info" "file_only" "4300() DHCP client configuration for IPv6: '${TARGET}/etc/dhcpcd.conf' configured."
fi
if [[ "${network_autoconfig_enable}" == "true" && -n "${network_static_ipv4nameserver_0}" ]]; then
cat << EOF >> "${TARGET}/etc/dhcpcd.conf"
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=conf
EOF
fi
### Footer (always)
echo '' >> "${TARGET}/etc/dhcpcd.conf"
echo '# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=conf' >> "${TARGET}/etc/dhcpcd.conf"
guard_dir && return 0
}