-
Notifications
You must be signed in to change notification settings - Fork 1
/
updater.sh
executable file
·69 lines (58 loc) · 2.11 KB
/
updater.sh
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
#!/bin/bash
echo "MikroTik Updater"
echo "Version: 1.3.1"
echo "Created by: Cristián Pérez"
echo "--------------------------"
updaterpath="$( cd "$(dirname "$0")" ; pwd -P )"
sourcefile="$updaterpath/sources/$1"
if [[ -f "$sourcefile" ]]; then
source "$sourcefile"
else
if [[ -f "$1" ]]; then
source "$1"
else
echo "Source file doesn't exists"
exit 1
fi
fi
if [[ ! -f "$private_key" ]]; then
echo "Specified Private Key doesn't exists"
exit 1
fi
ros_command () {
ssh -o ConnectTimeout=5 -i $private_key -l $username $h $1 2>/dev/null
}
for h in "${hosts[@]}"
do
echo
echo "Gathering information from $h ..."
device_name="$(ros_command ':put [/system identity get name]')"
device_name="${device_name%?}" # the name comes with an extra character at the end so we remove it.
if [ -z "$device_name" ]; then
echo " --> Failed to gather information. Skipping update. ⚠️"
continue
fi
echo "Checking for updates on $device_name ($h) ..."
ros_command '/system package update check-for-updates once' > /dev/null
status="$(ros_command ':put [/system package update get status]')"
if [[ $status == *"System is already up to date"* ]];
then
echo " --> System up to date 👍"
firmware_cur="$(ros_command ':put [/system routerboard get current-firmware]')"
firmware_upd="$(ros_command ':put [/system routerboard get upgrade-firmware]')"
if [[ $firmware_cur == $firmware_upd ]];
then
echo " --> Firmware up to date 👍"
else
echo " --> Updating firmware 🛠 ... "
ros_command '/system routerboard upgrade'
ros_command ':execute "/system reboot"' # I think it only works if auto-upgrade=yes
echo " --> Firmware updated 👍"
echo " --> Rebooting ..."
fi
else
ros_command '/system package update install' | xargs -I % bash -c "tput el && echo -ne '%\r' | sed -e 's/^[ \\t]*status:/ --> Updating system 🛠:/g'";
echo " --> System updated 👍"
echo " --> Rebooting ..."
fi
done