
#!/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-rgma-servicetool_installer v. 4.1.5
#
# The glite-rgma-servicetool_installer installs the gLite R-GMA servicetool
#
# Usage: glite-rgma-servicetool_installer [-u|-v|-s|--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 SCRIPTLIST to execute all scripts
function parseScriptList()
{
        for i in $SCRIPTLIST
        do
        		if [ "$INSTALL" = "true" ]; then
	                $i
	            else
	            	$i -u
	            fi
        done
}


#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
}


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

	INSTALL=true

	version
	echo
	echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
	echo "x Please wait, downloading the gLite R-GMA servicetool ... x"
	echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
	echo

        mkdir -p glite-rgma-servicetool
        cd glite-rgma-servicetool

	# Download global dependencies	
	
 	

		# Download glite-rgma-servicetool scripts from repository
			
		
		# Download glite-rgma-servicetool dependencies RPMS from repository
		
				
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/externals/bin/rhel30/RPMS/glite-essentials-java-1.2.0-2_EGEE.noarch.rpm
if [ ! -f "glite-essentials-java-1.2.0-2_EGEE.noarch.rpm" ]
then
	echo 
	echo ERROR: glite-essentials-java-1.2.0-2_EGEE.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-essentials-java-1.2.0-2_EGEE.noarch.rpm"
			 
			

	# Download glite-rgma-servicetool RPMS from repository
		

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

				
                
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.0/R20050331/bin/rhel30/noarch/RPMS/glite-rgma-common-config-4.2.0-1.noarch.rpm
if [ ! -f "glite-rgma-common-config-4.2.0-1.noarch.rpm" ]
then
	echo 
	echo ERROR: glite-rgma-common-config-4.2.0-1.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-rgma-common-config-4.2.0-1.noarch.rpm"
			
                	
                
                
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.0/R20050331/bin/rhel30/noarch/RPMS/glite-rgma-servicetool-config-4.1.5-1.noarch.rpm
if [ ! -f "glite-rgma-servicetool-config-4.1.5-1.noarch.rpm" ]
then
	echo 
	echo ERROR: glite-rgma-servicetool-config-4.1.5-1.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-rgma-servicetool-config-4.1.5-1.noarch.rpm"
			
					
								                
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.0/R20050331/bin/rhel30/noarch/RPMS/glite-rgma-servicetool-4.1.14-3.noarch.rpm
if [ ! -f "glite-rgma-servicetool-4.1.14-3.noarch.rpm" ]
then
	echo 
	echo ERROR: glite-rgma-servicetool-4.1.14-3.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-rgma-servicetool-4.1.14-3.noarch.rpm"
			
					
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.0/R20050331/bin/rhel30/noarch/RPMS/glite-rgma-api-java-4.1.3-1.noarch.rpm
if [ ! -f "glite-rgma-api-java-4.1.3-1.noarch.rpm" ]
then
	echo 
	echo ERROR: glite-rgma-api-java-4.1.3-1.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-rgma-api-java-4.1.3-1.noarch.rpm"
			
					
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.0/R20050331/bin/rhel30/noarch/RPMS/glite-rgma-base-4.1.12-1.noarch.rpm
if [ ! -f "glite-rgma-base-4.1.12-1.noarch.rpm" ]
then
	echo 
	echo ERROR: glite-rgma-base-4.1.12-1.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-rgma-base-4.1.12-1.noarch.rpm"
			
					
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.0/R20050331/bin/rhel30/noarch/RPMS/glite-rgma-stubs-servlet-java-4.1.6-1.noarch.rpm
if [ ! -f "glite-rgma-stubs-servlet-java-4.1.6-1.noarch.rpm" ]
then
	echo 
	echo ERROR: glite-rgma-stubs-servlet-java-4.1.6-1.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-rgma-stubs-servlet-java-4.1.6-1.noarch.rpm"
			
					
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.0/R20050331/bin/rhel30/noarch/RPMS/glite-security-trustmanager-1.6.4-1.noarch.rpm
if [ ! -f "glite-security-trustmanager-1.6.4-1.noarch.rpm" ]
then
	echo 
	echo ERROR: glite-security-trustmanager-1.6.4-1.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-security-trustmanager-1.6.4-1.noarch.rpm"
			
				
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.0/R20050331/bin/rhel30/noarch/RPMS/glite-security-util-java-1.0.0-2.noarch.rpm
if [ ! -f "glite-security-util-java-1.0.0-2.noarch.rpm" ]
then
	echo 
	echo ERROR: glite-security-util-java-1.0.0-2.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-security-util-java-1.0.0-2.noarch.rpm"
				
											
			

		# Download glite-security-utils scripts from repository
		
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.0/R20050331/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 dependencies RPMS from repository
		

	# Download glite-security-utils RPMS from repository
		
		
	# Install all RPMS
	echo
	echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
	echo "x Please wait, installing the gLite R-GMA servicetool ... x"
	echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
	echo
	parseScriptList
	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!
	else
		echo
		echo An error occurred while installing the R-GMA servicetool 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.
		echo
	fi	
	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	
	
 	

		# Download glite-rgma-servicetool scripts from repository
		

	# glite-rgma-servicetool dependencies RPMS from repository
		
				
				
RPMLIST="$RPMLIST glite-essentials-java-1.2.0-2_EGEE"
					 
			

	# glite-rgma-servicetool RPMS from repository
		

					
				
						
				
RPMLIST="$RPMLIST glite-config-1.0.1-1"
                                        

				
                
RPMLIST="$RPMLIST glite-rgma-common-config-4.2.0-1"
                                        
                	
                
                
RPMLIST="$RPMLIST glite-rgma-servicetool-config-4.1.5-1"
                                        
					
								                
				
RPMLIST="$RPMLIST glite-rgma-servicetool-4.1.14-3"
                                        
					
				
RPMLIST="$RPMLIST glite-rgma-api-java-4.1.3-1"
                                        
					
				
RPMLIST="$RPMLIST glite-rgma-base-4.1.12-1"
                                        
					
				
RPMLIST="$RPMLIST glite-rgma-stubs-servlet-java-4.1.6-1"
                                        
					
				
RPMLIST="$RPMLIST glite-security-trustmanager-1.6.4-1"
                                        
				
				
RPMLIST="$RPMLIST glite-security-util-java-1.0.0-2"
                                        	
											
			

		# Download glite-security-utils scripts from repository
		
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.0/R20050331/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 "
			

	# glite-security-utils dependencies RPMS from repository
		

	# glite-security-utils RPMS from repository
		
		
	# Uninstall all RPMS
	echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
	echo "x  Please wait, uninstalling the gLite R-GMA servicetool ...   x"
	echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
	echo
	rpm -ev $RPMLIST
	if [ "$?" == "0" ]; then
		echo
		echo Done!
	else
		echo
		echo An error occurred while removing the R-GMA servicetool 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-rgma-servicetool_installer v. 4.1.5
	echo 
	echo The glite-rgma-servicetool_installer installs the gLite R-GMA servicetool
	echo 
	echo Usage: glite-rgma-servicetool_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-rgma-servicetool_installer v. 4.1.5
	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
	
