2020-09-26 16:19:37 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Initialize database (create tables) for a ScoDoc instance
|
2021-07-21 22:32:30 +02:00
|
|
|
# This script must be executed as user scodoc
|
2020-09-26 16:19:37 +02:00
|
|
|
#
|
|
|
|
# $db_name and $DEPT passed as environment variables
|
|
|
|
|
2021-08-02 10:34:28 +02:00
|
|
|
# Le répertoire de ce script:
|
|
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
|
|
|
|
|
|
|
source "$SCRIPT_DIR/config.sh"
|
|
|
|
source "$SCRIPT_DIR/utils.sh"
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2021-07-21 22:32:30 +02:00
|
|
|
if [ "$(id -nu)" != "$SCODOC_USER" ]
|
2020-09-26 16:19:37 +02:00
|
|
|
then
|
2021-07-21 22:32:30 +02:00
|
|
|
echo "$0: script must be runned as user $SCODOC_USER"
|
2020-09-26 16:19:37 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-12-19 19:22:22 +01:00
|
|
|
# shellcheck disable=SC2154
|
|
|
|
echo 'Initializing tables in database ' "$db_name"
|
|
|
|
$PSQL -U "$POSTGRES_USER" -p "$POSTGRES_PORT" "$db_name" -f "$SCODOC_DIR"/misc/createtables.sql
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Set DeptName in preferences:
|
2021-07-21 22:32:30 +02:00
|
|
|
echo "insert into sco_prefs (name, value) values ('DeptName', '"${DEPT}\'\) | $PSQL -U "$POSTGRES_USER" -p "$POSTGRES_PORT" "$db_name"
|