2022-09-30 15:25:09 +02:00
#!/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
2022-05-17 15:55:25 +02:00
log "ERROR" "Please provide a Project as argument"
2022-05-04 13:50:33 +02:00
exit 1
fi
2022-05-11 10:30:18 +02:00
export PROJECT = $1
2022-05-04 13:50:33 +02:00
2022-05-17 18:04:15 +02:00
checkRequirements noprivkey
2021-12-21 13:48:28 +01:00
2022-09-30 15:25:09 +02:00
log "INFO" "Allowing the bridgehead user to start/stop the bridgehead."
cat <<EOF > /etc/sudoers.d/bridgehead-"${PROJE CT} "
# 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, \\
2022-10-06 10:45:50 +02:00
/bin/systemctl restart bridgehead@*.service, \\
2023-01-27 11:26:31 +01:00
/bin/chown -R bridgehead /etc/bridgehead /srv/docker/bridgehead, \\
/usr/bin/chown -R bridgehead /etc/bridgehead /srv/docker/bridgehead
2022-09-30 15:25:09 +02:00
2022-09-30 15:35:37 +02:00
bridgehead ALL = NOPASSWD: BRIDGEHEAD${ PROJECT ^^ }
2022-09-30 15:25:09 +02:00
EOF
2022-05-17 18:04:15 +02:00
# TODO: Determine whether this should be located in setup-bridgehead (triggered through bridgehead install) or in update bridgehead (triggered every hour)
2022-11-03 17:29:52 +01:00
if [ -z " $LDM_PASSWORD " ] ; then
2022-11-03 17:19:15 +01:00
log "INFO" "Now generating a password for the local data management. Please save the password for your ETL process!"
2022-11-03 18:15:45 +01:00
generated_passwd = " $( cat /proc/sys/kernel/random/uuid | sed 's/[-]//g' | head -c 32) "
2022-10-25 15:30:14 +02:00
2022-10-26 10:48:55 +02:00
log "INFO" " Your generated credentials are:\n user: $PROJECT \n password: $generated_passwd "
2022-11-03 17:19:15 +01:00
echo -e " ## Local Data Management Basic Authentication\n# User: $PROJECT \nLDM_PASSWORD= $generated_passwd " >> /etc/bridgehead/${ PROJECT } .local.conf;
2022-10-26 10:48:55 +02:00
fi
2022-10-25 15:30:14 +02:00
2022-05-17 18:04:15 +02:00
log "INFO" "Registering 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 \
2022-01-11 14:40:16 +01:00
/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
2022-09-30 15:25:09 +02: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
2022-05-17 18:04:15 +02:00
STR = " \n\n systemctl start bridgehead@ ${ PROJECT } .service\n\nor by rebooting your machine. "
if [ -e /etc/bridgehead/pki/${ SITE_ID } .priv.pem ] ; then
STR = " Success. Next, start your bridgehead by running $STR "
else
STR = " Success. Next, enroll into the $PROJECT broker by creating a cryptographic certificate. To do so, run\n\n /srv/docker/bridgehead/bridgehead enroll $PROJECT \n\nThen, you may start the bridgehead by running $STR "
fi
2022-12-13 16:51:32 +01:00
log "INFO" " $STR "