99 lines
2.1 KiB
Bash
Executable File
99 lines
2.1 KiB
Bash
Executable File
#!/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
|
|
#
|
|
|
|
set -euo pipefail
|
|
|
|
source config.sh
|
|
source utils.sh
|
|
|
|
check_uid_root "$0"
|
|
|
|
usage() {
|
|
echo "$0 [-n DEPT]"
|
|
echo "(default to interactive mode)"
|
|
exit 1
|
|
}
|
|
[ $# = 0 ] || [ $# = 2 ] || usage
|
|
|
|
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
|
|
|
|
if [[ ! "$DEPT" =~ ^[A-Za-z0-9]+$ ]]
|
|
then
|
|
echo 'Nom de departement invalide !'
|
|
exit 2
|
|
fi
|
|
|
|
export DEPT
|
|
|
|
db_name=SCO$(to_upper "$DEPT")
|
|
export db_name
|
|
|
|
cfg_pathname="${SCODOC_VAR_DIR}/config/depts/$DEPT".cfg
|
|
|
|
if [ -e "$cfg_pathname" ]
|
|
then
|
|
echo 'Erreur: Il existe deja une configuration pour "'"$DEPT"'"'
|
|
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)
|
|
if [ "$interactive" = 1 ]
|
|
then
|
|
su -c ./initialize_database.sh "$POSTGRES_USER"
|
|
else
|
|
su -c ./initialize_database.sh "$POSTGRES_USER" > /dev/null 2>&1
|
|
fi
|
|
|
|
|
|
|
|
# ----------------------- Enregistre fichier config
|
|
echo "dbname=${db_name}" > "$cfg_pathname"
|
|
|
|
|
|
if [ "$interactive" = 1 ]
|
|
then
|
|
# ----------------------- Force mise à jour
|
|
echo -n "Voulez vous mettre a jour ScoDoc (tres recommande) ? (y/n) [y] "
|
|
read -r ans
|
|
if [ "$(norm_ans "$ans")" != 'N' ]
|
|
then
|
|
(cd "$SCODOC_DIR/config" || terminate "no config directory"; ./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
|
|
fi
|