
#!/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-file-transfer-service_installer v. 3.0.1
#
# The glite-file-transfer-service installs the gLite file transfer service Service
#
# Usage: glite-file-transfer-service [-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 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 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	echo x Please wait, downloading the gLite File Transfer Service... x
	echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	echo

        mkdir -p glite-file-transfer-service
        cd glite-file-transfer-service

	# Download global dependencies	
	
	

		# Download glite-data-transfer-fps scripts from repository
			

		# Download glite-data-transfer-fps dependencies RPMS from repository
		
				
wget -N -nv http://glite.web.cern.ch/glite/packages/externals/bin/rhel30/RPMS/tomcat5-5.0.28-11_EGEE.noarch.rpm
if [ ! -f "tomcat5-5.0.28-11_EGEE.noarch.rpm" ]
then
	echo 
	echo ERROR: tomcat5-5.0.28-11_EGEE.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST tomcat5-5.0.28-11_EGEE.noarch.rpm"
			 		
			
			

	# Download glite-data-transfer-fps RPMS from repository
		
                
wget -N -nv http://glite.web.cern.ch/glite/packages/R1.4/R20050916/bin/rhel30/noarch/RPMS/glite-file-transfer-service-config-3.0.1-2.noarch.rpm
if [ ! -f "glite-file-transfer-service-config-3.0.1-2.noarch.rpm" ]
then
	echo 
	echo ERROR: glite-file-transfer-service-config-3.0.1-2.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-file-transfer-service-config-3.0.1-2.noarch.rpm"
			
                        
			    
wget -N -nv http://glite.web.cern.ch/glite/packages/R1.4/R20050916/bin/rhel30/noarch/RPMS/glite-config-1.4.11-1.noarch.rpm
if [ ! -f "glite-config-1.4.11-1.noarch.rpm" ]
then
	echo 
	echo ERROR: glite-config-1.4.11-1.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-config-1.4.11-1.noarch.rpm"
			

                
wget -N -nv http://glite.web.cern.ch/glite/packages/R1.4/R20050916/bin/rhel30/noarch/RPMS/glite-security-util-java-1.1.3-2.noarch.rpm
if [ ! -f "glite-security-util-java-1.1.3-2.noarch.rpm" ]
then
	echo 
	echo ERROR: glite-security-util-java-1.1.3-2.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-security-util-java-1.1.3-2.noarch.rpm"
			
            							
            	
wget -N -nv http://glite.web.cern.ch/glite/packages/R1.4/R20050916/bin/rhel30/noarch/RPMS/glite-security-trustmanager-1.7.3-1.noarch.rpm
if [ ! -f "glite-security-trustmanager-1.7.3-1.noarch.rpm" ]
then
	echo 
	echo ERROR: glite-security-trustmanager-1.7.3-1.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-security-trustmanager-1.7.3-1.noarch.rpm"
			
            			
         	    
wget -N -nv http://glite.web.cern.ch/glite/packages/R1.4/R20050916/bin/rhel30/noarch/RPMS/glite-data-transfer-interface-3.1.0-3.noarch.rpm
if [ ! -f "glite-data-transfer-interface-3.1.0-3.noarch.rpm" ]
then
	echo 
	echo ERROR: glite-data-transfer-interface-3.1.0-3.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-data-transfer-interface-3.1.0-3.noarch.rpm"
					
			    		
			    
wget -N -nv http://glite.web.cern.ch/glite/packages/R1.4/R20050916/bin/rhel30/noarch/RPMS/glite-data-catalog-api-java-2.0.0-6.noarch.rpm
if [ ! -f "glite-data-catalog-api-java-2.0.0-6.noarch.rpm" ]
then
	echo 
	echo ERROR: glite-data-catalog-api-java-2.0.0-6.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-data-catalog-api-java-2.0.0-6.noarch.rpm"
			
            			
            	
wget -N -nv http://glite.web.cern.ch/glite/packages/R1.4/R20050916/bin/rhel30/noarch/RPMS/glite-data-transfer-fts-3.1.0-17.noarch.rpm
if [ ! -f "glite-data-transfer-fts-3.1.0-17.noarch.rpm" ]
then
	echo 
	echo ERROR: glite-data-transfer-fts-3.1.0-17.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-data-transfer-fts-3.1.0-17.noarch.rpm"
			            					

			    
wget -N -nv http://glite.web.cern.ch/glite/packages/R1.4/R20050916/bin/rhel30/noarch/RPMS/glite-data-common-1.2.2-1.noarch.rpm
if [ ! -f "glite-data-common-1.2.2-1.noarch.rpm" ]
then
	echo 
	echo ERROR: glite-data-common-1.2.2-1.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-data-common-1.2.2-1.noarch.rpm"
			
		
            

		# Download glite-security-utils scripts from repository
		
wget -N -nv http://glite.web.cern.ch/glite/packages/R1.4/R20050916/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
		

		# Download glite-rgma-servicetool scripts from repository
		
wget -N -nv http://glite.web.cern.ch/glite/packages/R1.4/R20050916/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 glite-service-discovery scripts from repository
		
wget -N -nv http://glite.web.cern.ch/glite/packages/R1.4/R20050916/installers/glite-service-discovery_installer.sh
if [ ! -f "glite-service-discovery_installer.sh" ]
then
	echo 
	echo ERROR: glite-service-discovery_installer.sh could not be downloaded!
	exit 1
fi
chmod u+x glite-service-discovery_installer.sh
SCRIPTLIST="$SCRIPTLIST ./glite-service-discovery_installer.sh "
				

		# Download glite-service-discovery dependencies RPMS from repository
		

	# Download glite-service-discovery RPMS from repository
		

		# Download glite-file-transfer-service-client scripts from repository
		
wget -N -nv http://glite.web.cern.ch/glite/packages/R1.4/R20050916/installers/glite-file-transfer-service-client_installer.sh
if [ ! -f "glite-file-transfer-service-client_installer.sh" ]
then
	echo 
	echo ERROR: glite-file-transfer-service-client_installer.sh could not be downloaded!
	exit 1
fi
chmod u+x glite-file-transfer-service-client_installer.sh
SCRIPTLIST="$SCRIPTLIST ./glite-file-transfer-service-client_installer.sh "
				

		# Download glite-file-transfer-service-client dependencies RPMS from repository
		

	# Download glite-file-transfer-service-client RPMS from repository
		
		
	# Install all RPMS
	echo
	echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	echo x Please wait, installing the gLite File Transfer Service... x
	echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	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!
		echo
		echo The default installation is to \$GLITE_LOCATION=/opt/glite
		echo
		echo Before starting the file transfer service  service, please do the following steps:
		echo
		echo "(1) Install Java"
		echo
		echo "    Due to license restrictions we cannot redistribute Java."
		echo "    If you have not installed Java, please install Java 1.4.2."
		echo "    You can download it from http://java.sun.com/."
		echo
		echo "(2) Create configuration"
		echo
		echo "    Create or update the file transfer service configuration file"
		echo "          /opt/glite/etc/config/glite-file-transfer-service.cfg.xml"
		echo "    the R-GMA common configuration file"
		echo "         \$GLITE_LOCATION/etc/config/glite-rgma-common.cfg.xml ,"
		echo "    the R-GMA servicetool configuration file"
		echo "         \$GLITE_LOCATION/etc/config/glite-rgma-servicetool.cfg.xml ,"
		echo "    the security utilities configuration file"
		echo "         \$GLITE_LOCATION/etc/config/glite-security-utils.cfg.xml"
		echo "    and the general glite configuration file"
		echo "         \$GLITE_LOCATION/etc/config/glite-global.cfg.xml"
		echo "    Templates are provided in \$GLITE_LOCATION/etc/config/templates/."
		echo "    Copy these templates if they do not exist yet to \$GLITE_LOCATION/etc/config/"
		echo "    and set the configuration values accordingly."
		echo "    Make sure that all parameters 'changeme' are properly set in the files."
		echo
		echo "(3) Configure and start the file transfer service service"
		echo
		echo "    Run the configuration script \$GLITE_LOCATION/etc/config/scripts/glite-file-transfer-service-config.py"
		echo "    The script will completely configure and start the file transfer service."
		echo
	else
		echo
		echo An error occurred while installing the file transfer service 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 For more information please 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-data-transfer-fps scripts from repository
			

		# glite-data-transfer-fps dependencies RPMS from repository
		
				
RPMLIST="$RPMLIST tomcat5-5.0.28-11_EGEE"
					 		
			
			

		# glite-data-transfer-fps RPMS from repository
		
                
RPMLIST="$RPMLIST glite-file-transfer-service-config-3.0.1-2"
                                        
                        
			    
RPMLIST="$RPMLIST glite-config-1.4.11-1"
                                        

                
RPMLIST="$RPMLIST glite-security-util-java-1.1.3-2"
                                        
            							
            	
RPMLIST="$RPMLIST glite-security-trustmanager-1.7.3-1"
                                        
            			
         	    
RPMLIST="$RPMLIST glite-data-transfer-interface-3.1.0-3"
                                        		
			    		
			    
RPMLIST="$RPMLIST glite-data-catalog-api-java-2.0.0-6"
                                        
            			
            	
RPMLIST="$RPMLIST glite-data-transfer-fts-3.1.0-17"
                                                    					

			    
RPMLIST="$RPMLIST glite-data-common-1.2.2-1"
                                        
		
            
	
		# Download glite-security-utils scripts from repository
		
wget -N -nv http://glite.web.cern.ch/glite/packages/R1.4/R20050916/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
		
	
		# Download glite-rgma-servicetool scripts from repository
		
wget -N -nv http://glite.web.cern.ch/glite/packages/R1.4/R20050916/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 "
				

		# glite-rgma-servicetool dependencies RPMS from repository
		

		# glite-rgma-servicetool RPMS from repository
		
	
		# Download glite-service-discovery scripts from repository
		
wget -N -nv http://glite.web.cern.ch/glite/packages/R1.4/R20050916/installers/glite-service-discovery_installer.sh
if [ ! -f "glite-service-discovery_installer.sh" ]
then
	echo 
	echo ERROR: glite-service-discovery_installer.sh could not be downloaded!
	exit 1
fi
chmod u+x glite-service-discovery_installer.sh
SCRIPTLIST="$SCRIPTLIST ./glite-service-discovery_installer.sh "
				

		# glite-service-discovery dependencies RPMS from repository
		

		# glite-service-discovery RPMS from repository
		
	
		# Download glite-file-transfer-service-client scripts from repository
		
wget -N -nv http://glite.web.cern.ch/glite/packages/R1.4/R20050916/installers/glite-file-transfer-service-client_installer.sh
if [ ! -f "glite-file-transfer-service-client_installer.sh" ]
then
	echo 
	echo ERROR: glite-file-transfer-service-client_installer.sh could not be downloaded!
	exit 1
fi
chmod u+x glite-file-transfer-service-client_installer.sh
SCRIPTLIST="$SCRIPTLIST ./glite-file-transfer-service-client_installer.sh "
				

		# glite-file-transfer-service-client dependencies RPMS from repository
		

		# glite-file-transfer-service-client RPMS from repository
		
		
	# Uninstall all RPMS
	echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	echo x  Please wait, uninstalling the gLite file transfer service...   x
	echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	echo
	rpm -ev $RPMLIST
	if [ "$?" == "0" ]; then
		echo
		echo Done!
	else
		echo
		echo An error occurred while removing the R-GMA 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-file-transfer-service_installer v. 3.0.1
	echo 
	echo The glite-file-transfer-service installs the gLite file transfer service
	echo 
	echo Usage: glite-file-transfer-service_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-file-transfer-service_installer v. 3.0.1
	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
	
