build.sh: Allow readlink for path-canonicalization
authorW. Trevor King <wking@tremily.us>
Fri, 27 Dec 2013 00:53:02 +0000 (16:53 -0800)
committerW. Trevor King <wking@tremily.us>
Thu, 2 Jan 2014 02:03:32 +0000 (18:03 -0800)
Debian doesn't have realpath installed by default [1], so fall back to
the more widely available readlink [2].

[1]: http://packages.debian.org/unstable/utils/realpath
[2]: http://www.gnu.org/software/coreutils/manual/html_node/readlink-invocation.html

build.sh

index 9c72780500e118b5dde198cae97cf65942d149ae..a21392bc89b88511d126d497c72e593e3c6ea997 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -54,6 +54,16 @@ die()
        exit 1
 }
 
+REALPATH="${REALPATH:-$(command -v realpath)}"
+if [ -z "${REALPATH}" ]; then
+       READLINK="${READLINK:-$(command -v readlink)}"
+       if [ -n "${READLINK}" ]; then
+               REALPATH="${READLINK} -f"
+       else
+               die "need realpath or readlink to canonicalize paths"
+       fi
+fi
+
 STAGE3_IMAGES=$(docker images "${NAMESPACE}/gentoo")
 STAGE3_MATCHES=$(echo "${STAGE3_IMAGES}" | grep "${DATE}")
 if [ -z "${STAGE3_MATCHES}" ]; then
@@ -97,7 +107,7 @@ fi
 docker tag -f "${NAMESPACE}/portage-import:${DATE}" "${NAMESPACE}/portage-import:latest" || die "failed to tag"
 
 # extract Busybox for the portage image
-THIS_DIR=$(dirname $(realpath $0))
+THIS_DIR=$(dirname $($REALPATH $0))
 CONTAINER="${NAMESPACE}-gentoo-${DATE}-extract-busybox"
 docker run -name "${CONTAINER}" -v "${THIS_DIR}/portage/":/tmp "${NAMESPACE}/gentoo:${DATE}" cp /bin/busybox /tmp/
 docker rm "${CONTAINER}"