tazpkg view modules/find-depends @ rev 828

Add modules "info", "list" with extended functions; update documentations and translations
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue Aug 11 01:09:15 2015 +0300 (2015-08-11)
parents f7e9a5b8477b
children a02e36d44d06
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 # Need by check_depends
8 TMPLOCALSTATE=
11 # Check for ELF file
13 is_elf() {
14 [ "$(dd if="$1" bs=1 skip=1 count=3 2>/dev/null)" == 'ELF' ]
15 }
18 # Print shared library dependencies
20 ldd() {
21 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so "$1" 2>/dev/null
22 }
25 # search dependencies for files in $TMP_DIR/$file/fs
27 find_depends() {
28 DEFAULT_DEPENDS='glibc-base gcc-lib-base'
30 [ -z "$TMPLOCALSTATE" ] && TMPLOCALSTATE="$PKGS_DB"
31 [ ! -f "$TMPLOCALSTATE/files.list.lzma" ] && tazpkg recharge >/dev/null
32 for i in $TMPLOCALSTATE/files.list.lzma \
33 $TMPLOCALSTATE/undigest/*/files.list.lzma ; do
34 [ -f "$i" ] && lzma d $i -so >> $TMP_DIR/files.list
35 done
37 _ 'Find depends...' 1>&2
38 libs_found=''
39 find ${1:-$TMP_DIR/$file/fs} -type f | \
40 while read chkfile ; do
41 is_elf "$chkfile" || continue
42 case "$chkfile" in
43 *.o|*.ko|*.ko.gz|*.ko.xz) continue;;
44 esac
46 for lib in $(ldd "$chkfile" | sed '/=>/!d;s/ =>.*//') ; do
47 case " $libs_found " in
48 *\ $lib\ *) continue
49 esac
50 libs_found="$libs_found $lib"
51 case "$lib" in
52 statically|linux-gate.so*|ld-*.so|*/ld-*.so) continue;;
53 esac
54 find ${1:-$TMP_DIR/$file/fs} | grep -q /$lib$ && continue
56 _n 'for %s' "$lib" 1>&2
57 echo -ne " \r" 1>&2
59 for dep in $(fgrep $lib files.list | cut -d: -f1); do
60 case " $DEFAULT_DEPENDS " in
61 *\ $dep\ *) continue 2;;
62 esac
63 grep -qs "^$dep$" $TMP_DIR/depends && continue 2
64 done
66 if [ -n "$dep" ]; then
67 echo "$dep" >> $TMP_DIR/depends
68 else
69 grep -qs ^$lib$ $TMP_DIR/unresolved ||
70 echo "$lib" >> $TMP_DIR/unresolved
71 fi
72 done
73 done
75 spc=''
76 [ -s "$TMP_DIR/depends" ] &&
77 sort < $TMP_DIR/depends 2>/dev/null | uniq | \
78 while read file; do
79 echo -n "$spc$file"
80 spc=' '
81 done
82 }