forked from ScoDoc/ScoDoc
Lyanis Souidi
99942f40ea
La base de données postgresql et le cache redis peuvent désormais être sur un serveur externe (pas localhost) grâce aux variables d'environnement `SCODOC_DATABASE_URI` et `CACHE_REDIS_HOST`.
41 lines
1.0 KiB
Bash
Executable File
41 lines
1.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Create database for ScoDoc
|
|
# This script must be executed as user "scodoc"
|
|
|
|
die() {
|
|
echo
|
|
echo "Erreur: $1"
|
|
echo
|
|
exit 1
|
|
}
|
|
[ $# = 1 ] || [ $# = 2 ] || die "Usage $0 [--drop] db_name"
|
|
|
|
if [ -z "${SCODOC_DATABASE_URI}" ]; then
|
|
PG_URI="postgresql:///postgres"
|
|
else
|
|
PG_URI=$(echo $SCODOC_DATABASE_URI | sed 's|/[^/]*$|/postgres|')
|
|
fi
|
|
|
|
if [ "$1" = "--drop" ]
|
|
then
|
|
db_name="$2"
|
|
echo "Dropping database $db_name..."
|
|
psql $PG_URI -c "DROP DATABASE IF EXISTS $db_name;"
|
|
else
|
|
db_name="$1"
|
|
fi
|
|
|
|
# Le répertoire de ce script:
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
|
|
|
source "$SCRIPT_DIR"/config.sh || die "config.sh not found, exiting"
|
|
source "$SCRIPT_DIR"/utils.sh || die "config.sh not found, exiting"
|
|
|
|
[ "$USER" = "$SCODOC_USER" ] || die "$0 must run as user $SCODOC_USER"
|
|
|
|
# ---
|
|
echo 'Creating postgresql database ' "$db_name"
|
|
psql $PG_URI -c "CREATE DATABASE \"$db_name\" WITH ENCODING 'UTF-8';"
|
|
psql $(echo $PG_URI | sed "s|/postgres\$|/$db_name|") -c 'CREATE EXTENSION IF NOT EXISTS "unaccent";'
|