Skip to content
Snippets Groups Projects
Commit 220f9318 authored by Tomáš Plesník's avatar Tomáš Plesník
Browse files

zmena verze skriptu; pridana kontrola nainstalovaneho klienta; zmena odsazeni

parent ae775364
No related branches found
No related tags found
No related merge requests found
...@@ -31,205 +31,216 @@ ...@@ -31,205 +31,216 @@
# otherwise) arising in any way out of the use of this software, even # otherwise) arising in any way out of the use of this software, even
# if advised of the possibility of such damage. # if advised of the possibility of such damage.
VERSION="1.1.0" VERSION="1.1"
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# FUNCTIONS # FUNCTIONS
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
usage() usage()
{ {
echo "Usage: `basename $0` [-d <directory>] [-u <user>] [-k <ssl_key_file>] [-c <ssl_cert_file>] [-a <ssl_ca_file>] [-hV]" echo "Usage: `basename $0` [-d <directory>] [-u <user>] [-k <ssl_key_file>] [-c <ssl_cert_file>] [-a <ssl_ca_file>] [-hV]"
echo "-d <directory> installation directory (default: /opt)" echo "-d <directory> installation directory (default: /opt)"
echo "-u <user> owner of warden client package (user for running detection scripts)" echo "-u <user> owner of warden client package (user for running detection scripts)"
echo "-k <ssl_key_file> path to SSL certificate key file" echo "-k <ssl_key_file> path to SSL certificate key file"
echo "-c <ssl_cert_file> path to SSL certificate file" echo "-c <ssl_cert_file> path to SSL certificate file"
echo "-a <ssl_ca_file> path to CA certificate file" echo "-a <ssl_ca_file> path to CA certificate file"
echo "-h print this help" echo "-h print this help"
echo "-V print script version number and exit" echo "-V print script version number and exit"
echo echo
echo "Example: ./`basename $0` -d /opt -u detector -k /etc/ssl/private/client.key -c /etc/ssl/certs/client.pem -a /etc/ssl/certs/tcs-ca-bundle.pem" echo "Example: ./`basename $0` -d /opt -u detector -k /etc/ssl/private/client.key -c /etc/ssl/certs/client.pem -a /etc/ssl/certs/tcs-ca-bundle.pem"
echo echo
echo "Note: You must be root for running this script." echo "Note: You must be root for running this script."
echo " For more information about installation process, see README file (section Installation)." echo " For more information about installation process, see README file (section Installation)."
echo echo
exit 0 exit 0
} }
version() version()
{ {
echo "`basename ${0}` - current version is $VERSION" echo "`basename ${0}` - current version is $VERSION"
exit 0 exit 0
} }
err() err()
{ {
echo "FAILED!" echo "FAILED!"
cat $err cat $err
rm -rf $err rm -rf $err
echo echo
echo "Installation of $package_name package FAILED!!!" echo "Installation of $package_version package FAILED!!!"
exit 1 exit 1
} }
err_clean() err_clean()
{ {
echo "FAILED!" echo "FAILED!"
echo " -> Uninstalling client package ... OK" echo " -> Uninstalling client package ... OK"
rm -rf $client_path > /dev/null 2>&1 rm -rf $client_path > /dev/null 2>&1
cat $err cat $err
rm -rf $err rm -rf $err
echo echo
echo "Installation of $package_name package FAILED!!!" echo "Installation of $package_version package FAILED!!!"
exit 1 exit 1
} }
os_chck() os_chck()
{ {
OS=`uname` OS=`uname`
if [ "$OS" != "Linux" ]; then if [ "$OS" != "Linux" ]; then
echo "Sorry, unsupported operating system detected - \"$OS\"!" echo "Sorry, unsupported operating system detected - \"$OS\"!"
exit 1 exit 1
fi fi
} }
shell_chck() shell_chck()
{ {
SHELL=`echo $SHELL` SHELL=`echo $SHELL`
if [ "$SHELL" != "/bin/bash" ]; then if [ "$SHELL" != "/bin/bash" ]; then
echo "Sorry, this script is usable in Bourne Again Shell (bash) only!" echo "Sorry, this script is usable in Bourne Again Shell (bash) only!"
exit 1 exit 1
fi fi
} }
root_chck() root_chck()
{ {
if [ $UID -ne 0 ]; then if [ $UID -ne 0 ]; then
echo "You must be root for running this script!" echo "You must be root for running this script!"
exit 1 exit 1
fi fi
} }
params_chck() params_chck()
{ {
if [ -z $prefix ]; then if [ -z $prefix ]; then
prefix=/opt prefix=/opt
echo "Warning: parameter -d <directory> is not set - default installation directory is $prefix!" echo "Warning: parameter -d <directory> is not set - default installation directory is $prefix!"
fi fi
if [ -z $user ]; then if [ -z $user ]; then
echo "Parameter -u <user> is not set!" echo "Parameter -u <user> is not set!"
exit 1 exit 1
fi fi
if [ -z $key ]; then if [ -z $key ]; then
echo "Parameter -k <ssl_key_file> is not set!" echo "Parameter -k <ssl_key_file> is not set!"
exit 1 exit 1
fi fi
if [ -z $cert ]; then if [ -z $cert ]; then
echo "Parameter -c <ssl_cert_file> is not set!" echo "Parameter -c <ssl_cert_file> is not set!"
exit 1 exit 1
fi fi
if [ -z $ca_file ]; then if [ -z $ca_file ]; then
echo "Parameter -a <ssl_ca_file> is not set!" echo "Parameter -a <ssl_ca_file> is not set!"
exit 1 exit 1
fi fi
}
old_client_chck()
{
old_package_version="$etc/package_version.txt"
if [ -f $old_package_version ]; then
echo "Sorry, but $old_package_version package is installed!"
echo "For update of warden client package please use update.sh script."
exit 1
fi
} }
perl_chck() perl_chck()
{ {
echo -n "Checking Perl interpreter ... " echo -n "Checking Perl interpreter ... "
which perl 1>/dev/null; ret_val=`echo $?` which perl 1>/dev/null; ret_val=`echo $?`
if [ $ret_val -eq 0 ]; then if [ $ret_val -eq 0 ]; then
echo "OK" echo "OK"
else else
echo "FAILED!" echo "FAILED!"
echo "Error: Perl interpreter is not installed!" echo "Error: Perl interpreter is not installed!"
exit 1 exit 1
fi fi
} }
modules_chck() modules_chck()
{ {
for module in ${modules[@]}; for module in ${modules[@]};
do do
echo -n "Checking $module module ... " echo -n "Checking $module module ... "
perl -e "use $module" 2> $err; ret_val=`echo $?` perl -e "use $module" 2> $err; ret_val=`echo $?`
if [ $ret_val -eq 0 ]; then if [ $ret_val -eq 0 ]; then
echo "OK" echo "OK"
else else
err err
fi fi
done done
} }
installation_dir_chck() installation_dir_chck()
{ {
echo -n "Checking installation directory ... " echo -n "Checking installation directory ... "
if [ ! -d $prefix ]; then if [ ! -d $prefix ]; then
echo "FAILED!" echo "FAILED!"
ls $prefix ls $prefix
exit 1 exit 1
else else
echo "OK" echo "OK"
fi fi
} }
make_warden_dir() make_warden_dir()
{ {
echo -n "Creating warden client directory ... " echo -n "Creating warden client directory ... "
cp -R `dirname $0`/warden-client $prefix 2> $err; ret_val=`echo $?` cp -R $dirname/warden-client $prefix 2> $err; ret_val=`echo $?`
if [ $ret_val -eq 0 ]; then if [ $ret_val -eq 0 ]; then
echo "OK" echo "OK"
else else
err_clean err_clean
fi fi
files=(CHANGELOG INSTALL LICENSE README README.cesnet) files=(CHANGELOG INSTALL LICENSE README README.cesnet)
for file in ${files[@]}; for file in ${files[@]};
do do
cp -u "`dirname $0`/$file" "$client_path/doc" cp -u $dirname/$file "$client_path/doc"
done done
cp -u "`dirname $0`/uninstall.sh" "$client_path" cp -u $dirname/uninstall.sh "$client_path"
} }
copy_key() copy_key()
{ {
echo -n "Copying certificate key file ... " echo -n "Copying certificate key file ... "
cp $key $etc 2> $err; ret_val=`echo $?` cp $key $etc 2> $err; ret_val=`echo $?`
if [ $ret_val -eq 0 ]; then if [ $ret_val -eq 0 ]; then
echo "OK" echo "OK"
else else
err_clean err_clean
fi fi
} }
copy_cert() copy_cert()
{ {
echo -n "Copying certificate file ... " echo -n "Copying certificate file ... "
cp $cert $etc 2> $err; ret_val=`echo $?` cp $cert $etc 2> $err; ret_val=`echo $?`
if [ $ret_val -eq 0 ]; then if [ $ret_val -eq 0 ]; then
echo "OK" echo "OK"
else else
err_clean err_clean
fi fi
} }
make_conf_file() make_conf_file()
{ {
echo -n "Creating configuration file ... " echo -n "Creating configuration file ... "
echo "# echo "#
# warden-client.conf - configuration file for the warden sender/receiver client # warden-client.conf - configuration file for the warden sender/receiver client
# #
...@@ -253,23 +264,24 @@ echo "# ...@@ -253,23 +264,24 @@ echo "#
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
\$SSL_CA_FILE = \"$ca_file\"; \$SSL_CA_FILE = \"$ca_file\";
" > $conf_file 2> $err; ret_val=`echo $?` " > $conf_file 2> $err; ret_val=`echo $?`
if [ $ret_val -eq 0 ]; then
echo "OK" if [ $ret_val -eq 0 ]; then
else echo "OK"
err_clean else
fi err_clean
fi
} }
change_permissions() change_permissions()
{ {
echo -n "Changing permissions to installed package ... " echo -n "Changing permissions to installed package ... "
chown -R $user: $client_path 2>$err; ret_val=`echo $?` chown -R $user: $client_path 2>$err; ret_val=`echo $?`
if [ $ret_val -eq 0 ]; then if [ $ret_val -eq 0 ]; then
echo "OK" echo "OK"
else else
err_clean err_clean
fi fi
} }
...@@ -289,16 +301,16 @@ shell_chck ...@@ -289,16 +301,16 @@ shell_chck
# read input # read input
while getopts "d:u:k:c:a:Vh" options; do while getopts "d:u:k:c:a:Vh" options; do
case $options in case $options in
d ) prefix=$OPTARG;; d ) prefix=$OPTARG;;
u ) user=$OPTARG;; u ) user=$OPTARG;;
k ) key=$OPTARG;; k ) key=$OPTARG;;
c ) cert=$OPTARG;; c ) cert=$OPTARG;;
a ) ca_file=$OPTARG;; a ) ca_file=$OPTARG;;
h ) usage;; h ) usage;;
V ) version;; V ) version;;
* ) usage;; * ) usage;;
esac esac
done done
# root test # root test
...@@ -308,7 +320,8 @@ root_chck ...@@ -308,7 +320,8 @@ root_chck
params_chck params_chck
# create variables # create variables
package_name="warden-client-$VERSION" dirname=`dirname $0`
package_version=`cat $dirname/warden-client/etc/package_version.txt`
key_file=`basename $key` key_file=`basename $key`
cert_file=`basename $cert` cert_file=`basename $cert`
client_path="$prefix/warden-client" client_path="$prefix/warden-client"
...@@ -316,6 +329,9 @@ etc="$client_path/etc" ...@@ -316,6 +329,9 @@ etc="$client_path/etc"
conf_file="$etc/warden-client.conf" conf_file="$etc/warden-client.conf"
err="/tmp/warden-err" err="/tmp/warden-err"
# check if warden-client is installed
old_client_chck
echo echo
echo "------------------------- Dependencies check-in -------------------------" echo "------------------------- Dependencies check-in -------------------------"
...@@ -350,7 +366,7 @@ change_permissions ...@@ -350,7 +366,7 @@ change_permissions
echo echo
echo "Please check configuration file in $conf_file!" echo "Please check configuration file in $conf_file!"
echo echo
echo "Installation of $package_name package was SUCCESSFUL!!!" echo "Installation of $package_version package was SUCCESSFUL!!!"
# cleanup section # cleanup section
rm -rf $err rm -rf $err
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment