2020-09-26 16:19:37 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-08-09 23:23:11 +02:00
|
|
|
# Create database for ScoDoc
|
|
|
|
# This script must be executed as user "scodoc"
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2021-07-30 17:34:47 +02:00
|
|
|
die() {
|
|
|
|
echo
|
|
|
|
echo "Erreur: $1"
|
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
}
|
2022-05-04 23:11:20 +02:00
|
|
|
[ $# = 1 ] || [ $# = 2 ] || die "Usage $0 [--drop] db_name"
|
|
|
|
|
|
|
|
if [ "$1" = "--drop" ]
|
|
|
|
then
|
|
|
|
db_name="$2"
|
|
|
|
echo "Dropping database $db_name..."
|
2022-12-07 13:22:11 +01:00
|
|
|
dropdb --if-exists "$db_name"
|
2022-05-04 23:11:20 +02:00
|
|
|
else
|
|
|
|
db_name="$1"
|
|
|
|
fi
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2021-08-09 23:23:11 +02:00
|
|
|
# Le répertoire de ce script:
|
|
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
2021-07-30 17:34:47 +02:00
|
|
|
|
2021-08-09 23:23:11 +02:00
|
|
|
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"
|
2021-07-27 13:27:21 +02:00
|
|
|
|
2021-07-30 09:36:30 +02:00
|
|
|
# ---
|
2021-07-30 17:34:47 +02:00
|
|
|
echo 'Creating postgresql database ' "$db_name"
|
|
|
|
createdb -E UTF-8 -p "$POSTGRES_PORT" -O "$POSTGRES_USER" "$db_name"
|
2023-06-20 07:51:40 +02:00
|
|
|
echo 'CREATE EXTENSION IF NOT EXISTS "unaccent";' | psql -p "$POSTGRES_PORT" "$db_name" "$POSTGRES_USER"
|