#!/bin/bash
# Convenience script for updating packages on debian-based OS'es
-DO_REBOOT=""
+set -euo pipefail
+STAGE=0
+UPDATE_ALL=""
-apt-get update;
-apt-get -y autoremove;
-apt-get -y dist-upgrade;
+function do_reboot {
+ echo ""
+ echo "--"
+ echo "Reboot? Type 'yes' to continue. Control-c to exit"
+ echo "--"
+
+ CONFIRM_REBOOT=""
+ read CONFIRM_REBOOT;
+
+ if [ "$CONFIRM_REBOOT" = "yes" ]; then
+ reboot;
+ fi;
+}
+
+function upgrade1 {
+ echo "Upgrade stage 1..."
+ apt-get update;
+ apt-get -y autoremove;
+ apt-get -y upgrade;
+ apt-get -y clean;
+}
+
+function upgrade2 {
+ echo "Upgrade stage 2..."
+ apt-get -y dist-upgrade;
+}
+
+while getopts "as:" opt; do
+ case $opt in
+ a) UPDATE_ALL="1";;
+ s) STAGE=$OPTARG;;
+ esac
+done;
+
+if [ -n "$UPDATE_ALL" ]; then
+ upgrade1;
+ upgrade2;
+ do_reboot;
+elif [ $STAGE == 1 ]; then
+ upgrade1;
+ do_reboot;
+elif [ $STAGE == 2 ]; then
+ upgrade2;
+ do_reboot;
+else
+ echo " use -s 1/2 or -a for full update"
+fi
-echo ""
-echo "--"
-echo "Reboot? Type 'yes' to continue. Control-c to exit"
-echo "--"
-read DO_REBOOT;
-if [ "$DO_REBOOT" = "yes" ]; then
- reboot;
-fi;