-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_remote.sh
More file actions
executable file
·62 lines (49 loc) · 1.55 KB
/
update_remote.sh
File metadata and controls
executable file
·62 lines (49 loc) · 1.55 KB
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
#!/usr/bin/env bash
set -e
DEBUG=${DEBUG:-0} # 0 = no debugging info,
# >0 = show error & minimal info,
# 2 = more info,
# 3 = verbose info,
# 4 = show debuging ip address ,
# 5 = bailout on error
ipList=( \
rpi4b-1 \
rpi4b-2 \
rpi4b-3 \
rpi4b-4 )
commandsToRun=( \
"export DEBIAN_FRONTEND=noninteractive" \
"sudo apt-get update" \
"sudo apt-get upgrade -y" \
"sudo apt-get autoremove -y" \
"sudo shutdown --reboot 1 \"$(hostname) rebooting now!\" || true" \
"exit 0" )
#"sudo apt-get upgrade -y --dry-run" \
#"sudo apt-get autoremove -y --dry-run" \
sshCommand="ssh -t"
for ipAddress in "${ipList[@]}"
do
[[ DEBUG -eq 4 ]] && \
printf "D: ipaddress: %s\n" "$ipAddress" >&2
runCommand="${sshCommand} ${ipAddress}"
[[ DEBUG -gt 1 ]] && \
printf "D: runCommand: %s\n" "$runCommand" >&2
for cmd in "${commandsToRun[@]}"
do
[[ DEBUG -gt 2 ]] && \
printf "D: cmd: %s\n" "$cmd" >&2
runCommand="$runCommand $cmd &&"
done
runCommand=${runCommand:0:-3}
[[ DEBUG -gt 0 ]] && \
printf "D: runCommand: %s\n" "$runCommand"
ret=0
${runCommand} || \
ret=$? && \
[[ DEBUG -gt 0 ]] && [[ ret -ne 0 ]] && \
printf "\nE: \`%s\' returned error: %i.\n" "$runCommand" $ret >&2 && \
[[ DEBUG -eq 5 ]] && \
printf "E: %s\n" "Bailing out." && \
exit $ret
done
exit 0