Combines the two database folders to a single variable during installation

This commit is contained in:
Trenton Holmes 2022-08-30 15:17:08 -07:00
parent ed2e884de8
commit 537e7c63f4

View File

@ -123,7 +123,7 @@ echo "if unsure. If you're running on a low-power device such as Raspberry"
echo "Pi, use SQLite to save resources."
echo ""
ask "Database backend" "postgres" "postgres sqlite" "mariadb"
ask "Database backend" "postgres" "postgres sqlite mariadb"
DATABASE_BACKEND=$ask_result
echo ""
@ -214,9 +214,9 @@ echo ""
ask_docker_folder "Data folder" ""
DATA_FOLDER=$ask_result
if [[ "$DATABASE_BACKEND" == "postgres" ]] ; then
if [[ "$DATABASE_BACKEND" == "postgres" || "$DATABASE_BACKEND" == "mariadb" ]] ; then
echo ""
echo "The database folder, where postgres stores its data."
echo "The database folder, where your database stores its data."
echo "Leave empty to have this managed by docker."
echo ""
echo "CAUTION: If specified, you must specify an absolute path starting with /"
@ -224,19 +224,7 @@ if [[ "$DATABASE_BACKEND" == "postgres" ]] ; then
echo ""
ask_docker_folder "Database folder" ""
POSTGRES_FOLDER=$ask_result
fi
if [[ "$DATABASE_BACKEND" == "mariadb" ]] ; then
echo ""
echo "The database folder, where mariadb stores its data."
echo ""
echo "CAUTION: If specified, you must specify an absolute path starting with /"
echo "or a relative path starting with ./ here."
echo ""
ask_docker_folder "Database folder" ""
MARIADB_FOLDER=$ask_result
DATABASE_FOLDER=$ask_result
fi
echo ""
@ -290,16 +278,14 @@ if [[ -z $DATA_FOLDER ]] ; then
else
echo "Data folder: $DATA_FOLDER"
fi
if [[ "$DATABASE_BACKEND" == "postgres" ]] ; then
if [[ -z $POSTGRES_FOLDER ]] ; then
echo "Database (postgres) folder: Managed by docker"
if [[ "$DATABASE_BACKEND" == "postgres" || "$DATABASE_BACKEND" == "mariadb" ]] ; then
if [[ -z $DATABASE_FOLDER ]] ; then
echo "Database folder: Managed by docker"
else
echo "Database (postgres) folder: $POSTGRES_FOLDER"
echo "Database folder: $DATABASE_FOLDER"
fi
fi
if [[ "$DATABASE_BACKEND" == "mariadb" ]] ; then
echo "Database (mariadb) folder: $MARIADB_FOLDER"
fi
echo ""
echo "URL: $URL"
echo "Port: $PORT"
@ -371,13 +357,16 @@ if [[ -n $DATA_FOLDER ]] ; then
sed -i "/^\s*data:/d" docker-compose.yml
fi
if [[ -n $POSTGRES_FOLDER ]] ; then
sed -i "s#- pgdata:/var/lib/postgresql/data#- $POSTGRES_FOLDER:/var/lib/postgresql/data#g" docker-compose.yml
sed -i "/^\s*pgdata:/d" docker-compose.yml
fi
if [[ -n $MARIADB_FOLDER ]] ; then
sed -i "s#- dbdata:/var/lib/mariadb/data#- $MARIADB_FOLDER:/var/lib/mariadb/data#g" docker-compose.yml
# If the database folder was provided (not blank), replace the pgdata/dbdata volume with a bind mount
# of the provided folder
if [[ -n $DATABASE_FOLDER ]] ; then
if [[ "$DATABASE_BACKEND" == "postgres" ]] ; then
sed -i "s#- pgdata:/var/lib/postgresql/data#- $DATABASE_FOLDER:/var/lib/postgresql/data#g" docker-compose.yml
sed -i "/^\s*pgdata:/d" docker-compose.yml
elif [[ "$DATABASE_BACKEND" == "mariadb" ]]; then
sed -i "s#- dbdata:/var/lib/mysql#- $DATABASE_FOLDER:/var/lib/mysql#g" docker-compose.yml
sed -i "/^\s*dbdata:/d" docker-compose.yml
fi
fi
# remove trailing blank lines from end of file
@ -394,4 +383,4 @@ ${DOCKER_COMPOSE_CMD} pull
${DOCKER_COMPOSE_CMD} run --rm -e DJANGO_SUPERUSER_PASSWORD="$PASSWORD" webserver createsuperuser --noinput --username "$USERNAME" --email "$EMAIL"
${DOCKER_COMPOSE_CMD} up -d
${DOCKER_COMPOSE_CMD} up --detach