forked from anirudhgupta109/gcc-prebuilts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
relocate-sdk.sh
executable file
·47 lines (40 loc) · 1.37 KB
/
relocate-sdk.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
45
46
47
#!/bin/sh
#
if [ "$#" -ne 0 ]; then
echo "Run this script to relocate the buildroot SDK at that location"
exit 1
fi
LOCFILE="share/buildroot/sdk-location"
FILEPATH="$(readlink -f "$0")"
NEWPATH="$(dirname "${FILEPATH}")"
cd "${NEWPATH}"
if [ ! -r "${LOCFILE}" ]; then
echo "Previous location of the buildroot SDK not found!"
exit 1
fi
OLDPATH="$(cat "${LOCFILE}")"
if [ "${NEWPATH}" = "${OLDPATH}" ]; then
echo "This buildroot SDK has already been relocated!"
exit 0
fi
# Check if the path substitution does work properly, e.g. a tree
# "/a/b/c" copied into "/a/b/c/a/b/c/" would not be allowed.
newpath="$(sed -e "s|${OLDPATH}|${NEWPATH}|g" "${LOCFILE}")"
if [ "${NEWPATH}" != "${newpath}" ]; then
echo "Something went wrong with substituting the path!"
echo "Please choose another location for your SDK!"
exit 1
fi
echo "Relocating the buildroot SDK from ${OLDPATH} to ${NEWPATH} ..."
# Make sure file uses the right language
export LC_ALL=C
# Replace the old path with the new one in all text files
grep -lr "${OLDPATH}" . | while read -r FILE ; do
if file -b --mime-type "${FILE}" | grep -q '^text/' && [ "${FILE}" != "${LOCFILE}" ]
then
sed -i "s|${OLDPATH}|${NEWPATH}|g" "${FILE}"
fi
done
# At the very end, we update the location file to not break the
# SDK if this script gets interruted.
sed -i "s|${OLDPATH}|${NEWPATH}|g" ${LOCFILE}