bridgehead/lib/setup-bridgehead-units.sh

69 lines
2.7 KiB
Bash
Raw Normal View History

#!/bin/bash -e
2021-12-21 13:48:28 +01:00
2022-01-10 15:31:07 +01:00
source lib/functions.sh
exitIfNotRoot
2022-05-04 13:50:33 +02:00
if [ $# -eq 0 ]; then
log "ERROR" "Please provide a Project as argument"
2022-05-04 13:50:33 +02:00
exit 1
fi
2022-10-25 11:45:01 +02:00
if [ $1 != "ccp" ] && [ $1 != "nngm" ] && [ $1 != "bbmri" ]; then
log "ERROR" "Please provide a supported project like ccp, bbmri or nngm"
2022-05-04 13:50:33 +02:00
exit 1
fi
export PROJECT=$1
2022-05-04 13:50:33 +02:00
checkRequirements
2021-12-21 13:48:28 +01:00
log "INFO" "Allowing the bridgehead user to start/stop the bridgehead."
cat <<EOF > /etc/sudoers.d/bridgehead-"${PROJECT}"
# This has been added by the Bridgehead installer. Remove with bridgehead uninstall.
2022-09-30 15:35:37 +02:00
Cmnd_Alias BRIDGEHEAD${PROJECT^^} = \\
/bin/systemctl start bridgehead@${PROJECT}.service, \\
/bin/systemctl stop bridgehead@${PROJECT}.service, \\
/bin/systemctl restart bridgehead@${PROJECT}.service, \\
/bin/systemctl restart bridgehead@*.service, \\
/bin/chown -R bridgehead /etc/bridgehead /srv/docker/bridgehead, \\
/usr/bin/chown -R bridgehead /etc/bridgehead /srv/docker/bridgehead
2022-09-30 15:35:37 +02:00
bridgehead ALL= NOPASSWD: BRIDGEHEAD${PROJECT^^}
EOF
# TODO: Determine wether this should be located in setup-bridgehead (triggered through bridgehead install) or in update bridgehead (triggered every hour)
if [ -z "$LDM_LOGIN" ]; then
log "INFO" "Now generating a password for the local datamangement. Please safe the password for your ETL process!"
generated_passwd="$(cat /proc/sys/kernel/random/uuid | sed 's/[-]//g' | head -c 20)"
log "INFO" "Your generated credentials are:\n user: $PROJECT\n password: $generated_passwd"
2022-11-03 09:26:01 +01:00
parsed_passwd=$(docker run --rm -it httpd:latest htpasswd -nb $PROJECT $generated_passwd | tr -d '\n' | tr -d '\r')
printf "##Localdatamanagement basic auth\n#User: $PROJECT\n#Password: $generated_passwd\n" >> /etc/bridgehead/${PROJECT}.local.conf;
log "INFO" "These credentials are now written to /etc/bridgehead/${PROJECT}.local.conf"
2022-11-03 09:26:01 +01:00
echo -n "LDM_LOGIN='${parsed_passwd}'" >> /etc/bridgehead/${PROJECT}.local.conf;
fi
log "INFO" "Register system units for bridgehead and bridgehead-update"
2022-01-10 15:31:07 +01:00
cp -v \
2022-01-10 16:42:13 +01:00
lib/systemd/bridgehead\@.service \
lib/systemd/bridgehead-update\@.service \
lib/systemd/bridgehead-update\@.timer \
/etc/systemd/system/
2021-12-21 13:48:28 +01:00
2022-01-10 15:31:07 +01:00
systemctl daemon-reload
2021-12-21 13:48:28 +01:00
log INFO "Trying to update your bridgehead ..."
systemctl start bridgehead-update@"${PROJECT}".service
log "INFO" "Enabling autostart of bridgehead@${PROJECT}.service"
systemctl enable bridgehead@"${PROJECT}".service
log "INFO" "Enabling auto-updates for bridgehead@${PROJECT}.service ..."
systemctl enable --now bridgehead-update@"${PROJECT}".timer
2022-01-10 16:31:48 +01:00
log "INFO" "\nSuccess - now start your bridgehead by running\n systemctl start bridgehead@${PROJECT}.service\n or by rebooting your machine."