"Fossies" - the Fresh Open Source Software Archive

Member "pandora_server/pandora_server_installer" (15 Sep 2021, 19768 Bytes) of package /linux/misc/pandorafms_server-7.0NG.757.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "pandora_server_installer": 7.0NG.756_vs_7.0NG.757.

    1 #!/bin/sh
    2 
    3 # Pandora FMS Server Installer (c) 2008-2013 Artica ST
    4 # Linux/FreeBSD Version (generic), for SuSe, Debian/Ubuntu and FreeBSD only
    5 # other Linux distros could not work properly without modifications
    6 # Please see http://www.pandorafms.org
    7 # v5.0 Build 130207
    8 # This code is licensed under GPL 2.0 license.
    9 # **********************************************************************
   10 
   11 PI_VERSION="7.0NG.757"
   12 PI_BUILD="210915"
   13 
   14 MODE=$1
   15 if [ $# -gt 1 ]; then
   16     shift
   17 fi
   18 
   19 # Defaults
   20 PREFIX=/usr
   21 PANDORA_SPOOL=/var/spool/pandora
   22 PANDORA_HOME=$PREFIX/share/pandora_server
   23 PANDORA_CFG_DIR=/etc/pandora
   24 PANDORA_LOG=/var/log/pandora
   25 PANDORA_SERVER=/etc/init.d/pandora_server
   26 TENTACLE_SERVER=/etc/init.d/tentacle_serverd
   27 PANDORA_CFG_FILE=$PANDORA_CFG_DIR/pandora_server.conf
   28 PANDORA_CFG_FILE_DIST=conf/pandora_server.conf.new
   29 PANDORA_INIT_SCRIPT=util/pandora_server
   30 TENTACLE_CFG_DIR=/etc/tentacle
   31 TENTACLE_CFG_FILE=$TENTACLE_CFG_DIR/tentacle_server.conf
   32 TENTACLE_CFG_FILE_DIST=conf/tentacle_server.conf.new
   33 TENTACLE_INIT_SCRIPT=util/tentacle_serverd
   34 PERL=perl
   35 MANDIR=$PREFIX/share/man/man1
   36 INITDIR=/etc/init.d
   37 WITHOUT_TENTACLE=0
   38 
   39 #
   40 # set_global_vars
   41 #   Check platform and set DISTRO, OS_VERSION and LINUX.
   42 #   Also, define some platform sepcific variables (e.g. PANDORA_RC_VAR for (Free|Net)BSD) 
   43 #   and override some of defaults defined above if needed.
   44 #
   45 set_global_vars () {
   46     # Default
   47     LINUX=NO
   48     OS_VERSION=`uname -r`
   49     DISTRO=`uname -s`
   50 
   51     # set correct value for LINUX_DISTRO
   52     case $DISTRO in
   53     Linux)
   54         # Default for Linux
   55         LINUX=YES
   56         DISTRO="GENERIC"
   57         # Get Linux Distro type and version
   58         # We assume we are on Linux unless told otherwise
   59         if [ -f "/etc/SuSE-release" ]
   60         then
   61             OS_VERSION=`cat /etc/SuSE-release | grep VERSION | cut -f 3 -d " "`
   62             DISTRO=SUSE
   63         elif [ -f "/etc/lsb-release" ] && [ ! -f "/etc/redhat-release" ]
   64         then
   65             OS_VERSION=`cat /etc/lsb-release | grep DISTRIB_RELEASE | cut -f 2 -d "="`
   66             DISTRO=UBUNTU
   67             OS_VERSION="UBUNTU $OS_VERSION"
   68         elif [ -f "/etc/debian_version" ]
   69         then
   70             OS_VERSION=`cat /etc/debian_version`
   71             OS_VERSION="DEBIAN $OS_VERSION"
   72             DISTRO=DEBIAN
   73         elif [ -f "/etc/fedora-release" ]
   74         then
   75             OS_VERSION=`cat /etc/fedora-release | cut -f 4 -d " "`
   76             OS_VERSION="FEDORA $OS_VERSION"
   77             DISTRO=FEDORA
   78         fi
   79         ;;
   80     Darwin|AIX)
   81         # For future reference, Darwin doesn't have /etc/init.d but uses LaunchDaemons.
   82         # AIX doesn't have /etc/init.d
   83         ;;
   84     SunOS)
   85         # Some Solaris and other Unices don't have /etc/init.d, some have /usr/spool instead of /var/spool
   86         DISTRO="Solaris"
   87         ;;
   88     FreeBSD)
   89         PREFIX=/usr/local
   90         PANDORA_HOME=$PREFIX/share/pandora_server
   91         PANDORA_CFG_DIR=$PREFIX/etc/pandora
   92         PANDORA_SERVER=$PREFIX/etc/rc.d/pandora_server
   93         TENTACLE_SERVER=$PREFIX/etc/rc.d/tentacle_server
   94         PANDORA_CFG_FILE=$PANDORA_CFG_DIR/pandora_server.conf
   95         PANDORA_CFG_FILE_DIST=$DISTRO/pandora_server.conf.new
   96         PANDORA_INIT_SCRIPT=$DISTRO/pandora_server
   97         TENTACLE_CFG_DIR=$PREFIX/etc/tentacle
   98         TENTACLE_CFG_FILE=$TENTACLE_CFG_DIR/tentacle_server.conf
   99         TENTACLE_INIT_SCRIPT=$DISTRO/tentacle_server
  100         MANDIR=$PREFIX/man/man1
  101         INITDIR=$PREFIX/etc/rc.d
  102         PERL=/usr/local/bin/perl
  103         PANDORA_RC_VAR="pandora_server_enable"
  104         TENTACLE_RC_VAR="tentacle_server_enable"
  105         ;;
  106     NetBSD)
  107         PREFIX=/usr/local
  108         PANDORA_HOME=$PREFIX/share/pandora_server
  109         PANDORA_CFG_DIR=$PREFIX/etc/pandora
  110         PANDORA_SERVER=/etc/rc.d/pandora_server
  111         TENTACLE_CFG_DIR=$PREFIX/etc/tentacle
  112         TENTACLE_CFG_FILE=$TENTACLE_CFG_DIR/tentacle_server.conf
  113         TENTACLE_SERVER=/etc/rc.d/tentacle_server
  114         PANDORA_CFG_FILE=$PANDORA_CFG_DIR/pandora_server.conf
  115         PANDORA_CFG_FILE_DIST=$DISTRO/pandora_server.conf.new
  116         PANDORA_INIT_SCRIPT=$DISTRO/pandora_server
  117         TENTACLE_INIT_SCRIPT=$DISTRO/tentacle_server
  118         PERL=/usr/pkg/bin/perl
  119         INITDIR=/etc/rc.d
  120         PANDORA_RC_VAR="pandora_server"
  121         TENTACLE_RC_VAR="tentacle_server"
  122         ;;
  123     esac
  124 }
  125 
  126 #
  127 # install_startup_script [options...] SRC
  128 #   copy SRC into the $INITDIR and do additional required operation according to $DISTRO
  129 #   if $INITDIR is not set or empty, do nothing.
  130 #   If $DESTDIR is set, skip enabling service
  131 #   OPTIONS:
  132 #       -s SPRIO  specify startup priority for service
  133 #
  134 install_startup_script () {
  135     [ "$INITDIR" ] || return 1
  136     if [ "$1" = "-s" ]
  137     then
  138         SPRIO=$2
  139         shift;shift
  140     fi
  141     SRC=$1
  142     SCRIPT_NAME=`basename $SRC`
  143 
  144     echo "Copying the daemon script into $INITDIR"
  145     [ -d $DESTDIR$INITDIR ] || mkdir -p $DESTDIR$INITDIR
  146     cp $SRC $DESTDIR$INITDIR
  147 
  148     [ "$DESTDIR" ] && return
  149 
  150     case $DISTRO in
  151     UBUNTU|DEBIAN)
  152         echo "Linking startup script to /etc/rc2.d"
  153         update-rc.d $SCRIPT_NAME defaults
  154         ;;
  155     SUSE)
  156         echo "Creating startup daemons"
  157         insserv $SCRIPT_NAME
  158         ;;
  159     FeeBSD|NetBSD)
  160         chmod 555 $DESTDIR$INITDIR/$SCRIPT_NAME
  161         ;;
  162     *)
  163         if [ "$LINUX" = YES ]
  164         then
  165             # Pandora FMS Server install (Other Distros)
  166             INITLV=`grep '[0-9]:initdefault' /etc/inittab | cut -f 2 -d ':'`
  167             : ${INITLV:=2}
  168             echo "Linking startup script to /etc/rc.d/rc$INITLV.d/S$SPRIO$SCRIPT_NAME"
  169             ln -s $INITDIR/$SCRIPT_NAME /etc/rc.d/rc$INITLV.d/S$SPRIO$SCRIPT_NAME
  170         fi
  171         ;;
  172     esac
  173 }
  174 
  175 install () {
  176     set_global_vars
  177 
  178     FORCE=0
  179     BINARIES=0
  180 
  181     # parse options
  182     while :
  183     do
  184         case $1 in
  185         --force) FORCE=1;;
  186         --from-binary) BINARIES=1;;
  187         --no-tentacle) WITHOUT_TENTACLE=1;;
  188         --destdir) DESTDIR=$2;shift;;
  189         *) break;;
  190         esac
  191         shift
  192     done
  193     
  194     if [ "$LINUX" = YES ]
  195     then
  196         echo "$DISTRO distribution detected"
  197     else 
  198         echo "$DISTRO detected"
  199     fi
  200     
  201     if [ ! $BINARIES -eq 1 ]
  202     # Do not compile files if binary is distributed
  203     then
  204         $PERL Makefile.PL INSTALLMAN1DIR=none WITHOUT_TENTACLE=$WITHOUT_TENTACLE > output 2>&1
  205         #&& sleep 2 && cat output | grep "found" | wc -l 
  206         DEPENDENCIAS=`cat output | grep "found" | wc -l`
  207 
  208         if [ $DEPENDENCIAS -gt 0 ] && [ $FORCE -eq 0 ]
  209         then
  210             echo "You are missing the following dependencies"
  211             echo " "
  212             cat output | awk -F ": prerequisite" '{print $2}' | awk -F " " '{print $1}'
  213             echo "The complete installation guide is at: https://pandorafms.com/docs/"
  214             echo " "
  215             echo "Debian-based distribution do:"
  216             echo "  # apt-get install snmp snmpd libjson-perllibio-socket-inet6-perl libsocket6-perl libxml-simple-perl libxml-twig-perl libnetaddr-ip-perl libdbi-perl libnetaddr-ip-perl libhtml-parser-perl wmi-client xprobe2 snmp-mibs-downloader"
  217             echo " "
  218             echo "For CentOS / RHEL do: "
  219             echo " "
  220             echo "  # yum install perl-XML-Simple* perl-XML-Twig  perl-JSON perl-IO-Socket* perl-Socket6 perl-Time-modules* perl-NetAddr-IP* perl-DateTime* perl-ExtUtils perl-DBI nmap "
  221             echo " "
  222             echo "For OpenSUSE / SLES do : "
  223             echo " "
  224             echo "  # zypper install nmap perl-DBD-mysql perl-DBI perl-HTML-Parser perl-JSON
  225     perl-HTML-Encoding perl-HTML-Tree perl-NetAddr-IP perl-IO-Socket-INET6 perl-Socket6
  226     perl-TimeDate perl-XML-Simple perl-XML-Twig perl-libwww-perl mysql-client"
  227             echo " "
  228             echo "  You also will need to install (optionally) xprobe2 and wmiclient from rpm (download from our website)"
  229             echo " "
  230             echo "For FreeBSD do : "
  231             echo " "
  232             echo "  Install following tools from ports or packages."
  233             echo "  Recommended: p5-DBI p5-NetAddr-IP p5-XML-Simple p5-XML-Twig p5-HTML-Parser p5-DBD-mysql p5-Socket6 p5-IO-Socket-INET6 p5-JSON"
  234             echo "  Optional: nmap xprobe"
  235             echo " "
  236             echo "  And install Geo::IP manually."
  237             echo " "
  238             echo "To get them from source through CPAN do"
  239             echo " "
  240             echo "  $ cpan Time::Local DBI Socket6 XML::Simple XML::Twig IO::Socket Time::HiRes NetAddr::IP HTML::Entities IO::Socket::INET6 JSON Geo::IP"
  241             echo " "
  242             rm output
  243             exit 1
  244         fi
  245         rm output
  246             
  247         echo "Installing binaries and libraries"
  248         make
  249         make DESTDIR=$DESTDIR install
  250             
  251         echo "Checking binaries at /usr/local/bin -> /usr/bin"
  252         if [ ! -f "$DESTDIR/usr/bin/pandora_server" ] 
  253         then
  254             if [ ! -f "$DESTDIR/usr/local/bin/pandora_server" ]
  255             then
  256                 echo "ERROR compiling Pandora FMS Server from sources. Aborting"
  257                 exit 1
  258             fi
  259             if [ "$DISTRO" != "FreeBSD" ] && [ "$DISTRO" != "NetBSD" ]
  260             then
  261                 [ -d $DESTDIR$PREFIX/bin ] || mkdir -p $DESTDIR$PREFIX/bin
  262                 ln -s /usr/local/bin/pandora_server $DESTDIR$PREFIX/bin
  263                 ln -s /usr/local/bin/pandora_exec $DESTDIR$PREFIX/bin
  264                 ln -s /usr/local/bin/tentacle_server $DESTDIR$PREFIX/bin
  265                 ln -s /usr/local/bin/tentacle_client $DESTDIR$PREFIX/bin
  266             fi
  267         fi
  268     fi
  269 
  270     echo "Creating common Pandora FMS directories"
  271     id pandora 2> /dev/null
  272     if [ $? -eq 0 ]; then
  273         echo " "
  274         echo "User pandora does exist, make sure the SSH directories are correct"
  275     elif [ "$DESTDIR" ]
  276     then
  277         # chown can fail with fakeroot installation
  278         echo "User 'pandora' does not exist. All chown operations may fail."
  279         echo "You should manualy set proper ownership to $DESTDIR$PANDORA_SPOOL if needed."
  280         echo
  281     else
  282         echo "Are you sure we can create a standard 'pandora' user locally? [y/N]"
  283         read AREYOUSURE
  284         if [ "$AREYOUSURE" = "y" ]; then
  285             if [ "$DISTRO" = "FreeBSD" ]
  286             then
  287                 echo "pandora:41121:::::Pandora FMS:/home/pandora:/usr/sbin/nologin:" | adduser -f - -w no 2> /dev/null
  288             else
  289                 useradd pandora 
  290                 mkdir /home/pandora 2> /dev/null
  291                 mkdir /home/pandora/.ssh 2> /dev/null
  292                 chown -R pandora /home/pandora 
  293             fi
  294         else
  295             echo "Please create the 'pandora' user manually according to your authentication scheme, then start again the installation"
  296             echo "Aborting..."
  297             exit 1
  298         fi
  299     fi
  300 
  301     mkdir -p $DESTDIR$PANDORA_SPOOL/data_in 2> /dev/null
  302     chmod 2770 $DESTDIR$PANDORA_SPOOL/data_in
  303     mkdir $DESTDIR$PANDORA_SPOOL/data_in/conf 2> /dev/null
  304     chmod 2770 $DESTDIR$PANDORA_SPOOL/data_in/conf
  305     mkdir $DESTDIR$PANDORA_SPOOL/data_in/md5 2> /dev/null
  306     chmod 2770 $DESTDIR$PANDORA_SPOOL/data_in/md5
  307     mkdir $DESTDIR$PANDORA_SPOOL/data_in/collections 2> /dev/null
  308     chmod 2770 $DESTDIR$PANDORA_SPOOL/data_in/collections
  309     mkdir $DESTDIR$PANDORA_SPOOL/data_in/netflow 2> /dev/null
  310     chmod 2770 $DESTDIR$PANDORA_SPOOL/data_in/netflow
  311     mkdir $DESTDIR$PANDORA_SPOOL/data_in/trans 2> /dev/null
  312     chmod 2770 $DESTDIR$PANDORA_SPOOL/data_in/trans
  313     mkdir $DESTDIR$PANDORA_SPOOL/data_in/commands 2> /dev/null
  314     chmod 2770 $DESTDIR$PANDORA_SPOOL/data_in/commands
  315     mkdir -p $DESTDIR$PANDORA_LOG 2> /dev/null  
  316     chown -R pandora:apache $DESTDIR$PANDORA_LOG 2> /dev/null
  317     chmod 2774 $DESTDIR$PANDORA_LOG 2> /dev/null
  318 
  319     echo "Giving proper permission to /var/spool/pandora"
  320     for group in "www-data" wwwrun www apache
  321     do
  322         IDGROUP=`id -g "$group" 2> /dev/null`
  323         if [ $? -eq 0 ]
  324         then
  325             GROUPNAME=`grep ":$IDGROUP:" /etc/group | awk -F":" '{print $1}'`
  326             break
  327         fi
  328     done
  329     if [ -z "$GROUPNAME" ]
  330     then
  331         echo "No web server user found, some functionality might not perform correctly"
  332         GROUPNAME=0
  333     fi
  334     # when fakeroot installation, this can fail
  335     chown -R pandora:$GROUPNAME $DESTDIR$PANDORA_SPOOL 2>/dev/null
  336         
  337     echo "Creating setup directory in $PANDORA_CFG_DIR"
  338     mkdir -p $DESTDIR$PANDORA_CFG_DIR 2> /dev/null
  339     if [ -f "$DESTDIR$PANDORA_CFG_FILE" ]
  340     then
  341         echo cp $PANDORA_CFG_FILE_DIST $DESTDIR$PANDORA_CFG_DIR
  342         cp $PANDORA_CFG_FILE_DIST $DESTDIR$PANDORA_CFG_DIR
  343     else
  344         echo cp $PANDORA_CFG_FILE_DIST $DESTDIR$PANDORA_CFG_FILE
  345         cp $PANDORA_CFG_FILE_DIST $DESTDIR$PANDORA_CFG_FILE
  346         chmod 770 $DESTDIR$PANDORA_CFG_FILE
  347     fi
  348 
  349     echo "Installing Pandora Server manual"
  350     [ -d $DESTDIR$MANDIR ] || mkdir -p $DESTDIR$MANDIR
  351     cp man/man1/pandora_server.1.gz $DESTDIR$MANDIR
  352 
  353     install_startup_script -s 90 $PANDORA_INIT_SCRIPT
  354 
  355     if [ -d /etc/logrotate.d ]
  356     then
  357         if [ -f $DESTDIR/etc/logrotate.d/pandora_server ]
  358         then
  359             echo "A logrotate.d entry for Pandora FMS log management already exists, skipping creation"
  360         else
  361             echo "Creating logrotate.d entry for Pandora FMS log management"
  362             [ -d $DESTDIR/etc/logrotate.d ] || mkdir -p $DESTDIR/etc/logrotate.d
  363             cp util/pandora_server_logrotate $DESTDIR/etc/logrotate.d/pandora_server
  364         fi
  365     else
  366         echo "Please add a log rotation schedule manually to your log rotation daemon (if any)"
  367     fi
  368     
  369     if [ $WITHOUT_TENTACLE -eq 0 ]
  370     then
  371         # tentacle_server is already installed by "make install"
  372         install_startup_script -s 80 $TENTACLE_INIT_SCRIPT
  373 
  374         # Create the directory to locate the Tentacle configuration file
  375         echo "Creating setup Tentacle directory in $TENTACLE_CFG_DIR"
  376         mkdir -p $DESTDIR$TENTACLE_CFG_DIR 2> /dev/null
  377         if [ -f "$DESTDIR$TENTACLE_CFG_FILE" ]
  378         then
  379             echo cp $TENTACLE_CFG_FILE_DIST $DESTDIR$TENTACLE_CFG_DIR
  380             cp $TENTACLE_CFG_FILE_DIST $DESTDIR$TENTACLE_CFG_DIR
  381         else
  382             echo cp $TENTACLE_CFG_FILE_DIST $DESTDIR$TENTACLE_CFG_FILE
  383             cp $TENTACLE_CFG_FILE_DIST $DESTDIR$TENTACLE_CFG_FILE
  384             chmod 774 $DESTDIR$TENTACLE_CFG_FILE
  385         fi
  386         
  387         echo "Installing Tentacle Server manual"
  388         cp man/man1/tentacle_server.1.gz $DESTDIR$MANDIR
  389     fi
  390 
  391     echo "Creating Pandora FMS distribution directory in $PANDORA_HOME"
  392     mkdir -p $DESTDIR$PANDORA_HOME 2> /dev/null
  393     cp -R util $DESTDIR$PANDORA_HOME
  394     find $DESTDIR$PANDORA_HOME -type l -delete
  395     case $DISTRO in
  396     FreeBSD)
  397         # adjust shebang
  398         for pl_script in `find $DESTDIR$PANDORA_HOME/util -name "*.pl"`
  399         do
  400             cat $pl_script | sed 's/^#!\/usr\/bin\/perl/#!\/usr\/local\/bin\/perl/g' > ${pl_script}.new 
  401             mv ${pl_script}.new $pl_script
  402             chmod a+x $pl_script
  403         done
  404         for sh_script in `find $DESTDIR$PANDORA_HOME/util -name "*.sh"`
  405         do
  406             cat $sh_script | sed 's/^#!\/bin\/bash/#!\/usr\/local\/bin\/bash/g' > ${sh_script}.new
  407             mv ${sh_script}.new $sh_script
  408             chmod a+x $sh_script
  409         done
  410         # install pandora_ha
  411         INSTALL_DIR="$DESTDIR$PREFIX/bin/"
  412         echo ">Installing the pandora_ha binary to $INSTALL_DIR..."
  413         cp -f $DESTDIR$PANDORA_HOME/util/pandora_ha.pl "$INSTALL_DIR/pandora_ha"
  414         chmod +x "$INSTALL_DIR/pandora_ha"
  415         ;;
  416     *)
  417         SYSTEMD_DIR=$DESTDIR/etc/systemd/system
  418         PID_DIR=$DESTDIR/var/run
  419         INSTALL_DIR="$DESTDIR$PREFIX/bin/"
  420 
  421         echo ">Installing the pandora_ha binary to $INSTALL_DIR..."
  422         cp -f util/pandora_ha.pl "$INSTALL_DIR/pandora_ha"
  423         chmod +x "$INSTALL_DIR/pandora_ha"
  424     
  425         echo ">Installing pandora_ha service to $INSTALL_DIR..."
  426         [ -d "$PID_DIR" ] || mkdir -p "$PID_DIR"
  427         [ -d "$SYSTEMD_DIR" ] || mkdir -p "$SYSTEMD_DIR"
  428         cat > $SYSTEMD_DIR/pandora_ha.service <<-EOF
  429 [Unit]
  430 Description=Pandora FMS Daemon Watchdog
  431 
  432 [Service]
  433 Type=forking
  434 
  435 User=$USER
  436 PIDFile=$PID_DIR/pandora_ha.pid
  437 Restart=always
  438 ExecStart=${INSTALL_DIR}pandora_ha -d -p $PID_DIR/pandora_ha.pid $PANDORA_CONF
  439 
  440 [Install]
  441 WantedBy=multi-user.target
  442 EOF
  443         ;;
  444     esac
  445 
  446     # install cron job
  447     if [ -d /etc/cron.hourly ]
  448     then
  449         [ ! -d $DESTDIR/etc/cron.hourly ] && mkdir -p $DESTDIR/etc/cron.hourly
  450         echo "Creating the Cron script to run Pandora DB tool each hour"
  451         echo "#!/bin/bash" > $DESTDIR/etc/cron.hourly/pandora_db    
  452         echo "perl $PANDORA_HOME/util/pandora_db.pl /etc/pandora/pandora_server.conf" >> $DESTDIR/etc/cron.hourly/pandora_db    
  453         chmod +x $DESTDIR/etc/cron.hourly/pandora_db
  454     elif [ "$DISTRO" = "FreeBSD" ] || [ "$DISTRO" = "NetBSD" ]
  455     then
  456         if [ "$DESTDIR" ]
  457         then
  458             echo "Skip adding cron entry for pandora_db.pl when performing fakeroot installation."
  459         else
  460             grep pandora_db.pl /etc/crontab > /dev/null 2>&1
  461             if [ $? -ne 0 ]
  462             then
  463                 echo "# Pandora FMS" >> /etc/crontab
  464                 echo "2 *   *   *   *   root    perl $PANDORA_HOME/util/pandora_db.pl $PANDORA_CFG_FILE" >> /etc/crontab
  465             else
  466                 echo "The crontab for pandora_db.pl is already configured."
  467             fi
  468         fi
  469     else
  470         echo "You're probably not using cron for automatic scheduling. You should schedule the following command to run frequently (hourly) on your master server:"
  471         echo "  perl $PANDORA_HOME/util/pandora_db.pl $PANDORA_CFG_FILE"
  472     fi
  473     echo
  474     echo "Now you have to edit your $PANDORA_CFG_FILE file to change the database password (default is pandora) with the one set in include/config.php of your Pandora FMS Console."
  475     echo "After setting password you can start your Pandora FMS Server!!"
  476 
  477     if [ "$DISTRO" = "FreeBSD" ] || [ "$DISTRO" = "NetBSD" ]
  478     then
  479         echo " "
  480         echo "Define '$PANDORA_RC_VAR=\"YES\"' in /etc/rc.conf to enable pandora server daemon."
  481         [ "$WITHOUT_TENTACLE" = 0 ] && \
  482             echo "Define '$TENTACLE_RC_VAR=\"YES\"' in /etc/rc.conf to enable tentacle server daemon."
  483     fi
  484 }
  485 
  486 uninstall () {
  487     set_global_vars
  488 
  489     if [ "$LINUX" != "YES" ] && [ "$DISTRO" != "FreeBSD" ] && [ "$DISTRO" != "NetBSD" ]
  490     then
  491         echo "This is not a Linux-based distro. Uninstaller is currently not working for your OS"
  492         exit 1
  493     fi
  494 
  495     echo "Removing PERL libs and man files"
  496     
  497     PERL_SITELIB=/usr/lib/perl5
  498     if [ "$DISTRO" != "FreeBSD" ] || [ "$DISTRO" != "NetBSD" ]
  499     then
  500         PERL_SITELIB=$(eval $($PERL -V:sitelib);echo $sitelib);
  501     fi
  502     PERL_SITEMAN3DIR=`eval \`$PERL -V:siteman3dir\`;echo $siteman3dir`;
  503 
  504     [ -d $DESTDIR/$PERL_SITELIB/PandoraFMS ] && rm -rf $DESTDIR/$PERL_SITELIB/PandoraFMS
  505     rm -f $DESTDIR/$PERL_SITEMAN3DIR/PandoraFMS::* 2>/dev/null
  506 
  507 
  508     echo "Removing Pandora Servers"
  509     if [ -d $DESTDIR$PANDORA_SPOOL/data_out ]; then
  510         rm -Rf $DESTDIR$PANDORA_SPOOL/data_in
  511     else
  512         rm -Rf $DESTDIR$PANDORA_SPOOL
  513     fi
  514 
  515     echo "If the user Pandora is not being used for any other operations, please delete using the following commands:"
  516     if [ "$DISTRO" != "FreeBSD" ] || [ "$DISTRO" != "NetBSD" ]
  517     then
  518         echo "  rmuser pandora"
  519     else
  520         echo "  userdel pandora"
  521         echo "  rm -Rf /home/pandora/"
  522     fi
  523 
  524     ## Just to clarify here. Some people (like me) are using the pandora user 
  525     ## for other purposes and/or using an LDAP-based user management
  526     ## I would hate to have a script clear out this users' information without any notification
  527 
  528 
  529     rm -Rf $DESTDIR$PANDORA_LOG 2> /dev/null 
  530     rm -f  $DESTDIR$PANDORA_CFG_FILE 2> /dev/null
  531     rm -f  "$DESTDIR$PANDORA_CFG_FILE.new" 2> /dev/null
  532     rm -f  $DESTDIR$TENTACLE_CFG_FILE 2> /dev/null
  533     rm -f  "$DESTDIR$TENTACLE_CFG_FILE.new" 2> /dev/null
  534     rm -f  $DESTDIR$PANDORA_SERVER 2> /dev/null 
  535     rm -f  $DESTDIR$PREFIX/bin/pandora_server 2> /dev/null
  536     rm -f  $DESTDIR$PREFIX/bin/pandora_exec 2> /dev/null
  537     # Do not remove tentacle files if agent is still installed...
  538     [ -e $DESTDIR$PREFIX/bin/pandora_agent ] || rm -f  $DESTDIR$PREFIX/bin/tentacle_server 2> /dev/null
  539     [ -e $DESTDIR$PREFIX/bin/pandora_agent ] || rm -f  $DESTDIR$PREFIX/bin/tentacle_client 2> /dev/null
  540     rm -Rf $DESTDIR$PANDORA_HOME
  541     rm -f  $DESTDIR/etc/cron.hourly/pandora_db
  542     rm -f  $DESTDIR/etc/logrotate.d/pandora_server
  543     if [ "$DESTDIR" ]
  544     then
  545         # do nothing with "fakeroot" uninstallation
  546         :
  547     elif [ "$DISTRO" = "UBUNTU" ] || [ "$DISTRO" = "DEBIAN" ]
  548     then
  549         update-rc.d -f pandora_server remove
  550         update-rc.d -f tentacle_serverd remove
  551     elif  [ "$DISTRO" != "FreeBSD" ] || [ "$DISTRO" != "NetBSD" ]
  552     then
  553         TMP_CRONTAB=/tmp/crontab.tmp
  554         egrep -v "Pandora FMS|pandora_db.pl" /etc/crontab > $TMP_CRONTAB
  555         cp $TMP_CRONTAB /etc/crontab
  556         rm $TMP_CRONTAB
  557     fi
  558     rm -f $DESTDIR/etc/rc2.d/S90pandora_server 2> /dev/null 
  559     rm -f $DESTDIR/etc/rc.d/rc3.d/S90pandora_server 2> /dev/null 
  560     rm -f $DESTDIR/etc/rc2.d/S80tentacle_serverd 2> /dev/null 
  561     rm -f $DESTDIR/etc/rc.d/rc3.d/S80tentacle_serverd 2> /dev/null 
  562     rm -f $DESTDIR$MANDIR/pandora_server.1.gz 2>/dev/null
  563     rm -f $DESTDIR$MANDIR/tentacle_server.1.gz 2>/dev/null
  564     echo "Done"
  565 }
  566 
  567 help () {
  568     echo "  --install   To install Pandora FMS Servers on this system (You have to be root)"
  569     echo "  --uninstall To uninstall and remove Pandora FMS Servers on this System"
  570     echo " "
  571     echo " Additional second parameter (after --install) "
  572     echo " "
  573     echo "  --force         Ignore dependency problems and do the install"
  574     echo "  --no-tentacle   Skip tentacle server installation (by default tentacle server installed)"
  575     echo "  --destdir DIR   Specify root directory for \"fakeroot\" installation"
  576     echo "  --from-binary   No compile Pandora Server and not execute Makefiles"
  577     echo " "
  578 }
  579 
  580 # Script banner at start
  581 echo " "
  582 echo "Pandora FMS Server Installer $PI_VERSION $PI_BUILD (c) 2008-2016 Artica ST"
  583 echo "This program is licensed under GPL2 Terms. http://pandorafms.com"
  584 echo " "
  585 
  586 case "$MODE" in
  587 
  588 '--install')
  589     install "$@"
  590     exit 0
  591     ;;
  592 
  593 '--uninstall')
  594     uninstall "$@"
  595     exit 0
  596     ;;
  597 
  598 *)
  599     help
  600 esac
  601