← Back to team overview

canonical-hw-cert team mailing list archive

[Merge] ~rodsmith/maas-cert-server:update-maniacs-setup-for-2204 into maas-cert-server:master

 

Rod Smith has proposed merging ~rodsmith/maas-cert-server:update-maniacs-setup-for-2204 into maas-cert-server:master.

Commit message:
Update maniacs-setup for Ubuntu 22.04

Requested reviews:
  hardware-certification-users (hardware-certification)

For more details, see:
https://code.launchpad.net/~rodsmith/maas-cert-server/+git/maas-cert-server/+merge/431157

This updates maniacs-setup for Ubuntu 22.04, including:

* Changes to packaging, since MAAS is now snap-only
* The script installs the MAAS snap if it's not already installed
* Miscellaneous changes to the script to work with MAAS 3.2.6 & Ubuntu 22.04
* Fixed the easiest of the complaints that shellcheck has about the script

To test the script:

1) Get an updated package (it can't be tested with an earlier package);
   either:
   * Get the repo via git and package it yourself; or
   * Get the package I made at https://drive.google.com/file/d/15Pw4dlv7vq6uawTUjMa8Q5i91N-49U8u/view?usp=sharing
2) Follow the MANIACS guide; but....
   1) Use Ubuntu 22.04
   2) After adding the certification PPA, install the downloaded package
      rather than the maas-cert-server package via the PPA
   3) Do a "snap install maas" (or let the script do it)
   4) Ignore the MANIACS guide's advice to install MAAS via a
      Debian package; it must now be installed via a snap.
   5) Run maniacs-setup normally.
   6) Because it's now installing from a snap, you'll be asked for
      a password for PostgresQL. This is expected.
   7) Hope it all works!

(I may have forgotten something. I'm working on documentation next....)
-- 
Your team hardware-certification-users is requested to review the proposed merge of ~rodsmith/maas-cert-server:update-maniacs-setup-for-2204 into maas-cert-server:master.
diff --git a/debian/changelog b/debian/changelog
index 102e899..c2a9691 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+maas-cert-server (0.6.9-0ppa1) jammy; urgency=medium
+
+* Update for Ubuntu 22.04
+
+ -- Rod Smith <rod.smith@xxxxxxxxxxxxx>  Thu, 06 Oct 2022 15:16:10 -0400
+
 maas-cert-server (0.6.8-0ppa1) focal; urgency=medium
 
   * Fix build problem on jammy pre-release
diff --git a/debian/control b/debian/control
index 9a94892..ab089a5 100644
--- a/debian/control
+++ b/debian/control
@@ -11,7 +11,7 @@ Homepage: https://launchpad.net/maas-cert-server
 
 Package: maas-cert-server
 Architecture: all
-Depends: ${misc:Depends}, amtterm, apache2, apt-mirror, certification-docs, certification-tools, distro-info, ipcalc, iperf, iperf3, jshon, maas (>= 2.1), maas-region-api, net-tools, network-manager, postgresql, python3, wsmancli
+Depends: ${misc:Depends}, apache2, apt-mirror, certification-docs, certification-tools, distro-info, ipcalc, iperf, iperf3, jshon, net-tools, network-manager, postgresql, python3, wsmancli
 Description: Ubuntu certification support files for MAAS server
  Support files used on a MAAS server configured for use in Ubuntu server
  certification tasks.
diff --git a/usr/sbin/maniacs-setup b/usr/sbin/maniacs-setup
index 504360b..d507888 100755
--- a/usr/sbin/maniacs-setup
+++ b/usr/sbin/maniacs-setup
@@ -35,7 +35,6 @@ get_params() {
     DOWNLOAD_VIRTUALIZATION_IMAGE=0
     IMPORT_BOOT_RESOURCES=0
     MIRROR_ARCHIVES=0
-    UPDATE_POINT_RELEASES=0
     UPDATE_PRESEEDS=0
     UPDATE_REPOSITORIES=0
     while [[ $# -gt 0 ]]; do
@@ -87,7 +86,7 @@ get_yn() {
             echo -n " (y/N)? "
         fi
         local answer
-        read answer
+        read -r answer
         if [ -z "$answer" ] ; then
             YN=$default
         else
@@ -124,10 +123,10 @@ get_release_info() {
 check_set_progress() {
     local mystatus=incomplete
     # Is our current op already in the tracker?
-    if [ `grep $1 $PROGRESS_TRACKER` ] ; then
+    if [ "$(grep "$1" "$PROGRESS_TRACKER")" ] ; then
         mystatus=completed
     else
-       echo $1 >> $PROGRESS_TRACKER
+       echo "$1" >> "$PROGRESS_TRACKER"
     fi  
     
     echo "$mystatus"
@@ -138,34 +137,34 @@ setup_globals() {
     # configured, and information on internal and external ports is in
     # /etc/maas-cert-server/config; but set some defaults here in case
     # the config file is missing. May automate this in a later version....
-    INSTALLED_RELEASE=`lsb_release -c |awk '{print $2}'`
+    INSTALLED_RELEASE=$(lsb_release -c |awk '{print $2}')
     INTERNAL_NET=eth0
     EXTERNAL_NET=eth1
     MCS_DATA=$HOME/.maas-cert-server
     PROGRESS_TRACKER=$MCS_DATA/progress
     MIRROR_TRACKER=$MCS_DATA/apt-mirror.out
     RERUN=no
-    DEFAULT_USER=`getent passwd | awk -v val=1000 -F ":" '$3==val{print $1}'`
+    DEFAULT_USER=$(getent passwd | awk -v val=1000 -F ":" '$3==val{print $1}')
     if [ -z "$DEFAULT_USER" ] ; then
         echo "The default user (who must have a UID of 1000) can't be determined!"
         echo "Exiting!"
         exit 1
     fi
-    DEFAULT_USERDIR=`eval echo ~$DEFAULT_USER`
+    DEFAULT_USERDIR="$(eval echo ~"$DEFAULT_USER")"
     MIRROR_HOME="/srv/mirrors"
     # Make an attempt to get original upstream in case we've previously
     # configured this machine to use a local mirror.
     if [ -e /etc/apt/sources.list.save ]; then
-        MIRROR_FROM_ARCHIVE=`grep -v -e cdrom -e extras -e deb-src -e "#" /etc/apt/sources.list.save | grep "main" | head -n1 | cut -d " " -f 2`
+        MIRROR_FROM_ARCHIVE=$(grep -v -e cdrom -e extras -e deb-src -e "#" /etc/apt/sources.list.save | grep "main" | head -n1 | cut -d " " -f 2)
     else
-        MIRROR_FROM_ARCHIVE=`grep -v -e cdrom -e extras -e deb-src -e "#" /etc/apt/sources.list | grep "main" | head -n1 | cut -d " " -f 2`
+        MIRROR_FROM_ARCHIVE=$(grep -v -e cdrom -e extras -e deb-src -e "#" /etc/apt/sources.list | grep "main" | head -n1 | cut -d " " -f 2)
     fi
-    MIRROR_HOSTNAME=`echo $MIRROR_FROM_ARCHIVE | cut -f3 -d "/"`
+    MIRROR_HOSTNAME=$(echo "$MIRROR_FROM_ARCHIVE" | cut -f3 -d "/")
     MIRROR_LIST="$MIRROR_HOME/mirror.list"
     ARCHIVE_MIRROR="$MIRROR_HOME/archive"
     # Below is URL given to nodes; it's also verified by the user later.
     DEFAULT_REPO_URL=$MIRROR_FROM_ARCHIVE
-    SUPPORTED_RELEASES=`distro-info --supported`
+    SUPPORTED_RELEASES=$(distro-info --supported)
     CLOUD_ARCHES="amd64 i386 arm64 armhf ppc64el s390x"
     CLOUD_MIRROR="$MIRROR_HOME/cloud"
     RETRY=10
@@ -200,16 +199,16 @@ setup_globals() {
 }
 
 setup_progress_tracker() {
-    if [ ! -d $MCS_DATA ] ; then
-        mkdir $MCS_DATA
+    if [ ! -d "$MCS_DATA" ] ; then
+        mkdir "$MCS_DATA"
     fi
-    if [ ! -e $PROGRESS_TRACKER ] ; then
-        touch $PROGRESS_TRACKER
+    if [ ! -e "$PROGRESS_TRACKER" ] ; then
+        touch "$PROGRESS_TRACKER"
     fi
 }
 
 setup_network_addresses() {
-    local internal_with_route=`route | grep default | grep $INTERNAL_NET`
+    local internal_with_route=$(route | grep default | grep $INTERNAL_NET)
     if [ ! -z "$internal_with_route" ] ; then
         echo "Your default route goes through $INTERNAL_NET, but you've set INTERNAL_NET"
         echo "to $INTERNAL_NET in /etc/maas-cert-server/config. Your internal network"
@@ -217,11 +216,11 @@ setup_network_addresses() {
         exit 1
     fi
 
-    INTERNAL_IP=`ip -4 addr show $INTERNAL_NET | grep inet | tr -s " " | cut -d" " -f3 | cut -d"/" -f1`
-    INTERNAL_BROADCAST=`ip -4 addr show $INTERNAL_NET | grep inet | tr -s " " | cut -d" " -f5`
-    INTERNAL_NETMASK=`ip -4 addr show $INTERNAL_NET | grep inet | tr -s " " | cut -d" " -f3 | cut -d"/" -f2`
-    INTERNAL_NETSTART=`ipcalc -n $INTERNAL_IP/$INTERNAL_NETMASK | grep Network | tr -s " " | cut -d " " -f 2 | cut -d "/" -f 1`
-    EXTERNAL_IP=`ip -4 addr show $EXTERNAL_NET | grep inet | tr -s " " | cut -d" " -f3 | cut -d"/" -f1`
+    INTERNAL_IP=$(ip -4 addr show "$INTERNAL_NET" | grep inet | tr -s " " | cut -d" " -f3 | cut -d"/" -f1)
+    INTERNAL_BROADCAST=$(ip -4 addr show "$INTERNAL_NET" | grep inet | tr -s " " | cut -d" " -f5)
+    INTERNAL_NETMASK=$(ip -4 addr show "$INTERNAL_NET" | grep inet | tr -s " " | cut -d" " -f3 | cut -d"/" -f2)
+    INTERNAL_NETSTART=$(ipcalc -n "$INTERNAL_IP"/"$INTERNAL_NETMASK" | grep Network | tr -s " " | cut -d " " -f 2 | cut -d "/" -f 1)
+    EXTERNAL_IP=$(ip -4 addr show "$EXTERNAL_NET" | grep inet | tr -s " " | cut -d" " -f3 | cut -d"/" -f1)
     MAAS_URL="http://$INTERNAL_IP:5240/MAAS";
     if [ -z "$INTERNAL_IP" ] ; then
         echo "The internal ($INTERNAL_NET) IP address can't be found; exiting!"
@@ -313,7 +312,7 @@ setup_postgresql() {
 reconfigure_controllers() {
     echo 
     echo "***************************************************************************"
-    if [ $(check_set_progress $FUNCNAME) == "completed" ] ; then
+    if [ "$(check_set_progress "$FUNCNAME")" == "completed" ] ; then
         echo "* Region and Cluster controllers have previously been reconfigured."
         RERUN=yes
         return
@@ -335,10 +334,10 @@ ensure_running() {
     local job="$1"
     local count=1
     while true; do
-        if (service $job status | grep -qs "running"); then
+        if (service "$job" status | grep -qs "running"); then
           break
         fi
-        invoke-rc.d $job start
+        invoke-rc.d "$job" start
         sleep 1
         count=$((count+1))
         if [ $count -gt $RETRY ]; then
@@ -382,7 +381,7 @@ setup_maas_admin() {
     # so ignore errors for idempotence
     echo
     echo "***************************************************************************"
-    if [ $(check_set_progress $FUNCNAME) == "completed" ] ; then
+    if [ "$(check_set_progress "$FUNCNAME")" == "completed" ] ; then
         echo "* MAAS Admin user has already been created for $DEFAULT_USER."
         RERUN=yes
         return
@@ -393,7 +392,7 @@ setup_maas_admin() {
     get_password
     echo "* Setting up the $DEFAULT_USER MAAS account using the supplied password"
     if [ $USE_SNAPS == "1" ] ; then
-        maas init --mode=region+rack \
+        maas init region+rack \
              --maas-url="$MAAS_URL" \
              --database-uri="postgres://maas:$DB_PASS@127.0.0.1/maasdb" \
              --admin-password="$PASSWORD" \
@@ -406,23 +405,23 @@ setup_maas_admin() {
 setup_ssh_keys() {
     echo
     echo "***************************************************************************"
-    if [ $(check_set_progress $FUNCNAME) == "completed" ] ; then
+    if [ "$(check_set_progress "$FUNCNAME")" == "completed" ] ; then
         echo "* SSH Keys have already been created for $DEFAULT_USER."
         RERUN=yes
 	return
     fi
     local create="create"
     echo "* Setting up SSH keys for $DEFAULT_USER"
-    if [ ! -e $DEFAULT_USERDIR/.ssh/id_rsa ]; then
-        su -l $DEFAULT_USER -c "ssh-keygen -N '' -f $DEFAULT_USERDIR/.ssh/id_rsa > /dev/null"
+    if [ ! -e "$DEFAULT_USERDIR"/.ssh/id_rsa ]; then
+        su -l "$DEFAULT_USER" -c "ssh-keygen -N '' -f $DEFAULT_USERDIR/.ssh/id_rsa > /dev/null"
     fi
-    maas admin sshkeys $create key="$(cat /$DEFAULT_USERDIR/.ssh/id_rsa.pub)" > /dev/null || true
-    if [ -f $DEFAULT_USERDIR/.ssh/authorized_keys ] ; then
+    maas admin sshkeys "$create" key="$(cat /"$DEFAULT_USERDIR"/.ssh/id_rsa.pub)" > /dev/null || true
+    if [ -f "$DEFAULT_USERDIR"/.ssh/authorized_keys ] ; then
         echo "* Adding keys in $DEFAULT_USERDIR/.ssh/authorized_keys"
         local line
-        while read line ; do
+        while read -r line ; do
             maas admin sshkeys $create key="$line" > /dev/null || true
-        done < $DEFAULT_USERDIR/.ssh/authorized_keys
+        done < "$DEFAULT_USERDIR"/.ssh/authorized_keys
     fi
     if [ -f /etc/ssh/ssh_config ] ; then
         sed -i '/StrictHostKeyChecking/d' /etc/ssh/ssh_config
@@ -432,16 +431,17 @@ setup_ssh_keys() {
 
 
 write_starting_mirror_config() {
+    base_path="/var/spool/apt-mirror"
     echo "############# config ##################" > $MIRROR_LIST
     echo "#" >> $MIRROR_LIST
     echo "# set base_path    /var/spool/apt-mirror" >> $MIRROR_LIST
     echo "#" >> $MIRROR_LIST
-    echo '# set mirror_path  $base_path/mirror' >> $MIRROR_LIST
-    echo '# set skel_path    $base_path/skel' >> $MIRROR_LIST
-    echo '# set var_path     $base_path/var' >> $MIRROR_LIST
-    echo '# set cleanscript $var_path/clean.sh' >> $MIRROR_LIST
+    echo "# set mirror_path  $base_path/mirror" >> $MIRROR_LIST
+    echo "# set skel_path    $base_path/skel" >> $MIRROR_LIST
+    echo "# set var_path     $base_path/var" >> $MIRROR_LIST
+    echo "# set cleanscript $base_path/var/clean.sh" >> $MIRROR_LIST
     echo "# set defaultarch  <running host architecture>" >> $MIRROR_LIST
-    echo '# set postmirror_script $var_path/postmirror.sh' >> $MIRROR_LIST
+    echo "# set postmirror_script $base_path/var/postmirror.sh" >> $MIRROR_LIST
     echo "# set run_postmirror 0" >> $MIRROR_LIST
     echo "set nthreads     20" >> $MIRROR_LIST
     echo "set _tilde 0" >> $MIRROR_LIST
@@ -469,13 +469,13 @@ write_partial_mirror_config() {
 
 
 write_closing_mirror_config() {
-    echo >> $MIRROR_LIST
-    echo "## Clean up archives" >> $MIRROR_LIST
-    echo >> $MIRROR_LIST
-    echo "clean $MIRROR_FROM_ARCHIVE" >> $MIRROR_LIST
-    echo "clean http://ppa.launchpad.net/hardware-certification/public/ubuntu"; >> $MIRROR_LIST
-    echo "clean http://ppa.launchpad.net/checkbox-dev/ppa/ubuntu"; >> $MIRROR_LIST
-    echo "clean http://ppa.launchpad.net/firmware-testing-team/ppa-fwts-stable/ubuntu"; >> $MIRROR_LIST
+    echo >> "$MIRROR_LIST"
+    echo "## Clean up archives" >> "$MIRROR_LIST"
+    echo >> "$MIRROR_LIST"
+    echo "clean $MIRROR_FROM_ARCHIVE" >> "$MIRROR_LIST"
+    echo "clean http://ppa.launchpad.net/hardware-certification/public/ubuntu"; >> "$MIRROR_LIST"
+    echo "clean http://ppa.launchpad.net/checkbox-dev/ppa/ubuntu"; >> "$MIRROR_LIST"
+    echo "clean http://ppa.launchpad.net/firmware-testing-team/ppa-fwts-stable/ubuntu"; >> "$MIRROR_LIST"
 }
 
 
@@ -530,16 +530,16 @@ mirror_archive() {
             if [ $YN = "N" ] ; then
                 echo "*"
                 echo -n "* Enter the correct archive site URL: "
-                read MIRROR_FROM_ARCHIVE
-                MIRROR_HOSTNAME=`echo $MIRROR_FROM_ARCHIVE | cut -f3 -d "/"`
+                read -r MIRROR_FROM_ARCHIVE
+                MIRROR_HOSTNAME=$(echo "$MIRROR_FROM_ARCHIVE" | cut -f3 -d "/")
             else
                 if [[ "$MIRROR_FROM_ARCHIVE" =~ "localhost" ]]; then
                     echo "* WARNING: System is configured to use local mirror, you must specify a valid"
                     echo "* Upstream URL for an archive to mirror"
                     echo "*"
                     echo -n "* Enter the correct archive site URL: "
-                    read MIRROR_FROM_ARCHIVE
-                    MIRROR_HOSTNAME=`echo $MIRROR_FROM_ARCHIVE | cut -f3 -d "/"`
+                    read -r MIRROR_FROM_ARCHIVE
+                    MIRROR_HOSTNAME=$(echo "$MIRROR_FROM_ARCHIVE" | cut -f3 -d "/")
                 fi
             fi
         done
@@ -573,7 +573,7 @@ mirror_archive() {
             # get installed on 64-bit systems; src is needed because default
             # /etc/apt/sources.list file refers to it.
             for architecture in amd64 i386 src ; do
-                write_partial_mirror_config $release $architecture
+                write_partial_mirror_config "$release" "$architecture"
             done
         done
         write_closing_mirror_config
@@ -587,16 +587,16 @@ mirror_archive() {
         echo "* Creating archive mirror in the background. Check $MIRROR_TRACKER"
         echo "* for status information."
         echo "*"
-        mkdir -p $MCS_DATA
-        (apt-mirror &> $MCS_DATA/apt-mirror.out; chown -R www-data:www-data $ARCHIVE_MIRROR/mirror/*; echo -e "Archive Mirror Action from MAAS Setup is now complete.\nYou should now be able to successfully deploy systems." |wall) &
+        mkdir -p "$MCS_DATA"
+        (apt-mirror &> "$MCS_DATA"/apt-mirror.out; chown -R www-data:www-data "$ARCHIVE_MIRROR"/mirror/*; echo -e "Archive Mirror Action from MAAS Setup is now complete.\nYou should now be able to successfully deploy systems." |wall) &
         echo "*"
         echo "* Mirror operation begun."
         echo "*"
         echo "* You will recieve a message on this console when the mirror"
         echo "* operation is complete. Once complete, running"
         echo "* $ARCHIVE_MIRROR/var/clean.sh can free up some disk space."
-        ln -sf $ARCHIVE_MIRROR/mirror/$MIRROR_HOSTNAME/ubuntu /var/www/html/ubuntu
-        ln -sf `find $ARCHIVE_MIRROR/mirror/ppa.launchpad.net/ -maxdepth 1 -mindepth 1 -type d` /var/www/html/
+        ln -sf "$ARCHIVE_MIRROR"/mirror/"$MIRROR_HOSTNAME"/ubuntu /var/www/html/ubuntu
+        ln -sf "$(find "$ARCHIVE_MIRROR"/mirror/ppa.launchpad.net/ -maxdepth 1 -mindepth 1 -type d)" /var/www/html/
         [ -e $ARCHIVE_MIRROR/mirror/maas.ubuntu.com ] && ln -sf $ARCHIVE_MIRROR/mirror/maas.ubuntu.com /var/www/html/
         MIRRORED=1
         echo "*"
@@ -610,7 +610,7 @@ mirror_archive() {
         echo "*"
 
         if [ "$USE_LOCAL_MIRROR" = "Y" ] ; then
-            sed -i s/$original_apt_source/localhost/g /etc/apt/sources.list
+            sed -i s/"$original_apt_source"/localhost/g /etc/apt/sources.list
             apt-get update
         fi
         DEFAULT_REPO_URL="http://$INTERNAL_IP/ubuntu";
@@ -653,7 +653,7 @@ retrieve_virtualization_image() {
         fi
         for release in $SUPPORTED_RELEASES; do
             local default_response="N"
-            if [ "$release" == `distro-info --lts` ] ; then
+            if [ "$release" == "$(distro-info --lts)" ] ; then
                 default_response="Y"
             fi
             get_yn "* Do you want to get images for $release release" "$default_response"
@@ -682,25 +682,24 @@ retrieve_virtualization_image() {
             # fail for each release.
             echo "*"
             for arch in $get_arches; do
-                local got_it="N"
                 echo "* Downloading images for $release on $arch in the background...."
                 # Cloud Images
                 if [ "$arch" == "arm64" ] || [ "$arch" == "armhf" ] ; then
-                    wget -nH -P $CLOUD_MIRROR --timestamping --convert-links \
-                        http://cloud-images.ubuntu.com/$release/current/$release-server-cloudimg-$arch.tar.gz -o $MCS_DATA/cloudimg-dl-$release-$arch.log &
+                    wget -nH -P "$CLOUD_MIRROR" --timestamping --convert-links \
+                        http://cloud-images.ubuntu.com/"$release"/current/"$release"-server-cloudimg-"$arch".tar.gz -o "$MCS_DATA"/cloudimg-dl-"$release"-"$arch".log &
                 else
-                    wget -nH -P $CLOUD_MIRROR --timestamping --convert-links \
-                        http://cloud-images.ubuntu.com/$release/current/$release-server-cloudimg-$arch.img -o $MCS_DATA/cloudimg-dl-$release-$arch.log &
-                    wget -nH -P $CLOUD_MIRROR --timestamping --convert-links \
-                        http://cloud-images.ubuntu.com/$release/current/$release-server-cloudimg-$arch-disk1.img -o $MCS_DATA/cloudimg-disk1-dl-$release-$arch.log &
+                    wget -nH -P "$CLOUD_MIRROR" --timestamping --convert-links \
+                        http://cloud-images.ubuntu.com/"$release"/current/"$release"-server-cloudimg-"$arch".img -o "$MCS_DATA"/cloudimg-dl-"$release"-"$arch".log &
+                    wget -nH -P "$CLOUD_MIRROR" --timestamping --convert-links \
+                        http://cloud-images.ubuntu.com/"$release"/current/"$release"-server-cloudimg-"$arch"-disk1.img -o "$MCS_DATA"/cloudimg-disk1-dl-"$release"-"$arch".log &
                 fi
                 # LXD Container Images
-                wget -nH -P $CLOUD_MIRROR --timestamping --convert-links \
-                    http://cloud-images.ubuntu.com/$release/current/$release-server-cloudimg-$arch-lxd.tar.xz -o $MCS_DATA/cloudimg-lxd-dl-$release-$arch.log &
-                wget -nH -P $CLOUD_MIRROR --timestamping --convert-links \
-                    http://cloud-images.ubuntu.com/$release/current/$release-server-cloudimg-$arch-root.tar.xz -o $MCS_DATA/cloudimg-root-dl-$release-$arch.log &
-                wget -nH -P $CLOUD_MIRROR --timestamping --convert-links \
-                    http://cloud-images.ubuntu.com/$release/current/$release-server-cloudimg-$arch.squashfs -o $MCS_DATA/cloudimg-squashfs-dl-$release-$arch.log &
+                wget -nH -P "$CLOUD_MIRROR" --timestamping --convert-links \
+                    http://cloud-images.ubuntu.com/"$release"/current/"$release"-server-cloudimg-"$arch"-lxd.tar.xz -o "$MCS_DATA"/cloudimg-lxd-dl-"$release"-"$arch".log &
+                wget -nH -P "$CLOUD_MIRROR" --timestamping --convert-links \
+                    http://cloud-images.ubuntu.com/"$release"/current/"$release"-server-cloudimg-"$arch"-root.tar.xz -o "$MCS_DATA"/cloudimg-root-dl-"$release"-"$arch".log &
+                wget -nH -P "$CLOUD_MIRROR" --timestamping --convert-links \
+                    http://cloud-images.ubuntu.com/"$release"/current/"$release"-server-cloudimg-"$arch".squashfs -o "$MCS_DATA"/cloudimg-squashfs-dl-"$release"-"$arch".log &
             done
         done 
         set -e
@@ -721,7 +720,7 @@ retrieve_virtualization_image() {
 setup_nat() {
     echo
     echo "***************************************************************************"
-    if [ $(check_set_progress $FUNCNAME) == "completed" ] ; then
+    if [ "$(check_set_progress "$FUNCNAME")" == "completed" ] ; then
         echo "* NAT has already been configured."
         RERUN=yes
         return
@@ -747,7 +746,7 @@ setup_nat() {
     fi
     set +e
     iptables -L &> /dev/null
-    if [ $? != 0 ] ; then
+    if [ "$?" != 0 ] ; then
         echo "* WARNING: There is a problem with the iptables/NAT configuration!"
         echo "* This must be investigated and fixed before MAAS will be able to"
         echo "* commission or deploy nodes!"
@@ -761,27 +760,27 @@ setup_nat() {
 setup_ip_ranges() {
     echo
     echo "***************************************************************************"
-    if [ $(check_set_progress $FUNCNAME) == "completed" ] ; then
+    if [ "$(check_set_progress "$FUNCNAME")" == "completed" ] ; then
         echo "* MAAS network ranges have already been configured."
         RERUN=yes
         return
     fi
 
-    local internal24=`echo $INTERNAL_IP | cut -d "." -f 1-3`
-    local internal16=`echo $INTERNAL_IP | cut -d "." -f 1-2`
-    local third_octet=`echo $INTERNAL_IP | cut -d "." -f 3`
-    let local third_octet_plus1=$third_octet+1
-    let local third_octet_plus2=$third_octet+2
-    let local third_octet_plus3=$third_octet+3
-    local cidr=`ipcalc -n $INTERNAL_IP/$INTERNAL_NETMASK | grep Netmask | tr -s " " | cut -d " " -f4`
+    local internal24=$(echo "$INTERNAL_IP" | cut -d "." -f 1-3)
+    local internal16=$(echo "$INTERNAL_IP" | cut -d "." -f 1-2)
+    local third_octet=$(echo "$INTERNAL_IP" | cut -d "." -f 3)
+    let local third_octet_plus1="$third_octet"+1
+    let local third_octet_plus2="$third_octet"+2
+    let local third_octet_plus3="$third_octet"+3
+    local cidr=$(ipcalc -n "$INTERNAL_IP"/"$INTERNAL_NETMASK" | grep Netmask | tr -s " " | cut -d " " -f4)
     if [ -z "$cidr" ] ; then
         local is_valid=false
         local numbers='^[0-9]+$'
-        while [ $is_valid != true ] ; do
+        while [ "$is_valid" != true ] ; do
             echo -n "* Could not compute the CIDR netmask! Please enter it here (1-31): "
-            read cidr
-            if [[ $cidr =~ $numbers ]] ; then
-                if [ $cidr -gt 0 ] && [ $cidr -lt 32 ] ; then
+            read -r cidr
+            if [[ "$cidr" =~ $numbers ]] ; then
+                if [ "$cidr" -gt 0 ] && [ "$cidr" -lt 32 ] ; then
                     is_valid=true
                 fi
             fi
@@ -792,7 +791,7 @@ setup_ip_ranges() {
     # * A range managed by DHCP (set explicitly)
     # * A reserved range NOT used by MAAS (set explicitly)
     # * A range used by MAAS for "auto-assign" addresses (everything not set explicitly)
-    if [ $cidr -gt 24 ] ; then
+    if [ "$cidr" -gt 24 ] ; then
         echo "* Your internal network has too few addresses; please specify the values"
         echo "* for two IP address ranges: reserved (never used by MAAS) and DHCP"
         echo "* (used by MAAS with DHCP). Note that a third range is implicit -- those"
@@ -800,15 +799,15 @@ setup_ip_ranges() {
         echo "* range is used by MAAS for auto-assigned static addresses."
         echo "*"
         echo -n "* Low IP address for reserved addresses: "
-        read RESERVED_RANGE_LOW
+        read -r RESERVED_RANGE_LOW
         echo -n "* High IP address for reserved addresses: "
-        read RESERVED_RANGE_HIGH
+        read -r RESERVED_RANGE_HIGH
         echo -n "* Low IP address for DHCP addresses: "
-        read DHCP_RANGE_LOW
+        read -r DHCP_RANGE_LOW
         echo -n "* High IP address for DHCP addresses: "
-        read DHCP_RANGE_HIGH
+        read -r DHCP_RANGE_HIGH
     else
-        if [ $cidr = 24 ] ; then
+        if [ "$cidr" = 24 ] ; then
             RESERVED_RANGE_LOW="$internal24.1"
             RESERVED_RANGE_HIGH="$internal24.9"
             DHCP_RANGE_LOW="$internal24.10"
@@ -816,7 +815,7 @@ setup_ip_ranges() {
             AUTO_ASSIGN_LOW="$internal24.128"
             AUTO_ASSIGN_HIGH="$internal24.254"
         fi
-        if [ $cidr = 23 ] ; then
+        if [ "$cidr" = 23 ] ; then
             RESERVED_RANGE_LOW="$internal24.1"
             RESERVED_RANGE_HIGH="$internal24.50"
             DHCP_RANGE_LOW="$internal24.51"
@@ -824,7 +823,7 @@ setup_ip_ranges() {
             AUTO_ASSIGN_LOW="$internal16.$third_octet_plus1.0"
             AUTO_ASSIGN_HIGH="$internal16.$third_octet_plus1.254"
         fi
-        if [ $cidr -lt 23 ] ; then
+        if [ "$cidr" -lt 23 ] ; then
             RESERVED_RANGE_LOW="$internal24.1"
             RESERVED_RANGE_HIGH="$internal24.255"
             DHCP_RANGE_LOW="$internal16.$third_octet_plus1.0"
@@ -842,16 +841,16 @@ setup_ip_ranges() {
     echo "*    Low auto-assign IP address (implicit) = $AUTO_ASSIGN_LOW"
     echo "*    High auto-assign IP address (implicit) = $AUTO_ASSIGN_HIGH"
 
-    local RANGES=`maas admin ipranges read | grep end_ip`
+    local RANGES=$(maas admin ipranges read | grep end_ip)
     if [ -z "$RANGES" ] ; then
         echo "* Initializing rack controller"
-        maas admin ipranges create type=dynamic start_ip=$DHCP_RANGE_LOW end_ip=$DHCP_RANGE_HIGH > /dev/null
-        maas admin ipranges create type=reserved start_ip=$RESERVED_RANGE_LOW end_ip=$RESERVED_RANGE_HIGH > /dev/null
-        INTERNAL_FABRIC=`maas admin ipranges read | jshon -a -e subnet -e vlan -e fabric | tr -d '"' | head -n 1`
-        PRIMARY_RACK=`maas admin rack-controllers read | jshon -a -e hostname | tr -d '"'`
-        maas admin vlan update $INTERNAL_FABRIC untagged dhcp_on=True primary_rack=$PRIMARY_RACK > /dev/null
-        local SUBNET_ID=`maas admin ipranges read | jshon -a -e subnet -e id | head -n 1`
-        maas admin subnet update $SUBNET_ID gateway_ip=$INTERNAL_IP
+        maas admin ipranges create type=dynamic start_ip="$DHCP_RANGE_LOW" end_ip="$DHCP_RANGE_HIGH" > /dev/null
+        maas admin ipranges create type=reserved start_ip="$RESERVED_RANGE_LOW" end_ip="$RESERVED_RANGE_HIGH" > /dev/null
+        INTERNAL_FABRIC=$(maas admin ipranges read | jshon -a -e subnet -e vlan -e fabric | tr -d '"' | head -n 1)
+        PRIMARY_RACK=$(maas admin rack-controllers read | jshon -a -e hostname | tr -d '"')
+        maas admin vlan update "$INTERNAL_FABRIC" untagged dhcp_on=True primary_rack="$PRIMARY_RACK" > /dev/null
+        local SUBNET_ID=$(maas admin ipranges read | jshon -a -e subnet -e id | head -n 1)
+        maas admin subnet update "$SUBNET_ID" gateway_ip="$INTERNAL_IP"
     else
         echo "* Rack controller DHCP configuration already exists; leaving it alone!"
         echo "* You should use the MAAS web UI to reconfigure your ranges!"
@@ -863,7 +862,7 @@ setup_ip_ranges() {
 # Add escapes ("\") before ".", "[", and "]" characters in the passed string.
 # Return modified string as modified_string
 add_escapes() {
-    local original_string=$1
+#     local original_string="$1"
     modified_string=${1//\./\\\.}
     modified_string=${modified_string//\[/\\\[}
     modified_string=${modified_string//\]/\\\]}
@@ -872,27 +871,32 @@ add_escapes() {
 setup_dns() {
     echo
     echo "***************************************************************************"
-    if [ $(check_set_progress $FUNCNAME) == "completed" ] ; then
+    if [ "$(check_set_progress "$FUNCNAME")" == "completed" ] ; then
         echo "* Upstread DNS has already been configured."
         RERUN=yes
         return
     fi
 
     # Set MAAS upstream DNS
-    local dns=`cat /etc/resolv.conf | grep -v $INTERNAL_IP | grep -v "#" | grep -i nameserver | head -n1 | cut -d ' ' -f2`
+    local dns=$(cat /etc/resolv.conf | grep -v "$INTERNAL_IP" | grep -v "#" | grep -i nameserver | head -n1 | cut -d ' ' -f2)
     # Below signals that NetworkManager is in charge of DNS, so extract real
     # upstream DNS using nmcli....
     if [ "$dns" = "127.0.1.1" ] || [ "$dns" = "127.0.0.53" ] ; then
-        if dpkg --compare-versions "`nmcli -v | grep -oE '[^ ]+$'`" "lt" "0.9.10" ; then
-            dns=`nmcli dev list iface $EXTERNAL_NET | grep -m 1 domain_name_servers | tr -s " " | grep -oE '[^ ]+$'` || true
+        if dpkg --compare-versions "$(nmcli -v | grep -oE '[^ ]+$')" "lt" "0.9.10" ; then
+            dns=$(nmcli dev list iface $EXTERNAL_NET | grep -m 1 domain_name_servers | tr -s " " | grep -oE '[^ ]+$') || true
         else
-            dns=`nmcli dev show $EXTERNAL_NET | grep -m 1 DNS | tr -s " " | grep -oE '[^ ]+$'` || true
+            dns=$(nmcli dev show $EXTERNAL_NET | grep -m 1 DNS | tr -s " " | grep -oE '[^ ]+$') || true
         fi
         # Ubuntu 18.04's NetPlan can look like NetworkManager, but NetPlan
         # doesn't use nmcli, so we must instead use systemd-resolve....
         if [ -z "$dns" ] ; then
-            dns=`systemd-resolve --status $EXTERNAL_NET | grep "DNS Servers" | cut -d ":" -f 2 | xargs`
+            dns=$(systemd-resolve --status $EXTERNAL_NET | grep "DNS Servers" | cut -d ":" -f 2 | xargs)
         fi
+        echo "dns is $dns"
+    fi
+    # None of the above works in Ubuntu 22.04, so try yet another approach....
+    if [ -z "$dns" ] ; then
+        dns=$(resolvectl status | grep "Current DNS Server" | head -n 1 | cut -d ":" -f 2 | sed 's/ //g')
     fi
     if [ -z "$dns" ] ; then
         dns="8.8.8.8"
@@ -905,17 +909,17 @@ setup_dns() {
         echo "nameserver $INTERNAL_IP" >> /etc/resolvconf/resolv.conf.d/head
         resolvconf -u
     elif [ -f 01-netcfg.yaml ] ; then # New style (NetPlan); Ubuntu 18.04
-        nameservers=`grep -A 1 nameservers /etc/netplan/01-netcfg.yaml | tail -n 1 | cut -d ":" -f 2`
+        nameservers=$(grep -A 1 nameservers /etc/netplan/01-netcfg.yaml | tail -n 1 | cut -d ":" -f 2)
         if [ -z "$nameservers" ] ; then # No name servers defined
-            if [ "`grep addresses /etc/netplan/01-netcfg.yaml`" ] ; then
+            if [ "$(grep addresses /etc/netplan/01-netcfg.yaml)" ] ; then
                 echo "      nameservers:" >> /etc/netplan/01-netcfg.yaml
                 echo "        addresses: [$INTERNAL_IP]" >> /etc/netplan/01-netcfg.yaml
             fi
-        elif [ ! "`echo $nameservers | grep $INTERNAL_IP`" ] ; then
+        elif [ ! "$(echo "$nameservers" | grep "$INTERNAL_IP")" ] ; then
             new_nameservers=${nameservers/\[/\[$INTERNAL_IP,}
-            add_escapes $new_nameservers
-            new_nameservers=$modified_string
-            add_escapes $nameservers
+            add_escapes "$new_nameservers"
+            new_nameservers="$modified_string"
+            add_escapes "$nameservers"
             nameservers=$modified_string
             sed -i "s/$nameservers/$new_nameservers/" /etc/netplan/01-netcfg.yaml
             echo "changed $nameservers to $new_nameservers"
@@ -929,7 +933,7 @@ setup_dns() {
 
 setup_flat_storage() {
     set +e
-    dpkg --compare-versions "1.9.0" "le" $MAAS_VERSION
+    dpkg --compare-versions "1.9.0" "le" "$MAAS_VERSION"
     if [ "$?" = 0 ] ; then
         set -e
         echo
@@ -946,7 +950,7 @@ setup_node_archive_site() {
     echo
     echo "***************************************************************************"
     echo "* MAAS tells nodes to look to an Ubuntu repository on the Internet. You"
-    if [ $(check_set_progress $FUNCNAME) == "completed" ] ; then
+    if [ "$(check_set_progress "$FUNCNAME")" == "completed" ] ; then
         echo "* MAAS has already been configured with a repository."
         RERUN=yes
         return
@@ -956,12 +960,12 @@ setup_node_archive_site() {
     echo "* to use the default value of $DEFAULT_REPO_URL."
     echo "*"
     echo -n "* Type your repository's URL, or press the Enter key: "
-    read new_repo_url
-    if [ -z $new_repo_url ] ; then
-        new_repo_url=$DEFAULT_REPO_URL
+    read -r new_repo_url
+    if [ -z "$new_repo_url" ] ; then
+        new_repo_url="$DEFAULT_REPO_URL"
     fi
     echo "* Setting the repository URL to $new_repo_url"
-    maas admin maas set-config name=main_archive value=$new_repo_url
+    maas admin maas set-config name=main_archive value="$new_repo_url"
 }
 
 
@@ -970,76 +974,22 @@ setup_certification_preseeds() {
     echo "***************************************************************************"
     echo "* Setting up certification preseed files...."
     echo "*"
+    # The certification preseed file is installed via the maas-cert-server
+    # package's postinst script; however, if the MAAS snap was not installed
+    # before the package was installed, the preseed won't be set up, so we
+    # should do it here....
+    if [ -f /usr/share/maas-cert-server/preseed/curtin_userdata_cert ] ; then
+        cp /usr/share/maas-cert-server/preseed/curtin_userdata_cert "$CURTIN_USERDATA"
+    else
+        echo "**"
+        echo "** /usr/share/mass-cert-server/preseed/curtin_userdata_cert file not found!"
+        echo "**"
+    fi
     if [ $MIRRORED -eq 1 ] ; then
         sed -i s/ppa.launchpad.net/"$INTERNAL_IP"/g "$CURTIN_USERDATA"
     fi
 }
 
-
-# Sets COMPLETE_RESOURCES to "true" if at least one boot source is present AND it's complete.
-# Also, if boot-resource download has not begun, start it.
-are_boot_resources_complete() {
-    local resource_ids=($(maas admin boot-resources read | jshon -a -e id))
-    COMPLETE_RESOURCES="false"
-    local resource_complete="true"
-    local resource_present="false"
-    for i in ${resource_ids[@]}; do
-        resource_present="true"
-        if [ "$(maas admin boot-resource read $i | jshon -e sets -a -e complete)" != "true" ] ; then
-            resource_complete="false"
-        fi
-    done
-    if [ "$resource_complete" = "true" ] && [ "$resource_present" = "true" ] ; then
-        COMPLETE_RESOURCES="true"
-    fi
-    if [ "${#resource_ids[@]}" = "0" ] ; then
-        # Boot resource import not started; do so
-        echo "* Beginning import of boot resources"
-        maas admin boot-resources import
-    fi
-}
-
-
-setup_standard_boot_resources() {
-    # Importing boot resources
-    # This might take a long time.
-    echo
-    echo "***************************************************************************"
-    echo "* MAAS requires boot resource images to be useful, and they will now be"
-    echo "* imported in the background. This can take a LONG time, but will not"
-    echo "* significantly slow down subsequent configuration steps."
-    are_boot_resources_complete
-}
-
-
-# Determine if any i386 images are loaded on the MAAS server.
-# Sets $is_i386 to "N" if no i386 images are found, "Y" if they are.
-is_i386_loaded() {
-    is_i386="N"
-    local resources=`maas admin boot-resources read`
-    # Look for evidence of i386 installation. Note that the below can produce
-    # false positives, so we do more shortly....
-    local maybe_i386=`echo $resources | jshon -a -e architecture | grep i386`
-    if [ ! -z "$maybe_i386" ] ; then
-        local num_entries=`echo $resources | jshon -l`
-        let last_entry=$num_entries-1
-        for entry in `seq 0 $last_entry`; do
-            one_entry=`echo $resources | jshon -e $entry`
-            local found_possible_i386=`echo $one_entry | grep i386`
-            if [ ! -z "$found_possible_i386" ] ; then
-               local is_pxelinux=`echo "$one_entry" | jshon -e name | grep pxelinux`
-               # False positive can result from pxelinux entry, which is why
-               # we filter it out. AFAIK, any other "i386" in "name" field is
-               # a legitimate i386 image.
-               if [ -z "$is_pxelinux" ] ; then
-                   is_i386="Y"
-               fi
-            fi
-        done
-    fi
-} # is_i386_loaded()
-
-
 setup_weblinks() {
     mkdir -p /var/www/html/doc
     if [ ! -f /var/www/html/index.html-orig ] ; then
@@ -1059,7 +1009,7 @@ setup_repositories() {
     echo "* tools when deploying the SUT."
     echo "*"
     # Get the existing repo names
-    REPO_NAMES=`maas admin package-repositories read |grep name|grep -v key|awk -F'"' '{print "\""$4"\""}'`
+    REPO_NAMES=$(maas admin package-repositories read |grep name|grep -v key|awk -F'"' '{print "\""$4"\""}')
     # Figure out what architectures to apply repos to:
     ARCHES=""
     for arch in $CLOUD_ARCHES; do
@@ -1099,7 +1049,7 @@ GsZVWOB3IQEZDOudR4jc7t4KdbWPAi2LzhOmmkDYiEsQ1dHum/XaaS1J78q3PVgfcJ6E5wM=
 =yMG1
 -----END PGP PUBLIC KEY BLOCK-----'
     ENABLED='true'
-    if [[ "$REPO_NAMES" =~ "$NAME" ]]; then
+    if [[ "$REPO_NAMES" =~ $NAME ]]; then
         echo "* - $NAME already exists. Please verify it in the MAAS Web Interface"
     else
         maas admin package-repositories create name="$NAME" url="$URL" key="$KEY" arches="$ARCHES" enabled="$ENABLED" >/dev/null
@@ -1122,7 +1072,7 @@ qBVICuW5JINuTzBTAJepQjz2RgNhsC8/E95P2hWMjrQFtz4GsMBXdi2mxVNE4yVBjBpm2lvn
 =jZn4
 -----END PGP PUBLIC KEY BLOCK-----'
     ENABLED='true'
-    if [[ "$REPO_NAMES" =~ "$NAME" ]]; then
+    if [[ "$REPO_NAMES" =~ $NAME ]]; then
         echo "* - $NAME already exists. Please verify it in the MAAS Web Interface"
     else
         maas admin package-repositories create name="$NAME" url="$URL" key="$KEY" arches="$ARCHES" enabled="$ENABLED" >/dev/null
@@ -1147,7 +1097,7 @@ pFd1I9KMiGEhzCrQDp8cYjZkdMDEPsO9A87S5BxpB9rwBj9cnYnpvbw5
 =JBdy
 -----END PGP PUBLIC KEY BLOCK-----'
     ENABLED='false'
-    if [[ "$REPO_NAMES" =~ "$NAME" ]]; then
+    if [[ "$REPO_NAMES" =~ $NAME ]]; then
         echo "* - $NAME already exists. Please verify it in the MAAS Web Interface"
     else
         maas admin package-repositories create name="$NAME" url="$URL" key="$KEY" arches="$ARCHES" enabled="$ENABLED" >/dev/null
@@ -1163,13 +1113,14 @@ pFd1I9KMiGEhzCrQDp8cYjZkdMDEPsO9A87S5BxpB9rwBj9cnYnpvbw5
 #
 ########
 
-if [ `whoami` != "root" ] ; then
+if [ "$(whoami)" != "root" ] ; then
     echo "This script must be run via sudo. Exiting!"
     exit 1
 fi
 
 
 get_params "$@"
+snap install maas
 get_release_info
 setup_globals
 setup_progress_tracker
@@ -1184,7 +1135,6 @@ if [ $DO_IT_ALL == 0 ] ; then
     fi
     if [ $IMPORT_BOOT_RESOURCES == 1 ] ; then
         setup_flat_storage
-        setup_standard_boot_resources
     fi
     if [ $UPDATE_PRESEEDS == 1 ] ; then
         setup_network_addresses
@@ -1220,7 +1170,6 @@ else
     setup_flat_storage
     setup_node_archive_site
     setup_certification_preseeds
-    setup_standard_boot_resources
     setup_repositories
 fi
 setup_weblinks
@@ -1243,8 +1192,8 @@ if [ "$RERUN" == "yes" ] ; then
     echo "*"
 fi
 
-if [ -f $DEFAULT_USERDIR/.maascli.db ] ; then
-    chown $DEFAULT_USER: $DEFAULT_USERDIR/.maascli.db
+if [ -f "$DEFAULT_USERDIR"/.maascli.db ] ; then
+    chown "$DEFAULT_USER": "$DEFAULT_USERDIR"/.maascli.db
 fi
 
 echo

Follow ups