Created
January 9, 2020 16:53
-
-
Save dakotahawkins/644e1338cf1ea010c043ba8a6ffaeb60 to your computer and use it in GitHub Desktop.
Debian update script
This file contains 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
#!/usr/bin/sudo bash | |
main() { | |
restart_if_required | |
run_apt update | |
run_apt full-upgrade | |
run_apt autoremove | |
} | |
run_apt() { | |
apt -y "$@" || error_exit "Failed to $@" | |
restart_if_required | |
} | |
restart_if_required() { | |
local check_file="/var/run/reboot-required" | |
[[ -f "$check_file" ]] && { | |
cat "$check_file" | |
IFS= read -r -s -n 1 -t 5 -p "Press any key to abort in the next 5 seconds." key && { | |
echo | |
error_exit "Aborting" | |
} || { | |
echo | |
reboot || error_exit "Failed to reboot" | |
} | |
} | |
} | |
error_exit() { | |
echo "$1" >&2 | |
echo | |
exit 1 | |
} | |
set -m | |
trap "" SIGINT | |
main "$@" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment