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 .../config
|
|
|
|
# ^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
# E. Viennet, Juin 2008
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
source config.sh
|
|
|
|
source utils.sh
|
|
|
|
|
2020-12-19 19:22:22 +01:00
|
|
|
check_uid_root "$0"
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
echo -n "Nom du departement (un mot sans ponctuation, exemple \"Info\"): "
|
2020-12-19 19:22:22 +01:00
|
|
|
read -r DEPT
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
if [[ ! "$DEPT" =~ ^[A-Za-z0-9]+$ ]]
|
|
|
|
then
|
|
|
|
echo 'Nom de departement invalide !'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
export DEPT
|
|
|
|
|
|
|
|
export db_name=SCO$(to_upper "$DEPT")
|
|
|
|
|
|
|
|
cfg_pathname="${SCODOC_VAR_DIR}/config/depts/$DEPT".cfg
|
|
|
|
|
2020-12-19 19:22:22 +01:00
|
|
|
if [ -e "$cfg_pathname" ]
|
2020-09-26 16:19:37 +02:00
|
|
|
then
|
2020-12-19 19:22:22 +01:00
|
|
|
echo 'Erreur: Il existe deja une configuration pour "'"$DEPT"'"'
|
2020-09-26 16:19:37 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# --- Ensure postgres user www-data exists
|
|
|
|
init_postgres_user
|
|
|
|
|
|
|
|
# ----------------------- Create database
|
|
|
|
su -c ./create_database.sh $POSTGRES_SUPERUSER
|
|
|
|
|
|
|
|
# ----------------------- Create tables
|
|
|
|
# POSTGRES_USER == regular unix user (www-data)
|
|
|
|
su -c ./initialize_database.sh $POSTGRES_USER
|
|
|
|
|
|
|
|
# ----------------------- Enregistre fichier config
|
2020-12-19 19:22:22 +01:00
|
|
|
echo "dbname=$db_name" > "$cfg_pathname"
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
# ----------------------- Force mise à jour
|
|
|
|
echo -n "Voulez vous mettre a jour ScoDoc (tres recommande) ? (y/n) [y] "
|
2020-12-19 19:22:22 +01:00
|
|
|
read -r ans
|
2020-09-26 16:19:37 +02:00
|
|
|
if [ "$(norm_ans "$ans")" != 'N' ]
|
|
|
|
then
|
|
|
|
(cd "$SCODOC_DIR/config"; ./upgrade.sh)
|
|
|
|
fi
|
|
|
|
|
|
|
|
# -----------------------
|
|
|
|
echo
|
|
|
|
echo " Departement $DEPT cree"
|
|
|
|
echo
|
|
|
|
echo " Attention: la base de donnees n'a pas de copies de sauvegarde"
|
|
|
|
echo
|
|
|
|
echo " Maintenant, vous pouvez ajouter le departement via l'application web"
|
|
|
|
echo " en suivant le lien \"Administration de ScoDoc\" sur la page d'accueil."
|
|
|
|
echo
|