#!/bin/bash

set -eEuo pipefail

if [[ "${OLD_VERSION}" =~ mr9.5 ]]; then
  echo "OLD_VERSION is '${OLD_VERSION}' so skipping this check"
  exit 0
fi

if ! command -v ngcp-virt-identify &>/dev/null; then
  echo "ngcp-virt-identify not available, skipping checks"
  exit 0
fi

if ngcp-virt-identify; then
  echo "ngcp-virt-identify reported virtualized environment, skipping check of smartmontools"
  exit 0
fi

echo "ngcp-virt-identify reported non-virtualized environment"
echo "Checking smartmontools is enabled"

smartmontools="$(ngcpcfg get monitoring.smartmontools.enable)"
if [[ "${smartmontools:-no}" == 'no' ]]; then
  echo "Hardware platform is detected and smartmontools is not enabled" >&2
  echo "please enable it with 'ngcpcfg set /etc/ngcp-config/config.yml monitoring.smartmontools.enable=yes' command" >&2
  exit 1
else
  echo "Hardware platform is detected and smartmontools is enabled, exiting..."
fi
