# ------------------------------------------
# 0. Remove all data and start from scratch
# ------------------------------------------
killproc /srv/app/nagios-3.3.1/bin/nagios
ps -ef |grep nagios

rm -rf /srv/www/std-root/nagios.frank4dd.com/nagios-3.3.1
rm -rf /home/sw/source/nagios/nagios-3.3.1
rm -rf /srv/app/nagios-3.3.1
rm -rf /var/spool/nagios-3.3.1
rm /var/lock/nagios-3.3.1.lock


# ------------------------------------------
# 1. Create the new source package directory
# ------------------------------------------

cd /home/sw/source/nagios/
mkdir nagios-3.3.1
cd nagios-3.3.1/

# ------------------------------------------
# 2. Download the source packes
# ------------------------------------------

wget -q http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.3.1.tar.gz
wget -q http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
ls -l

# ------------------------------------------
# 3. Unpack the source
# ------------------------------------------

tar xvfz nagios-3.3.1.tar.gz
tar xvfz nagios-plugins-1.4.15.tar.gz
chown -R root:root nagios nagios-plugins-1.4.15
ls -l
cd

# ------------------------------------------
# 4. Verify Nagios lib dependencies
# ------------------------------------------

rpm -q -a |grep 'gd-devel\|png-devel\|jpeg-devel\|zlib-devel'

# ------------------------------------------
# 5. Configure, make, make install
# ------------------------------------------

cd /home/sw/source/nagios/nagios-3.3.1/nagios
./configure --prefix=/srv/app/nagios-3.3.1 --with-command-group=nagcmd --with-nagios-user=nagios --with-nagios-group=nagios --with-httpd-conf=/etc/apache2 --with-init-dir=/etc/init.d --with-lockfile=/var/lock/nagios-3.3.1.lock --with-checkresult-dir=/var/spool/nagios-3.3.1 --with-htmurl=/nagios-3.3.1 --with-cgiurl=/nagios-3.3.1/cgi-bin

make all

mkdir /srv/app/nagios-3.3.1
ls -l /srv/app |grep nagios

make install
make install-commandmode
cd

# ------------------------------------------
# 6. copy external nagiosgraph CGI
# ------------------------------------------

cp /srv/www/std-root/nagios.frank4dd.com/nagios/cgi-bin/show.cgi /srv/app/nagios-3.3.1/sbin
chown nagios:nagios /srv/app/nagios-3.3.1/sbin/show.cgi

# ------------------------------------------
# 7. Verify Plugin lib dependencies
# ------------------------------------------

rpm -q -a | grep 'ssl-dev\|fping\|ldap2-dev\|mysqlclient-dev\|snmp-dev\|perl-Net-SNMP'

# ------------------------------------------
# 8. Configure, make, make installl
# ------------------------------------------

cd /home/sw/source/nagios/nagios-3.3.1/nagios-plugins-1.4.15
./configure --prefix=/srv/app/nagios-3.3.1 --with-nagios-user=nagios --with-nagios-group=nagios --without-world-permissions --with-cgiurl=/nagios-3.3.1/cgi-bin --enable-perl-modules

make
make install
cd

# ------------------------------------------
# 9. Sync the remaining plugins from the old instance
# ------------------------------------------

rsync -uv --ignore-existing /srv/app/nagios-3.2.3/libexec/* /srv/app/nagios-3.3.1/libexec
chown nagios:nagios /srv/app/nagios-3.3.1/libexec/*