All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wolfgang Grandegger <wg@grandegger.com>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH v4 07/11] support/scripts: add reloacte-sdk.sh script for SDK relocation
Date: Tue, 27 Jun 2017 12:26:43 +0200	[thread overview]
Message-ID: <1498559207-8050-8-git-send-email-wg@grandegger.com> (raw)
In-Reply-To: <1498559207-8050-1-git-send-email-wg@grandegger.com>

It will install the script "relocate-sdk.sh" in the HOST_DIR
allowing to adjust the path to the SDK directory in all text
files after it has been moved to a new location.

Signed-off-by: Wolfgang Grandegger <wg@grandegger.com>
---
 support/misc/relocate-sdk.sh | 47 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100755 support/misc/relocate-sdk.sh

diff --git a/support/misc/relocate-sdk.sh b/support/misc/relocate-sdk.sh
new file mode 100755
index 0000000..1b0be33
--- /dev/null
+++ b/support/misc/relocate-sdk.sh
@@ -0,0 +1,47 @@
+#!/bin/bash
+#
+if [ "$#" -ne 0 ]; then
+    echo "Run this script to relocate the buildroot SDK at that location"
+    exit 1
+fi
+
+LOCFILE="./usr/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/" 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
+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 < <(grep -lr "${OLDPATH}" .)
+
+# 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}
-- 
2.7.4

  parent reply	other threads:[~2017-06-27 10:26 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-27 10:26 [Buildroot] [PATCH v4 00/11] Make the SDK relocatable Wolfgang Grandegger
2017-06-27 10:26 ` [Buildroot] [PATCH v4 01/11] package/patchelf: use most recent version as a base for rpath sanitation Wolfgang Grandegger
2017-06-27 10:26 ` [Buildroot] [PATCH v4 02/11] package/patchelf: add patch for rpath sanitation under a root directory Wolfgang Grandegger
2017-06-27 10:26 ` [Buildroot] [PATCH v4 03/11] support/scripts: add fix-rpath script to sanitize the rpath Wolfgang Grandegger
2017-07-04 12:15   ` Arnout Vandecappelle
2017-07-04 12:36     ` Wolfgang Grandegger
2017-07-04 13:23       ` Arnout Vandecappelle
2017-07-04 14:52         ` Wolfgang Grandegger
2017-07-04 15:00           ` Samuel Martin
2017-06-27 10:26 ` [Buildroot] [PATCH v4 04/11] core: sanitize RPATH in staging tree at the end of the target finalization Wolfgang Grandegger
2017-06-27 10:26 ` [Buildroot] [PATCH v4 05/11] core: sanitize RPATH in target " Wolfgang Grandegger
2017-06-27 10:26 ` [Buildroot] [PATCH v4 06/11] core: sanitize RPATH in host tree at the very end of the build Wolfgang Grandegger
2017-06-27 10:26 ` Wolfgang Grandegger [this message]
2017-06-27 10:26 ` [Buildroot] [PATCH v4 08/11] core: install relocation script and location at the " Wolfgang Grandegger
2017-06-27 10:26 ` [Buildroot] [PATCH v4 09/11] external-toolchain: check if a buildroot SDK has already been relocated Wolfgang Grandegger
2017-06-27 10:26 ` [Buildroot] [PATCH v4 10/11] support/scripts: check-host-rpath now handles $ORIGIN as well Wolfgang Grandegger
2017-06-27 10:26 ` [Buildroot] [PATCH v4 11/11] package/qt5base: provide "qt.conf" to make "qmake" relocatable Wolfgang Grandegger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1498559207-8050-8-git-send-email-wg@grandegger.com \
    --to=wg@grandegger.com \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.