diff options
author | Simon Rettberg | 2024-04-30 14:26:10 +0200 |
---|---|---|
committer | Simon Rettberg | 2024-04-30 14:26:10 +0200 |
commit | 6512e211c44832fae7d04684ac1820c0c28c8d0a (patch) | |
tree | 05b8665da19275e79183018725ca4e558312c5d8 /satellit_installer/static_files/system-base/usr/local/bin/netsetup | |
parent | [SS*S] lighttpd: Don't try to use ssl.ca-file for certificate chain (diff) | |
download | setup-scripts-6512e211c44832fae7d04684ac1820c0c28c8d0a.tar.gz setup-scripts-6512e211c44832fae7d04684ac1820c0c28c8d0a.tar.xz setup-scripts-6512e211c44832fae7d04684ac1820c0c28c8d0a.zip |
[SS?S] Split static_files/system into base and updates
base is considered static, i.e. only copied once when *installing* a
server, because they are config files the user/admin is expected to
edit, or because they have to match the specific Debian release the
installed server is based on, and thus should not - or only
selectively - be replaced by the satellite updater.
In other words, the system-updates module should be save to be copied
over a running satellite server on update via "install_files", while
files from system-base will only be updated selectively, if at all.
Diffstat (limited to 'satellit_installer/static_files/system-base/usr/local/bin/netsetup')
-rwxr-xr-x | satellit_installer/static_files/system-base/usr/local/bin/netsetup | 205 |
1 files changed, 205 insertions, 0 deletions
diff --git a/satellit_installer/static_files/system-base/usr/local/bin/netsetup b/satellit_installer/static_files/system-base/usr/local/bin/netsetup new file mode 100755 index 0000000..a824739 --- /dev/null +++ b/satellit_installer/static_files/system-base/usr/local/bin/netsetup @@ -0,0 +1,205 @@ +#!/bin/bash + +if [ "$UID" != 0 ]; then + exec sudo "$0" "$@" + exit 1 +fi + +DATUM=$(date +%Y%m%d_%H%M%S) +INTERFACES="/etc/network/interfaces" +ETHALIAS=$( ifconfig -a | grep -oEm1 '^e\w+' ) +RESOLV="/etc/resolv.conf" +HOSTNAMEFILE="/etc/hostname" +SKRIPT=$(readlink -f "$0") +ERR=0 + + +write_banner() { + echo + echo "Dieses Skript konfiguriert das Netzwerk-Interface." + echo + echo "Wenn Sie die Netzwerkkonfiguration ändern, sollten Sie anschließend" + echo "den Server rebooten." + echo +} + + +detect_config() { + if grep -q -E "^[[:space:]]*iface[[:space:]]+${ETHALIAS}[[:space:]]+inet[[:space:]]+dhcp" "$INTERFACES"; then + # dhcp detected, we presume + TYPE=dhcp-basierte + WUNSCH=statische + TOUCHE_TYPE=d + TOUCHE_DESIR=s + else + TYPE=statische + WUNSCH=dhcp-basierte + TOUCHE_TYPE=s + TOUCHE_DESIR=d + fi +} + +ask_config() { + echo + echo "Es ist aktuell eine $TYPE IP-Adresse konfiguriert." + echo + echo "Wollen Sie eine $WUNSCH IP konfigurieren (${TOUCHE_DESIR})," + echo "möchten Sie die $TYPE IP neu konfigurieren (${TOUCHE_TYPE})," + echo "oder möchten Sie gar nichts tun (leere Eingabe)?" + echo + echo -n "Ihre Wahl? [${TOUCHE_DESIR}/${TOUCHE_TYPE}/nichts]: " + read CONFIG_ME + [ "$CONFIG_ME" == "" ] && exit 0 +} + +decide_action() { + case "$CONFIG_ME" in + ${TOUCHE_DESIR}*) backup_configs + if [ "$WUNSCH" == "statische" ]; then + enter_values_static + write_config_static + else + write_config_dyn + fi + ;; + ${TOUCHE_TYPE}*) backup_configs + if [ "$TYPE" == "statische" ]; then + enter_values_static + write_config_static + else + write_config_dyn + fi + ;; + *) echo; echo + echo "Ihre eingegebene Option $CONFIG_ME wurde nicht erkannt - Neustart." + echo + sleep 1 + exec "$SKRIPT" + ;; + esac +} + +backup_configs() { + if [ -f "$INTERFACES" ]; then + cp -p "$INTERFACES" "$INTERFACES.${DATUM}" || \ + { echo "Konnte Datei $INTERFACES nicht nach $INTERFACES.$DATUM sichern - Abbruch."; \ + exit 1 ; } + cp -p "$RESOLV" "$RESOLV.${DATUM}" || \ + { echo "Konnte Datei $RESOLV nicht nach $RESOLV.$DATUM sichern - Abbruch."; \ + exit 1 ; } + fi +} + +restore_configs() { + cp -p "$INTERFACES.$DATUM" "$INTERFACES" + cp -p "$RESOLV.{DATUM}" "$RESOLV" +} + +write_config_static() { + cat > "$INTERFACES" <<-HIER + # This file was written by the satellite auto installer. + # If any problems arise, copy $INTERFACES.${DATUM}. + # The loopback network interface + auto lo + iface lo inet loopback + + # Primary network interface + auto $ETHALIAS + iface $ETHALIAS inet static + address $IPADRESS + gateway $GATEWAY + netmask $NETMASK + HIER + + echo "# This file was written by the satellite server install script." > "$RESOLV" + echo "# If any problems arise, copy $RESOLV.${DATUM}." >> "$RESOLV" + [ -n "$DOMAIN" ] && echo "domain $DOMAIN" >> "$RESOLV" + [ -n "$SEARCH" ] && echo "search $SEARCH" >> "$RESOLV" + [ -n "$PRIMARYDNS" ] && echo "nameserver $PRIMARYDNS" >> "$RESOLV" + [ -n "$SECONDARYDNS" ] && echo "nameserver $SECONDARYDNS" >> "$RESOLV" + + echo "$HOSTNAME" > "$HOSTNAMEFILE" + + [ -n "$DOMAIN" ] && DOMAIN=".${DOMAIN}" + sed "s/127.0.1.1.*/127.0.1.1\t${HOSTNAME}${DOMAIN}\t${HOSTNAME}/g" -i /etc/hosts --in-place=.alt + +} + +write_config_dyn() { + cat > "$INTERFACES" <<-HIER + # This file was written by the satellite auto installer. + # If any problems arise, copy $INTERFACES.${DATUM}. + # The loopback network interface + auto lo + iface lo inet loopback + + # Primary network interface + auto $ETHALIAS + iface $ETHALIAS inet dhcp + # Leaving /etc/resolv alone; pump/dhclient/whatever will take care of that. + HIER +} + +enter_values_static() { + OLDHOSTNAME=$(hostname) + unset ENTRY + while true; do + echo + echo -n "IP-Adresse: " + read IPADRESS + echo -n "Gateway: " + read GATEWAY + echo -n "Netzmaske - leere Eingabe für 255.255.255.0: " + read NETMASK + [ -z "$NETMASK" ] && NETMASK=255.255.255.0 + echo -n "Domain - leere Eingabe, wenn nicht erwünscht: " + read DOMAIN + echo -n "Search domain - leere Eingabe, wenn nicht erwünscht: " + read SEARCH + echo -n "Primärer Nameserver: " + read PRIMARYDNS + echo -n "Sekundärer Nameserver - Leere Eingabe, wenn nicht vorhanden: " + read SECONDARYDNS + echo -n "Hostname - leere Eingabe für bestehenden Hostname $OLDHOSTNAME: " + read HOSTNAME + [ "$HOSTNAME" == "" ] && HOSTNAME="$OLDHOSTNAME" + echo + echo "# IP-Adresse : $IPADRESS" + echo "# Gateway : $GATEWAY" + echo "# Netzmaske : $NETMASK" + echo "# Domain : $DOMAIN" + echo "# Search domain : $SEARCH" + echo "# Primärer Nameserver : $PRIMARYDNS" + echo "# Sekundärer Nameserver : $SECONDARYDNS" + echo "# Hostname : $HOSTNAME" + echo + while true; do + echo -n "Sind diese Eingaben korrekt? [J/n]: " + read ENTRY + echo + [[ -z "$ENTRY" || "$ENTRY" == j* || "$ENTRY" == J* ]] && return + if [[ "$ENTRY" == n* || "$ENTRY" == N* ]]; then + echo "Neustart der Eingabe..." + echo + break + fi + done + done +} + +last_words() { + echo + echo "Einträge geschrieben... beende Skript." + echo +} + +detect_config +write_banner +ask_config + +decide_action # do the stuff! + +last_words + +exit 0 + |