#!/bin/bash
#
# NINO cleanup script for LiNUX
#
# This script will:
# - Restore libraries
# - Restore original cron
# - Cleanup statistics
# - remove startup scripts
#
# The NINO files must be located in /var/nino (BASEDIR)
#
# NINO basedir:

BASEDIR=`dirname $0 `
cd ${BASEDIR}
BASEDIR=` pwd | sed s/[/]scripts// `

LOG="${BASEDIR}/scripts/install.log"
echo "NINO cleanup on `date` " > ${LOG}

# Setup cron settings:

#echo "CRON:" >> ${LOG}
#crontab -l | grep -v "${BASEDIR}" > ${BASEDIR}/mod_perl/newcron.txt
#crontab ${BASEDIR}/mod_perl/newcron.txt
#rm -f ${BASEDIR}/mod_perl/newcron.txt
#crontab -l >> ${LOG}

# cleanup NINO services
echo "NINO Services removed" >> ${LOG}

NINOSERVICES="nino"
/etc/init.d/${NINOSERVICES} stop
rm -f /etc/init.d/${NINOSERVICES}
#RC3=`find /etc -name "rc3.d" -print | head -1 `
#cd ${RC3}
#rm -f S99${NINOSERVICES}

# Setup Apache configuration

HTTPD_CONF=`find /etc /usr/local/etc -name "httpd2.conf" -print  2> /dev/null | sort |  head -1 `
if [ "${HTTPD_CONF}" == "" ] ; then
  HTTPD_CONF=`find /etc /usr/local/etc -name "httpd.conf" -print  2> /dev/null | sort |  head -1 `
fi
echo "Configured ${HTTPD_CONF}" >> ${LOG}
if [ "${HTTPD_CONF}" != "" ] ; then

  cp ${HTTPD_CONF} ${HTTPD_CONF}.old
  cat ${HTTPD_CONF}.old | grep -v "httpd-nino.conf" > ${HTTPD_CONF}
fi

## Setup Perl libs:

cp ${BASEDIR}/mod_perl/libcompat/NINOSNMP-ucd.pm  ${BASEDIR}/mod_perl/lib/NINOSNMP.pm

## Remove statistics

cd ${BASEDIR}/mod_perl/statistics
rm -f *
echo Monitoring collect data > readme.txt


cd ${BASEDIR}/htdocs/nino/upload/
rm -f *
echo Uploads in here > readme.txt
cd ${BASEDIR}/htdocs/nino/reports/
rm -f *.html
cd ${BASEDIR}/htdocs/nino/reports/statistics
rm -f *
echo Monitoring collect data > readme.txt
echo [/] > ${BASEDIR}/mod_perl/nodes.txt
echo [/] > ${BASEDIR}/htdocs/nino/nodes

echo Cleanup complete >> ${LOG}

 
