#!/bin/bash # Reference-only fresh KIM2027 ALT clones. Called by kim2027-apply.py via QGA. set -euo pipefail : "${ROLE:?}" "${BUNDLE:?}" nic() { local suffix=$1 path for path in /sys/class/net/*; do [[ -e $path/device ]] || continue if [[ $(cat "$path/address") == "02:27:00:0${BUNDLE}:${ROLE_ID}:0${suffix}" ]]; then basename "$path"; return fi done echo "Expected fixture MAC not found" >&2; return 1 } uplink=$(nic 0) iface() { local name=$1 address=${2:-} gateway=${3:-} type=${4:-eth} mkdir -p "/etc/net/ifaces/$name" printf 'TYPE=%s\nBOOTPROTO=static\nCONFIG_IPV4=yes\nDISABLED=no\nNM_CONTROLLED=no\n' "$type" > "/etc/net/ifaces/$name/options" : > "/etc/net/ifaces/$name/ipv4address" : > "/etc/net/ifaces/$name/ipv4route" [[ -z $address ]] || printf '%s\n' "$address" > "/etc/net/ifaces/$name/ipv4address" [[ -z $gateway ]] || printf 'default via %s\n' "$gateway" > "/etc/net/ifaces/$name/ipv4route" } hostnamectl --static set-hostname "$ROLE.au-team.irpo" hostnamectl --transient set-hostname "$ROLE.au-team.irpo" timedatectl set-timezone Asia/Yekaterinburg touch /etc/cloud/cloud-init.disabled systemctl disable --now NetworkManager 2>/dev/null || true case "$ROLE" in isp) iface "$uplink" sed -i 's/BOOTPROTO=static/BOOTPROTO=dhcp/' "/etc/net/ifaces/$uplink/options" iface "$(nic 1)" 172.16.1.1/28 iface "$(nic 2)" 172.16.2.1/28 sources='172.16.1.0/28, 172.16.2.0/28' ;; hq-rtr) iface "$uplink" 172.16.1.2/28 172.16.1.1 trunk=$(nic 1); iface "$trunk" for pair in 100:192.168.100.1/27 200:192.168.100.33/28 999:192.168.100.49/29; do vlan=${pair%%:*}; iface "$trunk.$vlan" "${pair#*:}" '' vlan printf 'HOST=%s\nVID=%s\n' "$trunk" "$vlan" >> "/etc/net/ifaces/$trunk.$vlan/options" done localip=172.16.1.2 remoteip=172.16.2.2 tunnelip=10.10.10.0 sources='192.168.100.0/27, 192.168.100.32/28, 192.168.100.48/29' ;; br-rtr) iface "$uplink" 172.16.2.2/28 172.16.2.1 iface "$(nic 1)" 192.168.254.0/31 localip=172.16.2.2 remoteip=172.16.1.2 tunnelip=10.10.10.1 sources='192.168.200.0/28, 192.168.254.0/31' ;; hq-srv) iface "$uplink" 192.168.100.2/27 192.168.100.1 ;; br-srv) iface "$uplink" 192.168.200.2/28 192.168.200.1 ;; hq-cli) iface "$uplink" sed -i 's/BOOTPROTO=static/BOOTPROTO=dhcp/' "/etc/net/ifaces/$uplink/options" ;; *) exit 2 ;; esac # Template has a stale eth0 directory; keep it but disable when its NIC is absent. if [[ ! -e /sys/class/net/eth0 && -f /etc/net/ifaces/eth0/options ]]; then sed -i 's/DISABLED=no/DISABLED=yes/' /etc/net/ifaces/eth0/options fi printf 'search au-team.irpo\nnameserver 77.88.8.8\n' > /etc/resolv.conf # Some cloud templates symlink resolv.conf to systemd-resolved's runtime file. # Persist bootstrap DNS instead of trusting the temporary contents of that file. if [[ $ROLE == *-rtr || $ROLE == br-srv ]]; then install -d -m 755 /etc/systemd/resolved.conf.d printf '[Resolve]\nDNS=77.88.8.8\nDomains=au-team.irpo\nFallbackDNS=\n' > /etc/systemd/resolved.conf.d/kim2027.conf chmod 644 /etc/systemd/resolved.conf.d/kim2027.conf systemctl enable --now systemd-resolved systemctl restart systemd-resolved fi if [[ $ROLE == isp || $ROLE == *-rtr ]]; then printf 'net.ipv4.ip_forward=1\nnet.ipv4.conf.all.rp_filter=0\nnet.ipv4.conf.default.rp_filter=0\n' > /etc/sysctl.d/90-routing.conf sysctl -p /etc/sysctl.d/90-routing.conf sed -i -E 's/^(net.ipv4.ip_forward)[[:space:]]*=.*/\1 = 1/; s/^(net.ipv4.conf.default.rp_filter)[[:space:]]*=.*/\1 = 0/' /etc/net/sysctl.conf mkdir -p /etc/nftables cat > /etc/nftables/nftables.nft <> /etc/net/ifaces/gre1/options fi for path in /sys/class/net/*; do [[ $(cat "$path/address") != 02:27:00:* ]] || ip link set "${path##*/}" down done systemctl enable network systemctl restart network ip -br address ip route