92 lines
1.8 KiB
Bash
Executable File
92 lines
1.8 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
|
|
|
|
# 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"
|
|
|
|
[ "$USER" = "$SCODOC_USER" ] || die "$0 must run as user $SCODOC_USER"
|
|
|
|
cd "$SCRIPT_DIR"
|
|
|
|
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
|
|
|
|
# ----------------------- Create Dept database
|
|
# (créée en tant qu'utilisateur scodoc)
|
|
./create_database.sh
|
|
|
|
# ----------------------- Initialize table database
|
|
# POSTGRES_USER == regular unix user (scodoc)
|
|
if [ "$interactive" = 1 ]
|
|
then
|
|
./initialize_database.sh
|
|
else
|
|
./initialize_database.sh > /dev/null 2>&1
|
|
fi
|
|
|
|
|
|
|
|
# ----------------------- Enregistre fichier config
|
|
echo "dbname=${db_name}" > "$cfg_pathname"
|
|
|
|
|
|
if [ "$interactive" = 1 ]
|
|
then
|
|
# -----------------------
|
|
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
|
|
fi
|