Docker-Compose/setup.sh

149 lines
4.9 KiB
Bash
Raw Normal View History

2024-12-07 22:18:01 +01:00
#!/bin/bash
2024-12-08 11:10:26 +01:00
echo "Welcome to the Docker Installer:"
echo ""
2024-12-08 11:22:22 +01:00
echo ""
2024-12-08 11:12:45 +01:00
echo "1. The installer will update all Repos"
apt update
2024-12-07 22:18:01 +01:00
2024-12-08 11:22:22 +01:00
echo ""
2024-12-08 11:12:45 +01:00
echo "2. The installer will install CURL and GIT"
apt install curl git -y
2024-12-08 11:22:22 +01:00
echo ""
2024-12-08 11:12:45 +01:00
echo "3. The installer will install Docker and Docker Compose"
apt install docker docker-compose -y
2024-12-08 11:25:53 +01:00
echo ""
2024-12-08 11:12:45 +01:00
echo "4. The installer will clone the Docker-Compose Repository"
2024-12-08 11:17:29 +01:00
HOME_DIR=/opt/odc
2024-12-08 14:44:53 +01:00
if [ -d $HOME_DIR ]
2024-12-08 11:17:29 +01:00
then
2024-12-08 14:44:53 +01:00
cd $HOME_DIR
git add . && git stash && git pull
2024-12-08 11:17:29 +01:00
else
2024-12-08 14:44:53 +01:00
mkdir $HOME_DIR && cd $HOME_DIR
git clone https://git.h2-invent.com/datenschutzcenter/docker-compose.git .
2024-12-08 11:17:29 +01:00
fi
2024-12-08 11:12:45 +01:00
2024-12-08 11:24:23 +01:00
echo ""
2024-12-08 11:12:45 +01:00
echo "5. The installer will setup all scripts, so you can docker-compose up"
echo ""
2024-12-08 18:41:22 +01:00
FILE=docker.config
2024-12-07 22:18:01 +01:00
if [ -f "$FILE" ]; then
source $FILE
else
touch $FILE
KEYCLOAK_PW=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
ODC_DB_PW=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
KEYCLOAK_ADMIN_PW=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
2024-12-08 18:39:50 +01:00
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
2024-12-07 22:21:44 +01:00
2024-12-07 22:18:01 +01:00
echo "KEYCLOAK_PW=$KEYCLOAK_PW" >> $FILE
echo "KEYCLOAK_ADMIN_PW=$KEYCLOAK_ADMIN_PW" >> $FILE
2024-12-08 18:39:50 +01:00
echo "NEW_UUID=$NEW_UUID" >> $FILE
2024-12-07 22:18:01 +01:00
echo "ODC_DB_PW=$ODC_DB_PW" >> $FILE
source $FILE
fi
2024-12-11 17:17:51 +01:00
VERSION=${VERSION:=latest}
read -p "Which Release Version do you want to install [$VERSION]: " input
VERSION=${input:=$VERSION}
sed -i '/VERSION/d' $FILE
echo "VERSION=$VERSION" >> $FILE
HTTP_METHOD=${HTTP_METHOD:=http}
read -p "Enter http/https for testing on local environment ALWAYS use http [$HTTP_METHOD]: " input
HTTP_METHOD=${input:=$HTTP_METHOD}
sed -i '/HTTP_METHOD/d' $FILE
echo "HTTP_METHOD=$HTTP_METHOD" >> $FILE
PUBLIC_URL=${PUBLIC_URL:=dev.domain.de}
read -p "Enter the url you want to enter the open-datenschutzcenter without http://, https:// or ports [$PUBLIC_URL]: " input
PUBLIC_URL=${input:=$PUBLIC_URL}
sed -i '/PUBLIC_URL/d' $FILE
echo "PUBLIC_URL=$PUBLIC_URL" >> $FILE
2024-12-07 22:18:01 +01:00
2024-12-08 07:17:28 +01:00
HOST_IP=$(ip a | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | head -n 1)
2024-12-07 22:18:01 +01:00
echo ------------------------------------------------------------
2024-12-08 07:42:29 +01:00
echo --- 1. Build the Keycloak ----------------------------------
2024-12-07 22:18:01 +01:00
echo ------------------------------------------------------------
2024-12-08 07:42:29 +01:00
echo ""
2024-12-07 22:18:01 +01:00
2024-12-08 19:59:36 +01:00
cp .templates/realm-export.json keycloak/realm-export.json
2024-12-08 18:39:50 +01:00
sed -i "s|<clientsecret>|$NEW_UUID|g" keycloak/realm-export.json
2024-12-07 22:18:01 +01:00
sed -i "s|<clientUrl>|$HTTP_METHOD://$PUBLIC_URL|g" keycloak/realm-export.json
echo ------------------------------------------------------------
2024-12-08 07:42:29 +01:00
echo ------ 2. Build Mysql Init DB ------------------------------
2024-12-07 22:18:01 +01:00
echo ------------------------------------------------------------
2024-12-08 07:42:29 +01:00
echo ""
2024-12-07 22:18:01 +01:00
2024-12-08 19:59:36 +01:00
cp .templates/init-userdb.sql mysql-initdb/init-userdb.sql
2024-12-07 22:18:01 +01:00
sed -i "s|<open-datenschutzcenter-pw>|$ODC_DB_PW|g" mysql-initdb/init-userdb.sql
sed -i "s|<keycloak-pw>|$KEYCLOAK_PW|g" mysql-initdb/init-userdb.sql
2024-12-07 22:30:24 +01:00
2024-12-08 18:39:50 +01:00
echo ------------------------------------------------------------
echo --------- 3. Setup .ENV.LOCAL ------------------------------
echo ------------------------------------------------------------
echo ""
2024-12-08 19:31:30 +01:00
touch .env
touch .env.custom
2024-12-08 18:39:50 +01:00
if [ -f .env.local ]; then
rm .env.local
fi
cat <<EOL > .env.local
# ENV FOR ODC
2024-12-08 21:04:21 +01:00
APP_SCHEME='$HTTP_METHOD'
2024-12-08 18:39:50 +01:00
PUBLIC_URL='$PUBLIC_URL'
MAILER_DSN='null://null'
2024-12-08 19:36:37 +01:00
DATABASE_URL='mysql://odc:$ODC_DB_PW@db-odc:3306/odc'
2024-12-08 18:39:50 +01:00
OAUTH_KEYCLOAK_SERVER='$HTTP_METHOD://$PUBLIC_URL/keycloak'
OAUTH_KEYCLOAK_CLIENT_ID=opendatenschutzcenter
2024-12-08 19:42:49 +01:00
OAUTH_KEYCLOAK_CLIENT_SECRET=$NEW_UUID
2024-12-08 18:39:50 +01:00
OAUTH_KEYCLOAK_REALM=opendatenschutzcenter
2024-12-08 19:46:24 +01:00
laF_version='3.0.4'
demo_installation='demo'
2024-12-08 18:39:50 +01:00
KEYCLOAK_ADMIN=admin
KEYCLOAK_ADMIN_PASSWORD=$KEYCLOAK_ADMIN_PW
KC_DB=mariadb
KC_DB_USERNAME=keycloak
KC_DB_PASSWORD=$KEYCLOAK_PW
KC_DB_URL='jdbc:mariadb://db-odc:3306/keycloak'
KC_HOSTNAME_URL='$HTTP_METHOD://$PUBLIC_URL/keycloak'
KC_HOSTNAME_PATH='$HTTP_METHOD://$PUBLIC_URL/keycloak'
KC_HOSTNAME_ADMIN_URL='$HTTP_METHOD://$PUBLIC_URL/keycloak'
KC_HTTP_RELATIVE_PATH=/keycloak
KC_PROXY=passthrough
EOL
2024-12-07 22:30:24 +01:00
echo ------------------------------------------------------------
2024-12-08 18:39:50 +01:00
echo ------------ 4. Build Docker Compose File ------------------
2024-12-07 22:30:24 +01:00
echo ------------------------------------------------------------
2024-12-08 07:42:29 +01:00
echo ""
2024-12-07 22:30:24 +01:00
2024-12-08 11:43:37 +01:00
cp .docker-compose.$HTTP_METHOD.yml docker-compose.yml
2024-12-08 07:40:04 +01:00
2024-12-07 22:50:33 +01:00
sed -i "s|<clientUrl>|$PUBLIC_URL|g" docker-compose.yml
2024-12-08 07:40:04 +01:00
sed -i "s|<hostIp>|$HOST_IP|g" docker-compose.yml
2024-12-11 17:17:51 +01:00
sed -i "s|<version>|$VERSION|g" docker-compose.yml
2024-12-08 18:39:50 +01:00
2024-12-08 07:42:29 +01:00
echo ""
echo ""
2024-12-08 07:44:29 +01:00
echo ------------------------------------------------------------
echo FINALY: Select and SPrepare tart Docker Compose ------------
echo ------------------------------------------------------------
2024-12-08 07:46:00 +01:00
echo ""
echo "DOCKER COMPOSE"
2024-12-08 11:31:16 +01:00
echo "run 'cd $HOME_DIR/docker-compose && docker-compose up --detach' to start the containers"
2024-12-08 07:46:00 +01:00
echo ""
echo "IMPORTANT"
2024-12-08 07:51:34 +01:00
echo "1. Wait for at least 10 Minutes for the containers to be up and healthy"
echo "2. Backup ALL Volumes and most important the DB and secretStorage"