"Fossies" - the Fresh Open Source Software Archive

Member "unix/pandora_agent_installer" (15 Sep 2021, 19793 Bytes) of package /linux/misc/pandorafms_agent_unix-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_agent_installer": 7.0NG.756_vs_7.0NG.757.

    1 #!/bin/sh
    2 
    3 # **********************************************************************
    4 # Pandora FMS Agent Installer for Unix (generic installer)
    5 # (c) 2008-2015 Artica ST
    6 # (c) 2008-2010 Sancho Lerena <slerena@gmail.com>
    7 # 
    8 # This is a generic installer for all Unix-like systems.(AIX, HP-UX, SunOS, Linux, FreeBSD, NetBSD)
    9 # Please see http://www.pandorafms.org. This code is licensed under GPL 2.0 license.
   10 # **********************************************************************
   11 
   12 PI_VERSION="7.0NG.757"
   13 PI_BUILD="210915"
   14 OS_NAME=`uname -s`
   15 
   16 FORCE=0
   17 LOG_TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"`
   18 
   19 PREFIX=/usr
   20 if [ "$OS_NAME" = "FreeBSD" ] || [ "$OS_NAME" = "NetBSD" ] || [ "$OS_NAME" = "Darwin" ]
   21 then
   22     PREFIX=/usr/local
   23 fi
   24 PANDORA_HOME=$PREFIX/share/pandora_agent
   25 PANDORA_BIN=$PREFIX/bin/pandora_agent
   26 PANDORA_EXEC_BIN=$PREFIX/bin/pandora_agent_exec
   27 PANDORA_REVENT_BIN=$PREFIX/bin/pandora_revent
   28 PANDORA_TEMP=/var/spool/pandora
   29 PANDORA_CFG=/etc/pandora
   30 PANDORA_LOG_DIR=/var/log/pandora
   31 PANDORA_LOG=pandora_agent.log
   32 TENTACLE=$PREFIX/bin/tentacle_client
   33 TENTACLE_SERVER=$PREFIX/bin/tentacle_server
   34 PANDORA_MAN=$PREFIX/share/man
   35 PANDORA_STARTUP=/etc/init.d/pandora_agent_daemon
   36 DAEMON_SCRIPT=pandora_agent_daemon
   37 PANDORA_USER="root"
   38 PANDORA_PERL_PATH="perl"
   39 WITHOUT_TENTACLE_SERVER=0
   40 FAKEROOT=0
   41 
   42 # defaults for each platforms
   43 case $OS_NAME in
   44 AIX)
   45     PANDORA_STARTUP=/etc/rc.pandora_agent_daemon
   46     ;;
   47 HP-UX)
   48     PANDORA_STARTUP=/sbin/init.d/pandora_agent_daemon
   49     ;;
   50 FreeBSD)
   51     PANDORA_CFG=$PREFIX/etc/pandora
   52     PANDORA_MAN=$PREFIX/man
   53     PANDORA_STARTUP=$PREFIX/etc/rc.d/pandora_agent
   54     DAEMON_SCRIPT=$OS_NAME/pandora_agent
   55     PANDORA_PERL_PATH=/usr/local/bin/perl
   56     ;;
   57 NetBSD)
   58     PANDORA_CFG=/usr/local/etc/pandora
   59     PANDORA_STARTUP=/etc/rc.d/pandora_agent
   60     DAEMON_SCRIPT=$OS_NAME/pandora_agent
   61     PANDORA_PERL_PATH=/usr/pkg/bin/perl
   62     ;;
   63 esac
   64 
   65 MODE=$1
   66 
   67 # options
   68 while :
   69 do
   70     case "$2" in 
   71     "--no-tentacle-server") WITHOUT_TENTACLE_SERVER=1;;
   72     "--fakeroot") FAKEROOT=1;;
   73     *) break;;
   74     esac
   75     shift
   76 done
   77 
   78 PANDORA_BASE=`echo $2 | sed -e 's|/$||'`
   79 if [ "$3" != "" ]
   80 then
   81     PANDORA_USER=$3
   82     if [ -z "$PANDORA_BASE" ]
   83     then
   84         echo "When specifying a custom user the agent must be installed to a custom location where that user has write permissions!"
   85         exit 1
   86     fi
   87 fi
   88 
   89 [ "$4" ] && PANDORA_PERL_PATH=$4
   90 
   91 # Check for Perl 5.6.x or higher available
   92 PERL_VERSION=`$PANDORA_PERL_PATH -v | egrep 'v5.[6-9]|v5.[1-3][0-9]' | grep perl`
   93 
   94 if [ -z "$PERL_VERSION" ]
   95 then
   96     echo "Perl 5.6.x or higher is not detected. This is required for Pandora FMS"
   97     echo "Detected: $PERL_VERSION "
   98     echo "Aborting install..."
   99     exit 2
  100 fi
  101 
  102 if [ -z "`echo Linux HP-UX SunOS AIX Solaris Darwin BSD bsd FreeBSD NetBSD | grep \"$OS_NAME\"`" ]
  103 then
  104     echo "This system: '$OS_NAME' is not supported by this script"
  105     echo "Please make the install yourself as it's described in documentation"
  106     exit 1
  107 fi
  108 
  109 
  110 # check for root to do the install
  111 if [ $FAKEROOT -ne 1 ] && [ -z "`id | grep \"uid=0(root)\"`" ]
  112 then
  113     echo "You need to be root to do the install. Please made a manual install"
  114     echo "if you want to install Pandora FMS agent without root"
  115     echo " "
  116     echo "Aborting install"
  117     exit 2
  118 fi
  119 
  120 help () {
  121     echo "Syntax":
  122     echo " "
  123     echo "    ./pandora_agent_installer < --mode > [ --option ] [ destination_path ] [ user_to_run_as ] [custom_perl_path]"
  124     echo " "
  125     echo "Modes:"
  126     echo " "
  127     echo "  --force-install      To force installation if already installed on system"
  128     echo "  --install            To install Pandora FMS Agent on this system"
  129     echo "  --uninstall          To uninstall/remove Pandora FMS Agent on this System"
  130     echo " "    
  131     echo "Option:"
  132     echo " "
  133     echo "  --no-tentacle-server  Skip tentacle server installation (by default tentalce server installed)"
  134     echo "  --fakeroot            treate \"destination_path\" as root directory"
  135     echo " "
  136     echo "Some exaples of how to use the installer:"
  137     echo " "
  138     echo "   ./pandora_agent_installer --install"
  139     echo "   ./pandora_agent_installer --install /opt/pandora"
  140     echo "   ./pandora_agent_installer --install \"\" pandora"
  141     echo "   ./pandora_agent_installer --install /opt/pandora root /opt/pandora/perl5/usr/local/bin/perl"
  142     echo "   ./pandora_agent_installer --uninstall /opt/pandora"
  143     echo " "
  144 }
  145 
  146 uninstall () {
  147     if [ "$OS_NAME" = "Darwin" ]
  148         then
  149         launchctl stop com.pandorafms.pandorafms
  150         launchctl remove com.pandorafms.pandorafms 
  151         rm /Library/LaunchDaemons/com.pandorafms.pandorafms.plist 2> /dev/null
  152     fi
  153 
  154     # Stops the agent on uninstall
  155     if [ -f /etc/init.d/pandora_agent_daemon ]; then
  156         /etc/init.d/pandora_agent_daemon stop 12> /dev/null
  157     else
  158         echo "$PANDORA_BASE/etc/init.d/pandora_agent_daemon not found to stop agent"
  159     fi
  160 
  161     echo "Removing Pandora FMS Agent..."
  162     rm -Rf $PANDORA_BASE$PANDORA_BIN 2> /dev/null
  163     rm -Rf $PANDORA_BASE$PANDORA_EXEC_BIN 2> /dev/null
  164     rm -Rf $PANDORA_BASE$PANDORA_REVENT_BIN 2> /dev/null
  165     rm -f  $DESTDIR/etc/logrotate.d/pandora_agent
  166     rm -f  $DESTDIR/etc/newsyslog.d/pandora_agent.conf
  167 
  168     # Remove systemd service if exists
  169     if [ `command -v systemctl` ]
  170     then
  171         PANDORA_AGENT_SERVICE="/etc/systemd/system/pandora_agent_daemon.service"
  172         rm -f $PANDORA_AGENT_SERVICE
  173         systemctl reset-failed
  174     fi
  175 
  176     #Test if exist Pandora Server in this machine
  177     if [ -d $PANDORA_BASE$PANDORA_TEMP/data_in ]
  178     then
  179         echo "You have a Pandora Server in this machine. Then don't delete "$PANDORA_TEMP
  180         rm -Rf $PANDORA_BASE$PANDORA_TEMP/data_out 2> /dev/null
  181     else
  182         rm -Rf $PANDORA_BASE$PANDORA_TEMP 2> /dev/null
  183         rm -Rf $PANDORA_BASE$TENTACLE_SERVER 2> /dev/null
  184     fi 
  185     rm -Rf $PANDORA_BASE$PANDORA_CFG/pandora_agent.conf 2> /dev/null
  186     
  187     rm -Rf $PANDORA_BASE/etc/init.d/pandora_agent_daemon 2> /dev/null
  188     rm -Rf $PANDORA_BASE/sbin/init.d/pandora_agent_daemon 2> /dev/null
  189     rm -Rf $PANDORA_BASE/etc/rc.pandora_agent_daemon 2> /dev/null
  190     rm -Rf $PANDORA_BASE/etc/rc?.d/S90pandora_agent_daemon 2> /dev/null
  191     rm -Rf $PANDORA_BASE/sbin/rc?.d/S90pandora_agent_daemon 2> /dev/null
  192     rm -Rf $PANDORA_BASE/etc/rc?.d/S90pandora_agent 2> /dev/null
  193     rm -Rf $PANDORA_BASE/sbin/rc?.d/S90pandora_agent 2> /dev/null
  194     rm -Rf $PANDORA_BASE/etc/rc.d/rc?.d/S90pandora_agent_daemon 2> /dev/null
  195     rm -Rf $PANDORA_BASE/etc/rc.d/rc?.d/S90pandora_agent 2> /dev/null
  196     rm -Rf $PANDORA_BASE/usr/local/etc/rc.d/pandora_agent 2> /dev/null
  197     if [ $FAKEROOT -ne 1 ]
  198     then
  199         rm -Rf /etc/init.d/pandora_agent_daemon 2> /dev/null
  200         rm -Rf /sbin/init.d/pandora_agent_daemon 2> /dev/null
  201         rm -Rf /etc/rc.pandora_agent_daemon 2> /dev/null
  202         rm -Rf /etc/rc?.d/S90pandora_agent_daemon 2> /dev/null
  203         rm -Rf /sbin/rc?.d/S90pandora_agent_daemon 2> /dev/null
  204         rm -Rf /etc/rc?.d/S90pandora_agent 2> /dev/null
  205         rm -Rf /sbin/rc?.d/S90pandora_agent 2> /dev/null
  206         rm -Rf /etc/rc.d/rc?.d/S90pandora_agent_daemon 2> /dev/null
  207         rm -Rf /etc/rc.d/rc?.d/S90pandora_agent 2> /dev/null
  208         rm -Rf /usr/local/etc/rc.d/pandora_agent 2> /dev/null
  209     fi
  210     
  211     rm -Rf $PANDORA_BASE$PANDORA_HOME 2> /dev/null
  212     rm -Rf $PANDORA_BASE$PANDORA_LOG_DIR/$PANDORA_LOG 2> /dev/null
  213     rm -Rf $PANDORA_BASE$TENTACLE 2> /dev/null
  214 
  215     rm -Rf $PANDORA_BASE$PANDORA_MAN/{man1,cat1}/tentacle_client.1.gz 2> /dev/null
  216     rm -Rf $PANDORA_BASE$PANDORA_MAN/{man1,cat1}/pandora_agent.1.gz 2> /dev/null
  217 
  218     # Skip delete of /etc/pandora if exists configuration of a server or satellite
  219     if [ ! -f $PANDORA_BASE/$PANDORA_CFG/pandora_server.conf -a ! -f $PANDORA_BASE/$PANDORA_CFG/satellite_server.conf ]
  220     then
  221         rm -Rf $PANDORA_BASE/$PANDORA_CFG 2> /dev/null
  222     fi
  223 
  224     if [ ! -z "$PANDORA_BASE" ]
  225     then
  226         echo "Please delete manually $PANDORA_BASE for complete uninstall"
  227     fi
  228 
  229     echo " "
  230     echo "Done"
  231 }
  232 
  233 #
  234 # install_perl_script [OPTIONS] SRCFILE DESTFILE
  235 #   Install perl script. If PANDORA_PERL_DECODED_PATH is set, path of the perl
  236 #   in shebang line is replaced with PANDORA_PERL_DECODED_PATH value.
  237 #   OPTIONS:
  238 #       -o OWNER  owner of the installed script
  239 #       -g GROUP  group of the installed script
  240 #       -m PREM   mode of the installed script
  241 #
  242 install_perl_script () {
  243     OWNER=""; GROUP=""; PERM=""
  244     while :
  245     do
  246         case $1 in
  247         -o) OWNER=$2;;
  248         -g) GROUP=$2;;
  249         -m) PERM=$2;;
  250         *)  break;;
  251         esac
  252         shift;shift
  253     done
  254     SRC="$1"
  255     DEST="$2"
  256 
  257     # do install
  258     if echo $PANDORA_PERL_PATH | grep "/" > /dev/null && [ "$PANDORA_PERL_PATH" != "/usr/bin/perl" ]
  259     then
  260         sed -e "s:^#\!.*:#\!$PANDORA_PERL_PATH:g" $SRC > $DEST
  261     else
  262         cp $SRC $DEST
  263     fi
  264 
  265     # set owner, group and permissions
  266     [ "$OWNER" ] && chown $OWNER $DEST 2>/dev/null
  267     [ "$GROUP" ] && chgrp $GROUP $DEST 2>/dev/null
  268     [ "$PERM"  ] && chmod $PERM  $DEST
  269 }
  270 
  271 install () {
  272     OS_VERSION=`uname -r`
  273     OLDFILENAMETMP=`date +"%Y-%m-%d"`
  274 
  275     echo "Detecting Unix distribution: $OS_NAME version $OS_VERSION"
  276     if [ -f $PANDORA_BASE$PANDORA_HOME ] && [ "$FORCE" = "0" ]
  277     then
  278         echo "Seems that default dir already exists. Please use --force-install to"
  279         echo "force installer to install on $PANDORA_BASE$PANDORA_HOME"
  280         exit
  281     else
  282         echo "Checking default dir $PANDORA_BASE$PANDORA_HOME..."
  283     fi
  284 
  285     if [ -f $PANDORA_BASE$PANDORA_BIN ] && [ "$FORCE" = "0" ]
  286     then
  287         echo "Seems that $PANDORA_BASE$PANDORA_BIN already exists. Please use --force-install to"
  288         echo "force installer to reinstall overwriting it"
  289         echo " "
  290         exit
  291     else
  292         echo "Checking Pandora FMS Agent on $PANDORA_BASE$PANDORA_BIN...."
  293     fi
  294 
  295     # Alter dynamically the daemon launcher and setup the new path 
  296     # if PANDORA_BASE is customized.
  297     if [ "$PANDORA_BASE" ] && [ $FAKEROOT -ne 1 ]
  298     then
  299         DAEMON_TEMP=pandora_agent_daemon_temp
  300 
  301         # Backup the daemon script
  302         cp -f "$DAEMON_SCRIPT" "${DAEMON_SCRIPT}.bak"
  303         
  304         AGENT_CFG=$OS_NAME/pandora_agent.conf
  305         AGENT_CFG_TEMP=$OS_NAME/pandora_agent.conf.temp
  306 
  307         # Backup the configuration file
  308         cp -f "$AGENT_CFG" "${AGENT_CFG}.bak"
  309 
  310         if [ "$OS_NAME" = "FreeBSD" ] || [ "$OS_NAME" = "NetBSD" ] || [ "$OS_NAME" = "Darwin" ]
  311         then
  312             sed -e "\|^PATH=|s|=|=$PANDORA_BASE$PREFIX/bin:|" \
  313                 -e "s|/usr/local/etc/pandora|$PANDORA_BASE$PANDORA_CFG|g" \
  314                 -e "s|/usr/local/bin/pandora_agent|$PANDORA_BASE$PANDORA_BIN|g" \
  315                 $DAEMON_SCRIPT > $DAEMON_TEMP
  316             mv $DAEMON_TEMP $DAEMON_SCRIPT
  317         else
  318             sed -e "\|^PATH=|s|=|=$PANDORA_BASE/usr/bin:|" \
  319                 -e "\|^PANDORA_PATH=|s|=|=$PANDORA_BASE|" \
  320                 -e "\|^LOGFILE=|s|=|=$PANDORA_BASE|" \
  321                 -e "\|^DAEMON=|s|=|=$PANDORA_BASE|" \
  322                 -e "\|^DAEMON_TENTACLE=|s|=|=$PANDORA_BASE|" \
  323                 -e "s/^PANDORA_USER=.*/PANDORA_USER=$PANDORA_USER/"  \
  324                 $DAEMON_SCRIPT > $DAEMON_TEMP
  325             mv  $DAEMON_TEMP $DAEMON_SCRIPT
  326         fi
  327 
  328         sed -e "s|^temporal[ \t][ \t]*|temporal $PANDORA_BASE|" \
  329             -e "s|^logfile[ \t][ \t]*|logfile $PANDORA_BASE|" \
  330             $AGENT_CFG > $AGENT_CFG_TEMP
  331         mv $AGENT_CFG_TEMP $AGENT_CFG
  332     fi
  333     echo "Creating Pandora FMS Agent home directory at $PANDORA_BASE$PANDORA_HOME"
  334     if [ "$PANDORA_BASE" ]
  335     then
  336         mkdir -p $PANDORA_BASE 2> /dev/null
  337         mkdir -p $PANDORA_BASE/var/log 2> /dev/null
  338         mkdir -p $PANDORA_BASE/$PANDORA_MAN/man1 2> /dev/null
  339         mkdir -p $PANDORA_BASE$PREFIX/bin 2> /dev/null
  340     fi
  341 
  342     mkdir -p $PANDORA_BASE$PANDORA_HOME 2> /dev/null
  343 
  344     # Create directories based on PANDORA_BASE 
  345 
  346     mkdir -p $PANDORA_BASE/tmp 2> /dev/null
  347     mkdir -p $PANDORA_BASE$PANDORA_TEMP/data_out 2> /dev/null
  348     mkdir -p $PANDORA_BASE$PANDORA_CFG 2> /dev/null
  349     mkdir -p $PANDORA_BASE$PANDORA_LOG_DIR 2> /dev/null
  350     
  351     # Set the user the agent will run as
  352     if [ "$PANDORA_USER" != "root" ]
  353     then
  354         sed -e "s/.*pandora_user .*/pandora_user $PANDORA_USER/" $AGENT_CFG > $AGENT_CFG_TEMP 2> /dev/null && \
  355             mv $AGENT_CFG_TEMP $AGENT_CFG
  356         chmod 755 pandora_agent_daemon
  357         chown -R $PANDORA_USER $PANDORA_BASE 2>/dev/null
  358     fi
  359 
  360     # Create logfile
  361     if [ ! -z "`touch $PANDORA_BASE$PANDORA_LOG_DIR/$PANDORA_LOG`" ]
  362     then
  363         echo "Seems to be a problem generating logfile ($PANDORA_BASE$PANDORA_LOG_DIR/$PANDORA_LOG) please check it";
  364     else
  365         echo "Created logfile at $PANDORA_BASE$PANDORA_LOG_DIR/$PANDORA_LOG..."
  366     fi
  367     echo "$LOG_TIMESTAMP Pandora FMS installer has created this file at startup" > $PANDORA_BASE$PANDORA_LOG_DIR/$PANDORA_LOG
  368 
  369     # Copying agent and securing it
  370     echo "Copying Pandora FMS Agent to $PANDORA_BASE$PANDORA_BIN..."
  371     install_perl_script -m 755 -o $PANDORA_USER -g 0 pandora_agent $PANDORA_BASE$PANDORA_BIN
  372     install_perl_script -m 755 -o $PANDORA_USER -g 0 pandora_agent_exec $PANDORA_BASE$PANDORA_EXEC_BIN
  373     install_perl_script -m 755 -o $PANDORA_USER -g 0 pandora_revent $PANDORA_BASE$PANDORA_REVENT_BIN
  374 
  375     echo "Copying Pandora FMS Agent configuration file to $PANDORA_BASE$PANDORA_CFG/pandora_agent.conf..."
  376     if [ -f $PANDORA_BASE/$PANDORA_CFG/pandora_agent.conf ]
  377     then
  378         cp $PANDORA_BASE/$PANDORA_CFG/pandora_agent.conf $PANDORA_BASE/$PANDORA_CFG/pandora_agent.conf.$OLDFILENAMETMP
  379         echo "Backing up old configuration file to $PANDORA_BASE/$PANDORA_CFG/pandora_agent.conf.$OLDFILENAMETMP"
  380     fi
  381 
  382     echo "Copying Pandora FMS Agent plugins to $PANDORA_BASE$PANDORA_HOME/plugins..."
  383 
  384     [ -d $PANDORA_BASE$PANDORA_HOME/plugins ] || mkdir -p $PANDORA_BASE$PANDORA_HOME/plugins >/dev/null 2>&1
  385     for PLUGIN in plugins/*
  386     do
  387         if grep '^#!.*/perl' $PLUGIN >/dev/null 2>&1
  388         then
  389             install_perl_script $PLUGIN $PANDORA_BASE$PANDORA_HOME/$PLUGIN
  390         else
  391             cp $PLUGIN $PANDORA_BASE$PANDORA_HOME/plugins
  392         fi
  393     done
  394     chmod -R 700 $PANDORA_BASE$PANDORA_HOME/plugins
  395 
  396     PANDORA_BASE_REAL="$PANDORA_BASE"
  397     [ $FAKEROOT -eq 1 ] && PANDORA_BASE_REAL=""
  398 
  399     ln -s $PANDORA_BASE_REAL$PANDORA_HOME/plugins $PANDORA_BASE$PANDORA_CFG
  400 
  401     echo "Creating the collections directory in to $PANDORA_BASE$PANDORA_HOME/collections..."
  402     mkdir -p $PANDORA_BASE$PANDORA_HOME/collections
  403     chmod -R 700 $PANDORA_BASE$PANDORA_HOME/collections
  404     ln -s $PANDORA_BASE_REAL$PANDORA_HOME/collections $PANDORA_BASE$PANDORA_CFG
  405 
  406     echo "Creating the commands directory in $PANDORA_BASE$PANDORA_HOME/commands..."
  407     mkdir -p $PANDORA_BASE$PANDORA_HOME/commands
  408     chmod -R 700 $PANDORA_BASE$PANDORA_HOME/commands
  409     ln -s $PANDORA_BASE_REAL$PANDORA_HOME/commands $PANDORA_BASE$PANDORA_CFG
  410     
  411     if [ $WITHOUT_TENTACLE_SERVER -eq 0 ]
  412     then
  413         echo "Copying tentacle server to $PANDORA_BASE$TENTACLE_SERVER"
  414         install_perl_script -m 755 -o $PANDORA_USER -g 0 tentacle_server $PANDORA_BASE$TENTACLE_SERVER
  415     fi
  416     
  417     echo "Copying tentacle client to $PANDORA_BASE$TENTACLE"
  418     install_perl_script -m 755 -o $PANDORA_USER -g 0 tentacle_client $PANDORA_BASE$TENTACLE 
  419 
  420     echo "Installing the Pandora Agent and Tentacle Client manuals"
  421     cp man/man1/tentacle_client.1.gz $PANDORA_BASE/$PANDORA_MAN/man1
  422     chmod 644 $PANDORA_BASE/$PANDORA_MAN/man1/tentacle_client.1.gz
  423     cp man/man1/pandora_agent.1.gz $PANDORA_BASE/$PANDORA_MAN/man1
  424     chmod 644 $PANDORA_BASE/$PANDORA_MAN/man1/pandora_agent.1.gz
  425 
  426     echo "Setting secure permissions and ownership for all Pandora FMS Agent files..."
  427     chown -R $PANDORA_USER $PANDORA_BASE$PANDORA_HOME  2>/dev/null
  428     chmod -R 700 $PANDORA_BASE$PANDORA_TEMP/data_out
  429     chmod 711 $PANDORA_BASE$PANDORA_LOG_DIR
  430     chmod 640 $PANDORA_BASE$PANDORA_LOG_DIR/$PANDORA_LOG
  431     chown $PANDORA_USER:0 $PANDORA_BASE$PANDORA_LOG_DIR/$PANDORA_LOG  2>/dev/null
  432     if [ "$OS_NAME" = "FreeBSD" ] || [ "$OS_NAME" = "NetBSD" ]
  433     then
  434         chown $PANDORA_USER:daemon $PANDORA_BASE$PANDORA_TEMP 2>/dev/null
  435         chmod -R 770 $PANDORA_BASE$PANDORA_TEMP
  436         chmod 775 $PANDORA_BASE$PANDORA_TEMP
  437     fi
  438 
  439     echo "Copying default agent configuration to $PANDORA_BASE$PANDORA_CFG/pandora_agent.conf"
  440 
  441     cp $OS_NAME/pandora_agent.conf $PANDORA_BASE$PANDORA_CFG/pandora_agent.conf
  442     chmod 600 $PANDORA_BASE$PANDORA_CFG/pandora_agent.conf
  443     chown $PANDORA_USER $PANDORA_BASE$PANDORA_CFG/pandora_agent.conf 2>/dev/null
  444 
  445     echo "Linking start-up daemon script '$DAEMON_SCRIPT' on $OS_NAME";
  446 
  447     if [ "$OS_NAME" = "Darwin" ]
  448     then
  449         # Specific service install on Darwin/macOSX
  450         launchctl load -F Darwin/com.pandorafms.pandorafms.plist
  451         echo "Start Pandora FMS service with 'launchctl start com.pandorafms.pandorafms'"
  452         echo "This service has been scheduled to launch on each system startup"
  453     else
  454         DESTDIR=""
  455         [ "$PANDORA_BASE" ] && [ $FAKEROOT -eq 1 ] && DESTDIR=$PANDORA_BASE
  456 
  457         cp $DAEMON_SCRIPT $DESTDIR$PANDORA_STARTUP
  458         chmod 755 $DESTDIR$PANDORA_STARTUP
  459         chown root:0 $DESTDIR$PANDORA_STARTUP 2>/dev/null
  460 
  461         RCDIRS=""
  462         MSG=""
  463         if [ "$OS_NAME" = "AIX" ]
  464         then
  465             RCDIRS=/etc/rc.d/rc2.d
  466             MSG="Pandora FMS agent has been included in $DESTDIR/etc/rc.d/rc2.d/S90pandora_agent_daemon"
  467         elif [ "$OS_NAME" = "HP-UX" ]
  468         then
  469             RCDIRS="/sbin/rc2.d /sbin/rc3.d"
  470             MSG="Pandora FMS agent has been included in $DESTDIR/sbin/rcX.d/S90pandora_agent_daemon"
  471         elif [ "$OS_NAME" = "SunOS" ]
  472         then
  473             RCDIRS=/etc/rc2.d
  474             MSG="Pandora FMS agent has been included in $DESTDIR/etc/rc2.d/S90pandora_agent_daemon"
  475         elif [ "$OS_NAME" = "Linux" ]
  476         then
  477             if [ -d /etc/rc.d/ ]
  478             then
  479                 RCDIRS="/etc/rc.d/rc2.d /etc/rc.d/rc3.d"
  480             else
  481                 RCDIRS="/etc/rc2.d /etc/rc3.d"
  482             fi
  483 
  484             # Create systemd service
  485             if [ `command -v systemctl` ]
  486             then
  487                 echo "Creating systemd service for pandora_agent_daemon"
  488 
  489                 PANDORA_AGENT_SERVICE="/etc/systemd/system/pandora_agent_daemon.service"
  490                 EXEC_START='ExecStart='$PANDORA_BASE$PANDORA_BIN' '$PANDORA_BASE$PANDORA_CFG
  491 
  492                 rm -f $PANDORA_AGENT_SERVICE
  493                 cp pandora_agent_daemon.service $PANDORA_AGENT_SERVICE
  494 
  495                 sed -i "s|^ExecStart=.*$|$EXEC_START|g" $PANDORA_AGENT_SERVICE
  496 
  497                 systemctl daemon-reload
  498             fi
  499         fi
  500         [ "$RCDIRS" ] && for RCDIR in $RCDIRS
  501         do
  502             [ $FAKEROOT -eq 1 ] && [ ! -d $DESTDIR$RCDIR ] && mkdir -p $DESTDIR$RCDIR >/dev/null 2>&1
  503             ln -s $PANDORA_STARTUP $DESTDIR$RCDIR/S90pandora_agent 2> /dev/null
  504         done
  505         [ "$MSG" ] && echo "$MSG"
  506     fi
  507     
  508     if [ -d /etc/logrotate.d ] && [ "$OS_NAME" != "Darwin" ]
  509     then
  510         [ -d $DESTDIR/etc/logrotate.d ] && mkdir -p $DESTDIR/etc/logrotate.d
  511         echo "Creating logrotate.d entry for Pandora FMS log management"
  512         sed -e "s|^/var/log/pandora/pandora_agent.log|$PANDORA_BASE_REAL$PANDORA_LOG_DIR/$PANDORA_LOG|" pandora_agent_logrotate \
  513             > $DESTDIR/etc/logrotate.d/pandora_agent
  514     elif [ "$OS_NAME" = "Darwin" ]
  515     then
  516         echo "Creating newsyslog entry for Pandora FMS log management"
  517         echo "/var/log/pandora/pandora_agent.log        :        640        5        2048        *        Z" > $DESTDIR/etc/newsyslog.d/pandora_agent.conf
  518     else
  519         echo "Please add a log rotation schedule manually to your log rotation daemon (if any)"
  520     fi
  521 
  522     echo "Done."
  523     echo " "
  524     echo "You have your startup script ready at $PANDORA_STARTUP"
  525     echo " "
  526     echo "Tentacle is the default transfer mode since 2.0 version."
  527     echo " "
  528     echo "If you want to use SSH, firstly you need to copy your public SSH keys "
  529     echo " ($HOME/.ssh/id_dsa) under /home/pandora/.ssh/authorized_keys "
  530     echo "on your Pandora FMS Server host"
  531     echo " "
  532     echo "You may need to install manually some additional required dependencies:"
  533     echo "perl-Sys-Syslog"
  534     echo " "
  535     echo "You also need to setup your $PANDORA_BASE$PANDORA_CFG/pandora_agent.conf config file"
  536     echo " "
  537     if [ "$OS_NAME" = "FreeBSD" ]
  538     then
  539         echo "Define 'pandora_agent_enable=\"YES\"' in /etc/rc.conf to enable the daemon."
  540     elif [ "$OS_NAME" = "NetBSD" ]
  541     then
  542         echo "Define 'pandora_agent=\"YES\"' in /etc/rc.conf to enable the daemon."
  543     else
  544         echo "Check your startup configuration to be sure Pandora FMS Agent is ready "
  545         echo "to start automatically when system restarts":
  546     fi
  547 
  548     # Restore the daemon script
  549     cp -f "$DAEMON_SCRIPT.bak" "$DAEMON_SCRIPT" >/dev/null 2>&1
  550     rm -f "$DAEMON_SCRIPT.bak" >/dev/null 2>&1
  551 
  552     # Restore the configuration file
  553     cp -f "$AGENT_CFG.bak" "$AGENT_CFG" >/dev/null 2>&1
  554     rm -f "$AGENT_CFG.bak" >/dev/null 2>&1
  555 
  556 }
  557 
  558 if [ ! -f "pandora_agent" ]
  559 then
  560     echo " "
  561     echo "Execute installer from the directory where you have your files. "
  562     help
  563     exit 1
  564 fi
  565 
  566 # Script banner at start
  567 echo " "
  568 echo "Pandora FMS Agent UNIX Installer $PI_VERSION $PI_BUILD (c) 2008-2015 ArticaST"
  569 echo "This program is licensed under GPL2 Terms. http://pandorafms.com"
  570 echo " "
  571 
  572 
  573 case "$MODE" in
  574 
  575 '--force-install')
  576     FORCE=1
  577     install
  578     exit
  579     ;;
  580 
  581 '--install')
  582     install
  583     exit
  584     ;;
  585 
  586 '--uninstall')
  587     uninstall
  588     exit
  589     ;;
  590 
  591 *)
  592     help
  593     ;;
  594 esac
  595