Files
hla_framework_bd/.gitea/scripts/common.sh

47 lines
1.5 KiB
Bash

#!/bin/bash
# Shared helpers for the scripts run by the gitea runner.
# Source it as: source "$(dirname "$0")/common.sh"
# Overridable so the scripts can be exercised outside of the runner
HLA_ROOT=${HLA_ROOT:-/sls/bd/hla}
# Sets AGEBD_ENV_SUFFIX_UPPER/LOWER for the given environment.
# Usage: set_env_suffix <dev|prod>
set_env_suffix() {
local ENV=$1
if [ "${ENV}" = "dev" ]; then
AGEBD_ENV_SUFFIX_UPPER="-DEV"
AGEBD_ENV_SUFFIX_LOWER="-dev"
elif [ "${ENV}" = "prod" ]; then
AGEBD_ENV_SUFFIX_UPPER=""
AGEBD_ENV_SUFFIX_LOWER=""
else
echo "Unknown environment '${ENV}', expected 'dev' or 'prod'" >&2
exit 1
fi
}
# Sets the naming and path variables used by the deploy and ioc scripts.
# Usage: init_service_env <service-name> <dev|prod>
init_service_env() {
local SERVICE_NAME=$1
AGEBD_ENV=$2
if [ -z "${SERVICE_NAME}" ] || [ -z "${AGEBD_ENV}" ]; then
echo "Usage: $0 <service-name> <dev|prod>" >&2
exit 1
fi
set_env_suffix "${AGEBD_ENV}"
SERVICE_NAME_LOWER=$(echo "${SERVICE_NAME}" | tr '[:upper:]' '[:lower:]')
SERVICE_NAME_UPPER=$(echo "${SERVICE_NAME}" | tr '[:lower:]' '[:upper:]')
SERVICE_DIR=${HLA_ROOT}/${AGEBD_ENV}/services/${SERVICE_NAME_LOWER}/current
IOC_DIR=${SERVICE_DIR}/ioc
IOC_NAME=AGEBD-CPCL-${SERVICE_NAME_UPPER}${AGEBD_ENV_SUFFIX_UPPER}
# Host running shellbox, i.e. the host the ioc itself runs on
IOC_HOST=sls-vserv-bd-01${AGEBD_ENV_SUFFIX_LOWER}
}