#!/bin/sh PROGNAME=`basename $0` main() { local SITEID if [ "X$1" = X ]; then cat /etc/motd exit 0 elif [ "X$2" != X ]; then usage else SITEID="$1" fi case $SITEID in esoredcable|esoair|mythcable|mythair|standalone) : ;; *) usage ;; esac ########################################################################## # # SHUTDOWN PHASE # ########################################################################## # NFS mounts will hang if they remain when we restart networking in # such a way that the network is no longer accessible (e.g. only eth0 # up --> only dummy0 up. info "unmounting NFS filesystems ..." umount -a -t nfs # AMD mount points show up as type 'nfs' but without the 'vers=3', and # we are only concerned with *true* NFS mounts which will hang. ! mount | egrep ' nfs .*vers=' || error "failed to unmount all NFS mounts" info "shutting down services ..." ! pidof chronyd > /dev/null || /etc/init.d/chrony stop /etc/init.d/am-utils stop /etc/init.d/nis stop #/etc/init.d/bind9 stop /etc/init.d/networking stop ifdown lo ########################################################################## # # SWITCHOVER PHASE # ########################################################################## info "making configuration changes ..." switch_$SITEID ########################################################################## # # STARTUP PHASE # ########################################################################## info "starting services ..." ifup lo /etc/init.d/networking start #/etc/init.d/bind9 start /etc/init.d/nis start /etc/init.d/am-utils start ! $RUN_CHRONYD || /etc/init.d/chrony start } usage() { echo "Usage: $PROGNAME { esoredcable | esoair | mythcable | mythair | standalone }" >&2 exit 1 } switch_mythclient() { local NIC NIC=$1 nisserver graces.myth.net autonics lo $NIC mythnetauthority false switchsym /pub amd.staging/graces-diska-pub switchsym /var/mail ../amd.staging/graces-diska-var-mail switchsym /usr/server ../amd.staging/graces-diska-usr-server firewall false RUN_CHRONYD=true switchmotd "$2" } switch_esoclient() { local NIC NISSERVER DESC NIC=$1 NISSERVER=$2 DESC="$3" nisserver $NISSERVER autonics lo $NIC dummy0 mythnetauthority true switchsym /pub amd.staging/leda-diska-pub switchsym /var/mail ../amd.staging/leda-diska-var-mail switchsym /usr/server ../amd.staging/leda-diska-usr-server firewall true RUN_CHRONYD=true switchmotd "$DESC" } switch_mythcable() { switch_mythclient eth0 "Home LAN (cable)" } switch_mythair() { switch_mythclient ath0 "Home LAN (wireless)" } switch_esoredcable() { switch_esoclient eth0 leda.myth.net "ESO (red cable)" } switch_esoair() { switch_esoclient ath0 leda.myth.net "ESO (wireless)" } switch_standalone() { nisserver `hostname -f` autonics lo dummy0 mythnetauthority true switchsym /pub amd.staging/leda-diska-pub switchsym /var/mail ../amd.staging/leda-diska-var-mail firewall true RUN_CHRONYD=false switchmotd "Standalone" } nisserver() { perl -pi -e "s/^(ypserver ).*/\$1$1/" /etc/yp.conf } autonics() { perl -pi -e "s/^(auto ).*/\$1$*/" /etc/network/interfaces } mythnetauthority() { local ISAUTHORITY ISAUTHORITY=$1 cp /etc/bind/named.conf.local /tmp if $ISAUTHORITY; then sed '/^\/\/ zone/,/^\/\/ }/s/^\/\/ //' /tmp/named.conf.local > /etc/bind/named.conf.local else sed '/^zone/,/^}/s/^/\/\/ /' /tmp/named.conf.local > /etc/bind/named.conf.local fi rm -f /tmp/named.conf.local } switchmotd() { local DESC [ "X$1" != X -a "X$2" = X ] || internal "switchmotd: usage error" perl -pi -e "s/(Current network config: ).*/\$1$1/" /etc/motd } switchsym() { local LINK TARGET [ "X$2" != X -a "X$3" = X ] || internal "switchsym: usage error" LINK="$1" TARGET="$2" # remove the link if [ -h $LINK ]; then rm -f $LINK elif [ -e $LINK ]; then error "$LINK: exists and is not symlink" fi # recreate link ln -s $TARGET $LINK } firewall() { local ENABLE [ "X$1" != X -a "X$2" = X ] || internal "firewall: usage error" ENABLE="$1" perl -pi -e "s/^(FIREWALL_FLAG=).*/\$1$ENABLE/" /etc/iptables.conf } error() { echo "$PROGNAME: ERROR: $1" >&2 exit 1 } info() { echo "$PROGNAME: INFO: $1" >&2 } main "$@"