-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdate
executable file
·152 lines (124 loc) · 3.05 KB
/
update
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env bash
#############################################################################
# Made by : Ewoud Dronkert
# Licence : GNU GPL v3
# Platform : Raspbian
# Requires : bash, pgrep, apt-get, rpi-update
# Location : /usr/local/bin/
# Name : update
# Version : 1.0.0
# Date : 2017-07-21
# Purpose : Easy updating on Raspberry Pi.
# Parameters : -f = also update firmware (using rpi-update)
# Settings : none
# Exit 0 : No script errors
# 1 : rpi-update not found
# 2 : wrong argument(s)
# 3 : no root privileges
# 4 : failed to retrieve updates (apt-get update)
# 5 : failed to install updates (apt-get upgrade)
# 6 : failed to install updates (apt-get dist-upgrade)
# 7 : failed to uninstall unneeded packages
# 8 : failed to install firmware update (rpi-update)
#############################################################################
FIRMWARE=
if [ -n "$1" ]; then
if [ "$1" = "-f" ]; then
RPIUPDATE=$(which rpi-update)
if [ -n "$RPIUPDATE" ]; then
FIRMWARE=1
else
echo "Error: firmware update tool rpi-update not found." >&2
exit 1
fi
else
echo "Error: wrong argument. Use -f to include firmware update & reboot." >&2
exit 2
fi
fi
ME=$(whoami)
if [[ "$ME" != "root" ]]; then
echo "Error: use sudo to execute this script." >&2
exit 3
fi
echo
echo " Stopping camera ..."
echo
for PNAME in webcam raspistill raspivid raspiyuv raspividyuv; do
pgrep -f $PNAME &>/dev/null && { echo -n "$PNAME ... "; pkill -f $PNAME; sleep 1; echo 'done'; }
done
echo
echo " Getting new updates ..."
echo
apt-get clean
if apt-get update; then
echo
echo " Installing available updates ('upgrade') ..."
echo
if apt-get -y upgrade; then
echo
echo " Installing available updates ('dist-upgrade') ..."
echo
if apt-get -y dist-upgrade; then
echo
echo " Removing unused packages ..."
echo
if apt-get -y --purge autoremove; then
if [ $FIRMWARE ]; then
echo
echo " Downloading and installing firmware update ..."
echo
if rpi-update; then
echo
echo " Firmware update successful, now rebooting."
echo
reboot
else
echo
echo -n " "
echo "Firmware update unsuccessful. Manual reboot may still be required." >&2
echo
exit 8
fi
else
echo
echo " Done."
echo
exit 0
fi
else
echo
echo -n " "
echo "Update successful but failed removing unneeded packages." >&2
if [ $FIRMWARE ]; then
echo -n " "
echo "Firmware update not performed." >&2
fi
echo
exit 7
fi
else
echo
echo -n " "
echo "Failed installing updates via 'dist-upgrade'. Update probably OK." >&2
if [ $FIRMWARE ]; then
echo -n " "
echo "Firmware update not performed." >&2
fi
echo
exit 6
fi
else
echo
echo -n " "
echo "Failed installing updates. Update incomplete." >&2
echo
exit 5
fi
else
echo
echo -n " "
echo "Failed getting updates. No update performed." >&2
echo
exit 4
fi