2010-07-04 02:44:56 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2011-03-02 22:56:48 +01:00
|
|
|
# Pandora FMS 4.0dev Console Upgrade (c) 2009-2011 Artica ST
|
2009-01-26 17:51:14 +01:00
|
|
|
# Please see http://www.pandorafms.com
|
|
|
|
# This code is licensed under GPL 2.0 license.
|
|
|
|
# **********************************************************************
|
|
|
|
|
2011-03-29 10:45:21 +02:00
|
|
|
PI_VERSION=4.0dev
|
2009-01-26 17:51:14 +01:00
|
|
|
USER=`whoami`
|
|
|
|
|
|
|
|
if [ $USER != "root" ]
|
|
|
|
then
|
|
|
|
echo "Upgrade process need to be executed by root"
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
|
|
|
|
MODE=$1
|
|
|
|
|
|
|
|
pandora_upgrade () {
|
|
|
|
|
|
|
|
if [ ! -e "$PANDORAPATH/index.php" ]
|
|
|
|
then
|
|
|
|
echo "ERROR: Provided path for current Pandora FMS console, do not exist ($PANDORAPATH)"
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
echo "Installing new console code in $PANDORAPATH"
|
|
|
|
cp -R * $PANDORAPATH
|
2009-04-03 12:44:26 +02:00
|
|
|
|
2010-06-07 00:00:52 +02:00
|
|
|
# This makes the old-style config.php file usable with 3.x
|
|
|
|
|
2009-04-03 12:44:26 +02:00
|
|
|
line=$(grep "?>" -n $PANDORAPATH/include/config.php | head -1 | cut -f1 -d:)
|
|
|
|
line=$(($line - 1))
|
|
|
|
head -$line $PANDORAPATH/include/config.php > /tmp/asdf
|
|
|
|
echo "require_once ('config_process.php');" >> /tmp/asdf
|
|
|
|
echo "?>" >> /tmp/asdf
|
|
|
|
mv /tmp/asdf $PANDORAPATH/include/config.php
|
|
|
|
|
|
|
|
# Upgrade Database ?
|
2009-01-26 17:51:14 +01:00
|
|
|
|
|
|
|
if [ "$UPGRADEDB" == "1" ]
|
|
|
|
then
|
|
|
|
echo "Setting database schema changes"
|
|
|
|
DBUSER=`cat $PANDORAPATH/include/config.php | grep dbuser | grep -v "^\/" | grep -o "\=\"[a-zA-Z0-9]*\"" | grep -o "[A-Za-z0-9]*"`
|
|
|
|
DBPASS=`cat $PANDORAPATH/include/config.php | grep dbpass | grep -v "^\/" | grep -o "\=\"[a-zA-Z0-9]*\"" | grep -o "[A-Za-z0-9]*"`
|
|
|
|
DBHOST=`cat $PANDORAPATH/include/config.php | grep dbhost | grep -v "^\/" | grep -o "\=\"[a-zA-Z0-9]*\"" | grep -o "[A-Za-z0-9]*"`
|
|
|
|
DBNAME=`cat $PANDORAPATH/include/config.php | grep dbname | grep -v "^\/" | grep -o "\=\"[a-zA-Z0-9]*\"" | grep -o "[A-Za-z0-9]*"`
|
2010-11-08 13:14:25 +01:00
|
|
|
cat extras/pandoradb_migrate_v3.1_to_v3.2.sql | mysql -f -u $DBUSER -p$DBPASS -h $DBHOST -D $DBNAME
|
2009-01-26 17:51:14 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
WWWUSER=`ls -la $PANDORAPATH/index.php | awk '{ print $3 }'`
|
|
|
|
echo "Setting permissions for $WWWUSER in $PANDORAPATH"
|
|
|
|
chown -R $WWWUSER $PANDORAPATH
|
2010-06-07 00:00:52 +02:00
|
|
|
if [ "$?" -ne 0 ]
|
2009-12-18 19:25:38 +01:00
|
|
|
then
|
|
|
|
echo "ERROR (Cannot change $PANDORAPATH to $WWWUSER ownership)!"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
WWWGROUP=`ls -la $PANDORAPATH/index.php | awk '{ print $4 }'`
|
2009-01-26 17:51:14 +01:00
|
|
|
echo "Setting permissions for $WWWUSER in /var/spool/pandora/data_in"
|
2009-12-18 19:25:38 +01:00
|
|
|
chgrp -R $WWWGROUP /var/spool/pandora/data_in
|
|
|
|
if [ "$?" -ne 0 ]
|
|
|
|
then
|
|
|
|
echo "ERROR (Cannot change group ownership to /var/spool/pandora/data_in to $WWWGROUP)!"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2010-06-07 00:00:52 +02:00
|
|
|
# Remove installer file
|
2009-12-18 19:25:38 +01:00
|
|
|
|
|
|
|
[ -f $PANDORAPATH/install.php ] && rm -f $PANDORAPATH/install.php
|
|
|
|
|
|
|
|
# Only root should have read/write access to config.php
|
|
|
|
|
|
|
|
chmod 600 $PANDORAPATH/include/config.php
|
|
|
|
if [ "$?" -ne 0 ]
|
|
|
|
then
|
|
|
|
echo "ERROR (Cannot do chmod 600 $PANDORAPATH/include/config.php)!"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2010-06-07 00:00:52 +02:00
|
|
|
# Remove unnecessary files (optional, set variable to activate)
|
2009-12-18 19:25:38 +01:00
|
|
|
|
|
|
|
REMOVEFILES=0
|
|
|
|
if [ "${REMOVEFILES}" -eq 1 ]
|
|
|
|
then
|
|
|
|
rm -f $PANDORAPATH/AUTHORS
|
|
|
|
rm -f $PANDORAPATH/COPYING
|
|
|
|
rm -f $PANDORAPATH/ChangeLog
|
|
|
|
rm -f $PANDORAPATH/pandora_console_install
|
|
|
|
rm -f $PANDORAPATH/pandora_console_upgrade
|
|
|
|
rm -f $PANDORAPATH/pandoradb.sql
|
|
|
|
rm -f $PANDORAPATH/pandoradb_data.sql
|
|
|
|
fi
|
|
|
|
|
2009-01-26 17:51:14 +01:00
|
|
|
echo " "
|
|
|
|
echo "DONE!"
|
|
|
|
echo " "
|
2009-12-18 19:25:38 +01:00
|
|
|
return 0
|
2009-01-26 17:51:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
help () {
|
2010-06-07 00:00:52 +02:00
|
|
|
echo " -p <path> Upgrade Pandora FMS Console in path (pe: /var/www/pandora_console)"
|
|
|
|
echo " -d Upgrade also Database (by default not upgrade Database) "
|
|
|
|
echo " "
|
|
|
|
exit 0
|
2009-01-26 17:51:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Script banner at start
|
|
|
|
echo " "
|
2015-12-01 12:15:20 +01:00
|
|
|
echo "Pandora FMS $PI_VERSION Console Upgrade (c) 2009-2015 Artica ST"
|
2009-01-26 17:51:14 +01:00
|
|
|
echo "This program is licensed under GPL2 Terms. http://pandorafms.com"
|
|
|
|
echo " "
|
|
|
|
|
|
|
|
UPGRADEDB=0
|
|
|
|
UPGRADE=0
|
|
|
|
|
|
|
|
if [ $# -eq 0 ]
|
|
|
|
then
|
|
|
|
help
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Main parsing code
|
|
|
|
|
|
|
|
while getopts ":hdp:" optname
|
2010-06-07 00:00:52 +02:00
|
|
|
do
|
|
|
|
case "$optname" in
|
|
|
|
"h")
|
|
|
|
help
|
|
|
|
;;
|
|
|
|
"d")
|
|
|
|
UPGRADEDB=1
|
|
|
|
;;
|
|
|
|
"p")
|
|
|
|
PANDORAPATH=$OPTARG
|
|
|
|
UPGRADE=1
|
|
|
|
;;
|
|
|
|
?)
|
|
|
|
help
|
|
|
|
;;
|
|
|
|
default)
|
|
|
|
help
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2009-01-26 17:51:14 +01:00
|
|
|
|
|
|
|
if [ "$UPGRADE" == "1" ]
|
|
|
|
then
|
|
|
|
pandora_upgrade
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit
|