#!/bin/sh -e

[ x"$1" = x ] && {
	print "E: You loose. Need the package build directory.\n"
	exit 1
}

[ x"$2" = x ] && {
	print "E: You loose. Need the subdirectory with symlinks to check up.\n"
	exit 1
}

DEB_BLD_DIR=$1
CRIS_CHK=$2

for L in $(find ${DEB_BLD_DIR}${CRIS_CHK} -type l | sort)
do
	L1=$(readlink ${L})
	echo ${L1} | grep ${CRIS_CHK} > /dev/null && {
		L2=$(echo ${L1} | sed -e "s#^.*\(${CRIS_CHK}.*$\)#\1#")
		[ "${L1}" = "${L2}" ] || {
			rm -f ${L}
			ln -s ${L2} ${L}
			printf "${L} relinked\n"
			printf "\tfrom: ${L1}\n"
			printf "\tto:	${L2}\n"
		}
	}
done

exit 0
