2022-05-09 15:13:38 +02:00
#!/bin/bash -e
baseDir() {
# see https://stackoverflow.com/questions/59895
SOURCE=${BASH_SOURCE[0]}
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
SOURCE=$(readlink "$SOURCE")
[[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
echo $DIR
}
BASE=$(baseDir)
cd $BASE
source ./lib/functions.sh
2022-05-11 10:30:18 +02:00
ACTION=$1
export PROJECT=$2
2022-05-09 15:13:38 +02:00
if [[ -z $1 || -z $2 ]]; then
printUsage
exit 1
fi
2022-05-11 10:30:18 +02:00
case "$PROJECT" in
2022-05-09 15:13:38 +02:00
ccp)
#nothing extra to do
;;
nngm)
#nothing extra to do
;;
2022-10-25 11:45:01 +02:00
bbmri)
2022-05-09 15:13:38 +02:00
#nothing extra to do
;;
*)
printUsage
exit 1
;;
esac
2022-09-30 16:05:36 +02:00
# Load variables from /etc/bridgehead and /srv/docker/bridgehead
set -a
2022-10-06 10:45:50 +02:00
source /etc/bridgehead/$PROJECT.conf || fail_and_report 1 "/etc/bridgehead/$PROJECT.conf not found"
2022-10-11 11:06:52 +02:00
if [ -e /etc/bridgehead/$PROJECT.local.conf ]; then
log INFO "Applying /etc/bridgehead/$PROJECT.local.conf"
source /etc/bridgehead/$PROJECT.local.conf || fail_and_report 1 "Found /etc/bridgehead/$PROJECT.local.conf but failed to import"
fi
2022-10-06 10:45:50 +02:00
fetchVarsFromVaultByFile /etc/bridgehead/$PROJECT.conf || fail_and_report 1 "Unable to fetchVarsFromVaultByFile"
2022-09-30 16:05:36 +02:00
[ -e ./$PROJECT/vars ] && source ./$PROJECT/vars
set +a
2022-10-26 11:50:21 +02:00
OVERRIDE=${OVERRIDE:=""}
2022-10-06 16:27:52 +02:00
if [ -f "$PROJECT/docker-compose.override.yml" ]; then
2022-10-11 11:06:52 +02:00
log INFO "Applying $PROJECT/docker-compose.override.yml"
2022-10-26 11:50:21 +02:00
OVERRIDE+=" -f ./$PROJECT/docker-compose.override.yml"
2022-10-06 16:27:52 +02:00
fi
2022-05-11 10:30:18 +02:00
case "$ACTION" in
2022-05-09 15:13:38 +02:00
start)
2022-10-06 10:45:50 +02:00
hc_send log "Bridgehead $PROJECT startup: Checking requirements ..."
2022-05-09 15:13:38 +02:00
checkRequirements
2022-10-06 10:45:50 +02:00
hc_send log "Bridgehead $PROJECT startup: Requirements checked out. Now starting bridgehead ..."
2022-10-06 16:27:52 +02:00
exec docker-compose -f ./$PROJECT/docker-compose.yml $OVERRIDE up --abort-on-container-exit
2022-05-09 15:13:38 +02:00
;;
stop)
2022-10-06 16:27:52 +02:00
exec docker-compose -f ./$PROJECT/docker-compose.yml $OVERRIDE down
2022-05-09 15:13:38 +02:00
;;
update)
2022-05-11 10:30:18 +02:00
exec ./lib/update-bridgehead.sh $PROJECT
2022-05-09 15:13:38 +02:00
;;
install)
2022-05-16 08:19:49 +02:00
exec ./lib/setup-bridgehead-units.sh $PROJECT
2022-05-09 15:13:38 +02:00
;;
uninstall)
2022-05-16 08:19:49 +02:00
exec ./lib/remove-bridgehead-units.sh $PROJECT
2022-05-09 15:13:38 +02:00
;;
2022-10-17 14:38:34 +02:00
enroll)
if [ -e $PRIVATEKEYFILENAME ]; then
echo "Private key already exists at $PRIVATEKEYFILENAME. Please delete first to proceed."
exit 1
fi
docker run --rm -ti -v /etc/bridgehead/pki:/etc/bridgehead/pki samply/beam-enroll:latest --output-file $PRIVATEKEYFILENAME --proxy-id $PROXY_ID --admin-email $SUPPORT_EMAIL
chmod 600 $PRIVATEKEYFILENAME
;;
2022-10-06 10:45:50 +02:00
preRun | preUpdate)
fixPermissions
;;
postRun | postUpdate)
2022-10-05 19:58:07 +02:00
;;
2022-05-09 15:13:38 +02:00
*)
printUsage
exit 1
;;
esac
exit 0