
#!/bin/sh

# Copyright (c) Members of the EGEE Collaboration. 2004 
# See http://eu-egee.org/partners/ for details on the copyright holders
# For license conditions see the license file or http://eu-egee.org/license.html

# glite-io-server_installer v. 2.0.0
#
# The glite-io-server_installer installs the gLite I\/O Server
#
# Usage: glite-io-server_installer [-u|-v|--help]
#        -u          uninstall
#        -v          print version
#        --help      print script usage info
# Return codes: 0 - Ok
#               1 - if a file could not be downloaded

###############################################################################

#Parse the RPMLIST to strip out the RPMS that are already installed
function parseRPMList()
{
        newRPMLIST=""
        localRPMLIST=`rpm -qa`
        for i in $RPMLIST
        do
                g=`echo $i | sed -e 's/\.i386\.rpm//g'`
                g=`echo $g | sed -e 's/\.noarch\.rpm//g'`
                if [ -z "`echo $localRPMLIST | grep $g`" ]; then
                        newRPMLIST="${newRPMLIST} $i"
                else
                        echo "$i is already installed. It will be skipped."
                fi
        done
                                                                                                                                                             
        RPMLIST=$newRPMLIST
}

#Parse the SCRIPTLIST to execute all scripts
function parseScriptList()
{
        for i in $SCRIPTLIST
        do
        		if [ "$INSTALL" = "true" ]; then
	                $i
	            else
	            	$i -u
	            fi
        done
}

#Downloads and install the module RPMS
function install()
{

	INSTALL=true

	version
	echo
	echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	echo x Please wait, downloading the gLite I\/O Server... x
	echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	echo
	
	mkdir -p glite-io-server
	cd glite-io-server
	
	# Download global dependencies	
	
	

	# Download glite-io-server-service scripts from repository
		

	# Download glite-io-server-service dependencies RPMS from repository
		
			
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/externals/bin/rhel30/RPMS/glite-essentials-cpp-1.1.1-1_EGEE.i386.rpm
if [ ! -f "glite-essentials-cpp-1.1.1-1_EGEE.i386.rpm" ]
then
	echo 
	echo ERROR: glite-essentials-cpp-1.1.1-1_EGEE.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-essentials-cpp-1.1.1-1_EGEE.i386.rpm"
			
					
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/externals/bin/rhel30/RPMS/vdt_globus_essentials-VDT1.2.2rh9-1.i386.rpm
if [ ! -f "vdt_globus_essentials-VDT1.2.2rh9-1.i386.rpm" ]
then
	echo 
	echo ERROR: vdt_globus_essentials-VDT1.2.2rh9-1.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST vdt_globus_essentials-VDT1.2.2rh9-1.i386.rpm"
			
					
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/externals/bin/rhel30/RPMS/gpt-VDT1.2.2rh9-1.i386.rpm
if [ ! -f "gpt-VDT1.2.2rh9-1.i386.rpm" ]
then
	echo 
	echo ERROR: gpt-VDT1.2.2rh9-1.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST gpt-VDT1.2.2rh9-1.i386.rpm"
			
					
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/externals/bin/rhel30/RPMS/CGSI_gSOAP_2.6-1.1.8-2.slc3.i386.rpm
if [ ! -f "CGSI_gSOAP_2.6-1.1.8-2.slc3.i386.rpm" ]
then
	echo 
	echo ERROR: CGSI_gSOAP_2.6-1.1.8-2.slc3.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST CGSI_gSOAP_2.6-1.1.8-2.slc3.i386.rpm"
			
					
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/externals/bin/rhel30/RPMS/CASTOR-client-1.7.1.5-1.longname.i386.rpm
if [ ! -f "CASTOR-client-1.7.1.5-1.longname.i386.rpm" ]
then
	echo 
	echo ERROR: CASTOR-client-1.7.1.5-1.longname.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST CASTOR-client-1.7.1.5-1.longname.i386.rpm"
			
					
			

	# Download glite-io-server-service RPMS from repository
		
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.2/R20050715/bin/rhel30/noarch/RPMS/glite-config-1.2.1-1.noarch.rpm
if [ ! -f "glite-config-1.2.1-1.noarch.rpm" ]
then
	echo 
	echo ERROR: glite-config-1.2.1-1.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-config-1.2.1-1.noarch.rpm"
			

				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.2/R20050715/bin/rhel30/noarch/RPMS/glite-io-server-config-2.0.0-1.noarch.rpm
if [ ! -f "glite-io-server-config-2.0.0-1.noarch.rpm" ]
then
	echo 
	echo ERROR: glite-io-server-config-2.0.0-1.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-io-server-config-2.0.0-1.noarch.rpm"
			

				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.2/R20050715/bin/rhel30/i386/RPMS/glite-data-io-daemon-1.2.2-1.i386.rpm
if [ ! -f "glite-data-io-daemon-1.2.2-1.i386.rpm" ]
then
	echo 
	echo ERROR: glite-data-io-daemon-1.2.2-1.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-data-io-daemon-1.2.2-1.i386.rpm"
			

				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.2/R20050715/bin/rhel30/i386/RPMS/glite-data-io-quanta-1.0.0-1.i386.rpm
if [ ! -f "glite-data-io-quanta-1.0.0-1.i386.rpm" ]
then
	echo 
	echo ERROR: glite-data-io-quanta-1.0.0-1.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-data-io-quanta-1.0.0-1.i386.rpm"
			

				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.2/R20050715/bin/rhel30/i386/RPMS/glite-data-io-protocol-rfio-1.3.2-1.i386.rpm
if [ ! -f "glite-data-io-protocol-rfio-1.3.2-1.i386.rpm" ]
then
	echo 
	echo ERROR: glite-data-io-protocol-rfio-1.3.2-1.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-data-io-protocol-rfio-1.3.2-1.i386.rpm"
			
						   
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.2/R20050715/bin/rhel30/i386/RPMS/glite-data-io-gss-auth-1.0.0-1.i386.rpm
if [ ! -f "glite-data-io-gss-auth-1.0.0-1.i386.rpm" ]
then
	echo 
	echo ERROR: glite-data-io-gss-auth-1.0.0-1.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-data-io-gss-auth-1.0.0-1.i386.rpm"
			
						   
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.2/R20050715/bin/rhel30/i386/RPMS/glite-data-config-service-1.1.8-1.i386.rpm
if [ ! -f "glite-data-config-service-1.1.8-1.i386.rpm" ]
then
	echo 
	echo ERROR: glite-data-config-service-1.1.8-1.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-data-config-service-1.1.8-1.i386.rpm"
			
						   
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.2/R20050715/bin/rhel30/i386/RPMS/glite-data-io-authz-catalogs-1.0.1-2.i386.rpm
if [ ! -f "glite-data-io-authz-catalogs-1.0.1-2.i386.rpm" ]
then
	echo 
	echo ERROR: glite-data-io-authz-catalogs-1.0.1-2.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-data-io-authz-catalogs-1.0.1-2.i386.rpm"
					
						   		
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.2/R20050715/bin/rhel30/i386/RPMS/glite-data-io-resolve-common-1.2.4-1.i386.rpm
if [ ! -f "glite-data-io-resolve-common-1.2.4-1.i386.rpm" ]
then
	echo 
	echo ERROR: glite-data-io-resolve-common-1.2.4-1.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-data-io-resolve-common-1.2.4-1.i386.rpm"
					
						   		
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.2/R20050715/bin/rhel30/i386/RPMS/glite-data-srm-api-c-1.0.0-15.i386.rpm
if [ ! -f "glite-data-srm-api-c-1.0.0-15.i386.rpm" ]
then
	echo 
	echo ERROR: glite-data-srm-api-c-1.0.0-15.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-data-srm-api-c-1.0.0-15.i386.rpm"
					
						   		
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.2/R20050715/bin/rhel30/i386/RPMS/glite-data-io-resolve-catalogs-1.2.1-2.i386.rpm
if [ ! -f "glite-data-io-resolve-catalogs-1.2.1-2.i386.rpm" ]
then
	echo 
	echo ERROR: glite-data-io-resolve-catalogs-1.2.1-2.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-data-io-resolve-catalogs-1.2.1-2.i386.rpm"
					
						   		
			
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.2/R20050715/bin/rhel30/i386/RPMS/glite-data-io-base-1.3.2-1.i386.rpm
if [ ! -f "glite-data-io-base-1.3.2-1.i386.rpm" ]
then
	echo 
	echo ERROR: glite-data-io-base-1.3.2-1.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-data-io-base-1.3.2-1.i386.rpm"
							
						   
			
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.2/R20050715/bin/rhel30/i386/RPMS/glite-data-io-authz-fas-1.1.3-3.i386.rpm
if [ ! -f "glite-data-io-authz-fas-1.1.3-3.i386.rpm" ]
then
	echo 
	echo ERROR: glite-data-io-authz-fas-1.1.3-3.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-data-io-authz-fas-1.1.3-3.i386.rpm"
							
						   						   
			
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.2/R20050715/bin/rhel30/noarch/RPMS/glite-data-catalog-interface-2.0.0-6.noarch.rpm
if [ ! -f "glite-data-catalog-interface-2.0.0-6.noarch.rpm" ]
then
	echo 
	echo ERROR: glite-data-catalog-interface-2.0.0-6.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-data-catalog-interface-2.0.0-6.noarch.rpm"
							
						   
			
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.2/R20050715/bin/rhel30/i386/RPMS/glite-data-io-resolve-fireman-1.3.4-4.i386.rpm
if [ ! -f "glite-data-io-resolve-fireman-1.3.4-4.i386.rpm" ]
then
	echo 
	echo ERROR: glite-data-io-resolve-fireman-1.3.4-4.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-data-io-resolve-fireman-1.3.4-4.i386.rpm"
							
						   
			
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.2/R20050715/bin/rhel30/i386/RPMS/glite-data-io-resolve-fr-1.3.4-3.i386.rpm
if [ ! -f "glite-data-io-resolve-fr-1.3.4-3.i386.rpm" ]
then
	echo 
	echo ERROR: glite-data-io-resolve-fr-1.3.4-3.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-data-io-resolve-fr-1.3.4-3.i386.rpm"
							
						   						   
			
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.2/R20050715/bin/rhel30/i386/RPMS/glite-data-catalog-api-c-2.0.0-2.i386.rpm
if [ ! -f "glite-data-catalog-api-c-2.0.0-2.i386.rpm" ]
then
	echo 
	echo ERROR: glite-data-catalog-api-c-2.0.0-2.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-data-catalog-api-c-2.0.0-2.i386.rpm"
							
						   						   
			

	# Download glite-security-utils-service scripts from repository
		
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.2/R20050715/installers/glite-security-utils_installer.sh
if [ ! -f "glite-security-utils_installer.sh" ]
then
	echo 
	echo ERROR: glite-security-utils_installer.sh could not be downloaded!
	exit 1
fi
chmod u+x glite-security-utils_installer.sh
SCRIPTLIST="$SCRIPTLIST ./glite-security-utils_installer.sh"
			

	# Download glite-security-utils-service dependencies RPMS from repository
		

	# Download glite-security-utils-service RPMS from repository
		

	# Download glite-rgma-servicetool scripts from repository
		
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.2/R20050715/installers/glite-rgma-servicetool_installer.sh
if [ ! -f "glite-rgma-servicetool_installer.sh" ]
then
	echo 
	echo ERROR: glite-rgma-servicetool_installer.sh could not be downloaded!
	exit 1
fi
chmod u+x glite-rgma-servicetool_installer.sh
SCRIPTLIST="$SCRIPTLIST ./glite-rgma-servicetool_installer.sh"
			

	# Download glite-rgma-servicetool dependencies RPMS from repository
		

	# Download glite-rgma-servicetool RPMS from repository
		
		
	# Download and install subservices

	parseScriptList

	# Install all RPMS
	echo
	echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	echo x Please wait, installing the gLite I/O Server... x
	echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	echo
	parseRPMList
	if [ ! -z "$RPMLIST" ]; then
		rpm -Uvh $RPMLIST
		rpm_return=$?
	else
		echo All required RPMS are already installed
		rpm_return=0
	fi
	if [ "$rpm_return" == "0" ]; then
		echo
		echo Done!
		echo
		echo Before using the gLite I/O Server:
		echo
		echo "(1) Create configuration"
		echo
		echo "    a) Centralized configuration:"
		echo "       Create or update the global gLite configuration file"
		echo "           /opt/glite/etc/config/glite-global.cfg.xml"
		echo "       Create or updated the Site Configuration file"
		echo "       with the values for this gLite I/O Server node and publish it"
		echo "       A template for site configuration of a typical"
		echo "       gLite I/O Server node is provided in"
		echo "           /opt/glite/etc/config/templates/glite-io-server-site-config.xml"
		echo
		echo "    b) Local configuration:"
		echo "       Create or update the I/O Server configuration file"
		echo "           /opt/glite/etc/config/glite-io-server.cfg.xml ,"		
		echo "       the gLite Security Utilities configuration file"
		echo "           /opt/glite/etc/config/glite-security-utils.cfg.xml"
		echo "       and the general glite configuration file"
		echo "           /opt/glite/etc/config/glite-global.cfg.xml"
		echo
		echo "       Configuration file templates are provided in"
		echo "           /opt/glite/etc/config/templates/."
		echo "       Copy these templates if they do not exist yet to /opt/glite/etc/config/"
		echo "       and set the configuration values accordingly."
		echo "       Make sure that all parameters 'changeme' are properly set in the files."
		echo
		echo "(2) Configure and start the I/O Server"
		echo
		echo "    Run the configuration script /opt/glite/etc/config/scripts/glite-io-server-config.py"
		echo "    The script will completely configure and start the gLite I/O Server."
		echo
	else
		echo
		echo
		echo An error occurred while installing the gLite I/O Server RPMS.
		echo Most likely one or more of the RPMS to be installed require
		echo additional dependencies or are older than already installed packages.
		echo Please refer to the rpm error message above for more details.
	fi
	echo
	echo For more information refer to the gLite Installation and User Guides
	echo or to the gLite web site \(http:\/\/www.glite.org\)
	echo Please report problems and comments to the gLite Team at
	echo project-eu-egee-glite-bugs@cern.ch

	cd ..
}

###############################################################################
function uninstall()
{
	version

	# Global dependencies	
	
	

	# glite-io-server-service dependencies RPMS from repository
		
			
				
RPMLIST="$RPMLIST glite-essentials-cpp-1.1.1-1_EGEE"
					
					
				
RPMLIST="$RPMLIST vdt_globus_essentials-VDT1.2.2rh9-1"
					
					
				
RPMLIST="$RPMLIST gpt-VDT1.2.2rh9-1"
					
					
				
RPMLIST="$RPMLIST CGSI_gSOAP_2.6-1.1.8-2.slc3"
					
					
				
RPMLIST="$RPMLIST CASTOR-client-1.7.1.5-1.longname"
					
					
			

	# glite-io-server-service RPMS from repository
		
				
RPMLIST="$RPMLIST glite-config-1.2.1-1"
                                        

				
RPMLIST="$RPMLIST glite-io-server-config-2.0.0-1"
                                        

				
RPMLIST="$RPMLIST glite-data-io-daemon-1.2.2-1"
                                        

				
RPMLIST="$RPMLIST glite-data-io-quanta-1.0.0-1"
                                        

				
RPMLIST="$RPMLIST glite-data-io-protocol-rfio-1.3.2-1"
                                        
						   
				
RPMLIST="$RPMLIST glite-data-io-gss-auth-1.0.0-1"
                                        
						   
				
RPMLIST="$RPMLIST glite-data-config-service-1.1.8-1"
                                        
						   
				
RPMLIST="$RPMLIST glite-data-io-authz-catalogs-1.0.1-2"
                                        		
						   		
				
RPMLIST="$RPMLIST glite-data-io-resolve-common-1.2.4-1"
                                        		
						   		
				
RPMLIST="$RPMLIST glite-data-srm-api-c-1.0.0-15"
                                        		
						   		
				
RPMLIST="$RPMLIST glite-data-io-resolve-catalogs-1.2.1-2"
                                        		
						   		
			
RPMLIST="$RPMLIST glite-data-io-base-1.3.2-1"
                                        				
						   
			
RPMLIST="$RPMLIST glite-data-io-authz-fas-1.1.3-3"
                                        				
						   						   
			
RPMLIST="$RPMLIST glite-data-catalog-interface-2.0.0-6"
                                        				
						   
			
RPMLIST="$RPMLIST glite-data-io-resolve-fireman-1.3.4-4"
                                        				
						   
			
RPMLIST="$RPMLIST glite-data-io-resolve-fr-1.3.4-3"
                                        				
						   						   
			
RPMLIST="$RPMLIST glite-data-catalog-api-c-2.0.0-2"
                                        				
						   						   
			

	# glite-security-utils-service dependencies RPMS from repository
		

	# glite-security-utils-service RPMS from repository
		

	# glite-rgma-servicetool dependencies RPMS from repository
		

	# glite-rgma-servicetool RPMS from repository
		
		
	# Uninstall all RPMS
	echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	echo x  Please wait, uninstalling the gLite I\/O Server...   x
	echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	echo
	rpm -ev $RPMLIST
	if [ "$?" == "0" ]; then
		echo
		echo Done!
	else
		echo
		echo An error occurred while removing the Glite I/O Server RPMS.
		echo Most likely one or more of the RPMS to be removed have
		echo dependent packages.
		echo Please refer to the rpm error message above for more details.
	fi
}

###############################################################################
function usage()
{
	echo 
	echo Copyright \(c\) Members of the EGEE Collaboration. 2004 
	echo See http://eu-egee.org/partners/ for details on the copyright holders
	echo For license conditions see the license file or http://eu-egee.org/license.html
	echo 
	echo glite-io-server_installer v. 2.0.0
	echo 
	echo The glite-io-server_installer installs the gLite I\/O Server
	echo 
	echo Usage: glite-io-server_installer \[-u\|-v\|--help\]
	echo -u          uninstall
	echo -v          print version
	echo --help      print script usage info
	echo 
	echo Return codes:
	echo 0 - Ok
	echo 1 - if a file could not be downloaded
	echo 
}

###############################################################################
function version
{
	echo 
	echo Copyright \(c\) Members of the EGEE Collaboration. 2004 
	echo See http://eu-egee.org/partners/ for details on the copyright holders
	echo For license conditions see the license file or http://eu-egee.org/license.html
	echo 
	echo glite-io-server_installer v. 2.0.0
	echo 
}


RPMLIST=

###############################################################################
# Main

while getopts uvh opt
do
	case $opt in
		'u') uninstall
		     exit 0	
		     ;;
		'v') version
		     exit 0	
		     ;;
		'h') usage
		     exit 0	
		     ;;
	esac
done

install

exit 0
	
