#!/bin/bash
# Check parent script to prevent scenarios execion outside ngcp-upgrade

set -e

if [ "${NGCP_UPGRADE}" != "ngcp-upgrade" ] ; then
  echo "ERROR: the script cannot be called directly!" >&2
  echo "Please run 'ngcp-upgrade' with root privileges instead!" >&2
  exit 1
fi

if [ -z "${OLD_VERSION}" ] ; then
  echo "ERROR: Missing mandatory environment variable '\$OLD_VERSION', cannot continue!" >&2
  exit 1
fi

if [ -z "${UPGRADE_VERSION}" ] ; then
  echo "ERROR: Missing mandatory environment variable '\$UPGRADE_VERSION', cannot continue!" >&2
  exit 1
fi

if [ -z "${BACKUP}" ] ; then
  echo "ERROR: Missing mandatory environment variable '\$BACKUP', cannot continue!" >&2
  exit 1
fi

if [ -z "${NGCP_NODENAME}" ] ; then
  echo "ERROR: Missing mandatory environment variable '\$NGCP_NODENAME', cannot continue!" >&2
  exit 1
fi

if [ -z "${LOGFILE}" ] ; then
  echo "ERROR: Missing mandatory environment variable '\$LOGFILE', cannot continue!" >&2
  exit 1
fi

if [ -z "${DIST}" ] ; then
  echo "ERROR: Missing mandatory environment variable '\$DIST', cannot continue!" >&2
  exit 1
fi

if [ -z "${LC_ALL}" ] ; then
  echo "ERROR: Missing mandatory environment variable '\$LC_ALL', cannot continue!" >&2
  exit 1
fi

if [ -z "${LANG}" ] ; then
  echo "ERROR: Missing mandatory environment variable '\$LANG', cannot continue!" >&2
  exit 1
fi

if [ -z "${DB_CFG_FILE}" ] ; then
  echo "ERROR: Missing mandatory environment variable '\$DB_CFG_FILE', cannot continue!" >&2
  exit 1
fi

if [ -z "${CARRIER_EDITION}" ] ; then
  echo "ERROR: Missing mandatory environment variable '\$CARRIER_EDITION', cannot continue!" >&2
  exit 1
fi

if [ -z "${APT_CMD}" ] ; then
  echo "ERROR: Missing mandatory environment variable '\$APT_CMD', cannot continue!" >&2
  exit 1
fi

if [ -z "${APT_OPTS}" ] ; then
  echo "ERROR: Missing mandatory environment variable '\$APT_OPTS', cannot continue!" >&2
  exit 1
fi

if [ -z "${APT_LISTCHANGES_FRONTEND}" ] ; then
  echo "ERROR: Missing mandatory environment variable '\$APT_LISTCHANGES_FRONTEND', cannot continue!" >&2
  exit 1
fi

if [ -z "${APT_LISTBUGS_FRONTEND}" ] ; then
  echo "ERROR: Missing mandatory environment variable '\$APT_LISTBUGS_FRONTEND', cannot continue!" >&2
  exit 1
fi

if [ -z "${DEBIAN_PRIORITY}" ] ; then
  echo "ERROR: Missing mandatory environment variable '\$DEBIAN_PRIORITY', cannot continue!" >&2
  exit 1
fi

if [ -z "${DEBIAN_FRONTEND}" ] ; then
  echo "ERROR: Missing mandatory environment variable '\$DEBIAN_FRONTEND', cannot continue!" >&2
  exit 1
fi

if [ -z "${FORCE_UPGRADE}" ] ; then
  echo "ERROR: Missing mandatory environment variable '\$FORCE_UPGRADE', exiting." >&2
  exit 1
fi

