@@ -33,22 +33,22 @@ PATCH_INTERPRETER=${PATCH_INTERPRETER:=0}
33
33
GIT_SHARUN_RELEASES=' https://github.com/VHSgunzo/sharun/releases'
34
34
35
35
usage () {
36
- echo -e " [ Usage ]: lib4bin [options ] /path/executable
36
+ echo -e " [ Usage ]: lib4bin [OPTIONS ] /path/executable -- [STRACE CMD ARGS]
37
37
38
38
[ Options ]:
39
- -s, --strip Strip binaries and libraries (env: STRIP=1)
40
- -v, --verbose Verbose mode (env: VERBOSE=1)
39
+ -a, --any-executable Pack any executable (env: ANY_EXECUTABLE=1)
41
40
-d, --dst-dir '/path' Destination directory (env: DST_DIR=/path)
42
- -n, --not-one-dir Separate directories for each executable (env: ONE_DIR=0)
43
- -l, --libs-only Pack only libraries (env: LIBS_ONLY=1)
44
- -p, --hard-links Create hard links to sharun (env: HARD_LINKS=1)
45
- -r, --patch-rpath Patch RPATH to a relative path (env: PATCH_RPATH=1)
41
+ -e, --strace-mode Use strace for get libs (env: STRACE_MODE=1, STRACE_TIME=5)
46
42
-g, --gen-lib-path Generate a lib.path file (env: GEN_LIB_PATH=1)
47
- -a , --any-executable Pack any executable (env: ANY_EXECUTABLE=1)
43
+ -h , --help Show this message
48
44
-i, --patch-interpreter Patch INTERPRETER to a relative path (env: PATCH_INTERPRETER=1)
45
+ -l, --libs-only Pack only libraries (env: LIBS_ONLY=1)
46
+ -n, --not-one-dir Separate directories for each executable (env: ONE_DIR=0)
47
+ -p, --hard-links Pack sharun and create hard links (env: HARD_LINKS=1)
49
48
-q, --quiet-mode Show only errors (env: QUIET_MODE=1)
50
- -e, --strace-mode Use strace for get libs (env: STRACE_MODE=1, STRACE_TIME=5)
51
- -h, --help Show this message
49
+ -r, --patch-rpath Patch RPATH to a relative path (env: PATCH_RPATH=1)
50
+ -s, --strip Strip binaries and libraries (env: STRIP=1)
51
+ -v, --verbose Verbose mode (env: VERBOSE=1)
52
52
-w, --with-sharun Pack sharun from PATH or env or download
53
53
(env: WITH_SHARUN=1, SHARUN=/path|URL, SHARUN_URL=URL, UPX_SHARUN=1)"
54
54
exit 1
@@ -122,7 +122,7 @@ get_libs() {
122
122
if [ " $STRACE_MODE " == 1 ]
123
123
then
124
124
local libs_file=" /tmp/libs.$$ "
125
- strace -f -e trace=openat --always-show-pid -o " $libs_file " " $1 " & > /dev/null &
125
+ strace -f -e trace=openat --always-show-pid -o " $libs_file " " $1 " " ${STRACE_CMD_ARGS[@]} " & > /dev/null &
126
126
sleep $STRACE_TIME
127
127
local pids=" $( cut -d ' ' -f1< " $libs_file " | sort -u) "
128
128
kill $pids 2> /dev/null
@@ -308,6 +308,13 @@ while [[ "$#" -gt 0 ]]; do
308
308
esac
309
309
done
310
310
311
+ if [ "$2 " == '--' ]
312
+ then
313
+ STRACE_MODE=1
314
+ BINARY_LIST=("$1 "); shift 2
315
+ STRACE_CMD_ARGS=("$@ ")
316
+ fi
317
+
311
318
check_deps
312
319
313
320
if [ "$VERBOSE " == 1 ]
@@ -468,30 +475,36 @@ for binary in "${BINARY_LIST[@]}"
468
475
lib_src_name="$(basename "$lib_src_pth ")"
469
476
grep -qE '/lib32 |/i386 -linux-gnu'<<<"$lib_src_dirname_pth " && \
470
477
lib_dir="lib32 "||lib_dir="lib"
471
- lib_dst_dir_pth="${dst_dir_pth} / ${lib_dir} $(sed 's| ^/ usr|| ;s| ^/ lib64 || ;s| ^/ lib32 || ;s| ^/ lib|| ;s| ^/ i386 - linux- gnu|| ;s| ^/ x86 _64 - linux- gnu|| '<<< "$lib_src_dirname_pth ")"
478
+ lib_dst_dir_pth="${dst_dir_pth} / ${lib_dir} $(sed 's| ^/ usr|| ;s| ^/ opt || ;s | ^ / lib64 || ;s| ^/ lib32 || ;s| ^/ lib|| ;s| ^/ i386 - linux- gnu|| ;s| ^/ x86 _64 - linux- gnu|| '<<< "$lib_src_dirname_pth ")"
472
479
lib_dst_pth="$lib_dst_dir_pth /$lib_src_name "
473
- try_mkdir " $lib_dst_dir_pth "
474
- if [[ " $HARD_LINKS " == 1 && ! -L "${dst_dir} / ${lib_dir} " ]]
480
+ if [[ " ${LIBRARIES["$lib_dst_pth"]} " != 1 ]] || \
481
+ [[ -n " $lib_src_real_pth " && "${LIBRARIES["$lib_src_real_pth"]} " != 1 ]]
475
482
then
476
- (try_cd "$dst_dir "
477
- try_ln shared/$lib_dir $lib_dir )||exit 1
478
- fi
479
- if [ -n "$lib_src_real_pth " ]
480
- then
481
- lib_src_real_name="$(basename "$lib_src_real_pth ")"
482
- try_cp "$lib_src_real_pth " "$lib_dst_dir_pth /$lib_src_real_name "
483
- if [[ "$lib_src_name " != "$lib_src_real_name " && ! -L "$lib_dst_pth " ]]
483
+ try_mkdir "$lib_dst_dir_pth "
484
+ if [[ "$HARD_LINKS " == 1 && ! -L "${dst_dir} / ${lib_dir} " ]]
485
+ then
486
+ (try_cd "$dst_dir "
487
+ try_ln shared/$lib_dir $lib_dir )||exit 1
488
+ fi
489
+ if [ -n "$lib_src_real_pth " ]
484
490
then
485
- (try_cd "$lib_dst_dir_pth "
486
- try_ln "$lib_src_real_name " "$lib_src_name ")||exit 1
487
- fi
488
- else
489
- try_cp "$lib_src_pth " "$lib_dst_dir_pth /$lib_src_name "
490
- fi
491
- repath_needed_libs "$lib_dst_pth "
492
- try_strip "$lib_dst_pth "
493
- if [[ ! "$lib_dst_pth " =~ "$INTERPRETER " ]]
494
- then try_set_rpath "$lib_dst_pth "
491
+ lib_src_real_name="$(basename "$lib_src_real_pth ")"
492
+ try_cp "$lib_src_real_pth " "$lib_dst_dir_pth /$lib_src_real_name "
493
+ if [[ "$lib_src_name " != "$lib_src_real_name " && ! -L "$lib_dst_pth " ]]
494
+ then
495
+ (try_cd "$lib_dst_dir_pth "
496
+ try_ln "$lib_src_real_name " "$lib_src_name ")||exit 1
497
+ fi
498
+ LIBRARIES["$lib_src_real_pth "]=1
499
+ else
500
+ try_cp "$lib_src_pth " "$lib_dst_dir_pth /$lib_src_name "
501
+ fi
502
+ repath_needed_libs "$lib_dst_pth "
503
+ try_strip "$lib_dst_pth "
504
+ if [[ ! "$lib_dst_pth " =~ "$INTERPRETER " ]]
505
+ then try_set_rpath "$lib_dst_pth "
506
+ fi
507
+ LIBRARIES["$lib_dst_pth "]=1
495
508
fi
496
509
LIBRARIES["$lib_src_pth "]=1
497
510
fi
@@ -507,7 +520,9 @@ for binary in "${BINARY_LIST[@]}"
507
520
patchelf $pvarg --set-interpreter "../$lib_dir /$INTERPRETER " "$binary_name "||exit 1
508
521
fi)||exit 1
509
522
fi
510
- # sed -i 's|/usr|/xxx|g;s|/lib|/XXX|g;s|/etc|/EEE|g' "${dst_dir} / shared/ $lib_dir / $INTERPRETER "|| exit 1
523
+ interpreter_pth="${dst_dir} / shared/ $lib_dir / $INTERPRETER "
524
+ info_msg "$YELLOW [ PATCH INTERPRETER ]: $BLUE [$interpreter_pth ]"
525
+ sed -i 's|/usr|/xxx|g;s|/lib|/XXX|g;s|/etc|/EEE|g' "$interpreter_pth "||exit 1
511
526
fi
512
527
info_msg "[ DONE ]"
513
528
binary_number=$(( $binary_number + 1 ))
0 commit comments