Newer
Older
#!/bin/bash
#
# update.sh
#
# Use of this source is governed by a BSD-style license, see LICENSE file.
#-------------------------------------------------------------------------------
# FUNCTIONS
#-------------------------------------------------------------------------------
usage()
{
Tomáš Plesník
committed
echo "Usage: `basename $0` [-d <directory>] [-hV]"
echo "-d <directory> destination directory (default: /opt)"
Tomáš Plesník
committed
echo "-h print this help"
echo "-V print script version number and exit"
echo
Tomáš Plesník
committed
echo
echo "Note: You must be root for running this script."
echo " For more information about update process, see README file (section Update)."
echo
exit 0
}
version()
{
Tomáš Plesník
committed
echo "`basename ${0}` - current version is $VERSION"
exit 0
}
err()
{
Tomáš Plesník
committed
echo "FAILED!"
cat $err
rm -rf $err
rm -rf $backup_dir
echo
echo "Update from $old_package_version to $package_version package FAILED!!!"
Tomáš Plesník
committed
exit 1
}
err_clean()
{
Tomáš Plesník
committed
echo "FAILED!"
echo " -> Reverting changes of warden client package ... OK"
rm -rf ${client_path}/* > /dev/null 2>&1
cp -R ${backup_dir}/* $client_path
Tomáš Plesník
committed
cat $err
rm -rf $err $backup_dir
echo
echo "Update from $old_package_version to $package_version package FAILED!!!"
Tomáš Plesník
committed
exit 1
}
root_chck()
{
Tomáš Plesník
committed
if [ $UID -ne 0 ]; then
echo "You must be root for running this script!"
exit 1
fi
}
params_chck()
{
Tomáš Plesník
committed
if [ -z $prefix ]; then
prefix=/opt
echo "Warning: parameter -d <directory> is not set - default installation directory is ${prefix}!"
Tomáš Plesník
committed
fi
}
obtain_package_version()
{
if [ -f $old_package_version_file ]; then
old_package_version=`cat $old_package_version_file`
if [ "$old_package_version" == "$package_version" ]; then
echo "Sorry, but $package_version package is already installed!"
exit 1
fi
Tomáš Plesník
committed
else
echo "Sorry, but warden-client package is not installed!"
echo "For installation of warden client package please use install.sh script."
exit 1
fi
}
perl_chck()
{
Tomáš Plesník
committed
echo -n "Checking Perl interpreter ... "
if which perl 1> /dev/null; then
Tomáš Plesník
committed
echo "OK"
else
echo "FAILED!"
echo "Error: Perl interpreter is not installed!"
exit 1
fi
}
modules_chck()
{
Tomáš Plesník
committed
for module in ${modules[@]};
do
echo -n "Checking $module module ... "
if perl -e "use $module" 2> $err; then
Tomáš Plesník
committed
echo "OK"
else
err
fi
done
}
warden_dir_chck()
{
Tomáš Plesník
committed
echo -n "Checking warden client directory ... "
if [ ! -d $client_path ]; then
echo "FAILED!"
Tomáš Plesník
committed
exit 1
else
echo "OK"
fi
backup()
{
Tomáš Plesník
committed
echo -n "Backing-up warden client directory ... "
mkdir $backup_dir
if cp -R ${client_path}/* $backup_dir 2> $err; then
Tomáš Plesník
committed
echo "OK"
else
err
}
obtain_warden_user()
{
Tomáš Plesník
committed
echo -n "Obtaining warden client directory owner ... "
if user=`stat -c %U $conf_file` 2> $err; then
Tomáš Plesník
committed
echo "OK"
else
err
fi
}
update_warden_dir()
{
Tomáš Plesník
committed
echo -n "Updating warden client directory ... "
if rsync -q --recursive --archive --delete --exclude='etc' --exclude='var' ${dirname}/warden-client $prefix 2> $err; then
Tomáš Plesník
committed
echo "OK"
else
err_clean
fi
files=(CHANGELOG INSTALL LICENSE README README.cesnet)
for file in ${files[@]};
do
cp ${dirname}/$file ${client_path}/doc
Tomáš Plesník
committed
done
cp ${dirname}/uninstall.sh $client_path
cp ${dirname}/warden-client/etc/package_version $etc
}
make_conf_file()
{
Tomáš Plesník
committed
echo -n "Creating configuration file ... "
uri=`cat $conf_file | grep '$URI'`
ssl_key_file=`cat $conf_file | grep '$SSL_KEY_FILE'`
ssl_cert_file=`cat $conf_file | grep '$SSL_CERT_FILE'`
ssl_ca_file=`cat $conf_file | grep '$SSL_CA_FILE'`
max_rcv_events_limit=`cat $conf_file | grep '$MAX_RCV_EVENTS_LIMIT'`
connection_timeout=`cat $conf_file | grep '$CONNECTION_TIMEOUT'`
log_stderr=`cat $conf_file | grep '$LOG_STDERR'`
if [ -z $log_stderr ]; then
log_stderr="\$LOG_STDERR = 1;"
fi
log_syslog=`cat $conf_file | grep '$LOG_SYSLOG'`
if [ -z $log_syslog ]; then
log_syslog="\$LOG_SYSLOG = 0;"
fi
log_syslog_facility=`cat $conf_file | grep '$LOG_SYSLOG_FACILITY'`
if [ -z $log_syslog_facility ]; then
log_syslog_facility="\$LOG_SYSLOG_FACILITY = \"local7\";"
fi
log_verbose=`cat $conf_file | grep '$LOG_VERBOSE'`
if [ -z $log_verbose ]; then
log_verbose="\$LOG_VERBOSE = 0;"
fi
Tomáš Plesník
committed
echo "#
# warden-client.conf - configuration file for the warden sender/receiver client
#
#-------------------------------------------------------------------------------
# URI - URI address of Warden server
#-------------------------------------------------------------------------------
$uri
#-------------------------------------------------------------------------------
# SSL_KEY_FILE - path to client SSL certificate key file
#-------------------------------------------------------------------------------
$ssl_key_file
#-------------------------------------------------------------------------------
# SSL_CERT_FILE - path to client SSL certificate file
#-------------------------------------------------------------------------------
$ssl_cert_file
#-------------------------------------------------------------------------------
# SSL_CA_FILE - path to CA certificate file
#-------------------------------------------------------------------------------
$ssl_ca_file
#-------------------------------------------------------------------------------
# MAX_RCV_EVENTS_LIMIT - maximum number of events the client is allowd to get
# from the Warden server in one batch
#-------------------------------------------------------------------------------
$max_rcv_events_limit
#-------------------------------------------------------------------------------
# CONNECTION_TIMEOUT - interval in seconds to timeout connection with Warden
# server. If your client timeouts, consider using higher
# timeout number. Also, in case of receiving clients, you
# can optimize the MAX_RCV_EVENTS_LIMIT value.
#-------------------------------------------------------------------------------
$connection_timeout
#-------------------------------------------------------------------------------
# Log options
#
# LOG_STDERR, LOG_SYSLOG - hide (0) or allow (1) error reporting on STDERR
# and/or to Syslog
# LOG_SYSLOG_FACILITY - specify a Syslog facility to log in
# LOG_VERBOSE - print only error message without a stack (0) or print debug info
# including err. message and stack (1)
#-------------------------------------------------------------------------------
$log_stderr
$log_syslog
$log_syslog_facility
$log_verbose
1;
" > $conf_file 2> $err; ret_val=`echo $?`
Tomáš Plesník
committed
if [ $ret_val -eq 0 ]; then
echo "OK"
else
err_clean
fi
}
change_permissions()
{
Tomáš Plesník
committed
echo -n "Changing permissions to updated package ... "
chown -R $user: $client_path 2>$err || err_clean
chmod 644 $old_package_version_file || err_clean
if chmod 600 $conf_file; then
Tomáš Plesník
committed
echo "OK"
else
err_clean
}
#-------------------------------------------------------------------------------
# MAIN
#-------------------------------------------------------------------------------
# list of used Perl modules
modules=(SOAP::Lite IO::Socket::SSL SOAP::Transport::HTTP FindBin DateTime Carp)
# read input
while getopts "d:Vh" options; do
Tomáš Plesník
committed
case $options in
d ) prefix=$OPTARG;;
h ) usage;;
V ) version;;
* ) usage;;
esac
done
# root test
root_chck
# params test
params_chck
# create variables
Tomáš Plesník
committed
dirname=`dirname $0`
package_version=`cat ${dirname}/warden-client/etc/package_version`
[[ $prefix == */ ]] && prefix="${prefix%?}" # remove last char (slash) from prefix
client_path="${prefix}/warden-client"
etc="${client_path}/etc"
old_package_version_file="${etc}/package_version"
conf_file="${etc}/warden-client.conf"
err="/tmp/warden-err"
backup_dir="/tmp/warden-backup"
Tomáš Plesník
committed
# obtain version of old warden client
obtain_package_version
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
echo
echo "------------------------- Dependencies check-in -------------------------"
# Perl interpreter test
perl_chck
# Perl modules test
modules_chck
echo
echo "------------------------- Update process --------------------------------"
# check warden client directory
warden_dir_chck
# backup old warden client installation
backup
# obtain current warden client user
obtain_warden_user
# make warden client directory
update_warden_dir
# create conf file
make_conf_file
# change permissions
change_permissions
echo
echo "Please check configuration file in ${conf_file}!"
echo "Warden client directory: $client_path"
echo
Tomáš Plesník
committed
echo "Update from $old_package_version to $package_version package was SUCCESSFUL!!!"
# cleanup section
Tomáš Plesník
committed
rm -rf $err $backup_dir
exit 0