tazpkg view lib/tazpkgbox/search @ rev 323

Show search Description button
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Feb 23 10:12:13 2010 +0100 (2010-02-23)
parents 9b57d55f7f65
children
line source
1 #!/bin/sh
2 #
3 # This script provides a suitable output for the search results.
4 #
6 # Clean preview results.
7 rm -f /tmp/tazpkgbox/search
8 touch /tmp/tazpkgbox/search
10 list_files()
11 {
12 sed 's/.\[[01]m//g' | awk 'BEGIN { show=0 } {
13 if (/^===/) show=1-show;
14 else if (/^Package/) pkg=$2;
15 else if ($0 != "" && show != 0) printf("%s %s\n",pkg,$0);
16 }' | while read pkg file; do
17 [ "$pkg" = "0" ] && continue
18 version=$(grep -hs "^$pkg " /var/lib/tazpkg/packages.desc \
19 /var/lib/tazpkg/undigest/*/packages.desc | awk '{ print $3 }')
20 if [ -d /var/lib/tazpkg/installed/$pkg ]; then
21 if [ -x $file ]; then
22 echo "exec|$pkg|$version|$file"
23 elif [ -f $file ]; then
24 echo "txt|$pkg|$version|$file"
25 elif [ -d $file ] ; then
26 echo "folder|$pkg|$version|$file"
27 else
28 # Missing installed file.
29 echo "dialog-warning|$pkg|$version|$file"
30 fi
31 else
32 echo "tazpkg|$pkg|$version|$file"
33 fi
34 done
35 }
37 list_package()
38 {
39 if [ -d /var/lib/tazpkg/installed/$1 ]; then
40 . /var/lib/tazpkg/installed/$1/receipt
41 echo "tazpkg-installed|$PACKAGE|$VERSION|$SHORT_DESC"
42 else
43 echo "tazpkg|$PACKAGE|$VERSION|$SHORT_DESC"
44 fi
45 }
47 search_package()
48 {
49 IFS="|"
50 cat /var/lib/tazpkg/packages.desc \
51 /var/lib/tazpkg/undigest/*/packages.desc 2> /dev/null | sort | \
52 while read PACKAGE VERSION SHORT_DESC; do
53 if echo "$PACKAGE $SHORT_DESC" | grep -iq "$SEARCH"; then
54 list_package ${PACKAGE%% *}
55 fi
56 done
57 unset IFS
58 }
60 case "$1" in
61 files)
62 tazpkg search-file "$SEARCH" --mirror | list_files > \
63 /tmp/tazpkgbox/search ;;
64 packages)
65 ( search_package ;
66 for i in $(grep ^$SEARCH= /var/lib/tazpkg/packages.equiv | \
67 cut -d= -f2); do
68 SEARCH=${i#*:}
69 search_package
70 done ) > /tmp/tazpkgbox/search ;;
71 tags)
72 grep -ls TAGS /home/slitaz/wok/*/receipt | while read file; do
73 TAGS=""
74 . $file
75 case "$TAGS" in
76 *$SEARCH*) list_package $PACKAGE ;;
77 esac
78 done > /tmp/tazpkgbox/search ;;
79 *)
80 echo "Usage: $0 [packages|files|tags]" ;;
81 esac
84 exit 0