View Full Version : ./uninstall.sh
stillcut
04-18-2008, 12:21 PM
Centreon n'est pas forcément facile d'accès.
C'est mon 2eme deploiement en un an et je me retrouve qd mm a réinstaller suite à diver aléas du à des imports de fichiers de conf' depuis un Nagios prééxistant.
Et que fais t'on quand à force de manip aléatoires et imprécises on doute du caractère sain d'une install ...
Ben on réinstall ...
Faut alors supprimer à la mano ce qui concerne Centreon , les plugins Centreon, ODS , les bases mySQL , les users SQL...
Modifier /etc/sudoers sinon y a des doublons a la reinstallation.
Un script de desintall' serait donc le bienvenu !
stillcut
04-18-2008, 02:20 PM
158 14:06 rm -rf /usr/local/centreon/
159 14:07 rm -rf /var/lib/ods
160 14:07 rm -rf /etc/oreon.conf
161 14:07 rm -rf /etc/init.d/ods
162 14:07 rm -rf /usr/local/nagios/libexec/centreon.*
168 14:08 rm /etc/httpd/conf.d/oreon.conf
183 14:10 rm -rf /etc/snmpcentreon_traps/
184 14:10 rm -rf /etc/snmp/centreon_traps/
modif /etc/sudoers
kill pid ODS
+ suppression databases et user dans mysql
Ya plus qu'a remplacer les chemins pour les bons pour chaque install et rules :)
Tu nous envoi le script ? :p
Guigui2607
04-22-2008, 10:13 AM
J'avais commencé un petit script de désinstallation.
C'était un premier jet...
J'ai essayé grossièrement de supprimer les fichiers créer par une install de Centreon et de modifier les éventuels fichiers de conf (sudoers, etc...)
# -*-Shell-script-*-
#
# functions This file contains functions to be used by Oreon install scripts
#
##
## COLOR FUNCTIONS
##
RES_COL=60
MOVE_TO_COL="echo -en \\033[${RES_COL}G"
SETCOLOR_INFO="echo -en \\033[1;38m"
SETCOLOR_SUCCESS="echo -en \\033[1;32m"
SETCOLOR_FAILURE="echo -en \\033[1;31m"
SETCOLOR_WARNING="echo -en \\033[1;33m"
SETCOLOR_NORMAL="echo -en \\033[0;39m"
function echo_info() {
echo -n "$1"
$MOVE_TO_COL
$SETCOLOR_INFO
echo -n "$2"
$SETCOLOR_NORMAL
echo -e "\r"
}
function echo_success() {
echo -n "$1"
$MOVE_TO_COL
$SETCOLOR_SUCCESS
echo -n "$2"
$SETCOLOR_NORMAL
echo -e "\r"
}
function echo_failure() {
echo -n "$1"
$MOVE_TO_COL
$SETCOLOR_FAILURE
echo -n "$2"
$SETCOLOR_NORMAL
echo -e "\r"
}
function echo_passed() {
echo -n "$1"
$MOVE_TO_COL
$SETCOLOR_WARNING
echo -n "$2"
$SETCOLOR_NORMAL
echo -e "\r"
}
function echo_warning() {
echo -n "$1"
$MOVE_TO_COL
$SETCOLOR_WARNING
echo -n "$2"
$SETCOLOR_NORMAL
echo -e "\r"
}
SNMP_DIR="/etc/snmp/";
OREON_CONF="/etc/oreon.conf"
HTTP_CONF="/etc/httpd/conf.d/oreon.conf"
INSTALL_DIR_OREON=$(cat $OREON_CONF | grep INSTALL_DIR_OREON | cut -d "=" -f 2)
NAGIOS_PLUGIN=$(cat $OREON_CONF | grep NAGIOS_PLUGIN | cut -d "=" -f 2)
SUDO_FILE=$(cat $OREON_CONF | grep SUDO_FILE | cut -d "=" -f 2)
HOST=$(cat $INSTALL_DIR_OREON/www/oreon.conf.php | grep -e "'host'" | cut -d '"' -f 2);
USER=$(cat $INSTALL_DIR_OREON/www/oreon.conf.php | grep -e "'user'" | cut -d '"' -f 2);
PASS=$(cat $INSTALL_DIR_OREON/www/oreon.conf.php | grep -e "'password'" | cut -d '"' -f 2);
BDCNT=$(cat $INSTALL_DIR_OREON/www/oreon.conf.php | grep -e "'db'" | cut -d '"' -f 2);
BDODS=$(cat $INSTALL_DIR_OREON/www/oreon.conf.php | grep -e "'ods'" | cut -d '"' -f 2);
service ods stop
if test -f $OREON_CONF then rm -f $OREON_CONF
if test -f $OREON_CONF then rm -f $OREON_CONF
then echo_failure "Fichier $OREON_CONF" "Non Supprime"
else echo_success "Fichier $OREON_CONF" "Supprime"
fi
else echo_warning "Fichier $OREON_CONF" "Deja supprime"
fi
if test -f $HTTP_CONF then rm -f $HTTP_CONF
if test -f $HTTP_CONF then rm -f $HTTP_CONF
then echo_failure "Fichier $HTTP_CONF" "Non Supprime"
else echo_success "Fichier $HTTP_CONF" "Supprime"
fi
else echo_warning "Fichier $HTTP_CONF" "Deja supprime"
fi
if test -f $NAGIOS_PLUGIN/centreon.conf then rm -f $NAGIOS_PLUGIN/centreon.conf
if test -f $NAGIOS_PLUGIN/centreon.conf then rm -f $NAGIOS_PLUGIN/centreon.conf
then echo_failure "Fichier $NAGIOS_PLUGIN/centreon.conf" "Non Supprime"
else echo_success "Fichier $NAGIOS_PLUGIN/centreon.conf" "Supprime"
fi
else echo_warning "Fichier $NAGIOS_PLUGIN/centreon.conf" "Deja supprime"
fi
if test -d $INSTALL_DIR_OREON then rm -rf $INSTALL_DIR_OREON
if test -d $INSTALL_DIR_OREON then rm -rf $INSTALL_DIR_OREON
then echo_failure "Repertoire $INSTALL_DIR_OREON" "Non Supprime"
else echo_success "Repertoire $INSTALL_DIR_OREON" "Supprime"
fi
else echo_warning "Repertoire $INSTALL_DIR_OREON" "Deja supprime"
fi
if (test `mysql mysql -s -e "select user from user;" | grep -c -e"$USER"`== "1")
then mysql -s -e "drop user $USER@$HOST;";
if (test `mysql mysql -s -e "select user from user;" | grep -c -e"$USER"`== "0")
then echo_success "User MySQL $USER" "Supprime"
else echo_failure "User MySQL $USER" "Non Supprime"
fi
else echo_warning "User MySQL $USER" "Deja supprime"
fi
if (test `mysql -s -e "show databases;" | grep -c -e"$BDCNT"`== "1")
then mysql -s -e "drop database $BDCNT;";
if (test `mysql -s -e "show databases;" | grep -c -e"$BDCNT"`== "0")
then echo_success "Base MySQL $BDCNT" "Supprime"
else echo_failure "Base MySQL $BDCNT" "Non Supprime"
fi
else echo_warning "Base MySQL $BDCNT" "Deja supprime"
fi
if (test `mysql -s -e "show databases;" | grep -c -e"$BDODS"`== "1")
then mysql -s -e "drop database $BDODS;";
if (test `mysql -s -e "show databases;" | grep -c -e"$BDODS"`== "0")
then echo_success "Base MySQL $BDODS" "Supprime"
else echo_failure "Base MySQL $BDODS" "Non Supprime"
fi
else echo_warning "Base MySQL $BDODS" "Deja supprime"
fi
if (test `crontab -u nagios -l | grep -c -e "$INSTALL_DIR_OREON"` > 0 )
then crontab -u nagios -r;
if (test `crontab -u nagios -l | grep -c -e "$INSTALL_DIR_OREON"` > 0 )
then echo_failure "Crontab user Nagios" "Non purgee"
else echo_success "Crontab user Nagios" "Purgee"
fi
else echo_warning "Crontab user Nagios" "Deja purgee"
fi
if (test `cat $SUDO_FILE | grep OREON` > 0 )
then cp $SUDO_FILE sudoers.tmp
sed "/#Add by OREON installation script/d" sudoers.tmp > sudoers
cp sudoers sudoers.tmp
sed "/User_Alias OREON= apache/d" sudoers.tmp > sudoers
cp sudoers sudoers.tmp
sed "/## Nagios Restart/d" sudoers.tmp > sudoers
cp sudoers sudoers.tmp
sed "/OREON ALL = NOPASSWD: \/etc\/init.d\/nagios restart/d" sudoers.tmp > sudoers
cp sudoers sudoers.tmp
sed "/## Nagios reload/d" sudoers.tmp > sudoers
cp sudoers sudoers.tmp
sed "/OREON ALL = NOPASSWD: \/etc\/init.d\/nagios reload/d" sudoers.tmp > sudoers
cp sudoers sudoers.tmp
sed "/## Snmptrapd Restart/d" sudoers.tmp > sudoers
cp sudoers sudoers.tmp
sed "/OREON ALL = NOPASSWD: \/etc\/init.d\/snmptrapd restart/d" sudoers.tmp > sudoers
mv -f sudoers $SUDO_FILE
rm -f sudoers.tmp
else if (test `cat $SUDO_FILE | grep CENTREON` > 0 )
then cp /etc/sudoers sudoers.tmp
sed "/#Add by CENTREON installation script/d" sudoers.tmp > sudoers
cp sudoers sudoers.tmp
sed "/User_Alias CENTREON= apache/d" sudoers.tmp > sudoers
cp sudoers sudoers.tmp
sed "/## Nagios Restart/d" sudoers.tmp > sudoers
cp sudoers sudoers.tmp
sed "/CENTREON ALL = NOPASSWD: \/etc\/init.d\/nagios restart/d" sudoers.tmp > sudoers
cp sudoers sudoers.tmp
sed "/## Nagios reload/d" sudoers.tmp > sudoers
cp sudoers sudoers.tmp
sed "/CENTREON ALL = NOPASSWD: \/etc\/init.d\/nagios reload/d" sudoers.tmp > sudoers
cp sudoers sudoers.tmp
sed "/## Snmptrapd Restart/d" sudoers.tmp > sudoers
cp sudoers sudoers.tmp
sed "/CENTREON ALL = NOPASSWD: \/etc\/init.d\/snmptrapd restart/d" sudoers.tmp > sudoers
mv -f sudoers $SUDO_FILE
rm -f sudoers.tmp
else echo_warning "Fichier sudoers" "Deja Nettoye"
fi
if (test `cat $SUDO_FILE | grep CENTREON` = 0 ) -o (test `cat $SUDO_FILE | grep OREON` = 0 )
then echo_success "Fichier Sudoers" "Nettoye" else echo_failure "Fichier Sudoers" "Non nettoye"
fi
Le début reprend les functions de l'install.sh :wink: de Centreon.
C'est un script qui doit être encore amélioré :)
Voilà de mon côté ce que j'ai déjà fait...
Tu as testé le script ?
parceque ca me semble etre sympa (surtout pour la préparation du script d'install de la V2).
J'ai testé... et voila le début ^^
if (condition) ; then...
et non pas
if (condition) then ...
Guigui2607
04-23-2008, 03:32 PM
J'ai fait une erreur de frappe quelque part?
Je ne l'ai pas testé depuis que j'ai remodifé quelques lignes...
Je ne désinstalle pas Centreon tous les jours !! :p Heureusement d'ailleurs !!
Il faudrait que je le reteste pour vérifier tout ça :wink:
EDIT: Je suis en train de tester une désinstallation...
Effectivement, y'a quelque chose qui coince :wink:
Je modifie tout ça et je remets en ligne ce que j'ai fait...
Guigui2607
04-24-2008, 04:44 PM
Bon voilà quelques modifications de faites...
# -*-Shell-script-*-
#
# functions This file contains functions to be used by Oreon install scripts
#
##
## COLOR FUNCTIONS
##
RES_COL=60
MOVE_TO_COL="echo -en \\033[${RES_COL}G"
SETCOLOR_INFO="echo -en \\033[1;38m"
SETCOLOR_SUCCESS="echo -en \\033[1;32m"
SETCOLOR_FAILURE="echo -en \\033[1;31m"
SETCOLOR_WARNING="echo -en \\033[1;33m"
SETCOLOR_NORMAL="echo -en \\033[0;39m"
function echo_info() {
echo -n "$1"
$MOVE_TO_COL
$SETCOLOR_INFO
echo -n "$2"
$SETCOLOR_NORMAL
echo -e "\r"
}
function echo_success() {
echo -n "$1"
$MOVE_TO_COL
$SETCOLOR_SUCCESS
echo -n "$2"
$SETCOLOR_NORMAL
echo -e "\r"
}
function echo_failure() {
echo -n "$1"
$MOVE_TO_COL
$SETCOLOR_FAILURE
echo -n "$2"
$SETCOLOR_NORMAL
echo -e "\r"
}
function echo_passed() {
echo -n "$1"
$MOVE_TO_COL
$SETCOLOR_WARNING
echo -n "$2"
$SETCOLOR_NORMAL
echo -e "\r"
}
function echo_warning() {
echo -n "$1"
$MOVE_TO_COL
$SETCOLOR_WARNING
echo -n "$2"
$SETCOLOR_NORMAL
echo -e "\r"
}
SNMP_DIR="/etc/snmp/";
OREON_CONF="/etc/oreon.conf"
HTTP_CONF="/etc/httpd/conf.d/oreon.conf"
INSTALL_DIR_OREON=$(cat $OREON_CONF | grep INSTALL_DIR_OREON | cut -d "=" -f 2)
NAGIOS_PLUGIN=$(cat $OREON_CONF | grep NAGIOS_PLUGIN | cut -d "=" -f 2)
SUDO_FILE=$(cat $OREON_CONF | grep SUDO_FILE | cut -d "=" -f 2)
HOST=$(cat $INSTALL_DIR_OREON/www/oreon.conf.php | grep -e "'host'" | cut -d '"' -f 2);
USER=$(cat $INSTALL_DIR_OREON/www/oreon.conf.php | grep -e "'user'" | cut -d '"' -f 2);
PASS=$(cat $INSTALL_DIR_OREON/www/oreon.conf.php | grep -e "'password'" | cut -d '"' -f 2);
BDCNT=$(cat $INSTALL_DIR_OREON/www/oreon.conf.php | grep -e "'db'" | cut -d '"' -f 2);
BDODS=$(cat $INSTALL_DIR_OREON/www/oreon.conf.php | grep -e "'ods'" | cut -d '"' -f 2);
INIT_ODS=$(mysql centreon -s -e "select nagios_init_script from general_opt where gopt_id='1';" | grep -e "/" | sed "s/nagios/ods/")
service ods stop
if (test -f $OREON_CONF); then rm -f $OREON_CONF;
if (test -f $OREON_CONF); then rm -f $OREON_CONF;
echo_failure "Fichier $OREON_CONF" "Non Supprime";
else echo_success "Fichier $OREON_CONF" "Supprime";
fi;
else echo_warning "Fichier $OREON_CONF" "Deja supprime";
fi;
if (test -f $HTTP_CONF) then rm -f $HTTP_CONF
if (test -f $HTTP_CONF) then rm -f $HTTP_CONF
echo_failure "Fichier $HTTP_CONF" "Non Supprime"
else echo_success "Fichier $HTTP_CONF" "Supprime"
fi
else echo_warning "Fichier $HTTP_CONF" "Deja supprime"
fi
if (test -f $NAGIOS_PLUGIN/centreon.conf) then rm -f $NAGIOS_PLUGIN/centreon.conf
if (test -f $NAGIOS_PLUGIN/centreon.conf) then rm -f $NAGIOS_PLUGIN/centreon.conf
echo_failure "Fichier $NAGIOS_PLUGIN/centreon.conf" "Non Supprime"
else echo_success "Fichier $NAGIOS_PLUGIN/centreon.conf" "Supprime"
fi
else echo_warning "Fichier $NAGIOS_PLUGIN/centreon.conf" "Deja supprime"
fi
if (test -d $INSTALL_DIR_OREON) then rm -rf $INSTALL_DIR_OREON
if (test -d $INSTALL_DIR_OREON) then rm -rf $INSTALL_DIR_OREON
echo_failure "Repertoire $INSTALL_DIR_OREON" "Non Supprime"
else echo_success "Repertoire $INSTALL_DIR_OREON" "Supprime"
fi
else echo_warning "Repertoire $INSTALL_DIR_OREON" "Deja supprime"
fi
if (test `mysql mysql -s -e "select user from user;" | grep -c -e $USER` == "1")
then mysql -s -e "drop user $USER@$HOST;";
if (test `mysql mysql -s -e "select user from user;" | grep -c -e $USER` == "0")
then echo_success "User MySQL $USER" "Supprime"
else echo_failure "User MySQL $USER" "Non Supprime"
fi
else echo_warning "User MySQL $USER" "Deja supprime"
fi
if (test `mysql -s -e "show databases;" | grep -c -e"$BDCNT"` == "1")
then mysql -s -e "drop database $BDCNT;";
if (test `mysql -s -e "show databases;" | grep -c -e"$BDCNT"` == "0")
then echo_success "Base MySQL $BDCNT" "Supprime"
else echo_failure "Base MySQL $BDCNT" "Non Supprime"
fi
else echo_warning "Base MySQL $BDCNT" "Deja supprime"
fi
if (test `mysql -s -e "show databases;" | grep -c -e"$BDODS"` == "1")
then mysql -s -e "drop database $BDODS;";
if (test `mysql -s -e "show databases;" | grep -c -e"$BDODS"` == "0")
then echo_success "Base MySQL $BDODS" "Supprime"
else echo_failure "Base MySQL $BDODS" "Non Supprime"
fi
else echo_warning "Base MySQL $BDODS" "Deja supprime"
fi
if (test `crontab -u nagios -l | grep -c -e "$INSTALL_DIR_OREON"` == 0 )
then echo_warning "Crontab user Nagios" "Deja purgee"
else crontab -u nagios -r;
if (test `crontab -u nagios -l | grep -c -e "$INSTALL_DIR_OREON"` == "0" )
then echo_success "Crontab user Nagios" "Purgee"
else echo_failure "Crontab user Nagios" "Non purgee"
fi
fi
if (test `cat $SUDO_FILE | grep -c -e "OREON"` != "0" )
then cp $SUDO_FILE sudoers.tmp;
sed "/OREON/d" sudoers.tmp > sudoers;
cp sudoers sudoers.tmp;
sed "/Oreon/d" sudoers.tmp > sudoers;
cp sudoers sudoers.tmp;
sed "/## Nagios/d" sudoers.tmp > sudoers;
cp sudoers sudoers.tmp;
sed "/## Snmptrapd/d" sudoers.tmp > sudoers;
mv -f sudoers $SUDO_FILE;
rm -f sudoers.tmp;
if (test `cat $SUDO_FILE | grep -c -e "OREON"` == "0" )
then echo_success "Fichier Sudoers" "Nettoye"
else echo_failure "Fichier Sudoers" "Non nettoye"
fi
elif (test `cat $SUDO_FILE | grep -c -e "CENTREON"` != "0" )
then cp $SUDO_FILE sudoers.tmp;
sed "/Centreon/d" sudoers.tmp > sudoers;
cp sudoers sudoers.tmp;
sed "/CENTREON/d" sudoers.tmp > sudoers;
cp sudoers sudoers.tmp;
sed "/## Nagios/d" sudoers.tmp > sudoers;
cp sudoers sudoers.tmp;
sed "/## Snmptrapd/d" sudoers.tmp > sudoers;
mv -f sudoers $SUDO_FILE;
rm -f sudoers.tmp;
if (test `cat $SUDO_FILE | grep -c -e "CENTREON"` == "0" )
then echo_success "Fichier Sudoers" "Nettoye"
else echo_failure "Fichier Sudoers" "Non nettoye"
fi
else echo_warning "Fichier sudoers" "Deja Nettoye"
fi
if (test -f $INIT_ODS); then rm -f $INIT_ODS
if (test -f $INIT_ODS); then rm -f $INIT_ODS;
echo_failure "Fichier $INIT_ODS" "Non Supprime";
else echo_success "Fichier $INIT_ODS" "Supprime"
fi
else echo_warning "Fichier $INIT_ODS" "Deja supprime"
fi
Le seul 'hic' c'est qu'il faut le lancer qu'une seule fois car lors de la seconde exécution, il va tenter de parser des fichiers de conf qui ont été effacés lors de la première exécution...
Sinon, il fonctionne :wink:
Ca fonctionne les () pour le if ?
Sur ma machine le HTTP_CONF c'est dans /etc/apache2/conf.d/centreon.conf
Guigui2607
04-25-2008, 07:27 AM
Sur mon serveur RH4, c'est passé sans erreur.
Pour le moment, je n'ai pas encore trouvé le moyen de récupérer dans une variable le chemin du centreon.conf d'apache...
Mais je ne lâche pas le morceau pour autant :wink:
A part le HTTP_CONF, tu as pu tester ?
Guigui2607
04-25-2008, 08:58 AM
Bon, j'ai repris la partie qui vérifie apache dans le script 'function':
Je récupère comme ça le bon chemin en fonction de la version:
#!/bin/sh
# -*-Shell-script-*-
#
# functions This file contains functions to be used by Oreon install scripts
#
##
## COLOR FUNCTIONS
##
RES_COL=60
MOVE_TO_COL="echo -en \\033[${RES_COL}G"
SETCOLOR_INFO="echo -en \\033[1;38m"
SETCOLOR_SUCCESS="echo -en \\033[1;32m"
SETCOLOR_FAILURE="echo -en \\033[1;31m"
SETCOLOR_WARNING="echo -en \\033[1;33m"
SETCOLOR_NORMAL="echo -en \\033[0;39m"
function echo_info() {
echo -n "$1"
$MOVE_TO_COL
$SETCOLOR_INFO
echo -n "$2"
$SETCOLOR_NORMAL
echo -e "\r"
}
function echo_success() {
echo -n "$1"
$MOVE_TO_COL
$SETCOLOR_SUCCESS
echo -n "$2"
$SETCOLOR_NORMAL
echo -e "\r"
}
function echo_failure() {
echo -n "$1"
$MOVE_TO_COL
$SETCOLOR_FAILURE
echo -n "$2"
$SETCOLOR_NORMAL
echo -e "\r"
}
function echo_passed() {
echo -n "$1"
$MOVE_TO_COL
$SETCOLOR_WARNING
echo -n "$2"
$SETCOLOR_NORMAL
echo -e "\r"
}
function echo_warning() {
echo -n "$1"
$MOVE_TO_COL
$SETCOLOR_WARNING
echo -n "$2"
$SETCOLOR_NORMAL
echo -e "\r"
}
SNMP_DIR="/etc/snmp/";
OREON_CONF="/etc/oreon.conf"
#HTTP_CONF="/etc/httpd/conf.d/oreon.conf"
INSTALL_DIR_OREON=$(cat $OREON_CONF | grep INSTALL_DIR_OREON | cut -d "=" -f 2)
NAGIOS_PLUGIN=$(cat $OREON_CONF | grep NAGIOS_PLUGIN | cut -d "=" -f 2)
SUDO_FILE=$(cat $OREON_CONF | grep SUDO_FILE | cut -d "=" -f 2)
HOST=$(cat $INSTALL_DIR_OREON/www/oreon.conf.php | grep -e "'host'" | cut -d '"' -f 2);
USER=$(cat $INSTALL_DIR_OREON/www/oreon.conf.php | grep -e "'user'" | cut -d '"' -f 2);
PASS=$(cat $INSTALL_DIR_OREON/www/oreon.conf.php | grep -e "'password'" | cut -d '"' -f 2);
BDCNT=$(cat $INSTALL_DIR_OREON/www/oreon.conf.php | grep -e "'db'" | cut -d '"' -f 2);
BDODS=$(cat $INSTALL_DIR_OREON/www/oreon.conf.php | grep -e "'ods'" | cut -d '"' -f 2);
INIT_ODS=$(mysql centreon -s -e "select nagios_init_script from general_opt where gopt_id='1';" | grep -e "/" | sed "s/nagios/ods/")
################################################## #####
if test -d /etc/apache/conf ; then
DIR_APACHE="/etc/apache/conf"
DIR_APACHE_CONF="/etc/apache/conf.d"
else if test -d /usr/local/apache2/conf ; then
DIR_APACHE="/usr/local/apache2/conf"
DIR_APACHE_CONF="/usr/local/apache2/conf"
else if test -d /etc/apache2 ; then
DIR_APACHE="/etc/apache2"
DIR_APACHE_CONF="/etc/apache2/conf.d"
else if test -d /etc/httpd/conf ; then
DIR_APACHE="/etc/httpd/conf"
DIR_APACHE_CONF="/etc/httpd/conf.d"
else if test -d /usr/local/etc/apache ; then
DIR_APACHE="/usr/local/etc/apache"
DIR_APACHE_CONF="/usr/local/etc/apache/Includes"
else if test -d /usr/local/etc/apache2 ; then
DIR_APACHE="/usr/local/etc/apache2"
DIR_APACHE_CONF="/usr/local/etc/apache2/Includes"
fi
fi
fi
fi
fi
fi
if test -e $DIR_APACHE/apache2.conf ; then
APACHE_CONF="apache2.conf"
else if test -e $DIR_APACHE/commondhttpd.conf ; then
APACHE_CONF="commondhttpd.conf"
else if test -e $DIR_APACHE/httpd.conf ; then
APACHE_CONF="httpd.conf"
fi
fi
fi
################################################## ####
service ods stop
if (test -f $OREON_CONF); then rm -f $OREON_CONF;
if (test -f $OREON_CONF); then rm -f $OREON_CONF;
echo_failure "Fichier $OREON_CONF" "Non Supprime";
else echo_success "Fichier $OREON_CONF" "Supprime";
fi;
else echo_warning "Fichier $OREON_CONF" "Deja supprime";
fi;
if (test -f $DIR_APACHE_CONF/oreon.conf) then rm -f $DIR_APACHE_CONF/oreon.conf
if (test -f $DIR_APACHE_CONF/oreon.conf); then rm -f $DIR_APACHE_CONF/oreon.conf
echo_failure "Fichier $DIR_APACHE_CONF/oreon.conf" "Non Supprime"
else echo_success "Fichier $DIR_APACHE_CONF/oreon.conf" "Supprime"
fi
else echo_warning "Fichier $DIR_APACHE_CONF/oreon.conf" "Deja supprime"
fi
if (test -f $NAGIOS_PLUGIN/centreon.conf) then rm -f $NAGIOS_PLUGIN/centreon.conf
if (test -f $NAGIOS_PLUGIN/centreon.conf) then rm -f $NAGIOS_PLUGIN/centreon.conf
echo_failure "Fichier $NAGIOS_PLUGIN/centreon.conf" "Non Supprime"
else echo_success "Fichier $NAGIOS_PLUGIN/centreon.conf" "Supprime"
fi
else echo_warning "Fichier $NAGIOS_PLUGIN/centreon.conf" "Deja supprime"
fi
if (test -d $INSTALL_DIR_OREON) then rm -rf $INSTALL_DIR_OREON
if (test -d $INSTALL_DIR_OREON) then rm -rf $INSTALL_DIR_OREON
echo_failure "Repertoire $INSTALL_DIR_OREON" "Non Supprime"
else echo_success "Repertoire $INSTALL_DIR_OREON" "Supprime"
fi
else echo_warning "Repertoire $INSTALL_DIR_OREON" "Deja supprime"
fi
if (test `mysql mysql -s -e "select user from user;" | grep -c -e $USER` == "1")
then mysql -s -e "drop user $USER@$HOST;";
if (test `mysql mysql -s -e "select user from user;" | grep -c -e $USER` == "0")
then echo_success "User MySQL $USER" "Supprime"
else echo_failure "User MySQL $USER" "Non Supprime"
fi
else echo_warning "User MySQL $USER" "Deja supprime"
fi
if (test `mysql -s -e "show databases;" | grep -c -e"$BDCNT"` == "1")
then mysql -s -e "drop database $BDCNT;";
if (test `mysql -s -e "show databases;" | grep -c -e"$BDCNT"` == "0")
then echo_success "Base MySQL $BDCNT" "Supprime"
else echo_failure "Base MySQL $BDCNT" "Non Supprime"
fi
else echo_warning "Base MySQL $BDCNT" "Deja supprime"
fi
if (test `mysql -s -e "show databases;" | grep -c -e"$BDODS"` == "1")
then mysql -s -e "drop database $BDODS;";
if (test `mysql -s -e "show databases;" | grep -c -e"$BDODS"` == "0")
then echo_success "Base MySQL $BDODS" "Supprime"
else echo_failure "Base MySQL $BDODS" "Non Supprime"
fi
else echo_warning "Base MySQL $BDODS" "Deja supprime"
fi
if (test `crontab -u nagios -l | grep -c -e "$INSTALL_DIR_OREON"` == 0 )
then echo_warning "Crontab user Nagios" "Deja purgee"
else crontab -u nagios -r;
if (test `crontab -u nagios -l | grep -c -e "$INSTALL_DIR_OREON"` == "0" )
then echo_success "Crontab user Nagios" "Purgee"
else echo_failure "Crontab user Nagios" "Non purgee"
fi
fi
if (test `cat $SUDO_FILE | grep -c -e "OREON"` != "0" )
then cp $SUDO_FILE sudoers.tmp;
sed "/OREON/d" sudoers.tmp > sudoers;
cp sudoers sudoers.tmp;
sed "/Oreon/d" sudoers.tmp > sudoers;
cp sudoers sudoers.tmp;
sed "/## Nagios/d" sudoers.tmp > sudoers;
cp sudoers sudoers.tmp;
sed "/## Snmptrapd/d" sudoers.tmp > sudoers;
mv -f sudoers $SUDO_FILE;
rm -f sudoers.tmp;
if (test `cat $SUDO_FILE | grep -c -e "OREON"` == "0" )
then echo_success "Fichier Sudoers(OREON)" "Nettoye"
else echo_failure "Fichier Sudoers(OREON)" "Non nettoye"
fi
elif (test `cat $SUDO_FILE | grep -c -e "CENTREON"` != "0" )
then cp $SUDO_FILE sudoers.tmp;
sed "/Centreon/d" sudoers.tmp > sudoers;
cp sudoers sudoers.tmp;
sed "/CENTREON/d" sudoers.tmp > sudoers;
cp sudoers sudoers.tmp;
sed "/## Nagios/d" sudoers.tmp > sudoers;
cp sudoers sudoers.tmp;
sed "/## Snmptrapd/d" sudoers.tmp > sudoers;
mv -f sudoers $SUDO_FILE;
rm -f sudoers.tmp;
if (test `cat $SUDO_FILE | grep -c -e "CENTREON"` == "0" )
then echo_success "Fichier Sudoers(CENTREON)" "Nettoye"
else echo_failure "Fichier Sudoers(CENTREON)" "Non nettoye"
fi
else echo_warning "Fichier sudoers" "Deja Nettoye"
fi
if (test -f $INIT_ODS); then rm -f $INIT_ODS
if (test -f $INIT_ODS); then rm -f $INIT_ODS;
echo_failure "Fichier $INIT_ODS" "Non Supprime";
else echo_success "Fichier $INIT_ODS" "Supprime"
fi
else echo_warning "Fichier $INIT_ODS" "Deja supprime"
fi
Ça devrait être bon du coup pour le fichier oreon.conf d'apache...
if (test `mysql -s -e "show databases;" | grep -c -e"$BDCNT"` == "1")
Tu fais des tests sur des chaine de caractère pour comparer des int ?
man test ne connais as "==" mais "=" (comment je pinaille ^^)
je suis sous debian, service n'est pas une fonction connu, chez moi c'est invoke-rc.d.
Je vois pour testé dans le journée. Il est compatible avec l'install de la v2 ? :p
Si tu ne veux pas te prendre la tete, je te conseil de faire un uninstall.sh du type
#!/bin/sh
. libinstall/functions
## invoke apache check function
check_httpd_directory
....
Comme ca on verra pour mettre ce script directement dans le paquet. (voir SVN si tu veux des détails sur le functions)
Guigui2607
04-25-2008, 09:41 AM
if (test `mysql -s -e "show databases;" | grep -c -e"$BDCNT"` == "1")
Tu fais des tests sur des chaine de caractère pour comparer des int ?
man test ne connais as "==" mais "=" (comment je pinaille ^^)
Mon grep -c -e"$BDCNT" compte le nombre d'occurrences du nom de la table recherchée, retournées par le grep -c -e"$BDCNT"...
En gros, je teste l'existence de la base recherchée... Je compare ainsi 2 int...
En fait, c'est bien de voir ce que les autres font aussi et comment ils font, la façon dont j'ai l'habitude de faire n'est pas forcement la meilleure
Le fait de partager tout ça permet à chacun de progresser (surtout moi :p :roll:)
Pour ma part, voici ce que je ferai (chacun son code :p )
C'est pas forcement mieux ce que je fais.
if [ `mysql -s -e "show databases;" | grep -c -e"$BDCNT"` -eq 1 ]
je n'utilise pas la fonction "test" mais "[]", ce qui reviens au même. Lorsque tu veux comparer deux "int" (par défault c'est pas typé en shell, faut un declare -i sinon) le man conseil l'utilisation de "-eq" pour egal, "-ne" pour diff ...
Voila :), n'hésite pas a poser des questions coté Shell.
WAtt
Guigui2607
04-25-2008, 10:49 AM
Ok, ça marche, je vais tester avec les [] et les -eq et -ne
Il est compatible avec l'install de la v2 ?
Si la V2 utilise les mêmes noms de fichiers ça peut être bon :wink:
:arrow: Faudrait que je regarde l'install de la V2 pour être sûr des noms des fichiers... Tiens, vais allez traîner du côté du SVN :rolleyes:
En effet, regarder l'install de la V2 est une très bonne idée :)
On a changé pas mal de choses. J'espère que ça va plaire :)
Guigui2607
04-29-2008, 08:40 AM
Je l'attends avec impatience :p
Je suis resté sur ma faim avec la démo flash dispo sur le site :wink:
Mais pour le coup, ca pourrai peut etre, etre interessant d'intégrer un script d'uninstall pour la v2. On ne sais jamais :)
Tu as commencé a regardé sur le svn ?
Guigui2607
04-29-2008, 09:18 AM
J'ai juste récupérer l'install du SVN sur mon PC, pas eu encore assez de temps hier pour me pencher dessus... J'essaye aujourd'hui si je peux.
J'ai juste vu et donc cru comprendre que l'install était répartie en 4 grandes parties. Dès que j'ai un peu de temps, je me plonge dedans :wink:
Exact,
Centreon 2 est prévu pour etre installé en distribué. Du coup, il est nécessaire de pouvoir installé uniquement certaine choses sur les pollers et pas d'autres.
faut que je fasse un Readme a ce sujet d'ailleurs...
Guigui2607
05-05-2008, 10:22 AM
Hello,
J'ai fait les modifications avec les [] et les -eq & -ne en enlevant les test comme tu me le préconisais. Voilà ce que ça donne:
#!/bin/sh
#
# Uninstall program for Centreon
# http://www.centreon.com
# Last modification: 05/05/2008
##
## COLOR FUNCTIONS
##
RES_COL=60
MOVE_TO_COL="echo -en \\033[${RES_COL}G"
SETCOLOR_INFO="echo -en \\033[1;38m"
SETCOLOR_SUCCESS="echo -en \\033[1;32m"
SETCOLOR_FAILURE="echo -en \\033[1;31m"
SETCOLOR_WARNING="echo -en \\033[1;33m"
SETCOLOR_NORMAL="echo -en \\033[0;39m"
function echo_info() {
echo -n "$1"
$MOVE_TO_COL
$SETCOLOR_INFO
echo -n "$2"
$SETCOLOR_NORMAL
echo -e "\r"
}
function echo_success() {
echo -n "$1"
$MOVE_TO_COL
$SETCOLOR_SUCCESS
echo -n "$2"
$SETCOLOR_NORMAL
echo -e "\r"
}
function echo_failure() {
echo -n "$1"
$MOVE_TO_COL
$SETCOLOR_FAILURE
echo -n "$2"
$SETCOLOR_NORMAL
echo -e "\r"
}
function echo_passed() {
echo -n "$1"
$MOVE_TO_COL
$SETCOLOR_WARNING
echo -n "$2"
$SETCOLOR_NORMAL
echo -e "\r"
}
function echo_warning() {
echo -n "$1"
$MOVE_TO_COL
$SETCOLOR_WARNING
echo -n "$2"
$SETCOLOR_NORMAL
echo -e "\r"
}
SNMP_DIR="/etc/snmp";
OREON_CONF="/etc/oreon.conf"
#HTTP_CONF="/etc/httpd/conf.d/oreon.conf"
INSTALL_DIR_OREON=$(cat $OREON_CONF | grep INSTALL_DIR_OREON | cut -d "=" -f 2)
NAGIOS_PLUGIN=$(cat $OREON_CONF | grep NAGIOS_PLUGIN | cut -d "=" -f 2)
SUDO_FILE=$(cat $OREON_CONF | grep SUDO_FILE | cut -d "=" -f 2)
HOST=$(cat $INSTALL_DIR_OREON/www/oreon.conf.php | grep -e "'host'" | cut -d '"' -f 2);
USER=$(cat $INSTALL_DIR_OREON/www/oreon.conf.php | grep -e "'user'" | cut -d '"' -f 2);
PASS=$(cat $INSTALL_DIR_OREON/www/oreon.conf.php | grep -e "'password'" | cut -d '"' -f 2);
BDCNT=$(cat $INSTALL_DIR_OREON/www/oreon.conf.php | grep -e "'db'" | cut -d '"' -f 2);
BDODS=$(cat $INSTALL_DIR_OREON/www/oreon.conf.php | grep -e "'ods'" | cut -d '"' -f 2);
INIT_ODS=$(mysql centreon -s -e "select nagios_init_script from general_opt where gopt_id='1';" | grep -e "/" | sed "s/nagios/ods/")
################################################## #####
if [ -d /etc/apache/conf ]; then
DIR_APACHE="/etc/apache/conf"
DIR_APACHE_CONF="/etc/apache/conf.d"
else if [ -d /usr/local/apache2/conf ]; then
DIR_APACHE="/usr/local/apache2/conf"
DIR_APACHE_CONF="/usr/local/apache2/conf"
else if [ -d /etc/apache2 ]; then
DIR_APACHE="/etc/apache2"
DIR_APACHE_CONF="/etc/apache2/conf.d"
else if [ -d /etc/httpd/conf ]; then
DIR_APACHE="/etc/httpd/conf"
DIR_APACHE_CONF="/etc/httpd/conf.d"
else if [ -d /usr/local/etc/apache ]; then
DIR_APACHE="/usr/local/etc/apache"
DIR_APACHE_CONF="/usr/local/etc/apache/Includes"
else if [ -d /usr/local/etc/apache2 ]; then
DIR_APACHE="/usr/local/etc/apache2"
DIR_APACHE_CONF="/usr/local/etc/apache2/Includes"
fi;fi;fi;fi;fi;fi;
if [ -e $DIR_APACHE/apache2.conf ]; then
APACHE_CONF="apache2.conf"
else if [ -e $DIR_APACHE/commondhttpd.conf ]; then
APACHE_CONF="commondhttpd.conf"
else if [ -e $DIR_APACHE/httpd.conf ]; then
APACHE_CONF="httpd.conf"
fi;fi;fi;
################################################## ####
service ods stop
if [ -f $OREON_CONF ]; then rm -f $OREON_CONF;
if [ -f $OREON_CONF ]; then rm -f $OREON_CONF;
echo_failure "Fichier $OREON_CONF" "Non Supprime";
else echo_success "Fichier $OREON_CONF" "Supprime";
fi;
else echo_warning "Fichier $OREON_CONF" "Deja supprime";
fi;
if [ -f $DIR_APACHE_CONF/oreon.conf ] then rm -f $DIR_APACHE_CONF/oreon.conf
if [ -f $DIR_APACHE_CONF/oreon.conf ]; then rm -f $DIR_APACHE_CONF/oreon.conf
echo_failure "Fichier $DIR_APACHE_CONF/oreon.conf" "Non Supprime"
else echo_success "Fichier $DIR_APACHE_CONF/oreon.conf" "Supprime"
fi
else echo_warning "Fichier $DIR_APACHE_CONF/oreon.conf" "Deja supprime"
fi
if [ -f $NAGIOS_PLUGIN/centreon.conf ] then rm -f $NAGIOS_PLUGIN/centreon.conf
if [ -f $NAGIOS_PLUGIN/centreon.conf ] then rm -f $NAGIOS_PLUGIN/centreon.conf
echo_failure "Fichier $NAGIOS_PLUGIN/centreon.conf" "Non Supprime"
else echo_success "Fichier $NAGIOS_PLUGIN/centreon.conf" "Supprime"
fi
else echo_warning "Fichier $NAGIOS_PLUGIN/centreon.conf" "Deja supprime"
fi
if [ -d $INSTALL_DIR_OREON/traps ] then rm -rf $INSTALL_DIR_OREON/traps
if [ -d $INSTALL_DIR_OREON/traps ] then rm -rf $INSTALL_DIR_OREON/traps
echo_failure "Repertoire $INSTALL_DIR_OREON/traps" "Non Supprime"
else echo_success "Repertoire $INSTALL_DIR_OREON/traps" "Supprime"
fi
else echo_warning "Repertoire $INSTALL_DIR_OREON/traps" "Deja supprime"
fi
if [ -d $INSTALL_DIR_OREON ] then rm -rf $INSTALL_DIR_OREON
if [ -d $INSTALL_DIR_OREON ] then rm -rf $INSTALL_DIR_OREON
echo_failure "Repertoire $INSTALL_DIR_OREON" "Non Supprime"
else echo_success "Repertoire $INSTALL_DIR_OREON" "Supprime"
fi
else echo_warning "Repertoire $INSTALL_DIR_OREON" "Deja supprime"
fi
if [ `mysql mysql -s -e "select user from user;" | grep -c -e $USER` -eq 1 ]
then mysql -s -e "drop user $USER@$HOST;";
if [ `mysql mysql -s -e "select user from user;" | grep -c -e $USER` -eq 0 ]
then echo_success "User MySQL $USER" "Supprime"
else echo_failure "User MySQL $USER" "Non Supprime"
fi
else echo_warning "User MySQL $USER" "Deja supprime"
fi
if [ `mysql -s -e "show databases;" | grep -c -e"$BDCNT"` -eq 1 ]
then mysql -s -e "drop database $BDCNT;";
if [ `mysql -s -e "show databases;" | grep -c -e"$BDCNT"` -eq 0 ]
then echo_success "Base MySQL $BDCNT" "Supprime"
else echo_failure "Base MySQL $BDCNT" "Non Supprime"
fi
else echo_warning "Base MySQL $BDCNT" "Deja supprime"
fi
if [ `mysql -s -e "show databases;" | grep -c -e"$BDODS"` -eq 1 ]
then mysql -s -e "drop database $BDODS;";
if [ `mysql -s -e "show databases;" | grep -c -e"$BDODS"` -eq 0 ]
then echo_success "Base MySQL $BDODS" "Supprime"
else echo_failure "Base MySQL $BDODS" "Non Supprime"
fi
else echo_warning "Base MySQL $BDODS" "Deja supprime"
fi
if [ `crontab -u nagios -l | grep -c -e "$INSTALL_DIR_OREON"` -eq 0 ]
then echo_warning "Crontab user Nagios" "Deja purgee"
else crontab -u nagios -r;
if [ `crontab -u nagios -l | grep -c -e "$INSTALL_DIR_OREON"` -eq 0 ]
then echo_success "Crontab user Nagios" "Purgee"
else echo_failure "Crontab user Nagios" "Non purgee"
fi
fi
if [ `cat $SUDO_FILE | grep -c -e "OREON"` -eq 0 ]
then cp $SUDO_FILE sudoers.tmp;
sed "/OREON/d" sudoers.tmp > sudoers;
cp sudoers sudoers.tmp;
sed "/Oreon/d" sudoers.tmp > sudoers;
cp sudoers sudoers.tmp;
sed "/## Nagios/d" sudoers.tmp > sudoers;
cp sudoers sudoers.tmp;
sed "/## Snmptrapd/d" sudoers.tmp > sudoers;
mv -f sudoers $SUDO_FILE;
rm -f sudoers.tmp;
if [ `cat $SUDO_FILE | grep -c -e "OREON"` -eq 0 ]
then echo_success "Fichier Sudoers(OREON)" "Nettoye"
else echo_failure "Fichier Sudoers(OREON)" "Non nettoye"
fi
elif [ `cat $SUDO_FILE | grep -c -e "CENTREON"` -eq 0 ]
then cp $SUDO_FILE sudoers.tmp;
sed "/Centreon/d" sudoers.tmp > sudoers;
cp sudoers sudoers.tmp;
sed "/CENTREON/d" sudoers.tmp > sudoers;
cp sudoers sudoers.tmp;
sed "/## Nagios/d" sudoers.tmp > sudoers;
cp sudoers sudoers.tmp;
sed "/## Snmptrapd/d" sudoers.tmp > sudoers;
mv -f sudoers $SUDO_FILE;
rm -f sudoers.tmp;
if [ `cat $SUDO_FILE | grep -c -e "CENTREON"` -eq 0 ]
then echo_success "Fichier Sudoers(CENTREON)" "Nettoye"
else echo_failure "Fichier Sudoers(CENTREON)" "Non nettoye"
fi
else echo_warning "Fichier sudoers" "Deja Nettoye"
fi
if [ -f $INIT_ODS ]; then rm -f $INIT_ODS
if [ -f $INIT_ODS ]; then rm -f $INIT_ODS;
echo_failure "Fichier $INIT_ODS" "Non Supprime";
else echo_success "Fichier $INIT_ODS" "Supprime"
fi
else echo_warning "Fichier $INIT_ODS" "Deja supprime"
fi
if [ -d $SNMP_DIR/centreon_traps ]; then rm -rf $SNMP_DIR/centreon_traps
if [ -d $INIT_ODS/centreon_traps ]; then rm -rf $SNMP_DIR/centreon_traps;
echo_failure "Fichier $SNMP_DIR/centreon_traps" "Non Supprime";
else echo_success "Fichier $SNMP_DIR/centreon_traps" "Supprime"
fi
else echo_warning "Fichier $SNMP_DIR/centreon_traps" "Deja supprime"
fi
Pour la V2, j'ai pas eu trop le temps d'y vraiment m'y plonger... (Week-end prolongé :wink: )