
#!/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-torque-server_installer v. 1.1.0
#
# The glite-torque-server_installer installs the torque server Element
#
# Usage: glite-torque-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 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	echo x Please wait, downloading the torque-server element... x
	echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	echo

    mkdir -p glite-torque-server
    cd glite-torque-server

	# Download global dependencies	
	
 	

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

	# Download glite-torque-server-service dependencies RPMS from repository
		
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/externals/bin/rhel30/RPMS/tclx-8.3-92.2.i386.rpm
if [ ! -f "tclx-8.3-92.2.i386.rpm" ]
then
	echo 
	echo ERROR: tclx-8.3-92.2.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST tclx-8.3-92.2.i386.rpm"
			 
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/externals/bin/rhel30/RPMS/torque-1.0.1p6-11.SL30X.st.i386.rpm
if [ ! -f "torque-1.0.1p6-11.SL30X.st.i386.rpm" ]
then
	echo 
	echo ERROR: torque-1.0.1p6-11.SL30X.st.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST torque-1.0.1p6-11.SL30X.st.i386.rpm"
			
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/externals/bin/rhel30/RPMS/torque-server-1.0.1p6-11.SL30X.st.i386.rpm
if [ ! -f "torque-server-1.0.1p6-11.SL30X.st.i386.rpm" ]
then
	echo 
	echo ERROR: torque-server-1.0.1p6-11.SL30X.st.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST torque-server-1.0.1p6-11.SL30X.st.i386.rpm"
			
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/externals/bin/rhel30/RPMS/torque-clients-1.0.1p6-11.SL30X.st.i386.rpm
if [ ! -f "torque-clients-1.0.1p6-11.SL30X.st.i386.rpm" ]
then
	echo 
	echo ERROR: torque-clients-1.0.1p6-11.SL30X.st.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST torque-clients-1.0.1p6-11.SL30X.st.i386.rpm"
			
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/externals/bin/rhel30/RPMS/torque-devel-1.0.1p6-11.SL30X.st.i386.rpm
if [ ! -f "torque-devel-1.0.1p6-11.SL30X.st.i386.rpm" ]
then
	echo 
	echo ERROR: torque-devel-1.0.1p6-11.SL30X.st.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST torque-devel-1.0.1p6-11.SL30X.st.i386.rpm"
			
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/externals/bin/rhel30/RPMS/maui-3.2.6p11-2_SL30X.i386.rpm
if [ ! -f "maui-3.2.6p11-2_SL30X.i386.rpm" ]
then
	echo 
	echo ERROR: maui-3.2.6p11-2_SL30X.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST maui-3.2.6p11-2_SL30X.i386.rpm"
			
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/externals/bin/rhel30/RPMS/maui-client-3.2.6p11-2_SL30X.i386.rpm
if [ ! -f "maui-client-3.2.6p11-2_SL30X.i386.rpm" ]
then
	echo 
	echo ERROR: maui-client-3.2.6p11-2_SL30X.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST maui-client-3.2.6p11-2_SL30X.i386.rpm"
				
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/externals/bin/rhel30/RPMS/maui-server-3.2.6p11-2_SL30X.i386.rpm
if [ ! -f "maui-server-3.2.6p11-2_SL30X.i386.rpm" ]
then
	echo 
	echo ERROR: maui-server-3.2.6p11-2_SL30X.i386.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST maui-server-3.2.6p11-2_SL30X.i386.rpm"
				
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/externals/bin/rhel30/RPMS/edg-pbs-utils-1.0.8-1_sl3.noarch.rpm
if [ ! -f "edg-pbs-utils-1.0.8-1_sl3.noarch.rpm" ]
then
	echo 
	echo ERROR: edg-pbs-utils-1.0.8-1_sl3.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST edg-pbs-utils-1.0.8-1_sl3.noarch.rpm"
			
				
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/externals/bin/rhel30/RPMS/lcg-pbs-utils-1.0.0-1.noarch.rpm
if [ ! -f "lcg-pbs-utils-1.0.0-1.noarch.rpm" ]
then
	echo 
	echo ERROR: lcg-pbs-utils-1.0.0-1.noarch.rpm could not be downloaded!
	exit 1
fi
RPMLIST="$RPMLIST lcg-pbs-utils-1.0.0-1.noarch.rpm"
			
			

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

	# Download glite-rgma-servicetool scripts from repository
		
wget -N --non-verbose http://glite.web.cern.ch/glite/packages/R1.1/R20050430/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 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	echo x Please wait, installing the torque server Element... x
	echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	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 torque server:
		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 "    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 "    b) Local configuration:"
		echo "       Create or update the torque-server configuration file"
		echo "           /opt/glite/etc/config/glite-torque-server.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 "(3) Configure and start the Torque Server"
		echo
		echo "    Run the configuration script /opt/glite/etc/config/scripts/glite-torque-server-config.py"
		echo
	else
		echo
		echo
		echo An error occurred while installing the torque-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-torque-server-service dependencies RPMS from repository
		
				
RPMLIST="$RPMLIST tclx-8.3-92.2"
					 
				
RPMLIST="$RPMLIST torque-1.0.1p6-11.SL30X.st"
					
				
RPMLIST="$RPMLIST torque-server-1.0.1p6-11.SL30X.st"
					
				
RPMLIST="$RPMLIST torque-clients-1.0.1p6-11.SL30X.st"
					
				
RPMLIST="$RPMLIST torque-devel-1.0.1p6-11.SL30X.st"
					
				
RPMLIST="$RPMLIST maui-3.2.6p11-2_SL30X"
					
				
RPMLIST="$RPMLIST maui-client-3.2.6p11-2_SL30X"
						
				
RPMLIST="$RPMLIST maui-server-3.2.6p11-2_SL30X"
						
				
RPMLIST="$RPMLIST edg-pbs-utils-1.0.8-1_sl3"
					
				
RPMLIST="$RPMLIST lcg-pbs-utils-1.0.0-1"
					
			

	# glite-torque-server-service RPMS from repository
		
				
RPMLIST="$RPMLIST glite-config-1.1.1-3"
                                        
				
				
RPMLIST="$RPMLIST glite-torque-server-config-1.1.0-2"
                                        
			

	# glite-rgma-servicetool dependencies RPMS from repository
		

	# glite-rgma-servicetool RPMS from repository
		
		
	# Uninstall all RPMS
	echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	echo x  Please wait, uninstalling the torque-server Element...     x
	echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	echo
	rpm -ev $RPMLIST
	if [ "$?" == "0" ]; then
		echo
		echo Done!
	else
		echo
		echo An error occurred while removing the torque-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-torque-server_installer v. 1.1.0
	echo 
	echo The glite-torque-server_installer installs the torque-server Element
	echo 
	echo Usage: glite-torque-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-torque-server_installer v. 1.1.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
	

