blob: f03e91b3085bb879eda97735f5a4512d005f99e0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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
|