2009-08-11 18:26:09 +02:00
#!/bin/bash
# Pandora FMS Server Installer (c) 2008-2009 Artica ST
# Linux Version (generic), for SuSe and Debian/Ubuntu only
# other Linux distros could not work properly without modifications
2009-04-20 17:14:04 +02:00
# Please see http://www.pandorafms.org
2009-11-06 20:48:48 +01:00
# v3.0 Build 091106
2008-04-07 00:11:16 +02:00
# This code is licensed under GPL 2.0 license.
# **********************************************************************
2009-11-06 20:48:48 +01:00
# TO DO: Add K Scripts
2008-04-07 00:11:16 +02:00
MODE=$1
2009-04-20 17:14:04 +02:00
SECOPT=$2
2008-04-07 00:11:16 +02:00
2009-08-11 18:26:09 +02:00
get_distro () {
# Get Linux Distro type and version
2009-09-21 22:26:23 +02:00
# We assume we are on Linux unless told otherwise
2009-09-22 12:38:53 +02:00
LINUX=YES
2009-08-11 18:26:09 +02:00
if [ -f "/etc/SuSE-release" ]
2008-06-19 16:53:10 +02:00
then
2009-08-11 18:26:09 +02:00
OS_VERSION=`cat /etc/SuSE-release | grep VERSION | cut -f 3 -d " "`
LINUX_DISTRO=SUSE
2009-09-21 22:26:23 +02:00
elif [ -f "/etc/lsb-release" ]
then
OS_VERSION=`cat /etc/lsb-release | grep DISTRIB_RELEASE | cut -f 2 -d "="`
LINUX_DISTRO=UBUNTU
OS_VERSION="UBUNTU $OS_VERSION"
elif [ -f "/etc/debian_version" ]
then
OS_VERSION=`cat /etc/debian_version`
OS_VERSION="DEBIAN $OS_VERSION"
LINUX_DISTRO=DEBIAN
elif [ -f "/etc/fedora-release" ]
then
OS_VERSION=`cat /etc/fedora-release | cut -f 4 -d " "`
OS_VERSION="FEDORA $OS_VERSION"
LINUX_DISTRO=FEDORA
elif [ `uname -s` == "Darwin" ]
then
# For future reference, Darwin doesn't have /etc/init.d but uses LaunchDaemons
LINUX_DISTRO="Darwin"
OS_VERSION=`uname -r`
2009-09-22 12:38:53 +02:00
LINUX=NO
elif [ `uname -s` == "AIX" ]
then
# For future reference, AIX doesn't have /etc/init.d
LINUX_DISTRO="AIX"
OS_VERSION=`uname -r`
LINUX=NO
2009-09-21 22:26:23 +02:00
elif [ `uname -s` == "SunOS" ]
then
# Some Solaris and other Unices don't have /etc/init.d, some have /usr/spool instead of /var/spool
LINUX_DISTRO="Solaris"
OS_VERSION=`uname -r`
2009-09-22 12:38:53 +02:00
LINUX=NO
2009-09-21 22:26:23 +02:00
elif [ `uname -s` == "Linux" ]
then
# Test for Linux to make sure we're on Linux
LINUX_DISTRO="GENERIC"
OS_VERSION=`uname -r`
2009-08-11 18:26:09 +02:00
else
2009-09-21 22:26:23 +02:00
# Default to Linux is false, test for real Linux above - that way we don't assume we can just plunk down files everywhere
LINUX_DISTRO=`uname -s`
OS_VERSION=`uname -r`
2009-09-22 12:38:53 +02:00
LINUX=NO
2008-06-19 16:53:10 +02:00
fi
2009-09-22 12:38:53 +02:00
echo "$LINUX_DISTRO:$OS_VERSION:$LINUX"
2009-08-11 18:26:09 +02:00
}
2008-06-19 16:53:10 +02:00
2009-04-18 14:37:18 +02:00
2009-08-11 18:26:09 +02:00
install () {
2009-04-18 14:37:18 +02:00
2009-08-11 18:26:09 +02:00
perl Makefile.PL > output 2>&1 #&& sleep 2 && cat output | grep "found" | wc -l
DEPENDENCIAS=`cat output | grep "found" | wc -l`
if [ $DEPENDENCIAS -gt 0 ]
2008-07-08 20:52:57 +02:00
then
2009-08-11 18:26:09 +02:00
echo "You are missing the following dependencies"
echo " "
cat output | awk -F ": prerequisite" '{print $2}' | awk -F " " '{print $1}'
echo "The complete installation guide is at: "http://www.openideas.info/wiki/index.php?title=Pandora_2.0:Documentation_en:Install_Server#Pandora_FMS_Server_installation" "
echo " "
echo "Debian-based distribution do:"
2009-09-16 02:02:23 +02:00
echo " $ apt-get install snmp snmpd libtime-format-perl libxml-simple-perl libnetaddr-ip-perl libdbi-perl libxml-simple-perl libnetaddr-ip-perl libhtml-parser-perl wmi-client xprobe2 libmail-sendmail-perl"
2009-08-11 18:26:09 +02:00
echo " "
echo "RPM distribution do"
echo " "
2009-09-16 02:02:23 +02:00
echo " $ yum perl-XML-SAX* perl-Tie* perl-XML-Simple* perl-IO-Socket* perl-Time-modules* perl-NetAddr-IP* perl-DateTime* perl-ExtUtils perl-DBI"
2009-08-11 18:26:09 +02:00
echo " "
echo "To get it from source through CPAN do"
echo " "
2009-09-16 02:02:23 +02:00
echo " $ cpan Digest::MD5 Time::Local DBI XML::Simple IO::Socket Time::HiRes Time::Format NetAddr::IP Mail::Sendmail Net::Traceroute::PurePerl HTML::Entities"
2009-08-11 18:26:09 +02:00
echo " "
rm output
2008-07-08 20:52:57 +02:00
else
2009-09-22 12:38:53 +02:00
# This returns a multiple value string, separated with ":" -> $LINUX_DISTRO:$OS_VERSION:$LINUX
GET_DISTRO="`get_distro`"
DISTRO=`echo $GET_DISTRO | cut -f 1 -d ":"`
OS_VERSION=`echo $GET_DISTRO | cut -f 2 -d ":"`
LINUX=`echo $GET_DISTRO | cut -f 3 -d ":"`
2009-08-11 18:26:09 +02:00
if [ "$DISTRO" == "UBUNTU" ]
then
echo "UBUNTU distribution detected"
2009-09-21 22:26:23 +02:00
elif [ "$DISTRO" == "SUSE" ]
2009-08-11 18:26:09 +02:00
then
echo "SUSE distribution detected"
fi
echo "Installing binaries and libraries"
make
make install
echo "Creating common Pandora FMS directories"
id pandora
if [ $? -eq 0 ]; then
echo " "
echo "User pandora does exist, make sure the SSH directories are correct"
else
2009-09-21 22:26:23 +02:00
echo "Are you sure we can create a standard 'pandora' user locally? [y/N]"
read AREYOUSURE
if [ "$AREYOUSURE" == "y" ]; then
useradd pandora
mkdir /home/pandora 2> /dev/null
mkdir /home/pandora/.ssh 2> /dev/null
chown -R pandora /home/pandora
else
echo "Please create the 'pandora' user manually according to your authentication scheme then restart the installation"
echo "Aborting..."
exit 1
fi
2009-08-11 18:26:09 +02:00
fi
2009-09-21 22:26:23 +02:00
mkdir /var/spool/pandora 2> /dev/null
mkdir /var/spool/pandora/data_in 2> /dev/null
mkdir /var/spool/pandora/data_in/conf 2> /dev/null
mkdir /var/spool/pandora/data_in/md5 2> /dev/null
2009-08-11 18:26:09 +02:00
mkdir /var/log/pandora 2> /dev/null
echo "Giving proper permission to /var/spool/pandora"
2009-09-21 22:26:23 +02:00
id -g www-data > /dev/null
if [ $? -eq 0 ]
2009-08-11 18:26:09 +02:00
then
chown -R pandora:www-data /var/spool/pandora/
else
2009-09-21 22:26:23 +02:00
id -g www > /dev/null
if [ $? -eq 0 ]
then
chown -R pandora:www /var/spool/pandora/
else
id -g apache > /dev/null
if [ $? -eq 0 ]
then
chown -R pandora:apache /var/spool/pandora/
else
echo "No web server user found, some functionality might not perform correctly"
chown -R pandora:root /var/spool/pandora
fi
fi
2009-08-11 18:26:09 +02:00
fi
2009-09-21 22:26:23 +02:00
2009-08-11 18:26:09 +02:00
echo "Creating setup directory in /etc/pandora"
mkdir /etc/pandora 2> /dev/null
if [ -e /etc/pandora/pandora_server.conf ]
then
OLDFILENAMETMP=`date +"%Y-%m-%d"`
echo "Old installation detected, backing up pandora_server.conf.$ODFILENAMETMP"
mv /etc/pandora/pandora_server.conf /etc/pandora/pandora_server.conf.$OLDFILENAMETMP
fi
cp conf/pandora_server.conf /etc/pandora/
chmod 770 /etc/pandora/pandora_server.conf
2009-09-22 12:38:53 +02:00
if [ "$LINUX" == "YES" ]
2009-08-11 18:26:09 +02:00
then
2009-09-21 22:26:23 +02:00
echo "Copying the daemon script into /etc/init.d/pandora_server"
cp util/pandora_server /etc/init.d/
if [ "$DISTRO" == "UBUNTU" ]
then
echo "Linking startup script to /etc/rc2.d"
ln -s /etc/init.d/pandora_server /etc/rc2.d/S90pandora_server
else
INITLV=`cat /etc/inittab | grep "[0-9]\:initdefault" | cut -f 2 -d ":"`
echo "Linking startup script to /etc/rc.d/rc$INITLV.d"
ln -s /etc/init.d/pandora_server /etc/rc.d/rc$INITLV.d/S90pandora_server
fi
2009-08-11 18:26:09 +02:00
fi
2009-09-21 22:26:23 +02:00
if [ -d /etc/logrotate.d ]; then
echo "Creating logrotate.d entry for Pandora FMS log management"
cp util/pandora_logrotate /etc/logrotate.d/pandora
else
echo "Please add a log rotation schedule manually to your log rotation daemon (if any)"
fi
2009-09-22 12:38:53 +02:00
if [ "$LINUX" == "YES" ]
2009-08-11 18:26:09 +02:00
then
2009-09-21 22:26:23 +02:00
if [ "$SECOPT" != "--no-tentacle" ]
2009-08-11 18:26:09 +02:00
then
2009-09-21 22:26:23 +02:00
if [ "$DISTRO" == "UBUNTU" ]
then
# Tentacle server install (Ubuntu)
echo "Installing tentacle server in /etc/rc2.d/S80tentacle_serverd"
cp bin/tentacle_server /usr/local/bin
cp util/tentacle_serverd /etc/init.d/tentacle_serverd
ln -s /etc/init.d/tentacle_serverd /etc/rc2.d/S80tentacle_serverd
else
# Tentacle server install (SUSE)
echo "Installing tentacle server in /etc/rc.d/rc$INITLV.d/S80tentacle_serverd"
cp bin/tentacle_server /usr/local/bin
cp util/tentacle_serverd /etc/init.d/tentacle_serverd
ln -s /etc/init.d/tentacle_serverd /etc/rc.d/rc$INITLV.d/S80tentacle_serverd
fi
2009-08-11 18:26:09 +02:00
fi
fi
2009-10-13 21:06:17 +02:00
echo "Creating Pandora FMS distribution directory in /usr/share/pandora_server"
mkdir /usr/share/pandora_server 2> /dev/null
cp -R util /usr/share/pandora_server
2009-09-21 22:26:23 +02:00
2009-08-11 18:26:09 +02:00
if [ -d /etc/cron.daily ]
then
2009-11-06 20:48:48 +01:00
echo "Creating the Cron script to run daily Pandora DB tool"
2009-10-13 21:06:17 +02:00
echo "#!/bin/bash" > /etc/cron.daily/pandora_db
echo "perl /usr/share/pandora_server/util/pandora_db.pl /etc/pandora/pandora_server.conf" >> /etc/cron.daily/pandora_db
chmod +x /etc/cron.daily/pandora_db
2009-08-11 18:26:09 +02:00
else
echo "You're probably not using cron for automatic scheduling. You should schedule the following command to run frequently (daily) on your master server:"
2009-10-13 21:06:17 +02:00
echo " perl /usr/share/pandora_server/util/pandora_db.pl /etc/pandora/pandora_server.conf"
2009-08-11 18:26:09 +02:00
fi
2009-11-06 20:48:48 +01:00
echo
echo "Now you have to edit your /etc/pandora/pandora_server.conf file to change the database password (default is pandora) with the one set in include/config.php of your Pandora FMS Console."
echo "After setting password you can start your Pandora FMS Server!!"
2009-08-11 18:26:09 +02:00
rm output
2008-07-08 20:52:57 +02:00
fi
2008-04-07 00:11:16 +02:00
}
uninstall () {
2008-09-08 18:12:57 +02:00
if [ "`uname -s`" != "Linux" ]; then
echo "This is not a Linux-based distro. Uninstaller is currently not working for your OS"
2008-07-08 20:52:57 +02:00
fi
echo "Removing Pandora Servers"
2009-09-22 12:38:53 +02:00
rm -Rf /var/spool/pandora/data_in/
2008-07-08 20:52:57 +02:00
echo "If the user Pandora is not being used for any other operations, please delete using the following commands:"
echo " userdel pandora"
echo " rm -Rf /home/pandora/"
2009-08-11 18:26:09 +02:00
## Just to clarify here. Some people (like me) are using the pandora user
## for other purposes and/or using an LDAP-based user management
2008-07-08 20:52:57 +02:00
## I would hate to have a script clear out this users' information without any notification
2008-08-22 20:02:23 +02:00
rm -Rf /var/log/pandora/ 2> /dev/null
2008-09-08 18:12:57 +02:00
rm -Rf /etc/pandora/pandora_server.conf 2> /dev/null
rm -Rf /etc/init.d/pandora_server 2> /dev/null
2008-08-22 20:02:23 +02:00
rm -Rf /etc/rc2.d/S90pandora_server 2> /dev/null
2009-08-11 18:26:09 +02:00
rm -Rf /etc/rc.d/rc3.d/S90pandora_server 2> /dev/null
2008-08-22 20:02:23 +02:00
rm -Rf /usr/local/bin/pandora_server 2> /dev/null
rm -Rf /usr/bin/pandora_server 2> /dev/null
2009-10-13 21:06:17 +02:00
rm -Rf /usr/share/pandora_server
rm -Rf /etc/cron.daily/pandora_db
2008-04-07 00:11:16 +02:00
echo "Done"
}
help () {
echo " --install To install Pandora FMS Servers on this system (You have to be root)"
echo " --uninstall To uninstall and remove Pandora FMS Servers on this System"
2009-04-20 17:14:04 +02:00
echo " "
echo " Additional parameters (after --install) "
2008-04-07 00:11:16 +02:00
echo " "
2009-04-20 17:14:04 +02:00
echo " --no-tentacle Skip tentacle server installation (by default tentacle server installed)"
echo " "
2008-04-07 00:11:16 +02:00
}
# Script banner at start
echo " "
2009-04-20 17:14:04 +02:00
echo "Pandora FMS 3.0 Server Installer (c) 2008-2009 Artica ST"
echo "This program is licensed under GPL2 Terms. http://pandorafms.org"
2008-04-07 00:11:16 +02:00
echo " "
case "$MODE" in
'--install')
install
exit
;;
'--uninstall')
uninstall
exit
;;
*)
help
esac