-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapt-upg
executable file
·72 lines (64 loc) · 1.49 KB
/
apt-upg
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
#!/bin/bash
# force only system paths
PATH=/bin:/sbin:/usr/bin:/usr/sbin
if [ -n "$(which at)" ]
then
echo "setting reboot canary for +1 hour"
at now + 1 hour <<EOF
shutdown -R now "apt-upg canary reboot"
EOF
else
cat >/tmp/reboot_canary.sh <<EOF
#!/bin/bash
sleep 3600
if [ -e /reboot_canary.txt ]
then
rm -f /reboot_canary.txt
shutdown -R +5s "apt-upg canary reboot" &
else
wall "shutdown aborted."
fi
rm -f /tmp/reboot_canary.sh
EOF
touch /reboot_canary.txt
nohup bash /tmp/reboot_canary.sh >/dev/null 2>&1 &
echo "reboot canary set for +1 hour"
fi
IONICE=$(which ionice)
NICE=$(which nice)
# fix broken packages
${IONICE} ${NICE} dpkg --configure -a
if [ $? -ne 0 ]
then
echo "manually fix broken packages"
exit 1
fi
# update the local repo info, allowing for minor release changes
${IONICE} ${NICE} apt-get update --allow-releaseinfo-change
if [ $? -ne 0 ]
then
echo "check network connectivity and apt repo sources"
exit 1
fi
# install updates
${IONICE} ${NICE} apt-get -y dist-upgrade
if [ $? -ne 0 ]
then
echo "manually check upgrade failures"
echo "'dpkg --configure -a' may provide additional information"
exit 1
fi
# Clean up old packages
${IONICE} ${NICE} apt-get -y autoclean && ${IONICE} ${NICE} apt-get -y autoremove
if [ $? -ne 0 ]
then
echo "manually check for cleanup issues"
exit 1
fi
# All done!
if [ -n "$(which at)" ]
then
echo "use atq and atrm to remove the reboot canary, or else your system will reboot soon."
else
echo "remove '/reboot_canary.txt' to abort"
fi