cookutils annotate modules/cdeps @ rev 950

cook: dot command may not search current directory first
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Jul 23 12:35:12 2017 +0200 (2017-07-23)
parents
children
rev   line source
al@890 1 #!/bin/sh
al@890 2 #
al@890 3 # cdeps - module of the SliTaz Cook
al@890 4 # Copyright (C) SliTaz GNU/Linux - GNU GPL v3
al@890 5 #
al@890 6
al@890 7 . /usr/lib/slitaz/libcook.sh
al@890 8
al@890 9
al@890 10 # Search file in mirrored packages
al@890 11
al@890 12 search_file_mirror() {
al@890 13 busybox unlzma -c $DB/files.list.lzma | grep $1\$ | cut -d: -f1 | sort -u
al@890 14 }
al@890 15
al@890 16
al@890 17 # Search file in local wok packages
al@890 18
al@890 19 search_file_local() {
al@890 20 # existing packages have precedence over the package/taz folder
al@890 21 srch=$1
al@890 22 { for package in $(find $PKGS -name '*.tazpkg'); do
al@890 23 if [ -n "$(busybox cpio --to-stdout --quiet -i files.list < $package | \
al@890 24 grep /$srch\$)" ]; then
al@890 25 busybox cpio -i receipt < $package | fgrep PACKAGE | cut -d\" -f2
al@890 26 fi
al@890 27 done } | sort -u
al@890 28 }
al@890 29
al@890 30
al@890 31 # Ask in multiple choice
al@890 32
al@890 33 ask_multiple() {
al@890 34 local multiples first my_choice
al@890 35 multiples="$1"
al@890 36 first=$(echo "$multiples" | head -n1)
al@890 37 newline; _ 'Multiple choice:'; echo "$multiples"; newline
al@890 38 _ 'Select one [%s]: ' "$first"; read my_choice
al@890 39 found="${my_choice:-$first}"
al@890 40 }
al@890 41
al@890 42
al@890 43 # Search file in local cache (fast), local wok packages, mirrored packages
al@890 44
al@890 45 search_file() {
al@890 46 local srch cache missing
al@890 47 srch="$1"
al@890 48 cache='/var/cache/ldsearch.cache'
al@890 49 missing='/var/cache/missing.file'
al@890 50 touch $cache $missing
al@890 51 found=$(grep $srch $cache | cut -d$'\t' -f2)
al@890 52 if [ -z "$found" ]; then
al@890 53 found=$(search_file_local $srch)
al@890 54 if [ -n "$found" ]; then
al@890 55 if [ $(echo "$found" | wc -l) -gt 1 ]; then
al@890 56 ask_multiple "$found"
al@890 57 fi
al@890 58 echo -e "$srch\t$found" >> $cache
al@890 59 else
al@890 60 found=$(search_file_mirror $srch)
al@890 61 if [ -n "$found" ]; then
al@890 62 if [ $(echo "$found" | wc -l) -gt 1 ]; then
al@890 63 ask_multiple "$found"
al@890 64 fi
al@890 65 echo -e "$srch\t$found" >> $cache
al@890 66 else
al@890 67 echo "$srch" >> $missing
al@890 68 fi
al@890 69 fi
al@890 70 fi
al@890 71 }
al@890 72
al@890 73
al@890 74
al@890 75
al@890 76
al@890 77
al@890 78 if [ ! -d $WOK/$pkg/taz ]; then
al@890 79 _ 'Need to build "%s"' "$pkg"
al@890 80 exit 0
al@890 81 fi
al@890 82
al@890 83 title 'Checking depends'
al@890 84 lddlist='/tmp/lddlist'; touch $lddlist
al@890 85 missing='/var/cache/missing.file'
al@890 86
al@890 87 # find all deps using ldd
al@890 88 for exe in $(find $WOK/$pkg/taz -type f -perm +111); do
al@890 89 [ "x$(dd if=$exe bs=4 count=1 2>/dev/null)" == "xELF" ] && #"
al@890 90 ldd $exe | sed 's| ||' | cut -d' ' -f1 >> $lddlist
al@890 91 done
al@890 92
al@890 93 # remove exe/so duplicates
al@890 94 sort -u $lddlist > $lddlist.sorted
al@890 95
al@890 96 # search packages
al@890 97 for exefile in $(cat $lddlist.sorted); do
al@890 98 search_file $exefile
al@890 99 echo "$found" >> $lddlist.pkgs
al@890 100 echo -n '.'
al@890 101 done
al@890 102 echo
al@890 103
al@890 104 # remove packages duplicates
al@890 105 sort -u $lddlist.pkgs > $lddlist.final
al@890 106 sort -u $missing > $missing.final
al@890 107 rm -f $lddlist $lddlist.sorted $lddlist.pkgs $missing
al@890 108 exit 0