-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupgrade
More file actions
executable file
·42 lines (32 loc) · 1.1 KB
/
upgrade
File metadata and controls
executable file
·42 lines (32 loc) · 1.1 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
#!/bin/bash -e
#Install directory
DIR=$(dirname $(readlink -fn $0))
cd "$DIR"
USER='mike';
HOME="$(cat /etc/passwd | grep $USER | cut -d : -f 6)";
source ./pprint
export LOGFILE='/var/log/upgrade.log'
if [ -e $LOGFILE ] ; then rm $LOGFILE ; touch $LOGFILE; fi
SUB="Automatic Upgrade Failed"
installlog=/tmp/apt.log
info_log "Starting upgrade"
if sudo apt-get -q update | grep 'dpkg' ; then
if ! sudo dpkg --configure -a ; then
die_mail "$SUB" 'Failed to reconfigure'
fi
fi
if ! sudo apt-get -y -q update ; then
die_mail "$SUB" 'Could not update'
fi
if ! sudo apt-get -q -y dist-upgrade | tee $installlog ; then
die_mail "$SUB" 'Failed to dist-upgrade'
elif ! sudo apt-get -q -y autoremove ; then
die_mail "$SUB" 'Failed to cleanup any unneeded packages'
elif ! ( sudo apt-get -q -y autoclean && sudo apt-get -q -y clean ) ; then
die_mail "$SUB" 'Failed to delete deb files'
fi
info_log "Automatic upgrade finished!"
mail_log "Finished upgrade!" "Upgrade succeeded."
if grep -q linux-image $installlog ; then
shutdown -r "00:00" 'Rebooting at midnight to complete system update.'
fi