From 8486ffdbc316838423e2d3e69ca42c7f581a0234 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Wed, 17 Sep 2014 16:25:31 -0700 Subject: [PATCH] chrootsetup: add optional 3rd argument to pull_in_bin If the 3rd argument is given and exists in the destination directory and is the same as the binary being copied in then just create a hard link instead. If the 3rd argument is the same as the basename of the binary being copied in then ignore it. --- chrootsetup_freebsd.sh | 6 ++++++ chrootsetup_linux.sh | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/chrootsetup_freebsd.sh b/chrootsetup_freebsd.sh index 7584c5a..80f6ba1 100644 --- a/chrootsetup_freebsd.sh +++ b/chrootsetup_freebsd.sh @@ -66,6 +66,7 @@ pull_in_lib() { # pull_in_bin takes two arguments: # 1: the full path to a binary to pull in (together with any library dependencies) # 2: the destination directory relative to the current directory to copy it to +# 3: optional name of binary that if already in $2 and the same as $1 hard link to instead # for example, "pull_in_bin /bin/sh bin" will install the shell into the chroot bin directory # IMPORTANT: argument 1 must be a machine binary, NOT a shell script or other interpreted text # IMPORTANT: text scripts can simply be copied in or installed as they don't have libraries to copy @@ -74,6 +75,11 @@ pull_in_lib() { # var/tmp directory and then force move it into place after the libs have been brought in. pull_in_bin() { bin="$1"; bdst="$2" + if [ -n "$3" ] && [ "$3" != "$(basename "$bin")" ] && \ + [ -r "${bdst%/}/$3" ] && cmp -s "$bin" "${bdst%/}/$3"; then + ln -f "${bdst%/}/$3" "${bdst%/}/$(basename "$bin")" + return 0 + fi cp -p "$bin" var/tmp/ # ...and all the dependencies. for lib in $(ldd "$bin" | grep '=>' | awk '{print $3}'); do diff --git a/chrootsetup_linux.sh b/chrootsetup_linux.sh index 29b4130..0af0610 100644 --- a/chrootsetup_linux.sh +++ b/chrootsetup_linux.sh @@ -94,6 +94,7 @@ pull_in_lib() { # pull_in_bin takes two arguments: # 1: the full path to a binary to pull in (together with any library dependencies) # 2: the destination directory relative to the current directory to copy it to +# 3: optional name of binary that if already in $2 and the same as $1 hard link to instead # for example, "pull_in_bin /bin/sh bin" will install the shell into the chroot bin directory # IMPORTANT: argument 1 must be a machine binary, NOT a shell script or other interpreted text # IMPORTANT: text scripts can simply be copied in or installed as they don't have libraries to copy @@ -102,6 +103,11 @@ pull_in_lib() { # var/tmp directory and then force move it into place after the libs have been brought in. pull_in_bin() { bin="$1"; bdst="$2" + if [ -n "$3" ] && [ "$3" != "$(basename "$bin")" ] && \ + [ -r "${bdst%/}/$3" ] && cmp -s "$bin" "${bdst%/}/$3"; then + ln -f "${bdst%/}/$3" "${bdst%/}/$(basename "$bin")" + return 0 + fi cp -p -t var/tmp "$bin" # ...and all the dependencies. for lib in $(extract_libs "$bin"); do -- 2.11.4.GIT