2020-09-26 16:19:37 +02:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# ScoDoc: suppression d'un departement
|
|
|
|
|
#
|
|
|
|
|
# Ce script supprime la base de donnees ScoDoc d'un departement
|
|
|
|
|
# *** le departement doit au prealable avoir <20>t<EFBFBD> supprime via l'interface web ! ***
|
|
|
|
|
#
|
|
|
|
|
# Ne fonctionne que pour les configurations "standards" (dbname=xxx)
|
|
|
|
|
#
|
|
|
|
|
# Il doit <20>tre lanc<6E> par l'utilisateur unix root dans le repertoire .../config
|
|
|
|
|
# ^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
# E. Viennet, Sept 2008
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
source config.sh
|
|
|
|
|
source utils.sh
|
|
|
|
|
|
|
|
|
|
check_uid_root $0
|
2020-12-26 00:11:55 +01:00
|
|
|
|
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
|
|
|
|
|
echo "Ce script supprime la base de donnees ScoDoc d'un departement"
|
|
|
|
|
echo
|
|
|
|
|
echo "Attention: le departement doit au prealable avoir ete supprime via l'interface web !"
|
|
|
|
|
echo "faites le AVANT d'executer ce script !!!"
|
|
|
|
|
echo
|
|
|
|
|
echo -n "Nom du departement a supprimer (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 !"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
export DEPT
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
# arret de ScoDoc
|
2020-12-05 17:29:26 +01:00
|
|
|
|
scodocctl stop
|
|
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
|
# suppression de la base postgres
|
2020-12-26 00:11:55 +01:00
|
|
|
|
db_name=$(cat "$cfg_pathname" | sed '/^dbname=*/!d; s///;q')
|
2020-09-26 16:19:37 +02:00
|
|
|
|
echo "suppression de la base postgres $db_name"
|
2020-12-26 00:11:55 +01:00
|
|
|
|
su -c "dropdb $db_name" "$POSTGRES_SUPERUSER" || terminate "ne peux supprimer base de donnees $db_name"
|
2020-09-26 16:19:37 +02:00
|
|
|
|
# suppression du fichier de config
|
2020-12-26 00:11:55 +01:00
|
|
|
|
/bin/rm -f "$cfg_pathname" || terminate "ne peux supprimer $cfg_pathname"
|
2020-09-26 16:19:37 +02:00
|
|
|
|
# relance ScoDoc
|
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 -n "Demarrer le serveur ScoDoc ? (y/n) [n]"
|
|
|
|
|
read -r ans
|
|
|
|
|
if [ "$(norm_ans "$ans")" = 'Y' ]
|
|
|
|
|
then
|
|
|
|
|
scodocctl start
|
|
|
|
|
fi
|
2020-09-26 16:19:37 +02:00
|
|
|
|
fi
|
|
|
|
|
exit 0
|
|
|
|
|
else
|
2020-12-26 00:11:55 +01:00
|
|
|
|
echo 'Erreur: pas de configuration trouvee pour "'"$DEPT"'"'
|
2020-09-26 16:19:37 +02:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|