2021-12-21 13:48:28 +01:00
#!/bin/bash
2022-05-09 15:13:38 +02:00
source lib/functions.sh
## Check for file permissions
if ! id "bridgehead" & >/dev/null; then
log ERROR "User bridgehead does not exist. Please consult readme for installation."
exit 1
fi
COUNT = $( find . ! -user bridgehead | wc -l)
if [ $COUNT -gt 0 ] ; then
log ERROR " $COUNT files in $( pwd ) are not owned by user bridgehead. Run find $( pwd ) ! -user bridgehead to see them, chown -R bridgehead $( pwd ) to correct this issue. "
exit 1
fi
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 ..."
2022-04-08 08:43:42 +02:00
prerequisites = "git docker docker-compose"
2021-12-21 13:48:28 +01:00
for prerequisite in $prerequisites ; do
$prerequisite --version 2>& 1
is_available = $?
if [ $is_available -gt 0 ] ; then
log "ERROR" " Prerequisite not fulfilled - $prerequisite is not available! "
exit 79
fi
# TODO: Check for specific version
done
2022-05-09 15:13:38 +02:00
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
2022-05-09 15:13:38 +02:00
log ERROR "Please set up the config folder at /etc/bridgehead. Instruction are in the readme."
2022-05-03 09:16:19 +02:00
exit 1
fi
2021-12-21 13:48:28 +01:00
#check if site.conf is created
2022-05-04 13:50:33 +02:00
if [ ! -f /etc/bridgehead/site.conf ] ; then
2022-05-09 15:13:38 +02:00
log ERROR "Please create your specific site.conf file from the site.dev.conf"
2022-05-03 09:16:19 +02:00
exit 1
2021-12-21 13:48:28 +01:00
fi
#Load site specific variables
2022-05-04 13:50:33 +02:00
source /etc/bridgehead/site.conf
2021-12-21 13:48:28 +01:00
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
if [ -z " $site_name " ] ; then
2022-05-09 15:13:38 +02:00
log ERROR "Please set site_name."
2022-05-03 09:16:19 +02:00
exit 1
2021-12-21 13:48:28 +01:00
fi
#check if project env is present
2022-05-04 13:50:33 +02:00
if [ -d " /etc/bridgehead/ ${ project } .env " ] ; then
2022-05-09 15:13:38 +02:00
log ERROR " Project config not found. Please copy the template from ${ project } and put it under /etc/bridgehead-config/ ${ project } .env. "
2022-05-03 09:16:19 +02:00
exit 1
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-05-09 15:13:38 +02:00
log INFO "Checking ssl cert"
if [ ! -d "certs" ] ; then
log WARN "TLS cert missing, we'll now create a self-signed one. Please consider getting an officially signed one (e.g. via Let's Encrypt ...)"
mkdir -p certs
2022-05-05 14:17:57 +02:00
fi
2022-05-11 09:05:23 +02:00
if [ ! -e "certs/traefik.crt" ] ; then
2022-05-05 14:17:57 +02:00
openssl req -x509 -newkey rsa:4096 -nodes -keyout certs/traefik.key -out certs/traefik.crt -days 365
fi
2022-05-09 15:13:38 +02:00
log INFO "Success - all prerequisites are met!"
exit 0