slitaz-forge view pkgs/mirror-search.sh @ rev 374

mirror-search: fix multiple LICENSE search
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Jul 16 08:52:49 2013 +0200 (2013-07-16)
parents 22d996164de0
children f7caab5251c0
line source
1 #!/bin/sh
3 # Tiny CGI search engine for SliTaz packages on http://pkgs.slitaz.org/
4 # Christophe Lincoln <pankso@slitaz.org>
5 # Pascal Bellard <pascal.bellard@slitaz.org>
6 # Aleksej Bobylev <al.bobylev@gmail.com>
7 #
9 renice -n 19 $$
11 # Parse query string
12 . /usr/lib/slitaz/httphelper.sh
14 case "$HTTP_USER_AGENT" in
15 */[Bb]ot*|*[Bb]ot/*|*spider/*) exec $PWD/Travaux.sh ;;
16 esac
18 # User preferred language
19 # parameter $1 have priority; without parameter $1 - browser language only
20 # if we don't support any of user languages (or only en), then return C locale
21 user_lang() {
22 LANG="C"
23 IFS=","
24 for lang in $1 $HTTP_ACCEPT_LANGUAGE
25 do
26 lang=${lang%;*} lang=${lang# } lang=${lang%-*} lang=${lang%_*}
27 case "$lang" in
28 de) LANG="de_DE" ;;
29 es) LANG="es_ES" ;;
30 fr) LANG="fr_FR" ;;
31 it) LANG="it_IT" ;;
32 pt) LANG="pt_BR" ;;
33 ru) LANG="ru_RU" ;;
34 zh) LANG="zh_TW" ;;
35 esac
36 if echo "de en fr pt ru zh" | fgrep -q "$lang"; then
37 break
38 fi
39 done
40 unset IFS
41 echo "$LANG"
42 }
44 # Short 2-letter lang code from ll_CC
45 ll_lang() {
46 ll_CC="$1"
47 echo ${ll_CC%_*}
48 }
50 # Nice URL replacer - to copy url from address bar
51 # TODO: deal with POST method of form submitting
52 nice_url() {
53 # if user submitted a form
54 if [ ! -z $(GET submit) ]; then
55 OBJECT="$(GET object)"
56 SEARCH="$(GET query)"
57 case $OBJECT in
58 Package) NICE="package=$SEARCH";;
59 Desc) NICE="desc=$SEARCH";;
60 Tags) NICE="tags=$SEARCH";;
61 Arch) NICE="arch=$SEARCH";;
62 Bugs) NICE="bugs=$SEARCH";;
63 Receipt) NICE="receipt=$SEARCH";;
64 Depends) NICE="depends=$SEARCH";;
65 BuildDepends) NICE="builddepends=$SEARCH";;
66 File) NICE="file=$SEARCH";;
67 File_list) NICE="filelist=$SEARCH";;
68 FileOverlap) NICE="fileoverlap=$SEARCH";;
69 esac
70 # version, if needed
71 version="$(GET version)"
72 if [ ! -z "$version" -a "$version" != "cooking" ]; then
73 NICE="${NICE}&version=${version:0:1}"
74 fi
75 # lang, if needed
76 query_lang="$(GET lang)"
77 pref_lang="$(user_lang)"
78 browser_lang="$(ll_lang $pref_lang)"
79 if [ ! -z "$query_lang" -a "$query_lang" != "$browser_lang" ]; then
80 NICE="${NICE}&lang=$query_lang"
81 fi
82 # verbose, if needed
83 verboseq="$(GET verbose)"
84 if [ ! -z "$verboseq" -a "$verboseq" != "0" ]; then
85 NICE="${NICE}&verbose=1"
86 fi
87 # redirect
88 # TODO: implement HTTP 301 Redirect
89 cat << EOT
90 Content-type: text/html
92 <!DOCTYPE html>
93 <html><head><meta http-equiv="refresh" content="0;url=$SCRIPT_NAME?$NICE" />
94 <title>Redirect</title></head></html>
95 EOT
96 # echo "Location: $SCRIPT_NAME?$NICE"
97 # echo
98 exit 0
99 fi
100 }
102 nice_url
106 OBJECT="$(GET object)"
107 SEARCH="$(GET query)"
108 SLITAZ_VERSION="$(GET version)"
109 VERBOSE="$(GET verbose)"
111 # Internal variables
112 #DATE=$(date +%Y-%m-%d\ %H:%M:%S)
114 # Internationalization
115 . /usr/bin/gettext.sh
116 export TEXTDOMAIN='tazpkg-web'
118 SEARCH=""
119 VERBOSE=0
120 for i in $(echo $QUERY_STRING | sed 's/[?&]/ /g'); do
121 # SLITAZ_VERSION=cooking
122 case "$(echo $i | tr [A-Z] [a-z])" in
123 query=*|search=*) [ ${i#*=} == Search ] || SEARCH=${i#*=};;
124 object=*) OBJECT=${i#*=};;
125 verbose=*) VERBOSE=${i#*=};;
126 lang=*) LANG=${i#*=};;
127 file=*) SEARCH=${i#*=}; OBJECT=File;;
128 desc=*) SEARCH=${i#*=}; OBJECT=Desc;;
129 tags=*) SEARCH=${i#*=}; OBJECT=Tags;;
130 arch=*) SEARCH=${i#*=}; OBJECT=Arch;;
131 bugs=*) SEARCH=${i#*=}; OBJECT=Bugs;;
132 receipt=*) SEARCH=${i#*=}; OBJECT=Receipt;;
133 filelist=*) SEARCH=${i#*=}; OBJECT=File_list;;
134 package=*) SEARCH=${i#*=}; OBJECT=Package;;
135 depends=*) SEARCH=${i#*=}; OBJECT=Depends;;
136 builddepends=*) SEARCH=${i#*=}; OBJECT=BuildDepends;;
137 fileoverlap=*) SEARCH=${i#*=}; OBJECT=FileOverlap;;
138 category=*) SEARCH=${i#*=}; OBJECT=Category;;
139 maintainer=*) SEARCH=${i#*=}; OBJECT=Maintainer;;
140 license=*) SEARCH=${i#*=}; OBJECT=License;;
141 version=[1-9]*) i=${i%%.*}; SLITAZ_VERSION=${i#*=}.0;;
142 version=s*|version=4*) SLITAZ_VERSION=stable;;
143 version=u*) SLITAZ_VERSION=undigest;;
144 version=t*) SLITAZ_VERSION=tiny;;
145 esac
146 done
147 [ -z "$SLITAZ_VERSION" ] && SLITAZ_VERSION=cooking
148 #[ -n "$SEARCH" ] && REQUEST_METHOD="POST"
149 #[ "$SEARCH" == "." ] && SEARCH=
152 # Content negotiation for Gettext
153 LANG=$(user_lang $(GET lang))
154 lang="$(ll_lang $LANG)"
155 export LANG LC_ALL=$LANG
158 case "$OBJECT" in
159 File) selected_file="selected";;
160 Desc) selected_desc="selected";;
161 Tags) selected_tags="selected";;
162 Arch) selected_arch="selected";;
163 Bugs) selected_bugs="selected";;
164 Receipt) selected_receipt="selected";;
165 File_list) selected_file_list="selected";;
166 Depends) selected_depends="selected";;
167 BuildDepends) selected_build_depends="selected";;
168 FileOverlap) selected_overlap="selected";;
169 esac
171 case "$SLITAZ_VERSION" in
172 tiny) selected_tiny="selected";;
173 1.0) selected_1="selected";;
174 2.0) selected_2="selected";;
175 3.0) selected_3="selected";;
176 stable) selected_stable="selected";;
177 undigest) selected_undigest="selected";;
178 esac
180 # unescape query
181 SEARCH="$(echo $SEARCH | sed 's/%2B/+/g; s/%3A/:/g; s|%2F|/|g')"
183 WOK=/home/slitaz/$SLITAZ_VERSION/wok
184 PACKAGES_REPOSITORY=/home/slitaz/$SLITAZ_VERSION/packages
187 # TODO: header function from httphelper
188 echo "Content-type: text/html"
189 echo
191 # Search form
192 # TODO: implement POST method
193 # ... method="post" enctype="multipart/form-data" ...
194 # TODO: add hint 'You are can search for depends loop, if textfield is empty'...
195 # add progress ticker while page is not complete
196 search_form()
197 {
198 cat << _EOT_
200 <form id="s_form" method="get" action="$SCRIPT_NAME">
201 <input type="hidden" name="lang" value="$lang" />
202 <select name="object">
203 <option value="Package">$(gettext "Package")</option>
204 <option $selected_desc value="Desc">$(gettext "Description")</option>
205 <option $selected_tags value="Tags">$(gettext "Tags")</option>
206 <!-- option $selected_arch value="Tags">$(gettext "Arch")</option -->
207 <!-- option $selected_bugs value="Bugs">$(gettext "Bugs")</option -->
208 <option $selected_receipt value="Receipt">$(gettext "Receipt")</option>
209 <option $selected_depends value="Depends">$(gettext "Depends")</option>
210 <option $selected_build_depends value="BuildDepends">$(gettext "Build depends")</option>
211 <option $selected_file value="File">$(gettext "File")</option>
212 <option $selected_file_list value="File_list">$(gettext "File list")</option>
213 <option $selected_overlap value="FileOverlap">$(gettext "common files")</option>
214 </select>
215 <input type="text" name="query" id="query" size="20" value="$SEARCH" />
216 <select name="version">
217 <option value="cooking">$(gettext "cooking")</option>
218 <option $selected_stable value="stable">4.0</option>
219 <option $selected_3 value="3.0">3.0</option>
220 <option $selected_2 value="2.0">2.0</option>
221 <option $selected_1 value="1.0">1.0</option>
222 <option $selected_tiny value="tiny">$(gettext "tiny")</option>
223 <option $selected_undigest value="undigest">$(gettext "undigest")</option>
224 </select>
225 <input type="submit" name="submit" value="$(gettext 'Search')" />
226 </form>
227 _EOT_
228 }
230 # xHTML5 Header.
231 xhtml_header() {
232 . lib/header.sh
233 }
235 cat_files_list()
236 {
237 local tmp=/tmp/files.list.$(basename ${1%/packages})
238 if [ ! -s $tmp -o $1/files.list.lzma -nt $tmp ]; then
239 unlzma -c $1/files.list.lzma > $tmp.$$ && mv $tmp.$$ $tmp
240 fi
241 case "$2" in
242 lines) if [ ! -s $tmp.lines -o $tmp -nt $tmp.lines ]; then
243 cat $tmp | wc -l > $tmp.lines.$$ &&
244 mv $tmp.lines.$$ $tmp.lines
245 fi
246 cat $tmp.lines ;;
247 *) cat $tmp ;;
248 esac
249 }
251 # xHTML Footer.
252 # TODO: caching the summary for 5 minutes
253 xhtml_footer() {
254 file=/tmp/footer-$SLITAZ_VERSION
255 [ ! -e $file -o $PACKAGES_REPOSITORY/packages.txt -nt $file ] &&
256 cat > $file.$$ <<EOT && mv -f $file.$$ $file
257 PKGS=$(ls $WOK/ | wc -l)
258 FILES=$(cat_files_list $PACKAGES_REPOSITORY lines)
259 EOT
260 PKGS=$(sed '/PKGS=/!d;s/PKGS=//' $file)
261 FILES=$(sed '/FILES=/!d;s/FILES=//' $file)
262 . lib/footer.sh
263 }
265 installed_size()
266 {
267 if [ $VERBOSE -gt 0 ]; then
268 inst=$(grep -A 3 "^$1\$" $PACKAGES_REPOSITORY/packages.txt | grep installed)
269 # size=$(echo $inst | cut -d'(' -f2 | cut -d' ' -f1)
270 echo $inst | sed 's/.*(\(.*\).*/(\1)/'
271 # echo $size
272 # | sed 's/.*(\(.*\) installed.*/(\1) /'
273 fi
274 }
276 package_entry()
277 {
278 if [ -s "$(dirname $0)/$SLITAZ_VERSION/$CATEGORY.html" ]; then
279 cat << _EOT_
280 <a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> $(installed_size $PACKAGE): $SHORT_DESC
281 _EOT_
282 else
283 PACKAGE_HREF="<u>$PACKAGE</u>"
284 PACKAGE_URL="http://mirror.slitaz.org/packages/$SLITAZ_VERSION/$PACKAGE-$VERSION$EXTRA_VERSION.tazpkg"
285 nslookup mirror.slitaz.org | grep -q 127.0.0.1 &&
286 [ -d /var/www/slitaz/mirror/packages/$SLITAZ_VERSION/$PACKAGE-$VERSION ] &&
287 PACKAGE_URL="http://mirror.slitaz.org/packages/$SLITAZ_VERSION/$PACKAGE-$VERSION" ||
288 PACKAGE_URL="http://mirror.slitaz.org/packages/$SLITAZ_VERSION/$(cd /var/www/slitaz/mirror/packages/$SLITAZ_VERSION ; ls $PACKAGE-$VERSION*.tazpkg)"
289 busybox wget -s $PACKAGE_URL 2> /dev/null &&
290 PACKAGE_HREF="<a href=\"$PACKAGE_URL\">$PACKAGE</a>"
291 COOKER=""
292 [ "$SLITAZ_VERSION" == "cooking" ] &&
293 COOKER="<a href=\"http://cook.slitaz.org/cooker.cgi?pkg=$PACKAGE\">$(gettext "Cooker")</a>"
294 cat << _EOT_
295 $PACKAGE_HREF $(installed_size $PACKAGE): $SHORT_DESC \
296 <a href="?receipt=$PACKAGE&amp;version=$SLITAZ_VERSION">$(gettext "Receipt")</a> $COOKER
297 _EOT_
298 fi
299 [ -n "$(GET debug)" ] && cat << _EOT_
300 <pre>
301 PACKAGE=$PACKAGE
302 VERSION=$VERSION
303 EXTRAVERSION=$EXTRAVERSION
304 SLITAZ_VERSION=$SLITAZ_VERSION
305 PACKAGE_URL=$PACKAGE_URL
306 $(cd /var/www/slitaz/mirror/packages/$SLITAZ_VERSION ; ls -l $PACKAGE*)
307 </pre>
308 _EOT_
309 }
311 # Show loop in depends/build_depends chains
312 show_loops()
313 {
314 awk '
315 function chkloop(pkg, i, n)
316 {
317 if (n < 8)
318 for (i = 1; i <= split(deps[pkg],curdep," "); i++) {
319 if (curdep[i] == base || chkloop(curdep[i], 0, n+1)) {
320 split(deps[pkg],curdep," ")
321 p = curdep[i] " " p
322 return 1
323 }
324 }
325 return 0
326 }
327 {
328 for (i = 2; i <= NF; i++)
329 deps[$1] = deps[$1] " " $i
330 }
331 END {
332 for (pkg in deps) {
333 base = pkg
334 p = ""
335 if (chkloop(pkg, 0, 0))
336 print pkg " " p
337 #print pkg " : " p "..."
338 }
339 }' | while read line; do
340 set -- $line
341 case " $last " in
342 *\ $1\ *) continue
343 esac
344 last="$line"
345 pkg=$1
346 shift
347 echo "<strong>$pkg </strong>: $@ ..."
348 done
349 }
351 # recursive dependencies scan
352 dep_scan()
353 {
354 for i in $1; do
355 case " $ALL_DEPS " in
356 *\ $i\ *) continue;;
357 esac
358 ALL_DEPS="$ALL_DEPS $i"
359 if [ -n "$2" ]; then
360 echo -n "$2"
361 (
362 . $WOK/$i/receipt
363 package_entry
364 )
365 fi
366 [ -f $WOK/$i/receipt ] || continue
367 DEPENDS=""
368 BUILD_DEPENDS=""
369 WANTED=""
370 . $WOK/$i/receipt
371 if [ -n "$3" ]; then
372 [ -n "$BUILD_DEPENDS$WANTED" ] &&
373 dep_scan "$WANTED $BUILD_DEPENDS" "$2 " $3
374 else
375 [ -n "$DEPENDS" ] && dep_scan "$DEPENDS" "$2 "
376 fi
377 done
378 }
380 # recursive reverse dependencies scan
381 rdep_scan()
382 {
383 SEARCH=$1
384 case "$SEARCH" in
385 glibc-base|gcc-lib-base)
386 $(gettext " glibc-base and gcc-lib-base are implicit dependencies,
387 <b>every</b> package is supposed to depend on them."); echo
388 return;;
389 esac
390 for i in $WOK/* ; do
391 DEPENDS=""
392 BUILD_DEPENDS=""
393 WANTED=""
394 . $i/receipt
395 if [ -n "$2" ]; then
396 echo "$(basename $i) $(echo $WANTED $BUILD_DEPENDS)"
397 else
398 echo "$(basename $i) $(echo $DEPENDS)"
399 fi
400 done | awk -v search=$SEARCH '
401 function show_deps(deps, all_deps, pkg, space)
402 {
403 if (all_deps[pkg] == 1) return
404 all_deps[pkg] = 1
405 if (space != "") printf "%s%s\n",space,pkg
406 for (i = 1; i <= split(deps[pkg], mydeps, " "); i++) {
407 show_deps(deps, all_deps, mydeps[i],"////" space)
408 }
409 }
411 {
412 all_deps[$1] = 0
413 for (i = 2; i <= NF; i++)
414 deps[$i] = deps[$i] " " $1
415 }
417 END {
418 show_deps(deps, all_deps, search, "")
419 }
420 ' | while read pkg; do
421 . $WOK/${pkg##*/}/receipt
422 cat << _EOT_
423 $(echo ${pkg%/*} | sed 's|/| |g') $(package_entry)
424 _EOT_
425 done
426 }
428 # Check package exists
429 package_exist()
430 {
431 [ -f $WOK/$1/receipt ] && return 0
432 cat << _EOT_
434 <h3>$(eval_gettext "No package \$SEARCH")</h3>
435 _EOT_
436 return 1
437 }
439 # Display < > &
440 htmlize()
441 {
442 sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g'
443 }
445 # Create some clickable links
446 urllink()
447 {
448 local tarball_url
449 sedit=""
450 [ -n "$WEB_SITE" ] && sedit="$sedit -e 's|^WEB_SITE=\"\\(.*\\)\"|WEB_SITE=\"<a href=\"$WEB_SITE\">\\1</a>\"|'"
451 [ -n "$WGET_URL" ] && sedit="$sedit -e 's#^WGET_URL=\"\\(.*\\)\"#WGET_URL=\"<a href=\"${WGET_URL##*|}\">\\1</a>\"#'"
452 [ -n "$CATEGORY" ] && sedit="$sedit -e 's|^CATEGORY=\"\\(.*\\)\"|CATEGORY=\"<a href=\"?category=$CATEGORY\\&amp;version=$SLITAZ_VERSION\">\\1</a>\"|'"
453 [ -n "$WANTED" ] && sedit="$sedit -e 's|^WANTED=\"\\(.*\\)\"|WANTED=\"<a href=\"?receipt=$WANTED\\&amp;version=$SLITAZ_VERSION\">\\1</a>\"|'"
454 [ -n "$BUGS" ] && sedit="$sedit -e 's|^BUGS=\"\\(.*\\)\"|BUGS=\"<a href=\"?bugs=$PACKAGE\\&amp;version=$SLITAZ_VERSION\">\\1</a>\"|'"
455 [ -f $WOK/$PACKAGE/description.txt ] && sedit="$sedit -e 's|^SHORT_DESC=\"\\(.*\\)\"|SHORT_DESC=\"<a href=\"?desc=$PACKAGE\\&amp;version=$SLITAZ_VERSION\">\\1</a>\"|'"
456 tarball_url=sources/packages-$SLITAZ_VERSION/${TARBALL:0:1}/$TARBALL
457 [ -f /var/www/slitaz/mirror/$tarball_url ] || case "$tarball_url" in
458 *.gz) tarball_url=${tarball_url%gz}lzma ;;
459 *.tgz) tarball_url=${tarball_url%tgz}tar.lzma ;;
460 *.bz2) tarball_url=${tarball_url%bz2}lzma ;;
461 esac
462 [ -f /var/www/slitaz/mirror/$tarball_url ] && sedit="$sedit -e 's|^TARBALL=\"\\(.*\\)\"|TARBALL=\"<a href=\"http://mirror.slitaz.org/$tarball_url\">\\1</a>\"|'"
463 if [ -n "$HOST_ARCH" ]; then
464 tmp=""
465 for i in $HOST_ARCH ; do
466 tmp="$tmp <a href=\\\"?arch=$i\\&amp;version=$SLITAZ_VERSION\\\">$i</a>"
467 done
468 sedit="$sedit -e 's|^HOST_ARCH=\".*\"|HOST_ARCH=\"${tmp# }\"|'"
469 fi
470 if [ -n "$TAGS" ]; then
471 tmp=""
472 for i in $TAGS ; do
473 tmp="$tmp <a href=\\\"?tags=$i\\&amp;version=$SLITAZ_VERSION\\\">$i</a>"
474 done
475 sedit="$sedit -e 's|^TAGS=\".*\"|TAGS=\"${tmp# }\"|'"
476 fi
477 if [ -n "$DEPENDS$BUILD_DEPENDS$SUGGESTED" ]; then
478 for i in $(echo $DEPENDS $BUILD_DEPENDS $SUGGESTED) ; do
479 sedit="$sedit -e 's|\\([\" ]\\)$i\\([\" \\]\\)|\\1<a href=\\\"?package=$i\\&amp;version=$SLITAZ_VERSION\\\">$i</a>\\2|'"
480 sedit="$sedit -e 's|\\([\" ]\\)$i\$|\\1<a href=\\\"?package=$i\\&amp;version=$SLITAZ_VERSION\\\">$i</a>|'"
481 sedit="$sedit -e 's|^$i\\([\" \\]\\)|<a href=\\\"?package=$i\\&amp;version=$SLITAZ_VERSION\\\">$i</a>\\1|'"
482 sedit="$sedit -e 's|^$i\$|<a href=\\\"?package=$i\\&amp;version=$SLITAZ_VERSION\\\">$i</a>|'"
483 done
484 fi
485 if [ -n "$CONFIG_FILES" ]; then
486 tmp=""
487 for i in $(echo $CONFIG_FILES) ; do
488 tmp="$tmp <a href=\\\"?file=$i\\&amp;version=$SLITAZ_VERSION\\\">$i</a>"
489 done
490 sedit="$sedit -e 's|^CONFIG_FILES=\".*\"|CONFIG_FILES=\"${tmp# }\"|'"
491 fi
492 if [ -n "$PROVIDE" ]; then
493 tmp=""
494 for i in $(echo $PROVIDE) ; do
495 tmp="$tmp <a href=\\\"?package=${i%:*}\\&amp;version=$SLITAZ_VERSION\\\">$i</a>"
496 done
497 sedit="$sedit -e 's|^PROVIDE=\".*\"|PROVIDE=\"${tmp# }\"|'"
498 fi
499 eval sed $sedit \
500 -e "'s|^MAINTAINER=\".*\"|MAINTAINER=\"<a href=\"?maintainer=$MAINTAINER\">$MAINTAINER</a>\"|'" \
501 -e "'s|^genpkg_rules|<a href=\"?filelist=$PACKAGE\\&amp;version=$SLITAZ_VERSION\">&</a>|'"
502 }
504 display_packages_and_files()
505 {
506 last=""
507 while read pkg file; do
508 pkg=${pkg%:}
509 if [ "$pkg" != "$last" ]; then
510 . $WOK/$pkg/receipt
511 package_entry
512 last=$pkg
513 fi
514 echo " $file"
515 done
516 }
518 build_cloud_cache()
519 {
520 grep -l ^$1= $WOK/*/receipt | while read file; do
521 eval $1=
522 . $file
523 eval echo \$$1
524 done | sed "$2" | awk '
525 {
526 for (i = 1; $i != ""; i++) {
527 count[$i]++
528 }
529 }
530 END {
531 min=10000
532 max=0
533 for (i in count) {
534 if (count[i] < min) min = count[i]
535 if (count[i] > max) max = count[i]
536 }
537 for (i in count)
538 print count[i] " " int((count[i] - min)*100/(max - min)) " " i
539 }' | sort -k 3
540 }
542 display_cloud()
543 {
544 echo "<p>"
545 while read cnt pct item ; do
546 pct=$(((10000 - ((100 - $pct)**2))/100))
547 pct=$(((10000 - ((100 - $pct)**2))/100))
548 cat <<EOT
549 <span style="color:#99f; font-size:9pt; padding-left:5px; padding-right:2px;">\
550 $cnt</span><a href="?$1=$item&amp;version=$SLITAZ_VERSION" style="\
551 font-size:$((8+($pct/10)))pt; font-weight:bold; \
552 color:black; text-decoration:none">$(echo $item | sed 's/-/\&minus;/g')</a>
553 EOT
554 done | tee /dev/stderr | printf "</p><p align=right>$2" $(wc -l)
555 echo "</p>"
556 }
558 xhtml_header
560 #
561 # Handle GET requests
562 #
563 case " $(GET) " in
564 *\ debug\ *|*\ debug*)
565 cat << EOT
566 <h2>Debug info</h2>
567 <pre>$(httpinfo)</pre>
568 <pre>LANG=$LANG;
569 OBJECT=$OBJECT;
570 SEARCH=$SEARCH;
571 SLITAZ_VERSION=$SLITAZ_VERSION;
572 WOK=$WOK;
573 </pre>
574 EOT
575 #$(xhtml_footer)
576 #EOT
577 # exit 0
578 ;;
579 esac
581 # Display search form and result if requested.
582 #xhtml_header
583 echo "<h2>$(gettext 'Search for packages')</h2>"
584 search_form
586 case "$OBJECT" in
589 ### Depends loops; [Reverse] Dependency tree [(SUGGESTED)]
590 Depends)
591 if [ -z "$SEARCH" ]; then
592 cat << _EOT_
594 <h3>$(gettext "Depends loops")</h3>
595 <pre>
596 _EOT_
597 for i in $WOK/*/receipt; do
598 PACKAGE=
599 DEPENDS=
600 . $i
601 echo "$PACKAGE $(echo $DEPENDS)"
602 done | show_loops
603 cat << _EOT_
604 </pre>
605 _EOT_
606 elif package_exist $SEARCH ; then
607 cat << _EOT_
609 <h3>$(eval_gettext "Dependency tree for: \$SEARCH")</h3>
610 <pre>
611 _EOT_
612 ALL_DEPS=""
613 dep_scan $SEARCH ""
614 SUGGESTED=""
615 . $WOK/$SEARCH/receipt
616 if [ -n "$SUGGESTED" ]; then
617 cat << _EOT_
618 </pre>
620 <h3>$(eval_gettext "Dependency tree for: \$SEARCH (SUGGESTED)")</h3>
621 <pre>
622 _EOT_
623 ALL_DEPS=""
624 dep_scan "$SUGGESTED" " "
625 fi
626 cat << _EOT_
627 </pre>
629 <h3>$(eval_gettext "Reverse dependency tree for: \$SEARCH")</h3>
630 <pre>
631 _EOT_
632 ALL_DEPS=""
633 rdep_scan $SEARCH
634 cat << _EOT_
635 </pre>
636 _EOT_
637 fi
638 ;;
641 ### Build depends loops; [Reverse] Build dependency tree
642 BuildDepends)
643 if [ -z "$SEARCH" ]; then
644 cat << _EOT_
646 <h3>$(gettext "Build depends loops")</h3>
647 <pre>
648 _EOT_
649 for i in $WOK/*/receipt; do
650 PACKAGE=
651 WANTED=
652 BUILD_DEPENDS=
653 . $i
654 echo "$PACKAGE $WANTED $(echo $BUILD_DEPENDS)"
655 done | show_loops
656 cat << _EOT_
657 </pre>
658 _EOT_
659 elif package_exist $SEARCH ; then
660 cat << _EOT_
662 <h3>$(eval_gettext "\$SEARCH needs these packages to be built")</h3>
663 <pre>
664 _EOT_
665 ALL_DEPS=""
666 dep_scan $SEARCH "" build
667 cat << _EOT_
668 </pre>
670 <h3>$(eval_gettext "Packages who need \$SEARCH to be built")</h3>
671 <pre>
672 _EOT_
673 ALL_DEPS=""
674 rdep_scan $SEARCH build
675 cat << _EOT_
676 </pre>
677 _EOT_
678 fi
679 ;;
682 ### Common files
683 FileOverlap)
684 if package_exist $SEARCH; then
685 cat << _EOT_
687 <h3>$(eval_gettext "These packages may overload files of \$SEARCH")</h3>
688 <pre>
689 _EOT_
690 ( cat_files_list $PACKAGES_REPOSITORY | grep ^$SEARCH: ;
691 cat_files_list $PACKAGES_REPOSITORY | grep -v ^$SEARCH: ) | awk '
692 BEGIN { pkg=""; last="x" }
693 {
694 if ($2 == "") next
695 if (index($2,last) == 1 && substr($2,1+length(last),1) == "/")
696 delete file[last]
697 last=$2
698 if (pkg == "") pkg=$1
699 if ($1 == pkg) file[$2]=$1
700 else if (file[$2] == pkg) print
701 }
702 ' | display_packages_and_files
703 cat << _EOT_
704 </pre>
705 _EOT_
706 fi
707 ;;
710 ### File search
711 File)
712 if [ -n "$SEARCH" ]; then
713 cat << _EOT_
715 <h3>$(eval_gettext "Result for: \$SEARCH")</h3>
716 <pre>
717 _EOT_
718 last=""
719 cat_files_list $PACKAGES_REPOSITORY \
720 | grep "$SEARCH" | while read pkg file; do
721 echo "$file" | grep -q "$SEARCH" || continue
722 if [ "$last" != "${pkg%:}" ]; then
723 last=${pkg%:}
724 (
725 . $WOK/$last/receipt
726 cat << _EOT_
728 <i>$(package_entry)</i>
729 _EOT_
730 )
731 fi
732 echo " $file"
733 done
734 cat << _EOT_
735 </pre>
736 _EOT_
737 fi
738 ;;
741 ### List of files
742 File_list)
743 if package_exist $SEARCH; then
744 cat << _EOT_
746 <h3>$(eval_gettext "Result for: \$SEARCH")</h3>
747 <pre>
748 _EOT_
749 last=""
750 cat_files_list $PACKAGES_REPOSITORY \
751 | grep ^$SEARCH: | sed 's/.*: / /' | sort
752 cat << _EOT_
753 </pre>
754 <pre>
755 _EOT_
756 filenb=$(cat_files_list $PACKAGES_REPOSITORY | grep ^$SEARCH: | wc -l)
757 eval_ngettext "\$filenb file" "\$filenb files" $filenb
758 cat << _EOT_
759 \
760 $(busybox sed -n "/^$SEARCH$/{nnnpq}" $PACKAGES_REPOSITORY/packages.txt)
761 </pre>
762 _EOT_
763 fi
764 ;;
767 ### Package description
768 Desc)
769 cat << _EOT_
771 <h3>$(eval_gettext "Result for: \$SEARCH")</h3>
772 <pre>
773 _EOT_
774 if [ -f $WOK/$SEARCH/description.txt ]; then
775 htmlize < $WOK/$SEARCH/description.txt
776 else
777 last=""
778 grep -i "$SEARCH" $PACKAGES_REPOSITORY/packages.desc | \
779 sort | while read pkg extras ; do
780 . $WOK/$pkg/receipt
781 package_entry
782 done
783 fi
784 cat << _EOT_
785 </pre>
786 _EOT_
787 ;;
790 ### Bugs
791 Bugs)
792 cat << _EOT_
794 <h3>$(eval_gettext "Result for known bugs")</h3>
795 <pre>
796 _EOT_
797 last=""
798 grep ^BUGS= $WOK/*/receipt | \
799 sed "s|$WOK/\(.*\)/receipt:.*|\1|" | sort | while read pkg ; do
800 BUGS=
801 . $WOK/$pkg/receipt
802 package_entry
803 echo " $BUGS "
804 done
805 cat << _EOT_
806 </pre>
807 _EOT_
808 ;;
811 ### Arch
812 Arch)
813 cat << _EOT_
815 <h3>$(eval_gettext "Result for: \$SEARCH")</h3>
816 <pre>
817 _EOT_
818 last=""
819 grep ^HOST_ARCH= $WOK/*/receipt | grep -i "$SEARCH" | \
820 sed "s|$WOK/\(.*\)/receipt:.*|\1|" | sort | while read pkg ; do
821 HOST_ARCH=
822 . $WOK/$pkg/receipt
823 echo " $HOST_ARCH " | grep -iq " $SEARCH " &&
824 package_entry
825 done
826 cat << _EOT_
827 </pre>
828 _EOT_
829 ;;
832 ### Tags
833 Tags)
834 if [ -n "$SEARCH" ]; then
835 cat << _EOT_
837 <h3>$(eval_gettext "Result for: \$SEARCH")</h3>
838 <pre>
839 _EOT_
840 last=""
841 grep ^TAGS= $WOK/*/receipt | grep -i "$SEARCH" | \
842 sed "s|$WOK/\(.*\)/receipt:.*|\1|" | sort | while read pkg ; do
843 TAGS=
844 . $WOK/$pkg/receipt
845 echo " $TAGS " | grep -iq " $SEARCH " &&
846 package_entry
847 done
848 cat << _EOT_
849 </pre>
850 _EOT_
851 else
852 # Display clouds
853 while read var arg title fmt filter; do
854 file=/tmp/$arg-$SLITAZ_VERSION
855 echo "<a name=\"$arg\"></a>"
856 echo "<h3>$title</h3>"
857 [ ! -e $file -o \
858 $PACKAGES_REPOSITORY/packages.txt -nt $file ] &&
859 build_cloud_cache $var "$filter" > $file.$$ &&
860 mv -f $file.$$ $file
861 display_cloud $arg "$fmt" < $file 2>&1
862 done << EOT
863 TAGS tags Tag\ cloud %d\ tags.
864 CATEGORY category Category\ cloud %d\ categories.
865 LICENSE license License\ cloud %d\ licenses.
866 MAINTAINER maintainer Maintainer\ cloud %d\ maintainers. s/.*<//;s/.*\ //;s/>//
867 EOT
868 fi
869 ;;
872 ### Package receipt
873 # TODO: add style highlighting
874 Receipt)
875 package_exist $SEARCH && cat << _EOT_
877 <h3>$(eval_gettext "Result for: \$SEARCH")</h3>
878 <pre>
879 $(receipt=$WOK/$SEARCH/taz/*/receipt
880 [ -f $receipt ] || receipt=$WOK/$SEARCH/receipt
881 . /home/slitaz/repos/cookutils/cook.conf
882 . $receipt
883 cat $receipt | htmlize | urllink)
884 </pre>
885 _EOT_
886 ;;
889 ### Package
890 Package)
891 #WHY# if package_exist $SEARCH; then
892 cat << _EOT_
894 <h3>$(eval_gettext "Result for: \$SEARCH")</h3>
895 <pre>
896 _EOT_
897 for pkg in `ls $WOK/ | grep "$SEARCH"`
898 do
899 . $WOK/$pkg/receipt
900 DESC=" <a href=\"?object=Desc&query=$pkg&lang=$lang&version=$SLITAZ_VERSION&submit=go\">$(gettext description)</a>"
901 [ -f $WOK/$pkg/description.txt ] || DESC=""
902 cat << _EOT_
903 $(package_entry)$DESC
904 _EOT_
905 done
906 equiv=$PACKAGES_REPOSITORY/packages.equiv
907 vpkgs="$(cat $equiv | cut -d= -f1 | grep $SEARCH)"
908 for vpkg in $vpkgs ; do
909 cat << _EOT_
910 </pre>
912 <h3>$(eval_gettext "Result for: \$SEARCH (package providing \$vpkg)")</h3>
913 <pre>
914 _EOT_
915 for pkg in $(grep $vpkg= $equiv | sed "s/$vpkg=//"); do
916 . $WOK/${pkg#*:}/receipt
917 package_entry
918 done
919 done
920 cat << _EOT_
921 </pre>
922 _EOT_
923 #WHY# fi
924 ;;
926 ### Category
927 Category)
928 cat << _EOT_
930 <h3>$(eval_gettext "Result for: \$SEARCH")</h3>
931 <pre>
932 _EOT_
933 for pkg in `ls $WOK/`
934 do
935 CATEGORY=
936 . $WOK/$pkg/receipt
937 DESC=" <a href=\"?object=Desc&query=$pkg&lang=$lang&version=$SLITAZ_VERSION&submit=go\">$(gettext description)</a>"
938 [ -f $WOK/$pkg/description.txt ] || DESC=""
939 [ "$CATEGORY" == "$SEARCH" ] && cat << _EOT_
940 $(package_entry)$DESC
941 _EOT_
942 done
943 ;;
945 ### Maintainer
946 Maintainer)
947 cat << _EOT_
949 <h3>$(eval_gettext "Result for: \$SEARCH")</h3>
950 <pre>
951 _EOT_
952 for pkg in `ls $WOK/`
953 do
954 MAINTAINER=
955 . $WOK/$pkg/receipt
956 DESC=" <a href=\"?object=Desc&query=$pkg&lang=$lang&version=$SLITAZ_VERSION&submit=go\">$(gettext description)</a>"
957 [ -f $WOK/$pkg/description.txt ] || DESC=""
958 [ "$MAINTAINER" == "$SEARCH" ] && cat << _EOT_
959 $(package_entry)$DESC
960 _EOT_
961 done
962 ;;
964 ### License
965 License)
966 cat << _EOT_
968 <h3>$(eval_gettext "Result for: \$SEARCH")</h3>
969 <pre>
970 _EOT_
971 for pkg in `ls $WOK/`
972 do
973 LICENSE=
974 . $WOK/$pkg/receipt
975 DESC=" <a href=\"?object=Desc&query=$pkg&lang=$lang&version=$SLITAZ_VERSION&submit=go\">$(gettext description)</a>"
976 [ -f $WOK/$pkg/description.txt ] || DESC=""
977 case " $LICENSE " in
978 *\ $SEARCH\ *) cat << _EOT_
979 $(package_entry)$DESC
980 _EOT_
981 esac
982 done
983 ;;
984 esac
986 xhtml_footer
988 exit 0