tazpkg view modules/find-depends @ rev 955

modules/search: allow search file with dash at start: tazpkg -sf "-spi"
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Dec 22 00:02:54 2017 +0200 (2017-12-22)
parents 3af642cd5e69
children
line source
1 #!/bin/sh
2 # TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg
3 # find-depends - TazPkg module
4 # Functions that are common to tazpkg and tazpkg-convert and sourced by them.
7 # search dependencies for files in $TMP_DIR/$file/fs
9 find_depends() {
10 DEFAULT_DEPENDS='glibc-base gcc-lib-base'
12 [ ! -f "$PKGS_DB/files.list.lzma" ] && tazpkg recharge >/dev/null
14 for i in "$PKGS_DB/files.list.lzma" \
15 "$PKGS_DB/undigest/"*"/files.list.lzma"; do
16 # Extract files.list.lzma to find dependencies
17 # only lines with .so libs produces much faster search
18 [ -f "$i" ] && lzma d "$i" -so | fgrep '.so' | fgrep '/lib/' >> "$TMP_DIR/files.list"
19 done
21 _ 'Find depends...' 1>&2
22 libs_found=''
23 find "$1" -type f | \
24 while read chkfile; do
25 [ "$(dd bs=1 skip=1 count=3 < "$chkfile" 2>/dev/null)" != 'ELF' ] && continue
27 case "$chkfile" in
28 *.o|*.ko|*.ko.gz|*.ko.xz) continue;;
29 esac
31 for lib in $(LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so "$chkfile" 2>/dev/null | sed '/=>/!d;s/ =>.*//'); do
32 debug "lib='$lib'"
33 case " $libs_found " in
34 *\ $lib\ *) continue;;
35 esac
36 libs_found="$libs_found $lib"
37 case "$lib" in
38 statically|linux-gate.so*|ld-*.so|*/ld-*.so) continue;;
39 esac
40 find "${1:-$TMP_DIR/$file/fs}" | grep -q /$lib$ && continue
42 _n 'for %s' "$lib" 1>&2
43 echo -ne ' \r' 1>&2
45 for dep in $(fgrep "$lib" "$TMP_DIR/files.list" | cut -d: -f1); do
46 debug " dep='$dep'"
47 case " $DEFAULT_DEPENDS " in
48 *\ $dep\ *) continue 2;;
49 esac
50 grep -qs "^$dep$" "$TMP_DIR/depends" && continue 2
51 done
53 if [ -n "$dep" ]; then
54 debug " add '$dep' to depends"
55 echo "$dep" >> "$TMP_DIR/depends"
56 else
57 debug " add '$lib' to unresolved"
58 grep -qs ^$lib$ "$TMP_DIR/unresolved" ||
59 echo "$lib" >> "$TMP_DIR/unresolved"
60 fi
61 done
62 done
64 spc=''
65 [ -s "$TMP_DIR/depends" ] &&
66 sort < "$TMP_DIR/depends" 2>/dev/null | uniq | \
67 while read file; do
68 echo -n "$spc$file"
69 spc=' '
70 done
71 }