vuls: init at 0.27.0 (#348530)
[NixPkgs.git] / maintainers / scripts / patchelf-hints.sh
blob802ecab0f0a16a325b0596427ea9b5e6893aa654
2 usage() {
3 echo "
4 $0 <path to unpacked binary distribution directory>
6 This program return the list of libraries and where to find them based on
7 your currently installed programs.
8 ";
9 exit 1
12 if test $# -ne 1; then
13 usage
16 binaryDist=$1
18 hasBinaries=false
19 for bin in $(find $binaryDist -executable -type f) :; do
20 if test $bin = ":"; then
21 $hasBinaries || \
22 echo "No patchable found in this directory."
23 break
25 hasBinaries=true
27 echo ""
28 echo "$bin:"
29 hasLibraries=false
30 unset interpreter
31 unset addRPath
32 for lib in $(strings $bin | grep '^\(/\|\)lib.*\.so' | sort | uniq) :; do
33 if test $lib = ":"; then
34 $hasLibraries || \
35 echo " This program is a script or it is statically linked."
36 break
38 hasLibraries=true
40 echo " $lib:";
42 libPath=$lib
43 lib=$(basename $lib)
45 #versionLessLib=$(echo $lib | sed 's,[.][.0-9]*$,,')
47 libs="$(
48 find /nix/store/*/lib* \( -type f -or -type l \) -name $lib |
49 grep -v '\(bootstrap-tools\|system-path\|user-environment\|extra-utils\)'
52 echo "$libs" |
53 sed 's,^/nix/store/[a-z0-9]*-\([^/]*\)/.*/\([^/]*\)$, \1 -> \2,' |
54 sort |
55 uniq;
57 names=$(
58 echo "$libs" |
59 sed 's,^/nix/store/[a-z0-9]*-\([^/]*\)-[.0-9]*/.*$,\1,' |
60 sort |
61 uniq;
64 if test "$names" = "glibc"; then names="glibc"; fi
65 if echo $names | grep -c "gcc" &> /dev/null; then names="stdenv.cc.cc"; fi
67 if test $lib != $libPath; then
68 interpreter="--interpreter \${$names}/lib/$lib"
69 elif echo $addRPath | grep -c "$names" &> /dev/null; then
71 else
72 addRPath=${addRPath+$addRPath:}"\${$names}/lib"
74 done;
75 $hasLibraries && \
76 echo "
77 Patchelf command:
79 patchelf $interpreter \\
80 ${addRPath+--set-rpath $addRPath \\
81 } \$out/$bin
84 done;