#!/bin/sh -e
#
# $Id: sisyphus_update_classic,v 1.4 2005/07/01 14:59:29 ldv Exp $
#
# Copyright (C) 2003-2005  Stanislav Ievlev <inger@altlinux.org>,
#                          Dmitry V. Levin <ldv@altlinux.org>,
#                          Alexey Gladkov <legion@altlinux.org>
# 
# sisyphus_update_classic script.
#
# This file 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
#

. /etc/sisyphus/config

cd "$PREFIX"

make_links()
{
	local source="$1"
	shift
	local target="$1"
	shift

	pushd "$PREFIX/$source" >/dev/null

	local rel=`relative "$PREFIX/$source" "$PREFIX/$target"`

	local f
	for f in *.rpm; do
		[ -f "$f" ] || continue
		[ ! -L "$PREFIX/$target/$f" ] || continue
		ln -s "$rel/$f" "$PREFIX/$target/"
	done
	popd >/dev/null
}

update_bin()
{
	local arch="$1" && shift || return 1
	find "$arch"/RPMS.classic/ -type l -delete

	local c
	for c in $LINKONLY_COMPONENTS; do
		make_links "$arch/RPMS.$c" "$arch/RPMS.classic/"
	done
}

update_src()
{
	local arch="$1" && shift || return 1
	find "$arch"/SRPMS.classic/ -type l -delete

	local rep
	for rep in $SRC_REPOSITORIES; do
		make_links "$arch/$rep" "$arch/SRPMS.classic/"
	done
}

for arch in $ARCHITECTURES; do
  update_bin "$arch"
  update_src "$arch"
done
