ScoDoc-Lille/tools/create_dept.sh

92 lines
1.8 KiB
Bash
Raw Normal View History

2020-09-26 16:19:37 +02:00
#!/bin/bash
#
# ScoDoc: creation initiale d'un departement
#
# Ce script prend en charge la creation de la base de donnees
# et doit être lancé par l'utilisateur unix root dans le repertoire .../tools
2020-09-26 16:19:37 +02:00
# ^^^^^^^^^^^^^^^^^^^^^
# E. Viennet, Juin 2008
#
2021-04-22 22:14:25 +02:00
set -eo pipefail
2020-09-26 16:19:37 +02:00
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
[ "$USER" = "$SCODOC_USER" ] || die "$0 must run as user $SCODOC_USER"
2020-09-26 16:19:37 +02:00
2021-08-02 10:34:28 +02:00
cd "$SCRIPT_DIR"
2020-12-26 00:11:55 +01:00
usage() {
echo "$0 [-n DEPT]"
echo "(default to interactive mode)"
exit 1
}
[ $# = 0 ] || [ $# = 2 ] || usage
2020-09-26 16:19:37 +02:00
2020-12-26 00:11:55 +01:00
if [ "$1" = "-n" ]
then
interactive=0
if [ $# -lt 2 ]
then
usage
fi
DEPT=$2
else
interactive=1
echo -n "Nom du departement (un mot sans ponctuation, exemple \"Info\"): "
read -r DEPT
fi
2020-09-26 16:19:37 +02:00
if [[ ! "$DEPT" =~ ^[A-Za-z0-9]+$ ]]
then
echo 'Nom de departement invalide !'
2020-12-26 00:11:55 +01:00
exit 2
2020-09-26 16:19:37 +02:00
fi
export DEPT
2020-12-26 00:11:55 +01:00
db_name=SCO$(to_upper "$DEPT")
export db_name
2020-09-26 16:19:37 +02:00
cfg_pathname="${SCODOC_VAR_DIR}/config/depts/$DEPT".cfg
2020-12-26 00:11:55 +01:00
if [ -e "$cfg_pathname" ]
2020-09-26 16:19:37 +02:00
then
2020-12-26 00:11:55 +01:00
echo 'Erreur: Il existe deja une configuration pour "'"$DEPT"'"'
2020-09-26 16:19:37 +02:00
exit 1
fi
# ----------------------- Create Dept database
# (créée en tant qu'utilisateur scodoc)
./create_database.sh
2020-09-26 16:19:37 +02:00
# ----------------------- Initialize table database
# POSTGRES_USER == regular unix user (scodoc)
2020-12-27 13:45:24 +01:00
if [ "$interactive" = 1 ]
then
./initialize_database.sh
2020-12-27 13:45:24 +01:00
else
./initialize_database.sh > /dev/null 2>&1
2020-12-27 13:45:24 +01:00
fi
2020-09-26 16:19:37 +02:00
# ----------------------- Enregistre fichier config
2020-12-26 00:11:55 +01:00
echo "dbname=${db_name}" > "$cfg_pathname"
2020-09-26 16:19:37 +02:00
2020-12-26 00:11:55 +01:00
if [ "$interactive" = 1 ]
2020-09-26 16:19:37 +02:00
then
2020-12-26 00:11:55 +01:00
# -----------------------
echo
echo " Departement $DEPT cree"
echo
echo " Attention: la base de donnees n'a pas de copies de sauvegarde"
echo "(XXX section à revoir en ScoDoc 8.1)" # #sco8
2020-09-26 16:19:37 +02:00
fi