From 976fc0b4c05ae07156885ec2a6ecfa7b267156bd Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sat, 15 Feb 2014 02:28:48 -0800 Subject: [PATCH] chrootsetup_linux.sh: do not hard-code library locations Other than the loader expected to be in /lib or /lib64, do not hard-code any library locations. They will all be found simply by following the ldd output. This improves compatibility with various distributions. --- chrootsetup_linux.sh | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/chrootsetup_linux.sh b/chrootsetup_linux.sh index 1c3aaf3..d626828 100644 --- a/chrootsetup_linux.sh +++ b/chrootsetup_linux.sh @@ -42,8 +42,25 @@ rm -f lib/* # ld.so: cp -p -t lib /lib/ld-linux.so.2 [ ! -d /lib64 ] || cp -p -t lib /lib64/ld-linux-x86-64.so.2 -# libc: -cp -p -t lib /lib/libc.so.6 /lib/libcrypt.so.1 /lib/libutil.so.1 /lib/libnsl.so.1 /lib/libnss_compat.so.2 /lib/libresolv.so.2 /lib/libdl.so.2 /lib/libgcc_s.so.1 + +extract_libs() { + ldd "$1" | grep -v linux-gate | grep -v linux-vdso | grep -v ld-linux | grep '=>' | awk '{print $3}' +} + +pull_in_lib() { + [ -f "$1" ] || return + dst="${2%/}/$(basename "$1")" + if [ ! -e "$dst" ] || [ "$1" -nt "$dst" ]; then + cp -p -t "$2" "$1" + for llib in $(extract_libs "$1"); do + (pull_in_lib "$llib" lib) + done + fi + case "$(basename "$1")" in libc.*) + # grab libnss_compat.so.2 from libc location + (pull_in_lib "$(dirname "$1")/libnss_compat.so.2" "$2") + esac +} # pull_in_bin takes two arguments: # 1: the full path to a binary to pull in (together with any library dependencies) @@ -56,7 +73,9 @@ pull_in_bin() { bin="$1"; dst="$2" cp -p -t "$dst" "$bin" # ...and all the dependencies. - ldd "$bin" | grep -v linux-gate | grep -v linux-vdso | grep -v ld-linux | grep '=>' | awk '{print $3}' | xargs -r -- cp -p -u -t lib + for lib in $(extract_libs "$bin"); do + pull_in_lib "$lib" lib + done } # A catch all that needs to be called after everything's been pulled in -- 2.11.4.GIT