2022-02-16 09:59:53 +01:00
#!/bin/bash
2022-05-09 15:13:38 +02:00
source lib/functions.sh
2022-10-28 10:17:14 +02:00
detectCompose
2024-10-02 07:53:20 +02:00
CONFIG_DIR = "/etc/bridgehead/"
COMPONENT_DIR = "/srv/docker/bridgehead/"
2022-10-28 10:17:14 +02:00
2022-05-09 15:13:38 +02:00
if ! id "bridgehead" & >/dev/null; then
2022-05-17 18:04:15 +02:00
log ERROR " User bridgehead does not exist. Please run bridgehead install $PROJECT "
2022-05-09 15:13:38 +02:00
exit 1
fi
2022-05-16 09:46:03 +02:00
2024-10-02 07:53:20 +02:00
checkOwner " ${ CONFIG_DIR } " bridgehead || exit 1
checkOwner " ${ COMPONENT_DIR } " bridgehead || exit 1
2021-12-21 13:48:28 +01:00
## Check if user is a su
2022-05-09 15:13:38 +02:00
log INFO "Checking if all prerequisites are met ..."
2023-09-21 18:23:22 +02:00
prerequisites = "git docker curl"
2022-02-16 09:59:53 +01:00
for prerequisite in $prerequisites ; do
$prerequisite --version 2>& 1
is_available = $?
if [ $is_available -gt 0 ] ; then
2022-10-06 10:45:50 +02:00
fail_and_report 79 " Prerequisite not fulfilled - $prerequisite is not available! "
2022-02-16 09:59:53 +01:00
fi
# TODO: Check for specific version
done
2022-09-30 15:25:09 +02:00
log INFO "Checking if sudo is installed ..."
if [ ! -d /etc/sudoers.d ] ; then
2022-10-06 10:45:50 +02:00
fail_and_report 1 "/etc/sudoers.d does not exist. Please install sudo package."
2022-09-30 15:25:09 +02:00
fi
2022-05-09 15:13:38 +02:00
log INFO "Checking configuration ..."
2022-05-03 09:16:19 +02:00
## Download submodule
2024-10-02 07:53:20 +02:00
if [ ! -d " ${ CONFIG_DIR } " ] ; then
fail_and_report 1 " Please set up the config folder at ${ CONFIG_DIR } . Instruction are in the readme. "
2022-05-03 09:16:19 +02:00
fi
2022-05-09 15:13:38 +02:00
# TODO: Check all required variables here in a generic loop
2021-12-21 13:48:28 +01:00
#check if project env is present
2024-10-02 07:53:20 +02:00
if [ -d " ${ CONFIG_DIR } ${ PROJECT } .conf " ] ; then
fail_and_report 1 " Project config not found. Please copy the template from ${ PROJECT } and put it under ${ CONFIG_DIR } ${ PROJECT } .conf. "
2021-12-21 13:48:28 +01:00
fi
2022-05-09 15:13:38 +02:00
# TODO: Make sure you're in the right directory, or, even better, be independent from the working directory.
2022-05-05 14:17:57 +02:00
2022-10-17 14:38:34 +02:00
log INFO "Checking ssl cert for accessing bridgehead via https"
2022-05-09 15:13:38 +02:00
2024-10-02 07:53:20 +02:00
if [ ! -d " ${ CONFIG_DIR } traefik-tls " ] ; then
2022-10-17 15:09:18 +02:00
log WARN "TLS certs for accessing bridgehead via https missing, we'll now create a self-signed one. Please consider getting an officially signed one (e.g. via Let's Encrypt ...) and put into /etc/bridgehead/traefik-tls"
mkdir -p /etc/bridgehead/traefik-tls
2022-05-05 14:17:57 +02:00
fi
2024-10-02 07:53:20 +02:00
if [ ! -e " ${ CONFIG_DIR } traefik-tls/fullchain.pem " ] ; then
2022-10-17 15:30:43 +02:00
openssl req -x509 -newkey rsa:4096 -nodes -keyout /etc/bridgehead/traefik-tls/privkey.pem -out /etc/bridgehead/traefik-tls/fullchain.pem -days 3650 -subj " /CN= $HOST "
2022-05-05 14:17:57 +02:00
fi
2024-10-02 07:53:20 +02:00
if [ -e " ${ CONFIG_DIR } " vault.conf ] ; then
2022-10-17 15:09:18 +02:00
if [ " $( stat -c "%a %U" /etc/bridgehead/vault.conf) " != "600 bridgehead" ] ; then
2022-10-06 10:45:50 +02:00
fail_and_report 1 "/etc/bridgehead/vault.conf has wrong owner/permissions. To correct this issue, run chmod 600 /etc/bridgehead/vault.conf && chown bridgehead /etc/bridgehead/vault.conf."
2022-10-17 15:09:18 +02:00
fi
2022-05-13 14:11:14 +02:00
fi
2023-08-07 13:00:37 +02:00
log INFO " Checking network access ( $BROKER_URL_FOR_PREREQ ) ... "
2022-09-30 17:02:05 +02:00
2024-10-02 07:53:20 +02:00
source " ${ CONFIG_DIR } ${ PROJECT } " .conf
2022-09-30 17:02:05 +02:00
source ${ PROJECT } /vars
2024-03-05 15:58:06 +01:00
if [ " ${ PROJECT } " != "minimal" ] ; then
set +e
SERVERTIME = " $( https_proxy = $HTTPS_PROXY_FULL_URL curl -m 5 -s -I $BROKER_URL_FOR_PREREQ 2>& 1 | grep -i -e '^Date: ' | sed -e 's/^Date: //i' ) "
RET = $?
set -e
if [ $RET -ne 0 ] ; then
log WARN " Unable to connect to Samply.Beam broker at $BROKER_URL_FOR_PREREQ . Please check your proxy settings.\nThe currently configured proxy was \" $HTTPS_PROXY_URL \". This error is normal when using proxy authentication. "
log WARN "Unable to check clock skew due to previous error."
else
log INFO "Checking clock skew ..."
SERVERTIME_AS_TIMESTAMP = $( date --date= " $SERVERTIME " +%s)
MYTIME = $( date +%s)
SKEW = $(( $SERVERTIME_AS_TIMESTAMP - $MYTIME ))
SKEW = $( echo $SKEW | awk -F- '{print $NF}' )
SYNCTEXT = "For example, consider entering a correct NTP server (e.g. your institution's Active Directory Domain Controller in /etc/systemd/timesyncd.conf (option NTP=) and restart systemd-timesyncd."
if [ $SKEW -ge 300 ] ; then
report_error 5 " Your clock is not synchronized ( ${ SKEW } s off). This will cause Samply.Beam's certificate will fail. Please setup time synchronization. $SYNCTEXT "
exit 1
elif [ $SKEW -ge 60 ] ; then
log WARN " Your clock is more than a minute off ( ${ SKEW } s). Consider syncing to a time server. $SYNCTEXT "
fi
fi
2022-09-28 17:37:11 +02:00
fi
2022-05-17 18:04:15 +02:00
checkPrivKey( ) {
2024-10-02 07:53:20 +02:00
if [ -e " ${ CONFIG_DIR } pki/ ${ SITE_ID } .priv.pem " ] ; then
2022-05-17 18:04:15 +02:00
log INFO "Success - private key found."
else
2024-10-02 07:53:20 +02:00
log ERROR " Unable to find private key at ${ CONFIG_DIR } pki/ ${ SITE_ID } .priv.pem. To fix, please run\n bridgehead enroll ${ PROJECT } \nand follow the instructions. "
2022-05-17 18:04:15 +02:00
return 1
fi
return 0
}
2022-10-17 14:38:34 +02:00
2024-03-05 15:58:06 +01:00
if [ [ " $@ " = ~ "noprivkey" || " ${ PROJECT } " != "minimal" ] ] ; then
2022-05-17 18:04:15 +02:00
log INFO "Skipping check for private key for now."
2022-10-17 14:38:34 +02:00
else
2022-05-17 18:04:15 +02:00
checkPrivKey || exit 1
2022-10-17 14:38:34 +02:00
fi
2024-10-02 07:53:20 +02:00
for dir in " ${ CONFIG_DIR } " " ${ COMPONENT_DIR } " ; do
log INFO " Checking branch: $( cd $dir && echo " $dir $( git branch --show-current) " ) "
hc_send log " Checking branch: $( cd $dir && echo " $dir $( git branch --show-current) " ) "
done
2022-05-09 15:13:38 +02:00
log INFO "Success - all prerequisites are met!"
2023-07-28 13:32:48 +02:00
hc_send log "Success - all prerequisites are met!"
2022-05-09 15:13:38 +02:00
exit 0