diff options
author | Rod Smith <rod.smith@canonical.com> | 2022-02-23 14:41:05 -0500 |
---|---|---|
committer | Rod Smith <rod.smith@canonical.com> | 2022-02-23 14:41:05 -0500 |
commit | 2acdd05aac72cd0f6fe49aa271b951a415e36bac (patch) | |
tree | e579ac3ef36e056f616f6c71410671b5156e6e19 /bin | |
parent | 4b243d446eac8d54819c297b4ed071dc5c8f31de (diff) |
Add: Two new checks in maas-version-check.sh test
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/maas-version-check.sh | 66 |
1 files changed, 55 insertions, 11 deletions
diff --git a/bin/maas-version-check.sh b/bin/maas-version-check.sh index 25e233f..49c3ce0 100755 --- a/bin/maas-version-check.sh +++ b/bin/maas-version-check.sh @@ -1,9 +1,10 @@ #!/bin/bash -# Copyright (C) 2012-2019 Canonical Ltd. +# Copyright (C) 2012-2022 Canonical Ltd. # Authors # Jeff Lane <jeff@ubuntu.com> +# Rod Smith <rod.smith@canonical.com> # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3, @@ -18,14 +19,57 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. MAAS_FILE="/etc/installed-by-maas" +DATASOURCE_FILE="/var/lib/cloud/instance/datasource" +MAAS_DATASOURCE="" +RETVAL="0" -# Is the file there? -if [ -s $MAAS_FILE ]; then - maas_version=$(cat $MAAS_FILE) - echo "$maas_version" - exit 0 -else - echo "ERROR: This system does not appear to have been installed by MAAS" - echo "ERROR: " "$(ls -l $MAAS_FILE 2>&1)" - exit 1 -fi +# Find the MAAS data source, as recorded in cloud installer files +get_maas_datasource() { + # Is the file there? + if [ -s $DATASOURCE_FILE ]; then + MAAS_DATASOURCE=$(cut -d "[" -f 2 $DATASOURCE_FILE | cut -d "]" -f 1) + echo "MAAS data source is $MAAS_DATASOURCE" + else + echo "ERROR: This system does not appear to have been installed by MAAS" + echo "ERROR: " "$(ls -l $DATASOURCE_FILE 2>&1)" + RETVAL="1" + fi +} + +# Verify that the $MAAS_DATASOURCE points to a valid IP address. +# Note: Function assumes that $MAAS_DATASOURCE is already set, as is +# done by the get_maas_datasource() function. +verify_maas_ip() { + if [[ $RETVAL == 0 ]]; then + MAAS_HOSTNAME=$(echo $MAAS_DATASOURCE | cut -d "/" -f 3 | cut -d ":" -f 1) + HOST_OUTPUT=$(host $MAAS_HOSTNAME | grep "has address") + status=$? + if [[ $status -eq 0 ]]; then + MAAS_IP=$(echo $HOST_OUTPUT | cut -d " " -f 4) + echo "MAAS server's IP address is $MAAS_IP" + else + echo "ERROR: Unable to determine MAAS server's IP address" + RETVAL=1 + fi + fi +} + +# Pull the MAAS version information from a file left here by the +# Server Certification pre-seed file +get_maas_version() { + # Is the file there? + if [ -s $MAAS_FILE ]; then + maas_version=$(cat $MAAS_FILE) + echo "MAAS version is $maas_version" + else + echo "ERROR: The MAAS version cannot be determined" + echo "ERROR: " "$(ls -l $MAAS_FILE 2>&1)" + RETVAL="1" + fi +} + +get_maas_datasource +verify_maas_ip +get_maas_version + +exit $RETVAL |