Debian Setup Script
Version vom 19. April 2026, 08:52 Uhr von Thomas.will (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „*cat /usr/local/sbin/debian-setup.sh <pre> #!/bin/bash # Standardwerte setzen FQDN="" ADDR="" GW="" NS="" USE_DHCP=0 # Optionen mit getopts parsen while ge…“)
- cat /usr/local/sbin/debian-setup.sh
#!/bin/bash
# Standardwerte setzen
FQDN=""
ADDR=""
GW=""
NS=""
USE_DHCP=0
# Optionen mit getopts parsen
while getopts "f:a:g:n:d" opt; do
case $opt in
f) FQDN="$OPTARG" ;;
a) ADDR="$OPTARG" ;;
g) GW="$OPTARG" ;;
n) NS="$OPTARG" ;;
d) USE_DHCP=1 ;;
*) echo "Ungültige Option" >&2; exit 1 ;;
esac
done
# Gültigkeit prüfen
if [[ -z "$FQDN" ]]; then
echo "Fehlender FQDN! Nutzung:"
echo "$0 -f <FQDN> [-d | -a <IP/CIDR> -g <Gateway> -n <Nameserver>]"
exit 1
fi
if (( USE_DHCP == 1 )); then
if [[ -n "$ADDR" || -n "$GW" || -n "$NS" ]]; then
echo "Fehler: -d darf nicht mit -a, -g oder -n kombiniert werden." >&2
exit 1
fi
else
if [[ -z "$ADDR" || -z "$GW" || -z "$NS" ]]; then
echo "Fehlende Argumente für statische Konfiguration! Nutzung:"
echo "$0 -f <FQDN> [-d | -a <IP/CIDR> -g <Gateway> -n <Nameserver>]"
exit 1
fi
fi
# SHORT und DOM aus FQDN berechnen
SHORT=$(echo "$FQDN" | cut -d'.' -f1)
DOM=$(echo "$FQDN" | cut -d'.' -f2-)
# /etc/network/interfaces schreiben
cat <<HERE > /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/*
auto lo
iface lo inet loopback
auto enp0s3
HERE
if (( USE_DHCP == 1 ))
then
echo "iface enp0s3 inet dhcp" >> /etc/network/interfaces
else
cat <<HERE >> /etc/network/interfaces
iface enp0s3 inet static
address $ADDR
gateway $GW
dns-nameservers $NS
dns-search $DOM
HERE
fi
# Hostname setzen
hostnamectl set-hostname "$FQDN"