38 lines
1.0 KiB
Bash
38 lines
1.0 KiB
Bash
|
#!/usr/bin/env bash
|
||
|
set -e
|
||
|
WAIT_TIMEOUT=10
|
||
|
|
||
|
# Retrieve proper environment variables
|
||
|
GUACAMOLE_VERSION=$(cat .env | grep GUACAMOLE_VERSION | sed 's/GUACAMOLE_VERSION=//')
|
||
|
MARIADB_NAME=$(cat .env | grep MARIADB_NAME | sed 's/MARIADB_NAME=//')
|
||
|
|
||
|
# Pull the Guacamole image
|
||
|
docker pull guacamole/guacamole:"${GUACAMOLE_VERSION}"
|
||
|
|
||
|
# Generate initial database schema from Guacamole's image
|
||
|
docker run -it --rm \
|
||
|
guacamole/guacamole:"${GUACAMOLE_VERSION}" \
|
||
|
/opt/guacamole/bin/initdb.sh \
|
||
|
--mysql > initdb.sql
|
||
|
|
||
|
# Start the database instance
|
||
|
docker compose up -d mariadb
|
||
|
|
||
|
# Wait a couple of seconds that the database is ready
|
||
|
for I in $(eval echo "{$WAIT_TIMEOUT..1}"); do
|
||
|
printf " ${I}"
|
||
|
sleep 1
|
||
|
done
|
||
|
echo
|
||
|
|
||
|
# Initialize the database
|
||
|
docker compose exec \
|
||
|
--no-TTY -e MARIADB_NAME="${MARIADB_NAME}" mariadb \
|
||
|
sh -c 'exec mysql -uroot -p"$MARIADB_ROOT_PASSWORD" "$MARIADB_NAME"' < initdb.sql
|
||
|
|
||
|
# Remove the unnecessary database init file
|
||
|
rm -rf initdb.sql
|
||
|
|
||
|
# Stop & remove the database container for good measure
|
||
|
docker compose rm -fs mariadb
|