pandorafms/pandora_agents/unix/pandora_agent_installer

312 lines
9.1 KiB
Bash
Executable File

#!/bin/sh
# **********************************************************************
# Pandora FMS Agent Installer for Unix (generic installer)
# (c) 2008-2009 Artica ST
# (c) 2008-2009 Sancho Lerena <slerena@gmail.com>
#
# This is a generic installer for all Unix-like systems.(AIX, HP-UX, SunOS, Linux)
# Please see http://www.pandorafms.org
# v3.0 Build 091215
# This code is licensed under GPL 2.0 license.
# **********************************************************************
PI_VERSION=3.0.0RC2
PI_BUILD=091119
OS_NAME=`uname -s`
PANDORA_HOME=/usr/share/pandora_agent
PANDORA_BIN=/usr/bin/pandora_agent
PANDORA_TEMP=/var/spool/pandora
PANDORA_CFG=/etc/pandora
PANDORA_LOG_DIR=/var/log/pandora
PANDORA_LOG=pandora_agent.log
TENTACLE=/usr/bin/tentacle_client
FORCE=0
USE_LINKS=0
LOG_TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"`
MODE=$1
if [ ! -z "$2" ]
then
PANDORA_HOME=$2
fi
# Check for Perl 5.8.x available
PERL_VERSION=`perl -v | egrep 'v5.8|v5.9|v5.1[0-9]' | grep perl`
if [ -z "$PERL_VERSION" ]
then
echo "Perl 5.8.x is not detected. This is required for Pandora FMS"
echo "Detected: $PERL_VERSION "
echo "Aborting install..."
exit 2
fi
UNIX_KIND=`uname -s`
if [ -z "`echo Linux HP-UX SunOS AIX Solaris Darwin BSD bsd | grep \"$UNIX_KIND\"`" ]
then
echo "This system: '$UNIX_KIND' is not supported by this script"
echo "Please make the install yourself as it's described in documentation"
exit 1
fi
# check for root to do the install
if [ -z "`id | grep \"uid=0(root)\"`" ]
then
echo "You need to be root to do the install. Please made a manual install"
echo "if you want to install Pandora FMS agent without root"
echo " "
echo "Aborting install"
exit 2
fi
if [ ! -f "pandora_agent" ]
then
echo " "
echo "Execute installer from the directory where you have your files. For example:"
echo " "
echo " cd /tmp/pandora_install "
echo " ./pandora_agent_installer --install"
echo " ./pandora_agent_installer --install-with-links /var/opt/PandoraFMS"
echo " "
exit 1
fi
uninstall () {
echo "Removing Pandora FMS Agent..."
rm -Rf $PANDORA_BIN
#Test if exist Pandora Server in this machine
if [ -d $PANDORA_TEMP/data_in ]
then
echo "You have a Pandora Server in this machine. Then don't delete "$PANDORA_TEMP
else
rm -Rf $PANDORA_TEMP
fi
rm -Rf $PANDORA_CFG/pandora_agent.conf
rm -Rf /etc/init.d/pandora_agent_daemon 2> /dev/null
rm -Rf /sbin/init.d/pandora_agent_daemon 2> /dev/null
rm -Rf /etc/rc.pandora_agent_daemon 2> /dev/null
rm -Rf /etc/rc?.d/S90pandora_agent_daemon 2> /dev/null
rm -Rf /sbin/rc?.d/S90pandora_agent_daemon 2> /dev/null
rm -Rf $PANDORA_HOME
rm -Rf $PANDORA_LOG_DIR
rm -Rf $TENTACLE
# Skip delete of /etc/pandora if exists configuration of a server
if [ ! -f /etc/pandora/pandora_server.conf ]
then
rm -Rf /etc/pandora
fi
echo "If you install Pandora FMS agent in a custom directory, you should"
echo " delete it yourself with command rm -Rf <yourdir>, for example:"
echo " "
echo " rm -Rf /opt/software/pandora"
echo " "
echo "Done"
}
install () {
OS_VERSION=`uname -r`
OS_NAME=`uname -s`
OLDFILENAMETMP=`date +"%Y-%m-%d"`
echo "Detecting Unix distribution: $OS_NAME version $OS_VERSION"
if [ -f $PANDORA_HOME ] && [ "$FORCE" = "0" ]
then
echo "Seems that default dir already exists. Please use --force to"
echo "force installer to install on $PANDORA_HOME"
exit
else
echo "Checking default dir $PANDORA_HOME..."
fi
if [ -f $PANDORA_BIN ] && [ "$FORCE" = "0" ]
then
echo "Seems that $PANDORA_BIN already exists. Please use --force to"
echo "force installer to reinstall overwriting it"
echo " "
exit
else
echo "Checking Pandora FMS Agent on $PANDORA_BIN...."
fi
echo "Creating Pandora FMS Agent home directory at $PANDORA_HOME ..."
mkdir -p $PANDORA_HOME 2> /dev/null
# IF USE_LINKS = 1 then append HOME to other paths
if [ "$USE_LINKS" = 1 ]
then
mkdir -p $PANDORA_HOME/$PANDORA_TEMP/data_out 2> /dev/null
mkdir -p $PANDORA_LOG_DIR 2> /dev/null
ln -s $PANDORA_HOME /etc/pandora
ln -s $PANDORA_HOME/$PANDORA_TEMP /var/spool/pandora
else
# Create directories on /
mkdir -p $PANDORA_TEMP/data_out 2> /dev/null
mkdir -p $PANDORA_CFG 2> /dev/null
mkdir -p $PANDORA_LOG_DIR 2> /dev/null
fi
# Create logfile
if [ ! -z "`touch $PANDORA_LOG_DIR/$PANDORA_LOG`" ]
then
echo "Seems to be a problem generating logfile ($PANDORA_LOG_DIR/$PANDORA_LOG) please check it";
else
echo "Created logfile at $PANDORA_LOG_DIR/$PANDORA_LOG..."
fi
echo "$LOG_TIMESTAMP Pandora FMS installer has created this file at startup" > $PANDORA_LOG_DIR/$PANDORA_LOG
# Copying agent and securing it
echo "Copying Pandora FMS Agent to $PANDORA_BIN..."
cp pandora_agent $PANDORA_BIN
chmod 755 $PANDORA_BIN
chown root:root $PANDORA_BIN
echo "Copying Pandora FMS Agent configuration file to $PANDORA_HOME/pandora_agent.conf..."
if [ -f /etc/pandora/pandora_agent.conf ]
then
cat /etc/pandora/pandora_agent.conf > /etc/pandora/pandora_agent.conf.$OLDFILENAMETMP
echo "Backing up old configuration file to /etc/pandora_agent.conf.$OLDFILENAMETMP"
fi
echo "Copying default agent configuration to $PANDORA_HOME/pandora_agent.conf"
cp $OS_NAME/pandora_agent.conf $PANDORA_HOME/pandora_agent.conf
chmod 600 $PANDORA_HOME/pandora_agent.conf
chown root $PANDORA_HOME/pandora_agent.conf
echo "Copying Pandora FMS Agent plugins to $PANDORA_HOME/plugins..."
cp -r plugins $PANDORA_HOME
chmod -R 700 $PANDORA_HOME/plugins
echo "Copying tentacle client to $TENTACLE"
cp tentacle_client $TENTACLE
chmod 755 $TENTACLE
if [ "$USE_LINKS" != 1 ]
then
echo "Linking Pandora FMS Agent plugins directory to $PANDORA_CFG/plugins..."
rm $PANDORA_CFG/plugins 2> /dev/null
ln -s $PANDORA_HOME/plugins $PANDORA_CFG/plugins 2> /dev/null
echo "Linking Pandora FMS Agent configuration to $PANDORA_CFG/pandora_agent.conf..."
rm $PANDORA_CFG/pandora_agent.conf 2> /dev/null
ln -s $PANDORA_HOME/pandora_agent.conf $PANDORA_CFG/pandora_agent.conf
fi
echo "Setting secure permissions and ownership for all Pandora FMS Agent files..."
chown -R root $PANDORA_HOME
chmod -R 600 $PANDORA_TEMP
chown root $PANDORA_TEMP
chmod 640 $PANDORA_LOG_DIR/$PANDORA_LOG
chown root:root $PANDORA_LOG_DIR/$PANDORA_LOG
echo "Linking start-up daemon script 'pandora_agent_daemon' on $OS_NAME";
if [ "$OS_NAME" = "AIX" ]
then
cp pandora_agent_daemon /etc/rc.pandora_agent_daemon
ln -s /etc/rc.pandora_agent_daemon /etc/rc.d/rc2.d/S90pandora_agent_daemon
echo "Pandora FMS agent has been included in /etc/rc.d/rc2.d/S90pandora_agent_daemon"
fi
if [ $OS_NAME = "HP-UX" ]
then
cp pandora_agent_daemon /sbin/init.d/pandora_agent_daemon
ln -s /sbin/init.d/pandora_agent_daemon /sbin/rc3.d/S90pandora_agent_daemon
ln -s /sbin/init.d/pandora_agent_daemon /sbin/rc2.d/S90pandora_agent_daemon
echo "Pandora FMS agent has been included in /sbin/rcX.d/S90pandora_agent_daemon"
fi
if [ $OS_NAME = "SunOS" ]
then
cp pandora_agent_daemon /etc/init.d/pandora_agent_daemon
ln -s /etc/init.d/pandora_agent_daemon /etc/rc2.d/S90pandora_agent_daemon
echo "Pandora FMS agent has been included in /etc/rc2.d/S90pandora_agent_daemon"
fi
if [ $OS_NAME = "Linux" ]
then
cp pandora_agent_daemon /etc/init.d/pandora_agent_daemon
if [ -d /etc/rc.d/ ]
then
ln -s /etc/init.d/pandora_agent_daemon /etc/rc.d/rc2.d/S90pandora_agent
ln -s /etc/init.d/pandora_agent_daemon /etc/rc.d/rc3.d/S90pandora_agent
else
ln -s /etc/init.d/pandora_agent_daemon /etc/rc2.d/S90pandora_agent
ln -s /etc/init.d/pandora_agent_daemon /etc/rc2.d/S90pandora_agent
fi
fi
echo "Done."
echo " "
echo "You have your startup script ready at $PANDORA_STARTUP"
echo " "
echo "Tentacle is the default transfer mode since 2.0 version."
echo "If you want to use SSH, firstly you need to copy your public SSH keys "
echo " ($HOME/.ssh/id_dsa) under /home/pandora/.ssh/authorized_keys "
echo "on your Pandora FMS Server host"
echo " "
echo "You also need to setup your $PANDORA_CFG/pandora_agent.conf config file"
echo " "
echo "Check your startup configuration to be sure Pandora FMS Agent is ready "
echo "to start automatically when system restarts":
}
help () {
echo " --force-install To force installation if already installed on system"
echo " (Not compatible with --install-with-links "
echo " --install To install Pandora FMS Agent on this system"
echo " --uninstall To uninstall/remove Pandora FMS Agent on this System"
echo " --install-with-links <base_dir> "
echo " To install Pandora FMS in a defined dir <base_dir>"
echo " and set all Pandora FMS directories as links to this"
echo " "
}
# Script banner at start
echo " "
echo "Pandora FMS Agent UNIX Installer $PI_VERSION $PI_BUILD (c) 2008-2009 ArticaST"
echo "This program is licensed under GPL2 Terms. http://pandorafms.com"
echo " "
case "$MODE" in
'--force-install')
FORCE=1
install
exit
;;
'--install')
install
exit
;;
'--install-with-links')
USE_LINKS=1
install
exit
;;
'--uninstall')
uninstall
exit
;;
*)
help
;;
esac