#!/bin/sh
# vim:set sw=4 ts=4:
#
# $Id: update_rpms,v 1.5 2005/04/11 14:14:39 fabian Exp $
#
#############################################################################
#
# ALICE
# Automatic Linux Installation and Configuration Environment
#
# Copyright (c) 2000-2002 SuSE Linux Solutions AG, Eschborn, Germany
#               2002-2004 SuSE Linux AG, Eschborn, Germany
#               2005           SUSE GmbH, Nuernberg, Germany
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#############################################################################
#
# Author: Juergen Henge-Ernst
#
#############################################################################
#
# update_rpms
# Updates RPMs of the system, which contain newer versions or security fixes
# TODO: Check, wether we can use that together with you_mirror
# TODO: Implement http:// and ftp:// client (use GET or something like that)
#
# Sections: sys
# Tags:     SYS_UPDATE_RPM_LOCATION
#
#############################################################################
#
# Notes:
#     TAG: SYS_UPDATE_RPM_LOCATION
#     VALUE: nsf://server/path
#            file:[//]/path
#

test -n "$alice_dir" || alice_dir="/usr/lib/alice2/"
export alice_dir
usage()
{
   cat <<EOF
usage: $0 -h | --help | -?

EOF
}

while [ $# -gt 0 ]
do
   case $1 in
       -h | --help | -? ) usage
                          exit 1
                          ;;
       -fqhn | --fqhn ) export fqhn=$2; shift
            ;;

   esac
   shift
done   

. $alice_dir/lib/alicerc

WELCOME

#
############################################################################
#
GET_CONFIGURATION --require sys $CFG_DEBUG
if [ -n "${SYS_UPDATE_RPM_LOCATION}" ]; then

	# Get the files
	LOCAL_DIR="/tmp/update_rpm.$$"
	method=${SYS_UPDATE_RPM_LOCATION%%:*}
	method=$(echo $method | tr '[:lower:]' '[:upper:]')
	URL=${SYS_UPDATE_RPM_LOCATION#*:}
	URL=${URL#//}
	case $method in
	NFS ) # //server/path
		url_server=${URL%%/*}
		url_path="/${URL#*/}"
		mkdir $LOCAL_DIR
		mount $url_server:$url_path $LOCAL_DIR
		;;
	FILE ) # ///path
		url_path="/${URL#*/}"
		ln -s $url_path $LOCAL_DIR
		;;
	esac

	# Find the packages and update them
	if [ -e $LOCAL_DIR ]
	then
		cd $LOCAL_DIR
		find -type f -name "*.rpm" ! -name "k_*" ! -name "*src.rpm" | grep -v "./kernel/" | while read line
		do
			rpm --nodeps -Fhv $line
		done
		cd -
	else
		echo "Can not change to directory $LOCAL_DIR"
	fi
	#
	# Clean up the temporary files
	#
	case $method in
	NFS ) # //server/path
		umount $LOCAL_DIR
		rmdir $LOCAL_DIR
		;;
	FILE ) # ///path
		rm $LOCAL_DIR
		;;
	esac
fi
#
############################################################################
# Thats all
GOOD_BYE 
