2010-05-24 18:38:04 +02:00
#!/bin/bash
# Automatically update Pandora FMS version and build where necessary.
2011-12-21 12:38:57 +01:00
source build_vars.sh
2010-05-24 18:38:04 +02:00
# Check command line arguments
2010-06-02 18:01:48 +02:00
if [ $# -lt 2 ] || [ $# -gt 3 ] ; then
2010-05-24 18:38:04 +02:00
echo " Usage: $0 <final|nightly> <version string> [build string] "
exit 1
fi
# Set some global vars
if [ " $1 " = = "nightly" ] ; then
NB = 1
else
NB = 0
fi
VERSION = $2
if [ $# = = 2 ] ; then
BUILD = ` date +%g%m%d`
else
2010-12-28 13:44:58 +01:00
BUILD = $3
2010-05-24 18:38:04 +02:00
fi
TEMP_FILE = "/tmp/pandora_update_version.tmp"
2011-12-21 12:38:57 +01:00
SPEC_FILES = " $CODEHOME /pandora_console/pandora_console.spec \
$CODEHOME /pandora_agents/unix/pandora_agent.spec \
$CODEHOME /pandora_server/pandora_server.spec \
$PANDHOME_ENT /pandora_console/enterprise/pandora_console_enterprise.spec \
$PANDHOME_ENT /pandora_server/PandoraFMS-Enterprise/pandora_server_enterprise.spec \
$CODEHOME /pandora_console/pandora_console.redhat.spec \
$CODEHOME /pandora_agents/unix/pandora_agent.redhat.spec \
$CODEHOME /pandora_server/pandora_server.redhat.spec \
$PANDHOME_ENT /pandora_console/enterprise/pandora_console_enterprise.redhat.spec \
$PANDHOME_ENT /pandora_server/PandoraFMS-Enterprise/pandora_server_enterprise.redhat.spec"
DEBIAN_FILES = " $CODEHOME /pandora_console/DEBIAN \
$CODEHOME /pandora_server/DEBIAN \
$CODEHOME /pandora_agents/unix/DEBIAN \
$PANDHOME_ENT /pandora_console/DEBIAN \
$PANDHOME_ENT /pandora_server/PandoraFMS-Enterprise/DEBIAN"
SERVER_FILE = " $CODEHOME /pandora_server/lib/PandoraFMS/Config.pm "
SERVER_DB_FILE = " $CODEHOME /pandora_server/util/pandora_db.pl "
SERVER_CLI_FILE = " $CODEHOME /pandora_server/util/pandora_manage.pl "
2012-06-11 16:01:16 +02:00
SERVER_CONF_FILE = " $CODEHOME /pandora_server/conf/pandora_server.conf "
2011-12-21 12:38:57 +01:00
CONSOLE_DB_FILE = " $CODEHOME /pandora_console/pandoradb_data.sql "
CONSOLE_FILE = " $CODEHOME /pandora_console/include/config_process.php "
CONSOLE_INSTALL_FILE = " $CODEHOME /pandora_console/install.php "
2012-06-20 15:42:17 +02:00
AGENT_BASE_DIR = " $CODEHOME /pandora_agents/ "
2011-12-21 12:38:57 +01:00
AGENT_UNIX_FILE = " $CODEHOME /pandora_agents/unix/pandora_agent "
AGENT_WIN_FILE = " $CODEHOME /pandora_agents/win32/pandora.cc "
AGENT_WIN_MPI_FILE = " $CODEHOME /pandora_agents/win32/installer/pandora.mpi "
2012-02-21 15:35:48 +01:00
AGENT_WIN_RC_FILE = " $CODEHOME /pandora_agents/win32/versioninfo.rc "
2010-05-24 18:38:04 +02:00
# Update version in spec files
function update_spec_version {
FILE = $1
if [ $NB = = 1 ] ; then
sed -e " s/^\s*%define\s\s*release\s\s*.*/%define release $BUILD / " " $FILE " > " $TEMP_FILE " && mv " $TEMP_FILE " " $FILE "
else
sed -e "s/^\s*%define\s\s*release\s\s*.*/%define release 1/" " $FILE " > " $TEMP_FILE " && mv " $TEMP_FILE " " $FILE "
fi
sed -e " s/^\s*%define\s\s*version\s\s*.*/%define version $VERSION / " " $FILE " > " $TEMP_FILE " && mv " $TEMP_FILE " " $FILE "
}
# Update version in debian dirs
function update_deb_version {
DEBIAN_DIR = $1
if [ $NB = = 1 ] ; then
LOCAL_VERSION = " $VERSION - $BUILD "
else
LOCAL_VERSION = " $VERSION "
fi
2011-10-27 18:40:27 +02:00
sed -e " s/^pandora_version\s*=.*/pandora_version=\" $LOCAL_VERSION \"/ " " $DEBIAN_DIR /make_deb_package.sh " > " $TEMP_FILE " && mv " $TEMP_FILE " " $DEBIAN_DIR /make_deb_package.sh " && sed -e " s/^Version:\s*.*/Version: $LOCAL_VERSION / " " $DEBIAN_DIR /control " > " $TEMP_FILE " && mv " $TEMP_FILE " " $DEBIAN_DIR /control "
2010-05-24 18:38:04 +02:00
}
# Spec files
for file in $SPEC_FILES ; do
echo " Updating spec file $file ... "
update_spec_version $file
done
# Debian dirs
for dir in $DEBIAN_FILES ; do
echo " Updating DEBIAN dir $dir ... "
update_deb_version $dir
done
# Pandora Server
echo "Updating Pandora Server version..."
sed -e " s/my\s\s*\$pandora_version\s*=.*/my \$pandora_version = \" $VERSION \";/ " " $SERVER_FILE " > " $TEMP_FILE " && mv " $TEMP_FILE " " $SERVER_FILE "
sed -e " s/my\s\s*\$pandora_build\s*=.*/my \$pandora_build = \" $BUILD \";/ " " $SERVER_FILE " > " $TEMP_FILE " && mv " $TEMP_FILE " " $SERVER_FILE "
2011-12-14 15:12:27 +01:00
echo "Updating DB maintenance script version..."
sed -e " s/my\s\s*\$version\s*=.*/my \$version = \" $VERSION PS $BUILD \";/ " " $SERVER_DB_FILE " > " $TEMP_FILE " && mv " $TEMP_FILE " " $SERVER_DB_FILE "
echo "Updating CLI script version..."
sed -e " s/my\s\s*\$version\s*=.*/my \$version = \" $VERSION PS $BUILD \";/ " " $SERVER_CLI_FILE " > " $TEMP_FILE " && mv " $TEMP_FILE " " $SERVER_CLI_FILE "
2012-06-11 16:01:16 +02:00
sed -e " s/\s*\#\s*\Version.*/\# Version $VERSION / " " $SERVER_CONF_FILE " > " $TEMP_FILE " && mv " $TEMP_FILE " " $SERVER_CONF_FILE "
2010-05-24 18:38:04 +02:00
# Pandora Console
echo "Updating Pandora Console DB version..."
sed -e " s/\s*[(]\s*'db_scheme_version'\s*\,.*/('db_scheme_version'\,' $VERSION '),/ " " $CONSOLE_DB_FILE " > " $TEMP_FILE " && mv " $TEMP_FILE " " $CONSOLE_DB_FILE "
sed -e " s/\s*[(]\s*'db_scheme_build'\s*\,.*/('db_scheme_build'\,'PD $BUILD '),/ " " $CONSOLE_DB_FILE " > " $TEMP_FILE " && mv " $TEMP_FILE " " $CONSOLE_DB_FILE "
echo "Updating Pandora Console version..."
sed -e " s/\s*\$pandora_version\s*=.*/\$pandora_version = 'v $VERSION ';/ " " $CONSOLE_FILE " > " $TEMP_FILE " && mv " $TEMP_FILE " " $CONSOLE_FILE "
2011-10-11 16:09:12 +02:00
sed -e " s/\s*\$build_version\s*=.*/\$build_version = 'PC $BUILD ';/ " " $CONSOLE_FILE " > " $TEMP_FILE " && mv " $TEMP_FILE " " $CONSOLE_FILE "
2010-12-28 13:44:58 +01:00
echo "Updating Pandora Console installer version..."
sed -e " s/\s*\$version\s*=.*/\$version = ' $VERSION ';/ " " $CONSOLE_INSTALL_FILE " > " $TEMP_FILE " && mv " $TEMP_FILE " " $CONSOLE_INSTALL_FILE "
sed -e " s/\s*\$build\s*=.*/\$build = ' $BUILD ';/ " " $CONSOLE_INSTALL_FILE " > " $TEMP_FILE " && mv " $TEMP_FILE " " $CONSOLE_INSTALL_FILE "
2010-06-02 18:01:48 +02:00
echo "Setting develop_bypass to 0..."
sed -e " s/\s*if\s*(\s*[!]\s*isset\s*(\s* $develop_bypass \s*)\s*)\s* $develop_bypass \s*=.*/if ([!]isset( $develop_bypass )) $develop_bypass = 0;/ " " $CONSOLE_FILE " > " $TEMP_FILE " && mv " $TEMP_FILE " " $CONSOLE_FILE "
2010-05-24 18:38:04 +02:00
# Pandora Agents
echo "Updating Pandora Unix Agent version..."
sed -e " s/\s*use\s*constant\s*AGENT_VERSION =>.*/use constant AGENT_VERSION => ' $VERSION ';/ " " $AGENT_UNIX_FILE " > " $TEMP_FILE " && mv " $TEMP_FILE " " $AGENT_UNIX_FILE "
sed -e " s/\s*use\s*constant\s*AGENT_BUILD =>.*/use constant AGENT_BUILD => ' $BUILD ';/ " " $AGENT_UNIX_FILE " > " $TEMP_FILE " && mv " $TEMP_FILE " " $AGENT_UNIX_FILE "
echo "Updating Pandora Windows Agent version..."
sed -e " s/\s*#define\s*PANDORA_VERSION\s*.*/#define PANDORA_VERSION (\" $VERSION (Build $BUILD )\")/ " " $AGENT_WIN_FILE " > " $TEMP_FILE " && mv " $TEMP_FILE " " $AGENT_WIN_FILE "
2010-11-03 18:23:26 +01:00
sed -e " s/{Pandora FMS Windows Agent v.*}/{Pandora FMS Windows Agent v $VERSION }/ " " $AGENT_WIN_MPI_FILE " > " $TEMP_FILE " && mv " $TEMP_FILE " " $AGENT_WIN_MPI_FILE "
NUMERIC_VERSION = $( echo $VERSION | sed -e "s/\([0-9]*\.[0-9]*\).*/\1/" )
2010-11-03 19:06:30 +01:00
sed -n " 1h;1!H;\${;g;s/[\r\n]InstallVersion[\r\n]{\S*}/\nInstallVersion\n{ $NUMERIC_VERSION .0.0}/g;p;} " " $AGENT_WIN_MPI_FILE " > " $TEMP_FILE " && mv " $TEMP_FILE " " $AGENT_WIN_MPI_FILE "
sed -n " 1h;1!H;\${;g;s/[\r\n]Version[\r\n]{[^\n\r]*}/\nVersion\n{ $BUILD }/g;p;} " " $AGENT_WIN_MPI_FILE " > " $TEMP_FILE " && mv " $TEMP_FILE " " $AGENT_WIN_MPI_FILE "
2011-10-27 20:11:02 +02:00
if [ $NB = = 1 ] ; then
2011-10-27 20:15:33 +02:00
sed -n "1h;1!H;\${;g;s/[\r\n]Windows\,Executable[\r\n]{[^\n\r]*}/\nWindows\,Executable\n{\<\%AppName\%\>\-\<\%Version\%\>\-Setup\<\%Ext\%\>}/g;p;}" " $AGENT_WIN_MPI_FILE " > " $TEMP_FILE " && mv " $TEMP_FILE " " $AGENT_WIN_MPI_FILE "
2011-10-27 20:11:02 +02:00
else
2011-10-27 20:15:33 +02:00
sed -n "1h;1!H;\${;g;s/[\r\n]Windows\,Executable[\r\n]{[^\n\r]*}/\nWindows\,Executable\n{\<\%AppName\%\>\-Setup\<\%Ext\%\>}/g;p;}" " $AGENT_WIN_MPI_FILE " > " $TEMP_FILE " && mv " $TEMP_FILE " " $AGENT_WIN_MPI_FILE "
2011-10-27 20:11:02 +02:00
fi
2012-02-21 15:35:48 +01:00
sed -e " s/\s*VALUE \"ProductVersion\".*/ VALUE \"ProductVersion\", \"( $VERSION (Build $BUILD ))\"/ " " $AGENT_WIN_RC_FILE " > " $TEMP_FILE " && mv " $TEMP_FILE " " $AGENT_WIN_RC_FILE "
2012-06-20 15:42:17 +02:00
echo "Updating Agent configuration files..."
for conf in ` find $AGENT_BASE_DIR -name pandora_agent.conf` ; do
sed -e " s/#\s*[Vv]ersion\s*[^\,]*/# Version $VERSION / " " $conf " > " $TEMP_FILE " && mv " $TEMP_FILE " " $conf "
done
2010-05-24 18:38:04 +02:00
rm -f " $TEMP_FILE "