#! /bin/bash
set -e
# Fix absolute symlinks to RPi sysroot
# Run script in raspbian root
PREF="/lib/arm-linux-gnueabihf"
DIR="usr/lib/arm-linux-gnueabihf/"
#"/soft/pi/lib/arm-linux-gnueabihf/"
#NEWDIR="/soft/picross/pitools/arm-bcm2708/arm-linux-gnueabihf/arm-linux-gnueabihf/sysroot/lib/"

PLEN=`expr length "$PREF"`
for f in `find $DIR -maxdepth 1 -type l`
do
	L=`readlink $f`
	D=`expr substr "$L" 1 $PLEN`
	if [[ "$D" = "$PREF" ]]
	then 
		echo "Relink $f"
		ln -sf "../../..$L" "$f"
	fi
done
