3fd21205842b758af068e7b5e0614d2d55216759
chmalee
  Fri Mar 3 09:16:19 2023 -0800
Add a 'vm' option to gbib's update script that can update the underlying operating system to the next version, refs #24254

diff --git src/browserbox/root/updateBrowser.sh src/browserbox/root/updateBrowser.sh
index c3734d4..56fb724 100755
--- src/browserbox/root/updateBrowser.sh
+++ src/browserbox/root/updateBrowser.sh
@@ -113,30 +113,64 @@
 wget -q --tries=1 --timeout=10 --spider http://hgdownload.soe.ucsc.edu -O /dev/null
 if [ $? -ne 0 ] ; then
     echoDebug GBiB has no connection to hgdownload.soe.ucsc.edu, cannot update now
     exit 3
 fi
 
 # check flag file if run with no parameter (=from cron)
 if [ "$#" -eq 0 ] ; then
    # check a flag file to see if anything on hgdownload actually changed
    if /root/urlIsNotNewerThanFile $UPDATEFLAG /root/lastUpdateTime.flag
    then
        exit 0
    fi
 fi
 
+# March 02, 2023 - do an update of the underlying Ubuntu operating system
+if [[ "$1" == "vm" ]] ; then
+    # remove swapfile to free up space if it's present
+    swapoff /swapfile
+    rm /swapfile
+
+    # check for upgrades first
+    apt-get install -y --only-upgrade apt
+
+    # remove old packages and linux versions to make sure there is enough free space
+    apt-get clean && sudo apt-get autoremove
+    apt-get purge -y $(dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve "$(uname -r | sed -r 's/-[a-z]+//')")
+
+    # add the below to /etc/apt/apt.conf so non-interactive update will work (https://bugs.launchpad.net/ubuntu/+source/ubuntu-release-upgrader/+bug/1640274/comments/5):
+    echo 'Dpkg::Options { "--force-confold"; }' >> /etc/apt/apt.conf
+
+    # finally do the upgrade
+    do-release-upgrade -f DistUpgradeViewNonInteractive
+
+    # turn off apparmor because it doesn't play nice with mysql
+    systemctl stop apparmor.service
+    update-rc.d -f apparmor remove
+
+    # do a restart to force apparmor changes
+    # need a flag to tell the OS to restart mysql after the changes
+    touch /root/doRestartMysql
+    shutdown -r now
+fi
+
+if [ -e /root/doRestartMysql ]; then
+    service mysql restart
+    rm -f /root/doRestartMysql
+fi
+
 # unless already calling self, update self and call self unless doing only cgis
 # self-updates are not done when suppressed with notSelf and also not in hgwdev-mode to allow testing of local updateBrowser.sh changes
 # Internal sidenote: if you want hgwdev CGIs and also the current hgwdev update
 # script, do a gbibCoreUpdateBeta+updateBrowser hgwdev
 
 # gbibCoreUpdateBeta ends with -Beta because it is used during beta time, to
 # test the current dev update script The update script itself has only a
 # two-stage release process, beta and final, as the alpha version of the script
 # is on the GBiB of the developer itself.
 # the file /root/gbibSkipUpdate allows to skip one single auto-update
 if [[ ( "$BASH_ARGV" != "notSelf" && "$1" != "hgwdev" ) && ( ! -e /root/gbibSkipNextUpdate ) ]] ; then
     echo getting new update script
     # we got three VMs where updateBrowser.sh was 0 bytes, so doing download/move now
     wget http://hgdownload.soe.ucsc.edu/gbib/updateBrowser.sh -O /root/updateBrowser.sh.new -q && mv /root/updateBrowser.sh.new /root/updateBrowser.sh
     chmod a+x /root/updateBrowser.sh