tazpkg annotate modules/find-depends @ rev 840
Add a bunch of modules with new-style support of 'root' (not all commands are modules yet); strip and compress resources.
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Fri Aug 28 16:10:34 2015 +0300 (2015-08-28) |
parents | 2f3580bd8c0c |
children | d6cbd0c5f273 |
rev | line source |
---|---|
al@822 | 1 #!/bin/sh |
al@828 | 2 # TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg |
al@828 | 3 # find-depends - TazPkg module |
al@828 | 4 # Functions that are common to tazpkg and tazpkg-convert, and sourced by them. |
al@822 | 5 |
al@822 | 6 |
al@822 | 7 # Need by check_depends |
al@840 | 8 unset TMPLOCALSTATE |
al@822 | 9 |
al@822 | 10 |
al@822 | 11 # Check for ELF file |
al@822 | 12 |
al@828 | 13 is_elf() { |
al@828 | 14 [ "$(dd if="$1" bs=1 skip=1 count=3 2>/dev/null)" == 'ELF' ] |
al@822 | 15 } |
al@822 | 16 |
al@822 | 17 |
al@822 | 18 # Print shared library dependencies |
al@822 | 19 |
al@828 | 20 ldd() { |
al@822 | 21 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so "$1" 2>/dev/null |
al@822 | 22 } |
al@822 | 23 |
al@822 | 24 |
al@822 | 25 # search dependencies for files in $TMP_DIR/$file/fs |
al@822 | 26 |
al@828 | 27 find_depends() { |
al@828 | 28 DEFAULT_DEPENDS='glibc-base gcc-lib-base' |
al@822 | 29 |
al@828 | 30 [ -z "$TMPLOCALSTATE" ] && TMPLOCALSTATE="$PKGS_DB" |
al@828 | 31 [ ! -f "$TMPLOCALSTATE/files.list.lzma" ] && tazpkg recharge >/dev/null |
al@840 | 32 for i in "$TMPLOCALSTATE/files.list.lzma" \ |
al@840 | 33 "$TMPLOCALSTATE/undigest/"*"/files.list.lzma"; do |
al@840 | 34 [ -f "$i" ] && lzma d "$i" -so >> "$TMP_DIR/files.list" |
al@822 | 35 done |
al@822 | 36 |
al@828 | 37 _ 'Find depends...' 1>&2 |
al@828 | 38 libs_found='' |
al@840 | 39 find "${1:-$TMP_DIR/$file/fs}" -type f | \ |
al@840 | 40 while read chkfile; do |
al@822 | 41 is_elf "$chkfile" || continue |
al@822 | 42 case "$chkfile" in |
al@828 | 43 *.o|*.ko|*.ko.gz|*.ko.xz) continue;; |
al@822 | 44 esac |
al@822 | 45 |
al@840 | 46 for lib in $(ldd "$chkfile" | sed '/=>/!d;s/ =>.*//'); do |
al@822 | 47 case " $libs_found " in |
al@822 | 48 *\ $lib\ *) continue |
al@822 | 49 esac |
al@822 | 50 libs_found="$libs_found $lib" |
al@822 | 51 case "$lib" in |
al@822 | 52 statically|linux-gate.so*|ld-*.so|*/ld-*.so) continue;; |
al@822 | 53 esac |
al@840 | 54 find "${1:-$TMP_DIR/$file/fs}" | grep -q /$lib$ && continue |
al@822 | 55 |
al@828 | 56 _n 'for %s' "$lib" 1>&2 |
al@828 | 57 echo -ne " \r" 1>&2 |
al@828 | 58 |
al@822 | 59 for dep in $(fgrep $lib files.list | cut -d: -f1); do |
al@822 | 60 case " $DEFAULT_DEPENDS " in |
al@822 | 61 *\ $dep\ *) continue 2;; |
al@822 | 62 esac |
al@840 | 63 grep -qs "^$dep$" "$TMP_DIR/depends" && continue 2 |
al@822 | 64 done |
al@822 | 65 |
al@822 | 66 if [ -n "$dep" ]; then |
al@840 | 67 echo "$dep" >> "$TMP_DIR/depends" |
al@822 | 68 else |
al@840 | 69 grep -qs ^$lib$ "$TMP_DIR/unresolved" || |
al@840 | 70 echo "$lib" >> "$TMP_DIR/unresolved" |
al@822 | 71 fi |
al@822 | 72 done |
al@822 | 73 done |
al@822 | 74 |
al@828 | 75 spc='' |
al@828 | 76 [ -s "$TMP_DIR/depends" ] && |
al@840 | 77 sort < "$TMP_DIR/depends" 2>/dev/null | uniq | \ |
al@822 | 78 while read file; do |
al@822 | 79 echo -n "$spc$file" |
al@828 | 80 spc=' ' |
al@822 | 81 done |
al@822 | 82 } |
al@822 | 83 |
al@822 | 84 |