bridgehead/lib/prerequisites.sh

81 lines
2.9 KiB
Bash
Raw Normal View History

2022-02-16 09:59:53 +01:00
#!/bin/bash
source lib/functions.sh
detectCompose
if ! id "bridgehead" &>/dev/null; then
log ERROR "User bridgehead does not exist. Please consult readme for installation."
exit 1
fi
2022-05-31 13:55:40 +02:00
checkOwner . bridgehead || exit 1
checkOwner /etc/bridgehead bridgehead || exit 1
2021-12-21 13:48:28 +01:00
## Check if user is a su
log INFO "Checking if all prerequisites are met ..."
2022-10-28 14:26:57 +02:00
prerequisites="git docker"
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
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
log INFO "Checking if sudo is installed ..."
if [ ! -d /etc/sudoers.d ]; then
fail_and_report 1 "/etc/sudoers.d does not exist. Please install sudo package."
fi
log INFO "Checking configuration ..."
2022-05-03 09:16:19 +02:00
## Download submodule
2022-05-04 13:50:33 +02:00
if [ ! -d "/etc/bridgehead/" ]; then
fail_and_report 1 "Please set up the config folder at /etc/bridgehead. Instruction are in the readme."
2022-05-03 09:16:19 +02:00
fi
# TODO: Check all required variables here in a generic loop
2021-12-21 13:48:28 +01:00
#check if project env is present
2022-05-17 09:37:20 +02:00
if [ -d "/etc/bridgehead/${PROJECT}.conf" ]; then
fail_and_report 1 "Project config not found. Please copy the template from ${PROJECT} and put it under /etc/bridgehead-config/${PROJECT}.conf."
2021-12-21 13:48:28 +01:00
fi
# TODO: Make sure you're in the right directory, or, even better, be independent from the working directory.
2022-10-17 14:38:34 +02:00
log INFO "Checking ssl cert for accessing bridgehead via https"
2022-10-17 15:09:18 +02:00
if [ ! -d "/etc/bridgehead/traefik-tls" ]; then
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
fi
2022-10-17 15:30:43 +02:00
if [ ! -e "/etc/bridgehead/traefik-tls/fullchain.pem" ]; then
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"
fi
if [ -e /etc/bridgehead/vault.conf ]; then
2022-10-17 15:09:18 +02:00
if [ "$(stat -c "%a %U" /etc/bridgehead/vault.conf)" != "600 bridgehead" ]; then
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
fi
2022-10-17 14:38:34 +02:00
log INFO "Checking your beam proxy private key"
if [ -e /etc/bridgehead/pki/${SITE_ID}.priv.pem ]; then
2022-10-17 15:09:18 +02:00
log INFO "Success - private key found."
2022-10-17 14:38:34 +02:00
else
2022-10-17 15:09:18 +02:00
log ERROR "Unable to find private key at /etc/bridgehead/pki/${SITE_ID}.priv.pem. To fix, please run bridgehead enroll ${PROJECT} and follow the instructions".
exit 1
2022-10-17 14:38:34 +02:00
fi
2022-11-04 16:18:30 +01:00
COMMIT_ETC=$(git -C /etc/bridgehead rev-parse HEAD | cut -c -8)
COMMIT_SRV=$(git -C /srv/docker/bridgehead rev-parse HEAD | cut -c -8)
log INFO "Success - all prerequisites are met! Git commits: etc:$COMMIT_ETC srv:$COMMIT_SRV"
hc_send log "Success - all prerequisites are met! Git commits: etc:$COMMIT_ETC srv:$COMMIT_SRV"
exit 0