#!/bin/sh -e
#
# $Id: sisyphus_migration_hack,v 1.3 2005/07/01 14:59:29 ldv Exp $
#
# Copyright (C) 2005  Alexey Gladkov <legion@altlinux.org>
# 
# sisyphus_migration_hack 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"

mklinks()
{
    local s="$1" && shift
    local d="$1" && shift

    full_s=`readlink -ev "$s"`
    full_d=`readlink -ev "$d"`

    for f in "$s"/*.rpm; do
	[ "$f" != "$s/*.rpm" ] || break
	[ ! -f "$d/${f##*/}" ] || continue
	r=`relative "$full_s" "$full_d/"`
	ln -s "$r/${f##*/}" "$full_d/" || rc=1
    done
}

s_arch='noarch i386'
d_arch=i586
rc=0
for comp in $ALL_COMPONENTS; do 
	for s in $s_arch; do
		echo "linking $s/RPMS.$comp into $d_arch/RPMS.$comp"
		mklinks "$s/RPMS.$comp" "$d_arch/RPMS.$comp"
	done
done
exit $rc
