2022-05-17 18:04:15 +02:00
#!/bin/bash -e
2023-02-24 16:32:17 +01:00
DEV_MODE = " ${ 1 :- NODEV } "
2022-05-17 18:04:15 +02:00
source lib/log.sh
source lib/functions.sh
log "INFO" "Preparing your system for bridgehead installation ..."
2023-02-22 15:32:21 +01:00
# Check, if running in WSL
if [ [ $( grep -i Microsoft /proc/version) ] ] ; then
# Check, if systemd is available
2023-02-24 11:41:05 +01:00
if [ " $( systemctl is-system-running) " = "offline" ] ; then
log "ERROR" "It seems you have no active systemd environment in your WSL environment. Please follow the guide in https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/"
2023-02-22 15:32:21 +01:00
exit 1
fi
fi
2022-05-17 18:04:15 +02:00
# Create the bridgehead user
if id bridgehead & >/dev/null; then
log "INFO" " Existing user with id $( id -u bridgehead) will be used by the bridgehead system units. "
else
log "INFO" "Now creating a system user to own the bridgehead's files."
useradd -M -g docker -N bridgehead || fail_and_report ""
fi
# Clone the OpenSource repository of bridgehead
2023-02-23 18:05:53 +01:00
set +e
bridgehead_repository_url = $( git remote get-url origin)
if [ $? -ne 0 ] ; then
bridgehead_repository_url = "https://github.com/samply/bridgehead.git"
fi
set -e
2022-05-17 18:04:15 +02:00
if [ -d "/srv/docker/bridgehead" ] ; then
current_owner = $( stat -c '%U' /srv/docker/bridgehead)
if [ " $( su -c 'git -C /srv/docker/bridgehead remote get-url origin' $current_owner ) " = = " $bridgehead_repository_url " ] ; then
log "INFO" "Bridgehead's open-source repository has been found at /srv/docker/bridgehead"
else
log "ERROR" " The directory /srv/docker/bridgehead seems to exist, but doesn't contain a clone of $bridgehead_repository_url \nPlease delete the directory and try again. "
exit 1
fi
else
log "INFO" " Cloning $bridgehead_repository_url to /srv/docker/bridgehead "
mkdir -p /srv/docker/
2023-02-23 18:05:34 +01:00
git clone $bridgehead_repository_url /srv/docker/bridgehead
2022-05-17 18:04:15 +02:00
fi
case " $PROJECT " in
ccp)
site_configuration_repository_middle = "git.verbis.dkfz.de/bridgehead-configurations/bridgehead-config-"
; ;
bbmri)
site_configuration_repository_middle = "git.verbis.dkfz.de/bbmri-bridgehead-configs/"
; ;
2023-05-10 20:15:14 +02:00
minimal)
site_configuration_repository_middle = "git.verbis.dkfz.de/minimal-bridgehead-configs/"
; ;
2022-05-17 18:04:15 +02:00
*)
log ERROR "Internal error, this should not happen."
exit 1
; ;
esac
# Clone the site-configuration
if [ -d /etc/bridgehead ] ; then
current_owner = $( stat -c '%U' /etc/bridgehead)
if [ " $( su -c 'git -C /etc/bridgehead remote get-url origin' $current_owner | grep $site_configuration_repository_middle ) " ] ; then
log "INFO" "Your site config repository in /etc/bridgehead seems to be installed correctly."
else
log "WARN" "Your site configuration repository in /etc/bridgehead seems to have another origin than git.verbis.dkfz.de. Please check if the repository is correctly cloned!"
fi
2023-02-24 16:32:17 +01:00
elif [ [ " $DEV_MODE " = = "NODEV" ] ] ; then
2022-05-17 18:04:15 +02:00
log "INFO" "Now cloning your site configuration repository for you."
2023-02-22 13:06:28 +01:00
if [ -z " $site " ] ; then
read -p "Please enter your site: " site
fi
if [ -z " $access_token " ] ; then
read -s -p "Please enter the bridgehead's access token for your site configuration repository (will not be echoed): " access_token
fi
2022-05-17 18:04:15 +02:00
site_configuration_repository_url = " https://bytoken: ${ access_token } @ ${ site_configuration_repository_middle } $( echo $site | tr '[:upper:]' '[:lower:]' ) .git "
git clone $site_configuration_repository_url /etc/bridgehead
if [ $? -gt 0 ] ; then
log "ERROR" "Unable to clone your configuration repository. Please obtain correct access data and try again."
fi
2023-02-24 16:32:17 +01:00
elif [ [ " $DEV_MODE " = = "DEV" ] ] ; then
log "INFO" "Now cloning your developer configuration repository for you."
read -p "Please enter your config repository URL: " url
git clone " $url " /etc/bridgehead
2022-05-17 18:04:15 +02:00
fi
2024-01-31 15:23:14 +01:00
mkdir -p /tmp/bridgehead /var/cache/bridgehead
chown -R bridgehead:docker /etc/bridgehead /srv/docker/bridgehead /tmp/bridgehead /var/cache/bridgehead
chmod -R g+wr /var/cache/bridgehead /tmp/bridgehead
2022-05-17 18:04:15 +02:00
2023-02-24 16:32:17 +01:00
log INFO "System preparation is completed and configuration is present."
2022-05-17 18:04:15 +02:00