OS update script staged updates
authorBill Erickson <berickxx@gmail.com>
Tue, 10 Jan 2017 16:49:35 +0000 (11:49 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Support update/upgrade in one stage, followed by dist-upgrade in a
secondary stage with optional reboot in between.  The goal is to reduce
the kernel / grub install errors for prod servers, where grub fails to
install correctly after dist-upgrade, requiring a manual grub reinstall.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/admin-scripts/os-update.sh

index 1b86d08..cf99f55 100755 (executable)
@@ -1,18 +1,56 @@
 #!/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;