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

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