Last active
August 28, 2022 17:12
-
-
Save johannesvedder/29a384f82e761527fc7acce1d06f78b9 to your computer and use it in GitHub Desktop.
Installs and updates a local StudyU and Supabase instance with customizable settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script installs or updates a self-hosted version of StudyU and Supabase locally using Docker. | |
# In order to run it securely, the default settings have to be modified by creating a copy of the following files: | |
# flutter_common/lib/envs/.env.selfhost | |
# docker/.env.example | |
# docker/volumes/api/kong.yml | |
# The customized copy of these files (with respect to their subdirectories) should be placed at: $CONF_FILE_LOC (see below) | |
# All variable changes of the modified files will be merged with the default files (except kong.yml for now, which will be replaced) | |
### CONFIG ### | |
# Directory with customized config files | |
export CONF_FILE_DIR=$PWD/studyu_conf | |
# Parent directory where studyU is or will be installed | |
export STUDYU_PARENT_DIR=$PWD | |
# Deploy branch | |
export STUDYU_BRANCH=dev | |
### SCRIPT ### | |
if [ $( docker ps -f name=studyu -f status=running -q | wc -l ) -gt 0 ]; then | |
echo "Running StudyU containers found. They will be removed first.." | |
docker compose -p 'studyu' down --remove-orphans # --rmi all --remove-orphans | |
fi | |
if [ $( docker ps -f name=supabase -f status=running -q | wc -l ) -gt 0 ]; then | |
echo "Running Supabase containers found. They will be removed first.." | |
docker compose -p 'supabase' down --remove-orphans #--rmi all --remove-orphans | |
fi | |
# Cloning StudyU repository if not existing | |
if [ ! -d "$STUDYU_PARENT_DIR/studyu" ]; then | |
echo "A local copy of the StudyU could not be found. Cloning.." | |
cd $STUDYU_PARENT_DIR/ | |
git clone https://github.com/hpi-studyu/studyu | |
cd studyu/ | |
git checkout $STUDYU_BRANCH | |
else | |
cd $STUDYU_PARENT_DIR/studyu/ | |
# Updating | |
echo "Updating StudyU copy.." | |
git checkout $STUDYU_BRANCH | |
git pull | |
fi | |
cd $STUDYU_PARENT_DIR/studyu/ | |
if [ ! -d "$CONF_FILE_DIR" ]; then | |
echo "The configuration directory for the StudyU and supabase installation cannot not be found." | |
echo "Do you want to create a default configuration directory? [Y,n]" | |
read input | |
if [[ $input == "Y" || $input == "y" ]]; then | |
mkdir -p $CONF_FILE_DIR/flutter_common/lib/envs/ | |
mkdir -p $CONF_FILE_DIR/supabase/volumes/api/ | |
cp -a flutter_common/lib/envs/.env.selfhost $CONF_FILE_DIR/flutter_common/lib/envs/ | |
cp -a supabase/.env.example $CONF_FILE_DIR/supabase/.env | |
cp -a supabase/volumes/api/kong.yml $CONF_FILE_DIR/supabase/volumes/api/kong.yml | |
echo "Your configuration directory has been created at: $CONF_FILE_DIR" | |
echo "You can change the path in the settings of this script." | |
echo " !!! Be aware that running StudyU with default settings is highly insecure !!!" | |
echo "Please modify the default configuration first before running StudyU." | |
echo "Open this script with you favorite text editor for more help on this or check the README file at the StudyU repository on how to do this: https://github.com/hpi-studyu/studyu" | |
exit; | |
else | |
echo "Please create the configuration directory yourself in order to use this script." | |
exit; | |
fi | |
fi | |
# Check if settings are still at default values | |
if cmp --silent -- $CONF_FILE_DIR/supabase/.env $STUDYU_PARENT_DIR/studyu/supabase/.env.example; then | |
echo " !!! YOUR STUDYU INSTALLATION IS IN AN INSECURE STATE !!! " | |
echo "Please modify the default configuration first before running StudyU at: $CONF_FILE_DIR" | |
echo "Open this script with you favorite text editor for more help on this or check the README file at the StudyU repository on how to do this: https://github.com/hpi-studyu/studyu" | |
exit; | |
fi | |
# Merge custom StudyU environment changes from $CONF_FILE_LOC into cloned studyu repository | |
# Adapted from: https://stackoverflow.com/questions/14017577/merge-two-properties-file-using-shell-scripts | |
cd $STUDYU_PARENT_DIR/studyu/ | |
mv flutter_common/lib/envs/.env.selfhost flutter_common/lib/envs/.env.selfhost.orig | |
awk -F= '!a[$1]++' $CONF_FILE_DIR/flutter_common/lib/envs/.env.selfhost flutter_common/lib/envs/.env.selfhost.orig | grep -v '^$\|^\s*\#' > flutter_common/lib/envs/.env.selfhost | |
# Merge custom supabase environment changes | |
awk -F= '!a[$1]++' $CONF_FILE_DIR/supabase/.env supabase/.env.example | grep -v '^$\|^\s*\#' > supabase/.env | |
mv supabase/volumes/api/kong.yml supabase/volumes/api/kong.yml.orig | |
# TODO: The following files needs to be merged in case of updates to the original version: supabase/volumes/api/kong.yml $CONF_FILE_DIR/supabase/volumes/api/kong.yml | |
# We just overwrite it for now | |
cp $CONF_FILE_DIR/supabase/volumes/api/kong.yml supabase/volumes/api/kong.yml | |
# Run everything with docker-compose | |
cd $STUDYU_PARENT_DIR/studyu/supabase/ | |
# docker compose -f docker-compose.yml -f ./dev/docker-compose.dev.yml up -d | |
docker compose up -d | |
cd $STUDYU_PARENT_DIR/studyu | |
# App and Designer can also be build simultaneously by adding --build to the up command | |
# This is omitted here for performance reasons | |
# docker compose -f docker-compose-designer-selfhost.yml build | |
# docker compose -f docker-compose-app-selfhost.yml build | |
docker compose -f docker-compose-full-selfhost.yml up -d --remove-orphans | |
echo "StudyU update finished!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment