debian-unattended/postinstall/init.sh
Bryan Joshua Pedini 935aa95ec7 added postinstall scripts
they will be versioned and accessed through a git web interface instead of a static website
2025-04-20 23:07:55 +02:00

46 lines
1.2 KiB
Bash

#!/usr/bin/env bash
# Sometimes the network is slow, wait a bit
sleep 10
# Get the current DHCP network address (and gateway)
NIC=$(ip link | grep "^2:" | awk '{print $2}' | tr -d ":")
IP_ADDRESS=$(ip address show ${NIC} | grep -E "inet " | awk '{print $2}')
NETMASK=$(echo ${IP_ADDRESS} | sed 's/.*\///')
IP_ADDRESS=$(echo ${IP_ADDRESS} | sed 's/\/.*//')
GATEWAY=$(ip route | grep "default" | awk '{print $3}')
# Network interfaces (static address)
cat << EOF > /etc/network/interfaces
auto lo
iface lo inet loopback
auto ${NIC}
iface ${NIC} inet static
address ${IP_ADDRESS}/${NETMASK}
gateway ${GATEWAY}
EOF
# Tabs instead of spaces, neat the file
sed -i 's/ /\t/gm' /etc/network/interfaces
# Hosts file
cat << EOF > /etc/hosts
127.0.0.1 localhost localhost.localdomain
::1 localhost localhost.localdomain
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
${IP_ADDRESS} $(hostname --fqdn) $(hostname)
EOF
# Tabs instead of spaces, neat the file
sed -i 's/ /\t/gm' /etc/hosts
# Personalizations
wget -O - https://45r.it/serversetup | bash
# Cleanup and reboot
rm -rf /etc/systemd/system/multi-user.target.wants/postinstall-init.service /var/lib/systemd/system/postinstall-init.service /debian-postinstall-init.sh /.wget-hsts
reboot