1#!/bin/sh 2# 3if [ "$#" -ne 0 ]; then 4 echo "Run this script to relocate the buildroot SDK at that location" 5 exit 1 6fi 7 8LOCFILE="share/buildroot/sdk-location" 9FILEPATH="$(readlink -f "$0")" 10NEWPATH="$(dirname "${FILEPATH}")" 11 12cd "${NEWPATH}" 13if [ ! -r "${LOCFILE}" ]; then 14 echo "Previous location of the buildroot SDK not found!" 15 exit 1 16fi 17OLDPATH="$(cat "${LOCFILE}")" 18 19if [ "${NEWPATH}" = "${OLDPATH}" ]; then 20 echo "This buildroot SDK has already been relocated!" 21 exit 0 22fi 23 24# Check if the path substitution does work properly, e.g. a tree 25# "/a/b/c" copied into "/a/b/c/a/b/c/" would not be allowed. 26newpath="$(sed -e "s|${OLDPATH}|${NEWPATH}|g" "${LOCFILE}")" 27if [ "${NEWPATH}" != "${newpath}" ]; then 28 echo "Something went wrong with substituting the path!" 29 echo "Please choose another location for your SDK!" 30 exit 1 31fi 32 33echo "Relocating the buildroot SDK from ${OLDPATH} to ${NEWPATH} ..." 34 35# Make sure file uses the right language 36export LC_ALL=C 37# Replace the old path with the new one in all text files 38grep -lr "${OLDPATH}" . | while read -r FILE ; do 39 if file -b --mime-type "${FILE}" | grep -q '^text/' && [ "${FILE}" != "${LOCFILE}" ] 40 then 41 sed -i "s|${OLDPATH}|${NEWPATH}|g" "${FILE}" 42 fi 43done 44 45# At the very end, we update the location file to not break the 46# SDK if this script gets interruted. 47sed -i "s|${OLDPATH}|${NEWPATH}|g" ${LOCFILE} 48