96 lines
1.9 KiB
Bash
Executable File
96 lines
1.9 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 .../tools
|
|
# ^^^^^^^^^^^^^^^^^^^^^
|
|
# E. Viennet, Juin 2008
|
|
#
|
|
|
|
set -eo 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 "scodoc" ($POSTGRES_USER) exists
|
|
init_postgres_user
|
|
|
|
# ----------------------- Create Dept database
|
|
su -c ./create_database.sh "$POSTGRES_SUPERUSER"
|
|
|
|
# ----------------------- Initialize table database
|
|
# POSTGRES_USER == regular unix user (scodoc)
|
|
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/tools" || 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
|
|
fi
|