"Fossies" - the Fresh Open Source Software Archive

Member "pandora_console/pandora_console_install" (15 Sep 2021, 7003 Bytes) of package /linux/misc/pandorafms_console-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_console_install": 7.0NG.756_vs_7.0NG.757.

    1 #!/bin/sh
    2 
    3 # Pandora FMS Console Installer (c) 2008-2015 Artica ST
    4 # Linux/FreeBSD/NetBSD Version (generic), for SuSe, Debian/Ubuntu,
    5 # RHEL/CentOS, Fedora, FreeBSD and NetBSD only
    6 # other Linux distros could not work properly without modifications
    7 # Please see http://www.pandorafms.org
    8 # v4.0dev Build 110203
    9 # This code is licensed under GPL 2.0 license.
   10 # **********************************************************************
   11 
   12 PI_VERSION="7.0NG.757"
   13 FORCE=0
   14 DESTDIR=""
   15 LOG_TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"`
   16 MODE=$1
   17 
   18 #
   19 # set_global_vars
   20 #   Check platform and set DISTRO, OS_VERSION, WWWUSER, WWWGROUP, WWWROOT,
   21 #   PANDORA_HOME and PANDORA_HOME_GROUP.
   22 #
   23 set_global_vars () {
   24     DISTRO="GENERIC"
   25 
   26     case `uname -s` in
   27     Linux)
   28         # Get Linux Distro type and version
   29         if [ -f "/etc/SuSE-release" ]
   30         then
   31             OS_VERSION=`cat /etc/SuSE-release | grep VERSION | cut -f 3 -d " "`
   32             DISTRO=SUSE
   33         elif [ -f "/etc/lsb-release" ] && [ ! -f "/etc/redhat-release" ]
   34         then
   35             OS_VERSION=`cat /etc/lsb-release | grep DISTRIB_RELEASE | cut -f 2 -d "="`
   36             DISTRO=UBUNTU
   37             OS_VERSION="UBUNTU $OS_VERSION"
   38         elif [ -f "/etc/debian_version" ]
   39         then
   40             OS_VERSION=`cat /etc/debian_version`
   41             OS_VERSION="DEBIAN $OS_VERSION"
   42             DISTRO=DEBIAN
   43         elif [ -f "/etc/fedora-release" ]
   44         then
   45             OS_VERSION=`cat /etc/fedora-release | cut -f 4 -d " "`
   46             OS_VERSION="FEDORA $OS_VERSION"
   47             DISTRO=FEDORA
   48         elif [ -f "/etc/redhat-release" ]
   49         then
   50             DISTRO=RHEL_CENTOS
   51         fi
   52         case $DISTRO in
   53         SUSE)
   54             WWWUSER=wwwrun
   55             WWWGROUP=www
   56             PANDORA_HOME_GROUP=root
   57             WWWROOT=/srv/www/htdocs
   58             ;;
   59         UBUNTU|DEBIAN)
   60             WWWUSER=www-data
   61             WWWGROUP=www-data
   62             WWWROOT=/var/www
   63             ;;
   64         FEDORA|RHEL_CENTOS)
   65             WWWUSER=apache
   66             WWWGROUP=apache
   67             WWWROOT=/var/www/html
   68             ;;
   69         esac
   70         ;;
   71     FreeBSD)
   72         DISTRO=FreeBSD
   73         WWWUSER=www
   74         WWWGROUP=www
   75         WWWROOT=/usr/local/www
   76 
   77         local apache
   78         for apache in apache24 apache22
   79         do
   80             [ ! -d $WWWROOT/$apache ] && continue
   81             WWWROOT=$WWWROOT/$apache/data
   82             break
   83         done
   84         ;;
   85     NetBSD)
   86         DISTRO=NetBSD
   87         WWWUSER=www
   88         WWWGROUP=www
   89         WWWROOT=/usr/pkg/share/httpd/htdocs
   90         ;;
   91     esac
   92 
   93     # backward compatible defaults (Assuming SUSE)
   94     if [ "$DISTRO" = GENERIC ]
   95     then
   96         WWWUSER=wwwrun
   97         WWWGROUP=www
   98         WWWROOT=/srv/www/htdocs
   99         PANDORA_HOME_GROUP=root
  100     fi
  101     # Use WWWGROUP as default for PANDORA_HOME_GROUP
  102     : ${PANDORA_HOME_GROUP:=$WWWGROUP}
  103 
  104     OS_VERSION=`uname -r`
  105     PANDORA_HOME="$WWWROOT/pandora_console"
  106 }
  107 
  108 uninstall () {
  109     set_global_vars
  110 
  111     echo "Removing Pandora FMS Console"
  112     rm -Rf $PANDORA_HOME
  113     rm -f  $DESTDIR/etc/logrotate.d/pandora_console
  114     echo "You need to drop manually pandora database from your Database server"
  115     echo "Done"
  116 }
  117 
  118 install () {
  119     set_global_vars
  120 
  121     OLDFILENAMETMP=`date +"%Y-%m-%d"`
  122     PANDORA_CONF=$PANDORA_HOME/include/config.php
  123 
  124     echo "Detecting operating system: $DISTRO"
  125     
  126     if [ -f $DESTDIR$PANDORA_HOME ] && [ "$FORCE" = "0" ]
  127     then
  128         echo "Seems that default dir already exists. Please use --force to"
  129         echo "force installer to install on $DESTDIR$PANDORA_HOME"
  130         exit
  131     else
  132         echo "Checking default dir $DESTDIR$PANDORA_HOME..."
  133     fi
  134 
  135     # Check and create 'pandora' user if needed
  136     id pandora 2> /dev/null
  137     if [ $? -eq 0 ]; then
  138         echo " "
  139         echo "User pandora does exist, skipping this step"
  140     elif [ "$DESTDIR" ]
  141     then
  142         # don't create user with "fakeroot" installation
  143         echo "User 'pandora' does not exist. All chown operations may fail."
  144         echo "You should manualy set proper ownership to $DESTDIR$PANDORA_HOME and $DESTDIR$PANDORA_SPOOL if it's required."
  145         echo
  146     else
  147         echo "Are you sure we can create a standard 'pandora' user locally? [y/N]"
  148         read AREYOUSURE
  149         if [ "$AREYOUSURE" != "y" ]
  150         then
  151             echo "Please create the 'pandora' user manually according to your authentication scheme, then start again the installation"
  152             echo "Aborting..."
  153             exit 1
  154         fi
  155         # creating user
  156         if [ "$DISTRO" = "FreeBSD" ]
  157         then
  158             echo "pandora:41121:::::Pandora FMS:/home/pandora:/usr/sbin/nologin:" | adduser -f - -w no 2> /dev/null
  159         else
  160             useradd pandora 
  161             mkdir /home/pandora 2> /dev/null
  162             mkdir /home/pandora/.ssh 2> /dev/null
  163             chown -R pandora /home/pandora 
  164         fi
  165     fi
  166 
  167     # Create directories
  168     echo "Creating Pandora FMS Console home directory at $DESTDIR$PANDORA_HOME ..."
  169     mkdir -p $DESTDIR$PANDORA_HOME 2> /dev/null
  170 
  171     # Copying Pandora FMS console
  172     echo "Copying Pandora FMS Console to $DESTDIR$PANDORA_HOME.."
  173     cp -R * $DESTDIR$PANDORA_HOME
  174     chmod -R u+rwX,g+rX,g-w,o-rwx $DESTDIR$PANDORA_HOME
  175 
  176     # prepare /var/spool/pandora/data_in and sub directories
  177     for subdir in collections conf md5 netflow
  178     do
  179         [ ! -d $DESTDIR/var/spool/pandora/data_in/$subdir ] && mkdir -p $DESTDIR/var/spool/pandora/data_in/$subdir
  180     done
  181 
  182     if [ -d /etc/logrotate.d ]
  183     then
  184         [ -d $DESTDIR/etc/logrotate.d ] && mkdir -p $DESTDIR/etc/logrotate.d
  185         echo "Creating logrotate.d entry for Pandora FMS log management"
  186         case $DISTRO in
  187             SUSE)
  188                 cp pandora_console_logrotate_suse $DESTDIR/etc/logrotate.d/pandora_console
  189                 ;;
  190             UBUNTU|DEBIAN)
  191                 cp pandora_console_logrotate_ubuntu $DESTDIR/etc/logrotate.d/pandora_console
  192                 ;;
  193             FEDORA|RHEL_CENTOS|GENERIC)
  194                 cp pandora_console_logrotate_centos $DESTDIR/etc/logrotate.d/pandora_console
  195                 ;;
  196             *)
  197                 echo "Please add a log rotation schedule manually to your log rotation daemon (if any)"
  198                 ;;
  199         esac
  200     else
  201         echo "Please add a log rotation schedule manually to your log rotation daemon (if any)"
  202     fi
  203 
  204     #Ownership
  205     chown -R $WWWUSER:$PANDORA_HOME_GROUP $DESTDIR$PANDORA_HOME 2> /dev/null
  206     chown -R pandora:$WWWGROUP $DESTDIR/var/spool/pandora/  2> /dev/null
  207 
  208     echo "Setting secure permissions for Pandora FMS spool dir..."
  209     chmod -R u+rwX,g+rwX,o-rwx $DESTDIR/var/spool/pandora/
  210 
  211     echo "Done."
  212     echo " "
  213     echo "You have your Pandora FMS console installed on $DESTDIR$PANDORA_HOME."
  214     echo " "
  215     echo "Now you can setup your Pandora FMS console and install"
  216     echo "database using a browser and point to: "
  217     echo " " 
  218     echo "  http://ip_address_of_this_server/pandora_console/install.php"
  219     echo " "
  220     echo " "
  221 }
  222 
  223 help () {
  224     echo "Syntax":
  225     echo
  226     echo "    ./pandora_console_install < --mode > [ --option ]"
  227     echo " "
  228     echo "Modes:"
  229     echo
  230     echo "    --force-install     To force installation if already installed on this system"
  231     echo "    --install           To install Pandora FMS Console on this system"
  232     echo "    --uninstall         To uninstall/remove Pandora FMS Console on this System"
  233     echo
  234     echo "Option:"
  235     echo
  236     echo "    --destdir DIR       Specify root directory for \"fakeroot\" installation"
  237     echo
  238 }
  239 
  240 # Script banner at start
  241 echo " "
  242 echo "Pandora FMS Console Installer $PI_VERSION $PI_BUILD (c) 2008-2015 ArticaST"
  243 echo "This program is licensed under GPL2 Terms. http://pandorafms.com"
  244 echo " "
  245 
  246 # parse option
  247 if [ "$2" = "--destdir" ]
  248 then
  249     if [ -z "$3" ]
  250     then
  251         echo '"--datadir" option requires an argument'
  252         help
  253         exit 1
  254     fi
  255     DESTDIR="$3"
  256 fi
  257 
  258 case "$MODE" in
  259 
  260 '--force-install')
  261     FORCE=1
  262     install
  263     exit
  264     ;;
  265 
  266 '--install')
  267     install
  268     exit
  269     ;;
  270 
  271 '--uninstall')
  272     uninstall
  273     exit
  274     ;;
  275 
  276 *)
  277     help
  278 esac
  279