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
|
2021-01-17 22:31:28 +01:00
|
|
|
# *** le departement doit au prealable avoir été supprime via l'interface web ! ***
|
2020-09-26 16:19:37 +02:00
|
|
|
#
|
|
|
|
# Ne fonctionne que pour les configurations "standards" (dbname=xxx)
|
|
|
|
#
|
2021-07-21 22:32:30 +02:00
|
|
|
# Il doit être lancé par l'utilisateur unix root dans le repertoire .../tools
|
2020-09-26 16:19:37 +02:00
|
|
|
# ^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
# E. Viennet, Sept 2008
|
|
|
|
#
|
|
|
|
|
2021-08-02 10:34:28 +02:00
|
|
|
# Le répertoire de ce script:
|
|
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2021-08-02 10:34:28 +02:00
|
|
|
source "$SCRIPT_DIR/config.sh"
|
|
|
|
source "$SCRIPT_DIR/utils.sh"
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2021-08-07 08:42:57 +02:00
|
|
|
# scodoc may now manage departments TODO To be fixed
|
|
|
|
# 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
|
2021-08-07 08:42:57 +02:00
|
|
|
# arret de ScoDoc (need root permissions so disabled for the moment TODO to be fixed)
|
|
|
|
# scodocctl stop
|
2020-12-05 17:29:26 +01:00
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
# suppression de la base postgres
|
2021-01-17 22:31:28 +01:00
|
|
|
db_name=$(sed '/^dbname=*/!d; s///;q' < "$cfg_pathname")
|
2021-08-07 08:42:57 +02:00
|
|
|
if psql -lt | cut -d \| -f 1 | grep -wq "$db_name"
|
2021-01-17 22:31:28 +01:00
|
|
|
then
|
|
|
|
echo "Suppression de la base postgres $db_name ..."
|
2021-08-07 08:42:57 +02:00
|
|
|
dropdb $db_name || terminate "ne peux supprimer base de donnees $db_name"
|
2021-01-17 22:31:28 +01:00
|
|
|
else
|
|
|
|
echo "la base postgres $db_name n'existe pas."
|
|
|
|
fi
|
2020-09-26 16:19:37 +02:00
|
|
|
# suppression du fichier de config
|
2021-01-17 22:31:28 +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
|
2021-01-17 22:31:28 +01:00
|
|
|
echo 'Attention: pas de configuration trouvee pour "'"$DEPT"'"'
|
2021-01-23 16:49:10 +01:00
|
|
|
echo " fichier cherché: $cfg_pathname"
|
2021-01-17 22:31:28 +01:00
|
|
|
echo " => ne fait rien."
|
|
|
|
exit 0
|
2020-09-26 16:19:37 +02:00
|
|
|
fi
|