tazpkg view oldstuff/libtazpkgbox @ rev 947

modules/get: get_pkg_cookmode(): file may be absent.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon Jun 05 22:36:04 2017 +0300 (2017-06-05)
parents f1d05bd96d7f
children
line source
1 #!/bin/sh
2 # The libtazpkgbox - Libraries used by tazpkg GUI box.
3 #
4 # These are functions to list installed packages in a suitable format for a
5 # GTK tree and list mirrored packages using the packages.desc file. The libs
6 # also provide functions to search packages and files, and the GUI box for
7 # package information.
8 #
9 # (C) 2010 SliTaz - GNU General Public License v3.
10 #
12 # Include gettext helper script.
13 . /usr/bin/gettext.sh
15 # Export package name for gettext.
16 TEXTDOMAIN='libtazpkgbox'
17 export TEXTDOMAIN
19 # Dont hardcore path, use $LIB
20 export LIB=/usr/lib/slitaz/libtazpkgbox
22 usage()
23 {
24 [ "$1" ] && echo "??? $0 $@"
25 echo -e "\nTazpkgbox library\n
26 Usage : $0 [function] [pkg|args] [pkg]
27 Functions:
28 list-all List all packages.
29 list-undigest List undigest packages.
30 list-blocked List blocked packages.
31 list-upgradeable List all upgradable packages.
32 search-packages Search for packages.
33 search-files Search for files.
34 search-tags Search for TAGS.
35 package-infos Display box with pkg information."
36 }
38 # List functions.
39 undigest_list()
40 {
41 IFS="|"
42 if [ "$1" -a "$1" != "all" ]; then
43 cut -f 1,2,3,4 -d "|" undigest/$1/packages.desc
44 else
45 cut -f 1,2,3,4 -d "|" undigest/*/packages.desc | sort
46 fi 2> /dev/null | while read PACKAGE VERSION SHORT_DESC CATEGORY; do
47 [ $CAT = all -o $CATEGORY = " $CAT " ] || continue
48 ICON=tazpkg
49 PACKAGE=${PACKAGE%% *}
50 if [ -d installed/$PACKAGE ]; then
51 [ "$2" = "installable" ] && continue
52 ICON=tazpkg-installed
53 if grep -qs "^$PACKAGE$" blocked-packages.list; then
54 ICON=stop
55 fi
56 else
57 [ "$2" = "installed" ] && continue
58 fi
59 [ "$2" = "blocked" -a "$ICON" != "stop" ] && continue
60 [ "$2" = "upgradeable" ] &&
61 ! grep -q ^$PACKAGE$ upgradeable-packages.list && continue
62 echo "$ICON|$PACKAGE|$VERSION|$SHORT_DESC"
63 done
64 unset IFS
65 }
67 installable_list()
68 {
69 local cache
70 cache=packages.installable_list.$CAT
71 if [ -s $cache -a $cache -nt packages.desc -a $cache -nt installed ]; then
72 cat $cache
73 return
74 fi
75 IFS="|"
76 cut -f 1,2,3,4 -d "|" packages.desc undigest/*/packages.desc 2> /dev/null | sort | \
77 while read PACKAGE VERSION SHORT_DESC CATEGORY; do
78 # Check first for category for more speed.
79 [ $CAT = all -o $CATEGORY = " $CAT " ] || continue
80 [ -d installed/${PACKAGE% } ] && continue
81 ICON=tazpkg
82 grep -qs "^$PACKAGE" undigest/*/packages.desc && ICON=add
83 echo "$ICON|$PACKAGE|$VERSION|$SHORT_DESC"
84 done | tee $cache
85 unset IFS
86 }
88 installed_list()
89 {
90 for pkg in ${1}installed/*
91 do
92 [ "$1" -a -s installed/$(basename $pkg)/receipt ] && continue
93 . $pkg/receipt
94 ICON=tazpkg-installed
95 [ $CAT = all -o $CATEGORY = $CAT ] || continue
96 if [ "$1" -o -L $pkg ]; then
97 ICON=media-flash
98 else
99 grep -qs "^$PACKAGE" undigest/*/packages.desc && ICON=add
100 fi
101 grep -qs "^$PACKAGE$" blocked-packages.list && ICON=stop
102 echo "$ICON|$PACKAGE|$VERSION|$SHORT_DESC"
103 done
104 }
106 all_list()
107 {
108 local cache
109 cache=packages.all_list.$CAT
110 if [ -s $cache -a $cache -nt packages.desc -a $cache -nt installed ]; then
111 cat $cache
112 return
113 fi
114 { installable_list ; installed_list; } | sort -t \| -k 2 -u | tee $cache
115 }
117 blocked_list()
118 {
119 ICON=tazpkg-installed
120 [ "$1" = "blocked" ] && ICON=stop
121 for pkg in $(cat $1-packages.list 2> /dev/null); do
122 [ -f installed/$pkg/receipt ] || continue
123 . installed/$pkg/receipt
124 [ $CAT = all -o $CATEGORY = $CAT ] || continue
125 AVAILABLE=$(grep -s "^$pkg " packages.desc \
126 undigest/*/packages.desc | awk '{ print $3 }')
127 echo "$ICON|$PACKAGE|$VERSION (Available: $AVAILABLE)|$SHORT_DESC"
128 done
129 }
131 # Search functions
133 clean_search()
134 {
135 # Clean preview results.
136 rm -f /tmp/tazpkgbox/search
137 touch /tmp/tazpkgbox/search
138 }
140 list_files()
141 {
142 sed -e "/^$/d" -e "1,/^=*$/d" -e "/^=*$/,/EOT/d" | while read input; do
143 if [ "$input" = "${input/ :/}" ]; then
144 # Input is a file.
145 if [ "$ICON" = tazpkg ]; then
146 echo "add|$PACKAGE| |$input"
147 else
148 if [ -d $input ] ; then
149 echo "folder|$PACKAGE| |$input"
150 elif [ -x $input ]; then
151 echo "exec|$PACKAGE| |$input"
152 elif [ -f $input ]; then
153 echo "txt|$PACKAGE| |$input"
154 else
155 # Missing installed file.
156 echo "dialog-warning|$PACKAGE| |$input"
157 fi
158 fi
159 else
160 # Input contains package name, don't refer to Package word as
161 # tazpkg can use other languages.
162 PACKAGE=$(echo $input | sed 's/^.* \(.*\) :.*$/\1/')
163 ICON=tazpkg
164 [ -d /var/lib/tazpkg/installed/$PACKAGE ] && ICON=tazpkg-installed
165 echo "$ICON|$PACKAGE |$(grep -hs "^$PACKAGE " /var/lib/tazpkg/packages.desc \
166 /var/lib/tazpkg/undigest/*/packages.desc | cut -f2,3 -d '|' | head -1)"
167 fi
168 done
169 }
171 list_package()
172 {
173 if [ -d /var/lib/tazpkg/installed/$1 ]; then
174 . /var/lib/tazpkg/installed/$1/receipt
175 echo "tazpkg-installed|$PACKAGE|$VERSION|$SHORT_DESC"
176 else
177 echo "tazpkg|$PACKAGE|$VERSION|$SHORT_DESC"
178 fi
179 }
181 search_package()
182 {
183 IFS="|"
184 cut -f1,2,3 -d '|' /var/lib/tazpkg/packages.desc \
185 /var/lib/tazpkg/undigest/*/packages.desc 2> /dev/null | sort | \
186 while read PACKAGE VERSION SHORT_DESC; do
187 [ "$PACKAGE" = "${PACKAGE/$SEARCH/}" -a "$SHORT_DESC" = "${SHORT_DESC/$SEARCH/}" ] \
188 && continue
189 list_package ${PACKAGE% }
190 done
191 unset IFS
192 }
194 case "$1" in
195 list-all)
196 cd /var/lib/tazpkg
197 CAT=`cat /tmp/tazpkgbox/category`
198 STATUS=`cat /tmp/tazpkgbox/status`
199 case $STATUS in
200 blocked|upgradeable)
201 blocked_list $STATUS;;
202 linkable)
203 [ -d fslink ] && installed_list \
204 $(readlink fslink)/var/lib/tazpkg/;;
205 installed)
206 installed_list ;;
207 installable)
208 installable_list ;;
209 *)
210 all_list ;;
211 esac ;;
212 list-undigest)
213 cd /var/lib/tazpkg
214 set -- `cat /tmp/tazpkgbox/undigest-category`
215 CAT="${1:-all}"
216 undigest_list $2 $3 ;;
217 list-blocked|list-upgradeable)
218 cd /var/lib/tazpkg
219 CAT=`cat /tmp/tazpkgbox/category`
220 blocked_list $1 ;;
221 search-files)
222 # Search for files
223 clean_search
224 tazpkg search-file "$SEARCH" --mirror | list_files > \
225 /tmp/tazpkgbox/search ;;
226 search-packages)
227 clean_search
228 { search_package ;
229 for i in $(grep ^$SEARCH= /var/lib/tazpkg/packages.equiv | \
230 cut -d= -f2); do
231 SEARCH=${i#*:}
232 search_package
233 done; } > /tmp/tazpkgbox/search ;;
234 search-tags)
235 clean_search
236 fgrep -ls TAGS /home/slitaz/wok/*/receipt | while read file; do
237 TAGS=""
238 . $file
239 case "$TAGS" in
240 *$SEARCH*) list_package $PACKAGE ;;
241 esac
242 done > /tmp/tazpkgbox/search ;;
243 package-infos)
244 # Dialog box to provide package info and actions
245 XTERM_OPTS="-geometry 80x16+120+120"
246 PKG=`cat /tmp/tazpkgbox/pkg | sed s/" "/""/g`
247 ROOT=/var/lib/tazpkg
248 if [ "$(cat /tmp/tazpkgbox/status)" = "linkable" ]; then
249 ROOT=$(readlink /var/lib/tazpkg/fslink)$ROOT
250 fi
251 TMP_DIR=/tmp/tazpkg-$$-$RANDOM
252 if [ "$2" = "sizes" ]; then
253 cat <<EOT
254 Dependencies for $3:
255 $(tazpkg depends $3)
257 Reverse dependencies for $3:
258 $(tazpkg rdepends $3)
259 EOT
260 exit 0
261 fi
262 if [ "$2" = "info" ]; then
263 RECEIPT=$ROOT/installed/$4/receipt
264 . $RECEIPT
265 case "$3" in
266 Web*) browser $WEB_SITE &;;
267 Tip*) browser http://hg.slitaz.org/wok/raw-file/tip/$4/receipt &;;
268 Siz*) xterm -T "$4 `gettext \"depends (q to quit)\"`" -e "$0 package-infos sizes $4 | less";;
269 Upg*) xterm -T "$4 `gettext \"upgrade\"`" -e "tazpkg get-install $4 --forced ; sleep 2";;
270 Hand*) browser $HANDBOOK_URL &;;
271 Sug*) $0 package-infos list_packages $SUGGESTED;;
272 Dep*) $0 package-infos list_packages $DEPENDS;;
273 Mod*) $0 package-infos list_packages $(xargs echo < $ROOT/installed/$3/modifiers);;
274 Con*) tazpkgbox list_config $4;;
275 Ver*) xterm -T "$4 `gettext \"receipt (q to quit)\"`" -e "cat $RECEIPT | less";;
276 esac
277 exit 0
278 fi
280 if [ "$2" = "list_files" ]; then
281 CONF_FILES="$(tazpkg list-config $3 | awk "$AWK_FILTER")"