
#!/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-lfc-oracle_installer v. 1.3.8
#
# The glite-lfc-oracle_installer installs the gLite lfc oracle
#
# Usage: glite-lfc-oracle_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 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
	echo "x Please wait, downloading the gLite lfc-oracle server ... x"
	echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
	echo

        mkdir -p glite-lfc-oracle
        cd glite-lfc-oracle

	# Download global dependencies	
	
	
	
	# Download glite-lfc-oracle-service scripts from repository
		
		
	# Download glite-lfc-oracle-service dependencies RPMS from repository
		
				
wget -N -nv 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 -nv 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 -nv http://glite.web.cern.ch/glite/packages/externals/bin/rhel30/RPMS/lcg-dm-common-1.3.8-1_sl3.i386.rpm
if [ ! -f "lcg-dm-common-1.3.8-1_sl3.i386.rpm" ]
then
	echo 
	echo ERROR: lcg-dm-common-1.3.8-1_sl3.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST lcg-dm-common-1.3.8-1_sl3.i386.rpm"
							  

	  			
wget -N -nv http://glite.web.cern.ch/glite/packages/externals/bin/rhel30/RPMS/LFC-client-1.3.8-1sec_sl3.i386.rpm
if [ ! -f "LFC-client-1.3.8-1sec_sl3.i386.rpm" ]
then
	echo 
	echo ERROR: LFC-client-1.3.8-1sec_sl3.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST LFC-client-1.3.8-1sec_sl3.i386.rpm"
							  

	  			
wget -N -nv http://glite.web.cern.ch/glite/packages/externals/bin/rhel30/RPMS/LFC-server-oracle-1.3.8-1sec_sl3.i386.rpm
if [ ! -f "LFC-server-oracle-1.3.8-1sec_sl3.i386.rpm" ]
then
	echo 
	echo ERROR: LFC-server-oracle-1.3.8-1sec_sl3.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST LFC-server-oracle-1.3.8-1sec_sl3.i386.rpm"
							  

	  			
wget -N -nv http://glite.web.cern.ch/glite/packages/externals/bin/rhel30/RPMS/LFC-interfaces-1.3.8-1_sl3.i386.rpm
if [ ! -f "LFC-interfaces-1.3.8-1_sl3.i386.rpm" ]
then
	echo 
	echo ERROR: LFC-interfaces-1.3.8-1_sl3.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST LFC-interfaces-1.3.8-1_sl3.i386.rpm"
							  

				
wget -N -nv http://glite.web.cern.ch/glite/packages/externals/bin/rhel30/RPMS/CGSI_gSOAP_2.6-1.1.9-1.slc3.i386.rpm
if [ ! -f "CGSI_gSOAP_2.6-1.1.9-1.slc3.i386.rpm" ]
then
	echo 
	echo ERROR: CGSI_gSOAP_2.6-1.1.9-1.slc3.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST CGSI_gSOAP_2.6-1.1.9-1.slc3.i386.rpm"
			

				
wget -N -nv http://glite.web.cern.ch/glite/packages/externals/bin/rhel30/RPMS/lcg-info-templates-1.0.13-1.noarch.rpm
if [ ! -f "lcg-info-templates-1.0.13-1.noarch.rpm" ]
then
	echo 
	echo ERROR: lcg-info-templates-1.0.13-1.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST lcg-info-templates-1.0.13-1.noarch.rpm"
			

                
wget -N -nv http://glite.web.cern.ch/glite/packages/externals/bin/rhel30/RPMS/lcg-info-generic-1.0.20-1_sl3.noarch.rpm
if [ ! -f "lcg-info-generic-1.0.20-1_sl3.noarch.rpm" ]
then
	echo 
	echo ERROR: lcg-info-generic-1.0.20-1_sl3.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST lcg-info-generic-1.0.20-1_sl3.noarch.rpm"
			
			

	# Download glite-lfc-oracle-service RPMS from repository
		
			    
wget -N -nv http://glite.web.cern.ch/glite/packages/R1.5/R20051130/bin/rhel30/noarch/RPMS/glite-config-1.6.22-1.noarch.rpm
if [ ! -f "glite-config-1.6.22-1.noarch.rpm" ]
then
	echo 
	echo ERROR: glite-config-1.6.22-1.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-config-1.6.22-1.noarch.rpm"
			
			    		
                
wget -N -nv http://glite.web.cern.ch/glite/packages/R1.5/R20051130/bin/rhel30/noarch/RPMS/glite-lfc-oracle-config-1.3.8-1.noarch.rpm
if [ ! -f "glite-lfc-oracle-config-1.3.8-1.noarch.rpm" ]
then
	echo 
	echo ERROR: glite-lfc-oracle-config-1.3.8-1.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST glite-lfc-oracle-config-1.3.8-1.noarch.rpm"
			

			
	
	# Download glite-security-utils scripts from repository
		
wget -N -nv http://glite.web.cern.ch/glite/packages/R1.5/R20051130/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.5/R20051130/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-rgma-gin scripts from repository
		
wget -N -nv http://glite.web.cern.ch/glite/packages/R1.5/R20051130/installers/glite-rgma-gin_installer.sh
if [ ! -f "glite-rgma-gin_installer.sh" ]
then
	echo 
	echo ERROR: glite-rgma-gin_installer.sh could not be downloaded!
	exit 1
fi
chmod u+x glite-rgma-gin_installer.sh
SCRIPTLIST="$SCRIPTLIST ./glite-rgma-gin_installer.sh"
			
		
	# Download glite-rgma-gin dependencies RPMS from repository
		

	# Download glite-rgma-gin RPMS from repository
		
	
	# Download and install subservices
	parseScriptList	
	
	# Install all RPMS
	echo
	echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
	echo "x Please wait, installing the gLite lfc-oracle server ... x"
	echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
	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 starting the lfc-oracle server, 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 lfc-oracle server configuration file"
	    echo "         /opt/glite/etc/config/glite-lfc.cfg.xml"
	    echo "    and the general glite configuration file"
	    echo "         /opt/glite/etc/config/glite-global.cfg.xml"
	    echo "    Templates are provided in /opt/glite/etc/config/templates/"
	    echo "    Make sure that all parameters 'changeme' are properly set in the files."
	    echo
	    echo "(3) Configure and start server"
	    echo
	    echo "    Run the configuration script /opt/glite/etc/config/scripts/glite-lfc-config.py --configure"
		echo "    Start the services /opt/glite/etc/config/scripts/glite-lfc-config.py --start"
	    echo "    The script will completely configure and start the lfc server."
	    echo
	    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
	else
		echo
		echo
		echo An error occurred while installing the lfc-oracle 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-lfc-oracle-service dependencies RPMS from repository
		
				
RPMLIST="$RPMLIST gpt-VDT1.2.2rh9-1"
					

                
RPMLIST="$RPMLIST vdt_globus_essentials-VDT1.2.2rh9-1"
					

	  			
RPMLIST="$RPMLIST lcg-dm-common-1.3.8-1_sl3"
									  

	  			
RPMLIST="$RPMLIST LFC-client-1.3.8-1sec_sl3"
									  

	  			
RPMLIST="$RPMLIST LFC-server-oracle-1.3.8-1sec_sl3"
									  

	  			
RPMLIST="$RPMLIST LFC-interfaces-1.3.8-1_sl3"
									  

				
RPMLIST="$RPMLIST CGSI_gSOAP_2.6-1.1.9-1.slc3"
					

				
RPMLIST="$RPMLIST lcg-info-templates-1.0.13-1"
					

                
RPMLIST="$RPMLIST lcg-info-generic-1.0.20-1_sl3"
					
			

	# glite-lfc-oracle-service RPMS from repository
		
			    
RPMLIST="$RPMLIST glite-config-1.6.22-1"
                                        
			    		
                
RPMLIST="$RPMLIST glite-lfc-oracle-config-1.3.8-1"
                                        

			

	# glite-security-utils dependencies RPMS from repository
		

	# glite-security-utils RPMS from repository
		

	# glite-rgma-servicetool dependencies RPMS from repository
		

	# glite-rgma-servicetool RPMS from repository
		

	# glite-rgma-gin dependencies RPMS from repository
		

	# glite-rgma-gin RPMS from repository
		
		
	# Uninstall all RPMS
	echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
	echo "x  Please wait, uninstalling the gLite lfc oracle ...   x"
	echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
	echo
	rpm -ev $RPMLIST
	if [ "$?" == "0" ]; then
		echo
		echo Done!
	else
		echo
		echo An error occurred while removing the lfc oracle 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-lfc-oracle_installer v. 1.3.8
	echo 
	echo The glite-lfc-oracle_installer installs the gLite RGMA server
	echo 
	echo Usage: glite-lfc-oracle_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-lfc-oracle_installer v. 1.3.8
	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
	

