From 2acdd05aac72cd0f6fe49aa271b951a415e36bac Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Wed, 23 Feb 2022 14:41:05 -0500 Subject: Add: Two new checks in maas-version-check.sh test --- bin/maas-version-check.sh | 66 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 11 deletions(-) (limited to 'bin') 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 +# Rod Smith # 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 . 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 -- cgit v1.2.3