Skip to content
Snippets Groups Projects
update.sh 8.67 KiB
Newer Older
Tomáš Plesník's avatar
Tomáš Plesník committed
# Copyright (C) 2011-2012 Cesnet z.s.p.o
# Use of this source is governed by a BSD-style license, see LICENSE file.

VERSION="2.1"

#-------------------------------------------------------------------------------
#				FUNCTIONS
#-------------------------------------------------------------------------------
usage()
{
	echo "Usage: `basename $0` [-d <directory>] [-hV]"
Tomáš Plesník's avatar
Tomáš Plesník committed
	echo "-d <directory>            destination directory (default: /opt)"
	echo "-h                        print this help"
	echo "-V                        print script version number and exit"
	echo
Tomáš Plesník's avatar
Tomáš Plesník committed
	echo "Example: # ./`basename $0` -d /opt"
	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
	echo "`basename ${0}` - current version is $VERSION"
	exit 0
	echo "Update from $old_package_version to $package_version package FAILED!!!"
	echo "FAILED!"
	echo " -> Reverting changes of warden client package ... OK"
	rm -rf ${client_path}/* > /dev/null 2>&1
	cp -R ${backup_dir}/* $client_path
	echo "Update from $old_package_version to $package_version package FAILED!!!"
	if [ $UID -ne 0 ]; then
		echo "You must be root for running this script!"
		exit 1
	fi
		echo "Warning: parameter -d <directory> is not set - default installation directory is ${prefix}!"
	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
	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
	if which perl 1> /dev/null; then
		echo "OK"
	else
		echo "FAILED!"
		echo "Error: Perl interpreter is not installed!" 
		exit 1
	fi
	for module in ${modules[@]};
	do
		echo -n "Checking $module module ... "
		if perl -e "use $module" 2> $err; then
	echo -n "Checking warden client directory ... "
	if [ ! -d $client_path ]; then
		echo "FAILED!"
		ls $client_path
	echo -n "Backing-up warden client directory ... "
	mkdir $backup_dir
	if cp -R ${client_path}/* $backup_dir 2> $err; then
	echo -n "Obtaining warden client directory owner ... "
	if user=`stat -c %U $conf_file` 2> $err; then
	echo -n "Updating warden client directory ... "
	if rsync -q --recursive --archive --delete --exclude='etc' --exclude='var' ${dirname}/warden-client $prefix 2> $err; then
		echo "OK"
	else
		err_clean
	fi

	files=(CHANGELOG INSTALL LICENSE README README.cesnet)
	for file in ${files[@]};
	do  
		cp ${dirname}/$file ${client_path}/doc
	cp ${dirname}/uninstall.sh $client_path
	cp ${dirname}/warden-client/etc/package_version $etc
	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
        
# 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 $?`
	echo -n "Changing permissions to updated package ... "
	chown -R $user: $client_path 2>$err || err_clean
       	chmod 644 $old_package_version_file || 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
	case $options in
		d ) prefix=$OPTARG;;
		h ) usage;;
		V ) version;;
		* ) usage;;
	esac
done

# root test
root_chck

# params test
params_chck

# create variables
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"


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
echo "Update from $old_package_version to $package_version package was SUCCESSFUL!!!"