From b4fc2d2e268a79e57c5613edfe8e3e281681c58a Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 11 Jan 2016 14:06:37 +0100 Subject: bin/switch_wfs_os: Adding script to switch the OS on the TU wfs system. --- bin/switch_wfs_os | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 bin/switch_wfs_os (limited to 'bin') 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 + -- cgit v1.2.3-70-g09d2