aboutsummaryrefslogtreecommitdiffstats
path: root/bin/switch_wfs_os
diff options
context:
space:
mode:
authorDavid Runge <dave@sleepmap.de>2016-01-11 14:06:37 +0100
committerDavid Runge <dave@sleepmap.de>2016-01-11 14:06:37 +0100
commitb4fc2d2e268a79e57c5613edfe8e3e281681c58a (patch)
tree7dc72766fbc06af6920580c6419d2fa97a7687ba /bin/switch_wfs_os
parent77d25762737ac194c85411f30aabd3269e090187 (diff)
downloaddotfiles-b4fc2d2e268a79e57c5613edfe8e3e281681c58a.tar.gz
dotfiles-b4fc2d2e268a79e57c5613edfe8e3e281681c58a.tar.bz2
dotfiles-b4fc2d2e268a79e57c5613edfe8e3e281681c58a.tar.xz
dotfiles-b4fc2d2e268a79e57c5613edfe8e3e281681c58a.zip
bin/switch_wfs_os: Adding script to switch the OS on the TU wfs system.
Diffstat (limited to 'bin/switch_wfs_os')
-rwxr-xr-xbin/switch_wfs_os75
1 files changed, 75 insertions, 0 deletions
diff --git a/bin/switch_wfs_os b/bin/switch_wfs_os
new file mode 100755
index 0000000..f03e91b
--- /dev/null
+++ b/bin/switch_wfs_os
@@ -0,0 +1,75 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+IFS=$'\n\t'
+
+os_new="arch-rt"
+os_old="ubuntu-studio"
+os_current=""
+os_set=""
+
+syslinux_location_arch="/mnt/boot/syslinux/syslinux.cfg"
+syslinux_location_ubuntu="/mnt/boot/syslinux/syslinux.cfg"
+syslinux_location=""
+
+reboot_cmd_arch="sudo systemctl reboot"
+reboot_cmd_ubuntu="sudo reboot -q"
+reboot_cmd=""
+
+hostnames_arch=( "wfs-master" "wfs-node1" "wfs-node2" )
+hostnames_ubuntu=( "wfs" "n101" "n102" )
+
+if [ $UID -ne 0 ]; then
+ echo "You need to be root or call this script with sudo to do this."
+ exit 1
+fi
+
+if [ -f /etc/arch-release ]; then
+ os_current=$os_new
+ syslinux_location=$syslinux_location_arch
+ reboot_cmd=$reboot_cmd_arch
+else
+ os_current=$os_old
+ syslinux_location=$syslinux_location_ubuntu
+ reboot_cmd=$reboot_cmd_ubuntu
+fi
+echo "Currently running: $os_current"
+
+if [ -f "${syslinux_location}" ]; then
+ os_set=$(sed -ne '/^DEFAULT/p' $syslinux_location| cut -d' ' -f2)
+ echo "Currently set up for next boot: $os_set"
+else
+ echo "Error: Syslinux configuration does not exist ($syslinux_location)"
+ exit 1
+fi
+
+if [ "$os_set" == "${os_new}" ] && [ "$os_current" == "${os_new}" ]; then
+ if [[ " ${hostnames_arch[@]} " =~ " $(hostname) " ]]; then
+ echo "Switching to: $os_old"
+ sed -i 's/^DEFAULT .*/DEFAULT '${os_old}'/' $syslinux_location
+ else
+ echo "Error: Script is not supposed to be running on this host!"
+ echo "$(hostname) is not one of the following: ${hostnames_arch[@]}"
+ echo "Exiting."
+ exit 1
+ fi
+elif [ "$os_set" == "${os_old}" ] && [ "$os_current" == "${os_old}" ]; then
+ if [[ " ${hostnames_ubuntu[@]} " =~ " $(hostname) " ]]; then
+ echo "Switching to: $os_new"
+ sed -i 's/^DEFAULT .*/DEFAULT '${os_new}'/' $syslinux_location
+ else
+ echo "Error: Script is not supposed to be running on this host!"
+ echo "$(hostname) is not one of the following: ${hostnames_ubuntu[@]}"
+ echo "Exiting."
+ exit 1
+ fi
+else
+ echo "Error: Current OS ($os_current) and OS to be booted ($os_set) are not the same."
+ echo "Fix this manually in $syslinux_location or just reboot (into the other OS)."
+ echo "Exiting."
+ exit 1
+fi
+
+echo "Rebooting."
+$reboot_cmd
+