#!/bin/bash set -e if [ $(id -u) -ne 0 ]; then echo 'must be root (sudo)' exit 1 fi echo 'detecting Ubuntu version' osver=`/usr/bin/lsb_release -r | /usr/bin/cut -f2` if [ "$osver" == "18.04" ]; then echo 'detected Ubuntu 18.04 (bionic)' echo 'performing step 1: upgrade to Ubuntu 20.04 (focal)' echo 'updating package list' /usr/bin/apt update echo 'upgrading installed packages' DEBIAN_FRONTEND=noninteractive /usr/bin/apt -y upgrade echo 'autoremoving unused packages' /usr/bin/apt -y autoremove echo 'upgrading operating system' DEBIAN_FRONTEND=noninteractive /usr/bin/do-release-upgrade echo 'upgrade complete' elif [ "$osver" == "22.04" ]; then echo 'detected Ubuntu 20.04 (bionic)' if [ -f /etc/apt/sources.list.d/lsfilter.list ]; then n=`/bin/grep 'deb ' /etc/apt/sources.list.d/lsfilter.list | /bin/grep -v '^#' | /usr/bin/wc -l` if [ $n -ne 0 ]; then echo 'upgraded system already initialized' echo 'nothing to do' exit 0 fi fi echo 'performing step 2: initialize upgraded system' if [ -f /etc/apt/sources.list.d/lsfilter.list ]; then echo 'cleaning up custom package repositories' /usr/local/bin/lspkg --remove-all-repos fi echo 'adding custom package repository' /usr/local/bin/lspkg --add-repo production echo 'updating custom package repository list' if [ -f /tmp/lsfilter.list ]; then /bin/rm -v /tmp/lsfilter.list fi /bin/cat /etc/apt/sources.list.d/lsfilter.list | /bin/sed 's/ bionic / focal /' > /tmp/lsfilter.list /bin/cp -v /tmp/lsfilter.list /etc/apt/sources.list.d/lsfilter.list echo 'updating package list' /usr/bin/apt update echo 'upgrading installed packages' DEBIAN_FRONTEND=noninteractive /usr/bin/apt -y upgrade else echo "unsupported Ubuntu version $osver" exit 1 fi