forked from VHSgunzo/sharun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib4bin
executable file
·677 lines (638 loc) · 36.4 KB
/
lib4bin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
#!/usr/bin/env bash
# deps: apt update && apt install bash file binutils patchelf findutils grep sed coreutils strace -y
# deps: apk add bash file binutils patchelf findutils grep sed coreutils strace
# deps: dnf install bash file binutils patchelf findutils grep sed coreutils strace -y
# deps: pacman -Sy bash file binutils patchelf findutils grep sed coreutils strace --noconfirm
# deps: xbps-install -Sy bash file binutils patchelf findutils grep sed coreutils strace
RED='\033[1;91m'
BLUE='\033[1;94m'
GREEN='\033[1;92m'
YELLOW='\033[1;33m'
RESETCOLOR='\033[1;00m'
ONE_DIR=${ONE_DIR:=1}
DST_DIR="${DST_DIR:=.}"
CREATE_LINKS=${CREATE_LINKS:=1}
STRIP=${STRIP:=0}
VERBOSE=${VERBOSE:=0}
LIBS_ONLY=${LIBS_ONLY:=0}
QUIET_MODE=${QUIET_MODE:=0}
HARD_LINKS=${HARD_LINKS:=0}
WITH_HOOKS=${WITH_HOOKS:=0}
WITH_SHARUN=${WITH_SHARUN:=0}
PATCH_RPATH=${PATCH_RPATH:=0}
STRACE_MODE=${STRACE_MODE:=0}
STRACE_TIME=${STRACE_TIME:=5}
GEN_LIB_PATH=${GEN_LIB_PATH:=0}
ANY_EXECUTABLE=${ANY_EXECUTABLE:=0}
PATCH_INTERPRETER=${PATCH_INTERPRETER:=0}
# BINARY_LIST=('/path/executable' '/path/executable')
GIT_SHARUN_RELEASES='https://github.com/VHSgunzo/sharun/releases'
usage() {
echo -e "[ Usage ]: lib4bin [OPTIONS] /path/executable -- [STRACE MODE EXEC ARGS]
[ Options ]:
-a, --any-executable Pack any executable (env: ANY_EXECUTABLE=1)
-d, --dst-dir '/path' Destination directory (env: DST_DIR=/path)
-e, --strace-mode Use strace for get libs (env: STRACE_MODE=1, STRACE_TIME=5)
-g, --gen-lib-path Generate a lib.path file (env: GEN_LIB_PATH=1)
-h, --help Show this message
-i, --patch-interpreter Patch INTERPRETER to a relative path (env: PATCH_INTERPRETER=1)
-k, --with-hooks Pack additional files required for libraries (env: WITH_HOOKS=1)
-l, --libs-only Pack only libraries without executables (env: LIBS_ONLY=1)
-n, --not-one-dir Separate directories for each executable (env: ONE_DIR=0)
-p, --hard-links Pack sharun and create hard links (env: HARD_LINKS=1)
-q, --quiet-mode Show only errors (env: QUIET_MODE=1)
-r, --patch-rpath Patch RPATH to a relative path (env: PATCH_RPATH=1)
-s, --strip Strip binaries and libraries (env: STRIP=1)
-v, --verbose Verbose mode (env: VERBOSE=1)
-w, --with-sharun Pack sharun from PATH or env or download
(env: WITH_SHARUN=1, SHARUN=/path|URL, SHARUN_URL=URL, UPX_SHARUN=1)"
exit 1
}
error_msg() {
echo -e "${RED}[ ERROR ][$(date +"%Y.%m.%d %T")]: $@ $RESETCOLOR"
return 1
}
info_msg() {
if [ "$QUIET_MODE" != 1 ]
then echo -e "${GREEN}[ INFO ][$(date +"%Y.%m.%d %T")]: $@ $RESETCOLOR"
fi
}
skip_msg() {
if [ "$QUIET_MODE" != 1 ]
then echo -e "${YELLOW}[ SKIPPED ][$(date +"%Y.%m.%d %T")]: $@ $RESETCOLOR"
fi
}
which_exe() { command -v "$@" ; }
is_exe_exist() { which_exe "$@" &>/dev/null ; }
check_deps() {
local ret=0
local binaries=(file patchelf find grep sed)
[ "$STRIP" != 1 ]||binaries+=(strip)
[ "$STRACE_MODE" != 1 ]||binaries+=(strace)
for bin in "${binaries[@]}"
do
if ! is_exe_exist $bin
then
error_msg "$BLUE[$bin]$YELLOW not found!"
ret=1
fi
done
if [ "$ret" != 0 ]
then
info_msg "You need to install ${BLUE}lib4bin${GREEN} dependencies: ${BLUE}file binutils patchelf findutils grep sed coreutils strace"
exit 1
fi
}
try_strip() {
if [ "$STRIP" == 1 ]
then
info_msg "$YELLOW[ STRIP ]: $BLUE[$1]"
strip -s -R .comment --strip-unneeded "$1"||exit 1
fi
}
try_set_rpath() {
if [ "$PATCH_RPATH" == 1 ]
then
info_msg "$YELLOW[ SET RPATH ]: $BLUE[$1]"
patchelf $pvarg --set-rpath '$ORIGIN/../lib:$ORIGIN/../lib32' "$1"||exit 1
else
local rpath="$(print_rpath "$1")"
if grep -qE '^/|:/'<<<"$rpath"
then
info_msg "$YELLOW[ REMOVE RPATH ]: $BLUE[$rpath]"
patchelf $pvarg --remove-rpath "$1"||exit 1
fi
fi
}
print_needed() { patchelf --print-needed "$1" 2>/dev/null ; }
print_rpath() { patchelf --print-rpath "$1" 2>/dev/null ; }
ldd_libs() {
ldd "$1" 2>/dev/null|grep -v 'error while loading shared libraries'|\
grep '/lib'|cut -d'>' -f2|sed 's| (.*)||g'|sed 's|^[[:space:]]*||g'
}
get_libs() {
unset libs libs4libs
if [[ "$STRACE_MODE" == 1 && ! -n "$IS_SO" ]]
then
local libs_file="/tmp/libs.$$"
strace -f -e trace=openat --always-show-pid -o "$libs_file" "$1" "${STRACE_CMD_ARGS[@]}" &>/dev/null &
sleep $STRACE_TIME
local pids="$(cut -d ' ' -f1<"$libs_file"|sort -u)"
kill $pids 2>/dev/null
local libs="$(echo -e "$(sed '/nvidia/d;/libcuda/d;/ENOENT/d;/unfinished/d'<"$libs_file"|\
grep -oP '".*lib.*\.so.*"'|sed -u 's|"||g')")\n"
rm -f "$libs_file"
fi
[ -n "$2" ] && local needed_libs="$2"||\
local needed_libs="$(print_needed "$1")"
local libs+="$(([ -z "$needed_libs" ]||\
grep -E "$(tr '\n' '|'<<<"$needed_libs"|sed 's|\||$\||g')libpthread.so.0$"<<<"$ALL_LIBS" ; \
ldd_libs "$1")|sort -u)"
[ -n "$IS_ELF32" ] && \
local libs="$(grep -vE '/lib/|/lib64/|/.*64-linux-gnu/'<<<"$libs")"||\
local libs="$(grep -vE '/lib32/|/i386-linux-gnu/|/arm-linux-gnu/'<<<"$libs")"
for lib in $libs
do local libs4libs="$(echo -e "$(ldd_libs "$lib")\n$libs4libs")"
done
echo -e "$libs\n$libs4libs"|sort -u|sed '/^$/d'
}
repath_needed_libs() {
[ -n "$2" ] && local needed_libs="$2"||\
local needed_libs="$(print_needed "$1")"
local patch_needed_libs="$(grep '^/'<<<"$needed_libs")"
if [ -n "$patch_needed_libs" ]
then
for lib in $patch_needed_libs
do
local relib="$(basename "$lib")"
info_msg "$YELLOW[ REPATH ]: $BLUE[$lib -> $relib]"
patchelf $pvarg --replace-needed "$lib" "$relib" "$1"||exit 1
done
fi
}
try_mkdir() {
if [ ! -d "$1" ]
then mkdir $varg -p "$1"||exit 1
fi
}
try_ln() {
if [ ! -L "$2" ]
then
[ "$VERBOSE" == 1 ] && \
echo -n "ln: "
ln $varg -sf "$1" "$2"||exit 1
fi
}
try_cp_exe() {
if [ ! -f "$2" ]
then
[ "$VERBOSE" == 1 ] && \
echo -n "cp: "
cp $varg -f "$1" "$2"||exit 1
chmod $varg 755 "$2"||exit 1
fi
}
try_cp() {
[ "$VERBOSE" == 1 ] && \
echo -n "cp: "
cp $varg -rf "$@"||exit 1
}
try_cd() {
[ "$VERBOSE" == 1 ] && \
echo "cd: '$1'"
cd "$1"||exit 1
}
find_so() { find "$@" -name '*.so' -o -name '*.so.*' 2>/dev/null ; }
check_url_stat_code() {
set -o pipefail
if is_exe_exist curl
then curl -sL -o /dev/null -I -w "%{http_code}" "$@" 2>/dev/null
elif is_exe_exist wget
then wget --no-check-certificate --server-response \
--spider "$@"|& awk '/^ HTTP/{print$2}'|tail -1
else return 1
fi
}
get_sharun_git_url() {
echo "${GIT_SHARUN_RELEASES}/download/$(NO_ARIA2C=1 try_dl "${GIT_SHARUN_RELEASES}/latest" \
/dev/stdout 2>/dev/null|grep -m1 "Release v.*"|awk '{print$2}')/sharun-$(uname -m)$([ "$UPX_SHARUN" != 1 ]||echo -upx)"
}
is_url() {
[ ! -n "$1" ] && \
return 1
if [ -n "$2" ]
then [ "$(check_url_stat_code "$1")" == "$2" ]
else [ "$(check_url_stat_code "$1")" == "200" ]
fi
}
is_net_conn() {
if is_exe_exist nc
then nc -zw1 github.com 443 &>/dev/null
elif is_exe_exist curl
then curl -Ifs github.com &>/dev/null
elif is_exe_exist wget
then wget -q --spider github.com &>/dev/null
elif is_exe_exist ping
then ping -c 2 github.com &>/dev/null
else return 1
fi
}
try_dl() {
if is_net_conn
then
if [ -n "$1" ]
then
URL="$1"
if [ -n "$2" ]
then
if [ -d "$2" ]
then
FILEDIR="$2"
FILENAME="$(basename "$1")"
else
FILEDIR="$(dirname "$2")"
FILENAME="$(basename "$2")"
fi
else
FILEDIR="."
FILENAME="$(basename "$1")"
fi
if is_url "$URL"
then
WGET_ARGS=(-q --no-check-certificate -t 3 -T 5 -w 0.5 "$URL" -O "$FILEDIR/$FILENAME")
try_mkdir "$FILEDIR"
if [ "$NO_ARIA2C" != 1 ] && is_exe_exist aria2c
then
aria2c --no-conf -R -x 13 -s 13 --allow-overwrite -d "$FILEDIR" -o "$FILENAME" "$URL"
elif is_exe_exist curl
then
curl -R --progress-bar --insecure --fail -L "$URL" -o "$FILEDIR/$FILENAME"
elif is_exe_exist wget2
then
wget2 --force-progress "${WGET_ARGS[@]}"
elif is_exe_exist wget
then
wget --show-progress "${WGET_ARGS[@]}"
else
error_msg "Downloader not found!"
fi
else
error_msg "$FILENAME not found in $(echo "$URL"|awk -F/ '{print$3"/"$4}')"
fi
else
error_msg "Specify download URL!"
fi
else
error_msg "There is no internet connection!"
fi
return $?
}
while [[ "$#" -gt 0 ]]; do
case $1 in
-h|--help) usage ;;
-s|--strip) STRIP=1; shift ;;
-v|--verbose) VERBOSE=1; shift ;;
-n|--not-one-dir) ONE_DIR=0; shift ;;
-l|--libs-only) LIBS_ONLY=1; shift ;;
-k|--with-hooks) WITH_HOOKS=1; shift ;;
-q|--quiet-mode) QUIET_MODE=1; shift ;;
-p|--hard-links) HARD_LINKS=1; shift ;;
-e|--strace-mode) STRACE_MODE=1; shift ;;
-w|--with-sharun) WITH_SHARUN=1; shift ;;
-r|--patch-rpath) PATCH_RPATH=1; shift ;;
-g|--gen-lib-path) GEN_LIB_PATH=1; shift ;;
-a|--any-executable) ANY_EXECUTABLE=1; shift ;;
-i|--patch-interpreter) PATCH_INTERPRETER=1; shift ;;
-d|--dst-dir)
if [[ -n "$2" && "$2" != -* ]]
then DST_DIR="$2"; shift 2
else
error_msg "${YELLOW}Option ${BLUE}$1 ${YELLOW}requires a non-empty argument!\n"
usage
fi
;;
-*) error_msg "Unknown parameter: ${BLUE}$1\n"; usage ;;
*) break ;;
esac
done
if [ "$2" == '--' ]
then
STRACE_MODE=1
BINARY_LIST=("$1"); shift 2
STRACE_CMD_ARGS=("$@")
fi
check_deps
if [ "$VERBOSE" == 1 ]
then
varg='-v'
pvarg='--debug'
else
unset varg pvarg
fi
if [ ! -n "$BINARY_LIST" ]
then
if [ -n "$1" ]
then
BINARY_LIST=("$@")
else
error_msg "Specify the executable!\n"
usage
fi
fi
ALL_LIBS="$(find_so \
/usr/lib /usr/libexec /usr/lib64 \
/usr/lib32 /lib /lib64 /lib32 \
|sort -u \
)"
binary_number=1
declare -A DST_DIRS
declare -A BINARIES
declare -A LIBRARIES
for binary in "${BINARY_LIST[@]}"
do
unset binary_real_name
if [ -L "$binary" ]
then
binary_src_pth="$(readlink -f "$binary")"
binary_real_name="$(basename "$binary_src_pth")"
else
binary_src_pth="$binary"
fi
if [[ "${BINARIES["$binary"]}" != 1 ]]
then
binary_name="$(basename "$binary")"
if [ "$ONE_DIR" == 1 ]
then
dst_dir="$DST_DIR"
dst_dir_pth="${DST_DIR}/shared"
sharun_bin_dir_pth="${DST_DIR}/bin"
else
dst_dir="${DST_DIR}/${binary_name}"
dst_dir_pth="${dst_dir}/shared"
sharun_bin_dir_pth="${dst_dir}/bin"
fi
[[ -f "$dst_dir_pth" || -L "$dst_dir_pth" ]] && \
dst_dir_pth="${dst_dir_pth}.dir"
DST_DIRS["$dst_dir_pth"]=
bin_dir_pth="${dst_dir_pth}/bin"
FILE_INFO="$(file "$binary_src_pth" 2>/dev/null)"
IS_ELF="$(grep -o 'ELF'<<<"$FILE_INFO")"
IS_STATIC="$(grep -o 'static'<<<"$FILE_INFO")"
IS_SCRIPT="$(grep -o 'script'<<<"$FILE_INFO")"
IS_ELF32="$(grep -q 'ELF 32-bit'<<<"$FILE_INFO")"
IS_SO="$(grep -o 'shared object'<<<"$FILE_INFO")"
IS_EXECUTABLE="$(grep -o 'executable'<<<"$FILE_INFO")"
info_msg "$YELLOW[ $binary_number ]: $BLUE[$binary_name] ${GREEN}..."
if [ "$HARD_LINKS" == 1 ] && [[ -n "$IS_SCRIPT" || -n "$IS_STATIC" ]]
then
hard_links=0
with_sharun=1
fi
hard_links=${HARD_LINKS:=0}
with_sharun=${WITH_SHARUN:=0}
if [[ -n "$IS_EXECUTABLE" || -n "$IS_SO" ]] && [[ "$ANY_EXECUTABLE" == 1 || -n "$IS_ELF" ]]
then
needed_libs="$(print_needed "$binary_src_pth")"
LIBS="$(get_libs "$binary_src_pth" "$needed_libs")"
[ -n "$IS_SO" ] && \
LIBS="$(echo -e "$LIBS\n$binary"|sort -u|sed '/^$/d')"
if [[ -n "$LIBS" && ! -n "$IS_SCRIPT" && ! -n "$IS_STATIC" ]]
then
INTERPRETER="$(basename "$(grep 'ld-linux'<<<"$LIBS"|cut -d'=' -f1|sed 's|\t||' )")"
[[ "$CREATE_LINKS" == 1 && "$hard_links" == 1 && ! -x "${dst_dir}/sharun" ]] && \
with_sharun=1
else
bin_dir_pth="$sharun_bin_dir_pth"
fi
if [[ -n "$LIBS" || "$ANY_EXECUTABLE" == 1 ]]
then
if [[ "$LIBS_ONLY" != 1 && ! -n "$IS_SO" ]]
then
if [[ "$with_sharun" == 1 && ! -x "${dst_dir}/sharun" ]]
then
TMP_SHARUN="/tmp/sharun-$(uname -m)$([ "$UPX_SHARUN" != 1 ]||echo -upx)"
SHARUN="${SHARUN:="$(readlink -f "$(which_exe sharun)")"}"
SHARUN="${SHARUN:="$TMP_SHARUN"}"
if [ ! -x "$SHARUN" ]
then
if grep -q '^http'<<<"$SHARUN"
then
SHARUN_URL="$SHARUN"
SHARUN="$TMP_SHARUN"
fi
SHARUN_URL="${SHARUN_URL:="$(get_sharun_git_url)"}"
info_msg "Downloading sharun -> '$SHARUN'..."
info_msg "$SHARUN_URL"
if try_dl "$SHARUN_URL" "$SHARUN"
then chmod $varg +x "$SHARUN"
else
error_msg "Failed to download sharun!"
exit 1
fi
fi
if [ -x "$SHARUN" ]
then
try_mkdir "$dst_dir"
try_cp_exe "$SHARUN" "${dst_dir}/sharun"
else
error_msg "sharun not found!"
exit 1
fi
fi
try_mkdir "$bin_dir_pth"
[ -n "$binary_real_name" ] && \
binary_dst_pth="$bin_dir_pth/$binary_real_name"||\
binary_dst_pth="$bin_dir_pth/$binary_name"
try_cp_exe "$binary_src_pth" "$binary_dst_pth"
if [[ -n "$binary_real_name" && "$binary_name" != "$binary_real_name" ]]
then
(try_cd "$bin_dir_pth"
try_ln "$binary_real_name" "$binary_name")||exit 1
fi
if [[ "${BINARIES["$binary_dst_pth"]}" != 1 ]]
then
if [ -n "$IS_ELF" ]
then try_strip "$binary_dst_pth"
fi
if [[ -n "$LIBS" && ! -n "$IS_SCRIPT" && ! -n "$IS_STATIC" ]]
then
repath_needed_libs "$binary_dst_pth" "$needed_libs"
try_set_rpath "$binary_dst_pth"
if [ "$CREATE_LINKS" == 1 ]
then
try_mkdir "$sharun_bin_dir_pth"
[ "$hard_links" == 1 ] && \
unset ln_args||ln_args='-s'
(try_cd "$sharun_bin_dir_pth"
[ "$VERBOSE" != 1 ]||echo -n "ln: "
ln $varg -f $ln_args ../sharun "$binary_name"||exit 1
if [ -n "$binary_real_name" ]
then
[ "$VERBOSE" != 1 ]||echo -n "ln: "
ln $varg $ln_args ../sharun "$binary_real_name"||exit 1
fi)||exit 1
fi
fi
BINARIES["$binary_dst_pth"]=1
fi
fi
for lib_src_pth in $LIBS
do
if [[ "${LIBRARIES["$lib_src_pth"]}" != 1 ]]
then
unset lib_src_real_pth lib_src_real_name
if [ -L "$lib_src_pth" ]
then
lib_src_real_pth="$(readlink -f "$lib_src_pth")"
lib_src_real_name="$(basename "$lib_src_real_pth")"
lib_src_dirname_pth="$(dirname "$lib_src_real_pth")"
lib_info="$(file "$lib_src_real_pth" 2>/dev/null)"
else
lib_src_dirname_pth="$(dirname "$lib_src_pth")"
lib_info="$(file "$lib_src_pth" 2>/dev/null)"
fi
if [[ "$lib_info" =~ 'shared object' ]]
then
lib_src_dirname_pth="$(sed 's|^\.\.$||;s|^\.$||;s|\.\./|/|g;s|^/*|/|;s|^/$||;s|^/\.\.$||'<<<"$lib_src_dirname_pth")"
lib_src_name="$(basename "$lib_src_pth")"
grep -qE '/lib32|/i386-linux-gnu|/arm-linux-gnu'<<<"$lib_src_dirname_pth" && \
lib_dir="lib32"||lib_dir="lib"
lib_dst_dir_pth="${dst_dir_pth}/${lib_dir}$(sed 's|^/usr||;s|^/opt||;s|^/lib64||;s|^/lib32||;s|^/lib||;s|^/.*-linux-gnu||'<<<"$lib_src_dirname_pth")"
[ -n "$lib_src_real_name" ] && \
lib_dst_pth="$lib_dst_dir_pth/$lib_src_real_name"||\
lib_dst_pth="$lib_dst_dir_pth/$lib_src_name"
try_mkdir "$lib_dst_dir_pth"
try_cp_exe "$lib_src_pth" "$lib_dst_pth"
if [[ -n "$lib_src_real_name" && "$lib_src_name" != "$lib_src_real_name" ]]
then
(try_cd "$lib_dst_dir_pth"
try_ln "$lib_src_real_name" "$lib_src_name")||exit 1
fi
if [[ "${LIBRARIES["$lib_dst_pth"]}" != 1 ]]
then
if [[ ! -n "$IS_SO" && "$hard_links" == 1 && ! -L "${dst_dir}/${lib_dir}" ]]
then
(try_cd "$dst_dir"
try_ln shared/$lib_dir $lib_dir)||exit 1
fi
repath_needed_libs "$lib_dst_pth"
try_strip "$lib_dst_pth"
if [[ ! "$lib_dst_pth" =~ "$INTERPRETER" ]]
then try_set_rpath "$lib_dst_pth"
fi
if [ "$WITH_HOOKS" == 1 ]
then
case "$lib_dst_pth" in
*/gio/modules/*.so)
sys_giom_cache='/usr/lib/*gio/modules/giomodule.cache'
dst_giom_dir="$(dirname "$lib_dst_pth")"
dst_giom_cache="$dst_giom_dir/giomodule.cache"
if [ -f $sys_giom_cache ] && [ ! -f "$dst_giom_cache" ]
then
info_msg "$YELLOW[ HOOK ]:$GREEN copy giomodule.cache..."
try_mkdir "$dst_giom_dir"
try_cp $sys_giom_cache "$dst_giom_cache"
fi ;;
*/libglib-*.so*)
glib="$(grep -o 'glib-.*\.so'<<<"$lib_src_name"|sed "s|\.so$||")"
sys_glib_schemas="/usr/share/$glib/schemas"
dst_glib_schemas="$dst_dir/share/$glib/schemas"
if [[ -d "$sys_glib_schemas" && ! -d "$dst_glib_schemas" ]]
then
info_msg "$YELLOW[ HOOK ]:$GREEN copy glib schemas..."
try_mkdir "$dst_glib_schemas"
try_cp -T "$sys_glib_schemas" "$dst_glib_schemas"
fi ;;
*/gdk-pixbuf-*/*/loaders/*.so)
sys_pixbufl_cache='/usr/lib/*gdk-pixbuf-*/*/loaders.cache'
dst_pixbufl_dir="$(dirname "$lib_dst_pth")"
dst_pixbufl_cache="${dst_pixbufl_dir}.cache"
if [ -f $sys_pixbufl_cache ] && [ ! -f "$dst_pixbufl_cache" ]
then
info_msg "$YELLOW[ HOOK ]:$GREEN copy gdk pixbuf loaders.cache..."
try_mkdir "$dst_pixbufl_dir"
try_cp $sys_pixbufl_cache "$dst_pixbufl_cache"
sed -i 's|/usr/lib/.*/loaders/||g' "$dst_pixbufl_cache"
fi ;;
*/gtk-*/*/immodules/*.so)
sys_gtkimm_cache="/usr/lib/*$(grep -o 'gtk-[0-9]\.[0-9]'<<<"$lib_dst_pth")/*/immodules.cache"
dst_gtkimm_dir="$(dirname "$lib_dst_pth")"
dst_gtkimm_cache="${dst_gtkimm_dir}.cache"
if [ -f $sys_gtkimm_cache ] && [ ! -f "$dst_gtkimm_cache" ]
then
info_msg "$YELLOW[ HOOK ]:$GREEN copy gtk immodules.cache..."
try_mkdir "$dst_gtkimm_dir"
try_cp $sys_gtkimm_cache "$dst_gtkimm_cache"
sed -i 's|/usr/lib/.*/immodules/||g' "$dst_gtkimm_cache"
fi ;;
*/libfontconfig.so*)
sys_fcfg='/etc/fonts/fonts.conf'
dst_fcfg="$dst_dir/etc/fonts/fonts.conf"
if [[ -f "$sys_fcfg" && ! -f "$dst_fcfg" ]]
then
info_msg "$YELLOW[ HOOK ]:$GREEN copy fonts.conf..."
try_mkdir "$dst_dir/etc/fonts"
try_cp "$sys_fcfg" "$dst_fcfg"
fi ;;
*/libxkbcommon*.so*)
sys_xcb_dir='/usr/share/X11/xkb'
dst_xcb_dir="$dst_dir/share/X11/xkb"
if [[ -d "$sys_xcb_dir" && ! -d "$dst_xcb_dir" ]]
then
info_msg "$YELLOW[ HOOK ]:$GREEN copy X11 xkb..."
try_mkdir "$dst_xcb_dir"
try_cp -T "$sys_xcb_dir" "$dst_xcb_dir"
fi ;;
*/libEGL_mesa.so*)
sys_glvnd_dir='/usr/share/glvnd/egl_vendor.d'
dst_glvnd_dir="$dst_dir/share/glvnd/egl_vendor.d"
if [[ -d "$sys_glvnd_dir" && ! -d "$dst_glvnd_dir" ]]
then
info_msg "$YELLOW[ HOOK ]:$GREEN copy EGL vendors..."
try_mkdir "$dst_glvnd_dir"
try_cp -T "$sys_glvnd_dir" "$dst_glvnd_dir"
fi ;;
*/libvulkan.so*)
sys_vk_icd_dir='/usr/share/vulkan/icd.d'
dst_vk_icd_dir="$dst_dir/share/vulkan/icd.d"
if [[ -d "$sys_vk_icd_dir" && ! -d "$dst_vk_icd_dir" ]]
then
info_msg "$YELLOW[ HOOK ]:$GREEN copy Vulkan ICD..."
try_mkdir "$dst_vk_icd_dir"
try_cp -T "$sys_vk_icd_dir" "$dst_vk_icd_dir"
sed -i 's|/usr/lib||g;s|/.*-linux-gnu||g;s|"/|"|g' "$dst_vk_icd_dir"/*
fi ;;
esac
fi
LIBRARIES["$lib_dst_pth"]=1
fi
else
skip_msg "$BLUE[$lib_src_pth]$YELLOW not shared object!"
fi
LIBRARIES["$lib_src_pth"]=1
fi
done
if [[ -n "$INTERPRETER" && "$PATCH_INTERPRETER" == 1 && "${LIBRARIES["${INTERPRETER}_patched"]}" != 1 ]]
then
if [[ "$LIBS_ONLY" != 1 && ! -n "$IS_SO" ]]
then
(try_cd "$bin_dir_pth"
if [ -f "../$lib_dir/$INTERPRETER" ]
then
info_msg "$YELLOW[ SET INTERPRETER ]: $BLUE[$bin_dir_pth/$binary_name -> ../$lib_dir/$INTERPRETER]"
patchelf $pvarg --set-interpreter "../$lib_dir/$INTERPRETER" "$binary_name"||exit 1
fi)||exit 1
fi
interpreter_pth="${dst_dir}/shared/$lib_dir/$INTERPRETER"
info_msg "$YELLOW[ PATCH INTERPRETER ]: $BLUE[$interpreter_pth]"
sed -i 's|/usr|/xxx|g;s|/lib|/XXX|g;s|/etc|/EEE|g' "$interpreter_pth"||exit 1
LIBRARIES["${INTERPRETER}_patched"]=1
fi
info_msg "[ DONE ]"
binary_number=$(( $binary_number + 1 ))
else
skip_msg "$BLUE[$binary]$YELLOW not dynamically linked!"
fi
else
skip_msg "$BLUE[$binary]$YELLOW not ELF!"
fi
BINARIES["$binary"]=1
fi
done
unset BINARIES LIBRARIES
if [ "$GEN_LIB_PATH" == 1 ]
then
for dst_dir in "${!DST_DIRS[@]}"
do
(for lib_dir in lib lib32
do
lib_dir="${dst_dir}/${lib_dir}"
if [ -d "$lib_dir" ]
then
info_msg "$YELLOW[ GEN LIB PATH ]: $BLUE[${lib_dir}/lib.path]" && \
find_so "$lib_dir"|xargs -I {} dirname "{}"|\
sort -u|sed "s|${lib_dir}|+|g" > "${lib_dir}/lib.path"||exit 1
fi
done)||exit 1
done
fi