summaryrefslogtreecommitdiffstats
path: root/satellit_installer/static_files/system/usr/local/bin/netsetup
diff options
context:
space:
mode:
Diffstat (limited to 'satellit_installer/static_files/system/usr/local/bin/netsetup')
-rwxr-xr-xsatellit_installer/static_files/system/usr/local/bin/netsetup205
1 files changed, 205 insertions, 0 deletions
diff --git a/satellit_installer/static_files/system/usr/local/bin/netsetup b/satellit_installer/static_files/system/usr/local/bin/netsetup
new file mode 100755
index 0000000..a824739
--- /dev/null
+++ b/satellit_installer/static_files/system/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
+