~fkooman/vpn-maint-scripts

ref: 88822af5af870561b9260fcc7f0d20f76bebe4da vpn-maint-scripts/bin/vpn-maint-update-system-multi -rwxr-xr-x 2.0 KiB
88822af5François Kooman add warning 10 months ago
                                                                                
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
#!/bin/sh

SERVER_LIST_FILE=server.list
REBOOT_TIME_CONTROLLER=180

if [ ! -f "${SERVER_LIST_FILE}" ]; then
    echo "\"${SERVER_LIST_FILE}\" not found!"
    exit 1
fi

# import the "server.list" file
. ./${SERVER_LIST_FILE}

if [ -z "${CONTROLLER}" ]; then
    echo "\"CONTROLLER\" not set in \"${SERVER_LIST_FILE}\""
    exit 1
fi

if [ -z "${NODES}" ]; then
    echo "\"NODES\" not set in \"${SERVER_LIST_FILE}\""
    exit 1
fi

echo "**********************************************************"
echo "*                                                        *"
echo "*   Are you sure you want to UPDATE your VPN servers?    *"
echo "*                                                        *"
echo "*         All VPN clients will be disconnected!          *"
echo "*                                                        *"
echo "**********************************************************"
echo
printf "Continue? (y/n) [n]: "; read -r CONFIRM
if ! [ "${CONFIRM}" = "y" ] && ! [ "${CONFIRM}" = "Y" ]; then
    exit 1
fi

# stop all nodes
for NODE in ${NODES}
do
    echo "Stopping NODE ${NODE}..."
    ssh -t "${NODE}" "/usr/bin/tmux new '/usr/bin/sudo /usr/sbin/vpn-maint-stop-node'"
done

# update controller
echo "Updating CONTROLLER ${CONTROLLER}..."

ssh -t "${CONTROLLER}" "/usr/bin/tmux new '/usr/bin/sudo /usr/sbin/vpn-maint-update-controller -y'"
if [ "--reboot" = "${1}" ]; then
echo "Rebooting CONTROLLER ${CONTROLLER}..."
    ssh "${CONTROLLER}" "/usr/bin/sudo /sbin/reboot"
    echo "Waiting ${REBOOT_TIME_CONTROLLER}s for CONTROLLER ${CONTROLLER} to come back..."
    sleep ${REBOOT_TIME_CONTROLLER}
fi

# update nodes
for NODE in ${NODES}
do
    echo "Updating NODE ${NODE}..."
    ssh -t "${NODE}" "/usr/bin/tmux new '/usr/bin/sudo /usr/sbin/vpn-maint-update-node'"
    if [ "--reboot" = "${1}" ]; then
        echo "Rebooting NODE ${NODE}..."
        ssh "${NODE}" "/usr/bin/sudo /sbin/reboot"
    else
        echo "Starting NODE ${NODE}..."
        ssh -t "${NODE}" "/usr/bin/tmux new '/usr/bin/sudo /usr/sbin/vpn-maint-start-node'"
    fi
done