2022-01-10 15:31:07 +01:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
|
|
|
exitIfNotRoot() {
|
|
|
|
if [ "$EUID" -ne 0 ]; then
|
2022-05-17 15:55:25 +02:00
|
|
|
log "ERROR" "Please run as root"
|
2022-01-10 15:31:07 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
log() {
|
2022-05-17 15:55:25 +02:00
|
|
|
echo -e "$(date +'%Y-%m-%d %T')" "$1:" "$2"
|
2022-01-10 15:31:07 +01:00
|
|
|
}
|
2022-05-09 15:13:38 +02:00
|
|
|
|
|
|
|
printUsage() {
|
|
|
|
echo "Usage: bridgehead start|stop|update|install|uninstall PROJECTNAME"
|
2022-05-16 09:25:15 +02:00
|
|
|
echo "PROJECTNAME should be one of ccp|nngm|gbn"
|
2022-05-09 15:13:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
checkRequirements() {
|
|
|
|
if ! lib/prerequisites.sh; then
|
2022-05-17 15:55:25 +02:00
|
|
|
log "ERROR" "Validating Prerequisites failed, please fix the error(s) above this line."
|
2022-05-09 15:13:38 +02:00
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
}
|
2022-05-12 18:23:52 +02:00
|
|
|
|
|
|
|
fetchVarsFromVault() {
|
|
|
|
VARS_TO_FETCH=""
|
|
|
|
|
|
|
|
for line in $(cat $@); do
|
|
|
|
if [[ $line =~ .*=\<VAULT\>.* ]]; then
|
|
|
|
VARS_TO_FETCH+="$(echo -n $line | sed 's/=.*//') "
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -z "$VARS_TO_FETCH" ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2022-05-17 15:55:25 +02:00
|
|
|
log "INFO" "Fetching secrets from vault ..."
|
2022-05-13 14:11:14 +02:00
|
|
|
|
|
|
|
[ -e /etc/bridgehead/vault.conf ] && source /etc/bridgehead/vault.conf
|
|
|
|
|
|
|
|
if [ -z "$BW_MASTERPASS" ] || [ -z "$BW_CLIENTID" ] || [ -z "$BW_CLIENTSECRET" ]; then
|
2022-05-17 15:55:25 +02:00
|
|
|
log "ERROR" "Please supply correct credentials in /etc/bridgehead/vault.conf."
|
2022-05-13 14:11:14 +02:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
set +e
|
|
|
|
|
2022-05-13 15:59:05 +02:00
|
|
|
PASS=$(BW_MASTERPASS="$BW_MASTERPASS" BW_CLIENTID="$BW_CLIENTID" BW_CLIENTSECRET="$BW_CLIENTSECRET" docker run --rm -e BW_MASTERPASS -e BW_CLIENTID -e BW_CLIENTSECRET -e http_proxy samply/bridgehead-vaultfetcher $VARS_TO_FETCH)
|
2022-05-13 14:11:14 +02:00
|
|
|
RET=$?
|
|
|
|
|
|
|
|
if [ $RET -ne 0 ]; then
|
|
|
|
echo "Code: $RET"
|
|
|
|
echo $PASS
|
|
|
|
return $RET
|
|
|
|
fi
|
|
|
|
|
|
|
|
eval $(echo -e "$PASS" | sed 's/\r//g')
|
|
|
|
|
|
|
|
set -e
|
2022-05-12 18:23:52 +02:00
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
2022-05-16 09:21:42 +02:00
|
|
|
|
|
|
|
##Setting Network properties
|
|
|
|
export HOSTIP=$(MSYS_NO_PATHCONV=1 docker run --rm --add-host=host.docker.internal:host-gateway ubuntu cat /etc/hosts | grep 'host.docker.internal' | awk '{print $1}');
|
2022-05-17 15:55:25 +02:00
|
|
|
export HOST=$(hostname)
|