forked from twobitcircus/rpi-build-and-boot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fixQualifiedLibraryPaths.sh
executable file
·44 lines (36 loc) · 1.03 KB
/
fixQualifiedLibraryPaths.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
#This script is ugly, feel free to fix it
if [ "$#" -ne 2 ]; then
echo "usage ./cmd target-rootfs target-toolchain"
exit -1
fi
#passed args
ROOTFS=$1
TOOLCHAIN=$2
if [ -x $TOOLCHAIN ]; then
echo "Passed valid toolchain"
MACHINE=$($TOOLCHAIN -dumpmachine)
DEB_MULTI_ARCH_MADNESS=$ROOTFS/usr/lib/$MACHINE
fi
CURRENTDIR=$PWD
function adjustSymLinks
{
echo "Adjusting the symlinks in $1 to be relative"
cd $1
find . -maxdepth 1 -type l | while read i;
do qualifies=$(file $i | sed -e "s/.*\`\(.*\)'/\1/g" | grep ^/lib)
if [ -n "$qualifies" ]; then
newPath=$(file $i | sed -e "s/.*\`\(.*\)'/\1/g" | sed -e "s,\`,,g" | sed -e "s,',,g" | sed -e "s,^/lib,$2/lib,g");
echo $i
echo $newPath;
sudo rm $i;
sudo ln -s $newPath $i;
fi
done
}
adjustSymLinks $ROOTFS/usr/lib "../.."
if [ -n "$DEB_MULTI_ARCH_MADNESS" -a -d "$DEB_MULTI_ARCH_MADNESS" ]; then
echo "Debian multiarch dir exists, adjusting"
adjustSymLinks $DEB_MULTI_ARCH_MADNESS "../../.."
fi
cd $CURRENTDIR