From 935aa95ec739b3420f98048c1aec2a511585f26d Mon Sep 17 00:00:00 2001 From: Bryan Joshua Pedini Date: Sun, 20 Apr 2025 23:07:55 +0200 Subject: [PATCH] added postinstall scripts they will be versioned and accessed through a git web interface instead of a static website --- postinstall/init.service | 8 +++++++ postinstall/init.sh | 45 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 postinstall/init.service create mode 100644 postinstall/init.sh diff --git a/postinstall/init.service b/postinstall/init.service new file mode 100644 index 0000000..b69f3b9 --- /dev/null +++ b/postinstall/init.service @@ -0,0 +1,8 @@ +[Unit] +Description=Postinstall Init + +[Service] +ExecStart=/usr/bin/env bash /debian-postinstall-init.sh + +[Install] +WantedBy=multi-user.target diff --git a/postinstall/init.sh b/postinstall/init.sh new file mode 100644 index 0000000..b7906c9 --- /dev/null +++ b/postinstall/init.sh @@ -0,0 +1,45 @@ +#!/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