mirror of
				https://github.com/samply/bridgehead.git
				synced 2025-11-04 04:50:17 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			103 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			103 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
#!/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
 | 
						|
 | 
						|
ACTION=$1
 | 
						|
export PROJECT=$2
 | 
						|
 | 
						|
if [[ -z $1 || -z $2 ]]; then
 | 
						|
	printUsage
 | 
						|
	exit 1
 | 
						|
fi
 | 
						|
 | 
						|
case "$PROJECT" in
 | 
						|
	ccp)
 | 
						|
		#nothing extra to do
 | 
						|
		;;
 | 
						|
	nngm)
 | 
						|
		#nothing extra to do
 | 
						|
		;;
 | 
						|
	bbmri)
 | 
						|
		#nothing extra to do
 | 
						|
		;;
 | 
						|
	*)
 | 
						|
		printUsage
 | 
						|
		exit 1
 | 
						|
		;;
 | 
						|
esac
 | 
						|
 | 
						|
# Load variables from /etc/bridgehead and /srv/docker/bridgehead
 | 
						|
set -a
 | 
						|
source /etc/bridgehead/$PROJECT.conf || fail_and_report 1 "/etc/bridgehead/$PROJECT.conf not found"
 | 
						|
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
 | 
						|
fetchVarsFromVaultByFile /etc/bridgehead/$PROJECT.conf || fail_and_report 1 "Unable to fetchVarsFromVaultByFile"
 | 
						|
[ -e ./$PROJECT/vars ] && source ./$PROJECT/vars
 | 
						|
set +a
 | 
						|
 | 
						|
OVERRIDE=${OVERRIDE:=""}
 | 
						|
if [ -f "$PROJECT/docker-compose.override.yml" ]; then
 | 
						|
	log INFO "Applying $PROJECT/docker-compose.override.yml"
 | 
						|
	OVERRIDE+=" -f ./$PROJECT/docker-compose.override.yml"
 | 
						|
fi
 | 
						|
 | 
						|
detectCompose
 | 
						|
setLdmPassword
 | 
						|
 | 
						|
case "$ACTION" in
 | 
						|
	start)
 | 
						|
		hc_send log "Bridgehead $PROJECT startup: Checking requirements ..."
 | 
						|
		checkRequirements
 | 
						|
		hc_send log "Bridgehead $PROJECT startup: Requirements checked out. Now starting bridgehead ..."
 | 
						|
		exec $COMPOSE -f ./$PROJECT/docker-compose.yml $OVERRIDE up --abort-on-container-exit
 | 
						|
		;;
 | 
						|
	stop)
 | 
						|
		exec $COMPOSE -f ./$PROJECT/docker-compose.yml $OVERRIDE down
 | 
						|
		;;
 | 
						|
	update)
 | 
						|
		exec ./lib/update-bridgehead.sh $PROJECT
 | 
						|
		;;
 | 
						|
	install)
 | 
						|
		exec ./lib/setup-bridgehead-units.sh $PROJECT
 | 
						|
		;;
 | 
						|
	uninstall)
 | 
						|
		exec ./lib/remove-bridgehead-units.sh $PROJECT
 | 
						|
		;;
 | 
						|
	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
 | 
						|
		;;
 | 
						|
	preRun | preUpdate)
 | 
						|
		fixPermissions
 | 
						|
		;;
 | 
						|
	postRun | postUpdate)
 | 
						|
		;;
 | 
						|
	*)
 | 
						|
		printUsage
 | 
						|
		exit 1
 | 
						|
		;;
 | 
						|
esac
 | 
						|
 | 
						|
exit 0
 |