Last active
February 9, 2022 13:48
-
-
Save stefan736/87a4a1d4f35b387f9901c20aa181fa29 to your computer and use it in GitHub Desktop.
Auto Update Linux Machine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Auto Updating Debian (means also Ubuntu) based Linux installations | |
# | |
# add to crontab ($ crontab -e) | |
# @reboot /home/username/update.sh >> /home/username/update.sh.log 2>&1 | |
# 30 1 * * * /home/username/update.sh >> /home/username/update.sh.log 2>&1 | |
# | |
# recognize wether we are currently inside an update process | |
update_transaction_file=~/update.sh.transaction | |
if [ ! -f $update_transaction_file ]; then | |
cat /home/username/update.sh.log >> /home/username/update.sh.log.archive | |
echo "" > /home/username/update.sh.log | |
fi | |
echo | |
echo "################### START $(date) #############" | |
touch $update_transaction_file | |
sudo DEBIAN_FRONTEND=noninteractive apt-get update -yq | |
sudo DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade --auto-remove --purge -yq | |
if [ -f /var/run/reboot-required ]; then | |
echo "Reboot required!" | |
sudo rm /var/run/reboot-required | |
echo "################### END BEFORE REBOOT $(date) #############" | |
sudo reboot | |
exit 0 | |
fi | |
# do additional things | |
rm $update_transaction_file | |
echo "################### END $(date) #############" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment