wok-current view tazpkg-web/stuff/search.cgi @ rev 5822
tazpkg-web: check CATEGORY page
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Thu Jul 15 14:33:06 2010 +0200 (2010-07-15) |
parents | ce3fc5cd3c68 |
children | f7b4acf937ec |
line source
1 #!/bin/sh
2 # Tiny CGI search engine for SliTaz packages on http://pkgs.slitaz.org/
3 # Christophe Lincoln <pankso@slitaz.org>
4 #
6 read QUERY_STRING
7 for i in $(echo $QUERY_STRING | sed 's/&/ /g'); do
8 eval $i
9 done
10 LANG=$lang
11 SEARCH=$query
12 SLITAZ_VERSION=$version
13 OBJECT=$object
14 DATE=`date +%Y-%m-%d\ \%H:%M:%S`
15 VERSION=cooking
16 if [ "$REQUEST_METHOD" = "GET" ]; then
17 SEARCH=""
18 VERBOSE=0
19 for i in $(echo $REQUEST_URI | sed 's/[?&]/ /g'); do
20 SLITAZ_VERSION=cooking
21 case "$i" in
22 verbose=*)
23 VERBOSE=${i#*=};;
24 lang=*)
25 LANG=${i#*=};;
26 file=*)
27 SEARCH=${i#*=}
28 OBJECT=File;;
29 desc=*)
30 SEARCH=${i#*=}
31 OBJECT=Desc;;
32 tags=*)
33 SEARCH=${i#*=}
34 OBJECT=Tags;;
35 receipt=*)
36 SEARCH=${i#*=}
37 OBJECT=Receipt;;
38 filelist=*)
39 SEARCH=${i#*=}
40 OBJECT=File_list;;
41 package=*)
42 SEARCH=${i#*=}
43 OBJECT=Package;;
44 depends=*)
45 SEARCH=${i#*=}
46 OBJECT=Depends;;
47 BuildDepends=*)
48 SEARCH=${i#*=}
49 OBJECT=BuildDepends;;
50 FileOverlap=*)
51 SEARCH=${i#*=}
52 OBJECT=FileOverlap;;
53 version=s*|version=3*)
54 SLITAZ_VERSION=stable;;
55 version=2*)
56 SLITAZ_VERSION=2.0;;
57 version=1*)
58 SLITAZ_VERSION=1.0;;
59 esac
60 done
61 [ -n "$SEARCH" ] && REQUEST_METHOD="POST"
62 fi
64 case "$OBJECT" in
65 File) selected_file="selected";;
66 Desc) selected_desc="selected";;
67 Tags) selected_tags="selected";;
68 Receipt) selected_receipt="selected";;
69 File_list) selected_file_list="selected";;
70 Depends) selected_depends="selected";;
71 BuildDepends) selected_build_depends="selected";;
72 FileOverlap) selected_overlap="selected";;
73 esac
75 case "$SLITAZ_VERSION" in
76 1.0) selected_1="selected";;
77 2.0) selected_2="selected";;
78 stable) selected_stable="selected";;
79 esac
81 # unescape query
82 SEARCH="$(echo $SEARCH | sed 's/%2B/+/g' | sed 's/%3A/:/g' | sed 's|%2F|/|g')"
84 if [ -z "$LANG" ]; then
85 for i in $(echo $HTTP_ACCEPT_LANGUAGE | sed 's/[,;]/ /g'); do
86 case "$i" in
87 fr|de|pt|cn)
88 LANG=$i
89 break;;
90 esac
91 done
92 fi
94 package="Package"
95 file="File"
96 desc="Description"
97 tags="Tags"
98 receipt="Receipt"
99 file_list="File list"
100 depends="Depends"
101 bdepends="Build depends"
102 search="Search"
103 cooking="cooking"
104 stable="stable"
105 result="Result for : $SEARCH"
106 noresult="No package $SEARCH"
107 deptree="Dependency tree for : $SEARCH"
108 rdeptree="Reverse dependency tree for : $SEARCH"
109 bdeplist="$SEARCH needs these packages to be built"
110 rbdeplist="Packages who need $SEARCH to be built"
111 overloading="Theses packages may overload files of "
112 overlap="common files"
113 charset="ISO-8859-1"
115 case "$LANG" in
117 fr) package="Paquet"
118 receipt="Recette"
119 depends="Dépendances"
120 bdepends="Fabrication"
121 search="Recherche"
122 result="Recherche de : $SEARCH"
123 noresult="Paquet $SEARCH introuvable"
124 deptree="Arbre des dépendances de $SEARCH"
125 rdeptree="Arbre inversé des dépendances de $SEARCH"
126 bdeplist="$SEARCH a besion de ces paquets pour être fabriqué"
127 rbdeplist="Paquets ayant besion de $SEARCH pour être fabriqués"
128 overloading="Paquets pouvant écraser des fichiers de "
129 overlap="Fichiers communs"
130 file_list="Liste des fichiers"
131 file="Fichier";;
133 de) package="Paket"
134 depends="Abhängigkeiten"
135 desc="Beschreibung"
136 search="Suche"
137 cooking="Cooking"
138 stable="Stable"
139 result="Resultate für : $SEARCH"
140 noresult="Kein Paket für $SEARCH"
141 deptree="Abhängigkeiten von: $SEARCH"
142 rdeptree="Abhängigkeit für: $SEARCH"
143 file_list="Datei liste"
144 file="Datei";;
146 pt) package="Pacote"
147 search="Buscar"
148 cooking="cooking"
149 stable="stable"
150 result="Resultado para : $SEARCH"
151 noresult="Sem resultado: $SEARCH"
152 deptree="Árvore de dependências para: $SEARCH"
153 rdeptree="Árvore de dependências reversa para: $SEARCH"
154 depends="Dependências"
155 desc="Descrição"
156 file_list="Arquivo lista"
157 file="Arquivo";;
159 cn) package="软件包:"
160 cooking="å¼€å‘版"
161 stable="稳定版"
162 desc="æè¿°"
163 tags="æ ‡ç¾"
164 depends="ä¾èµ–"
165 file="文件"
166 file_list="文件列表"
167 search="Search"
168 result="Result for : $SEARCH"
169 noresult="No package $SEARCH"
170 deptree="Dependency tree for : $SEARCH"
171 rdeptree="Reverse dependency tree for : $SEARCH"
172 charset="UTF-8";;
174 *) LANG="en";;
176 esac
178 WOK=/home/slitaz/$SLITAZ_VERSION/wok
179 PACKAGES_REPOSITORY=/home/slitaz/$SLITAZ_VERSION/packages
181 echo Content-type: text/html
182 echo
184 # Search form
185 search_form()
186 {
187 cat << _EOT_
189 <div style="text-align: center; padding: 20px;">
190 <form method="post" action="search.cgi">
191 <input type="hidden" name="lang" value="$LANG" />
192 <select name="object">
193 <option value="Package">$package</option>
194 <option $selected_desc value="Desc">$desc</option>
195 <option $selected_tags value="Tags">$tags</option>
196 <option $selected_receipt value="Receipt">$receipt</option>
197 <option $selected_depends value="Depends">$depends</option>
198 <option $selected_build_depends value="BuildDepends">$bdepends</option>
199 <option $selected_file value="File">$file</option>
200 <option $selected_file_list value="File_list">$file_list</option>
201 <option $selected_overlap value="FileOverlap">$overlap</option>
202 </select>
203 <strong>:</strong>
204 <input type="text" name="query" size="20" value="$SEARCH" />
205 <select name="version">
206 <option value="cooking">$cooking</option>
207 <option $selected_stable value="stable">$stable</option>
208 <option $selected_1 value="1.0">1.0</option>
209 <option $selected_2 value="2.0">2.0</option>
210 </select>
211 <input type="submit" name="search" value="$search" />
212 </form>
213 </div>
214 _EOT_
215 }
217 # xHTML Header.
218 xhtml_header()
219 {
220 cat << _EOF_
221 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
222 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
223 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="$LANG" lang="$LANG">
224 <head>
225 <title>SliTaz Packages - Search $SEARCH</title>
226 <meta http-equiv="content-type" content="text/html; charset=$charset" />
227 <meta name="description" content="Au sujet de SliTaz GNU/Linux mini système d'exploitation" />
228 <meta name="keywords" lang="fr" content="Système, libre, gnu, linux, opensource, livecd" />
229 <meta name="robots" content="index, follow, all" />
230 <meta name="revisit-after" content="7 days" />
231 <meta name="expires" content="never" />
232 <meta name="modified" content="$DATE" />
233 <meta name="author" content="ash, awk, grep, sed and cat"/>
234 <meta name="publisher" content="www.slitaz.org" />
235 <link rel="shortcut icon" href="/favicon.ico" />
236 <link rel="stylesheet" type="text/css" href="/slitaz.css" />
237 </head>
238 <body bgcolor="#ffffff">
240 <!-- Header -->
241 <div id="header">
242 <a name="top"></a>
243 <!-- Access -->
244 <div id="access">
245 <a href="http://www.slitaz.org/" title="SliTaz Web site">Website</a> |
246 <a href="http://wiki.slitaz.org/" title="SliTaz Community Wiki">Wiki</a> |
247 <a href="http://labs.slitaz.org/" title="SliTaz laboratories">Labs</a>
248 </div>
249 <a href="http://pkgs.slitaz.org/"><img id="logo"
250 src="/pics/website/logo.png" title="pkgs.slitaz.org" alt="pkgs.slitaz.org"
251 style="border: 0px solid ; width: 200px; height: 74px;" /></a>
252 <p id="titre">#!/tazpkg/packages</p>
253 </div>
254 _EOF_
255 }
257 # xHTML Footer.
258 xhtml_footer()
259 {
260 cat << _EOT_
261 <center>
262 <i>$(ls $WOK/ | wc -l) packages and $(unlzma -c $PACKAGES_REPOSITORY/files.list.lzma | wc -l) files in $SLITAZ_VERSION database</i>
263 </center>
265 <!-- End of content with round corner -->
266 </div>
267 <div id="content_bottom">
268 <div class="bottom_left"></div>
269 <div class="bottom_right"></div>
270 </div>
272 <!-- Start of footer and copy notice -->
273 <div id="copy">
274 <p>
275 Dernière modification : $DATE -
276 <a href="#top">Top of the page</a>
277 </p>
278 <p>
279 Copyright © $(date +%Y) <a href="http://www.slitaz.org/">SliTaz</a> -
280 <a href="http://www.gnu.org/licenses/gpl.html">GNU General Public License</a>
281 </p>
282 <!-- End of copy -->
283 </div>
285 <!-- Bottom and logo's -->
286 <div id="bottom">
287 <p>
288 <a href="http://validator.w3.org/check?uri=referer"><img
289 src="/pics/website/xhtml10.png" alt="Valid XHTML 1.0"
290 title="Code validé XHTML 1.0"
291 style="width: 80px; height: 15px;" /></a>
292 </p>
293 </div>
295 </body>
296 </html>
297 _EOT_
298 }
300 installed_size()
301 {
302 [ $VERBOSE -gt 0 ] &&
303 grep -A 3 "^$1\$" /home/slitaz/$SLITAZ_VERSION/packages/packages.txt | \
304 grep installed | sed 's/.*(\(.*\) installed.*/(\1) /'
305 }
307 package_entry()
308 {
309 if [ -s "$(dirname $0)/$SLITAZ_VERSION/$CATEGORY.html" ]; then
310 cat << _EOT_
311 <a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> $(installed_size $PACKAGE): $SHORT_DESC
312 _EOT_
313 else
314 cat << _EOT_
315 <a href="http://mirror.slitaz.org/packages/$SLITAZ_VERSION/$PACKAGE-$VERSION$EXTRA_VERSION.tazpkg">$PACKAGE</a> $(installed_size $PACKAGE): $SHORT_DESC
316 _EOT_
317 fi
318 }
320 # recursive dependencies scan
321 dep_scan()
322 {
323 for i in $1; do
324 case " $ALL_DEPS " in
325 *\ $i\ *) continue;;
326 esac
327 ALL_DEPS="$ALL_DEPS $i"
328 if [ -n "$2" ]; then
329 echo -n "$2"
330 (
331 . $WOK/$i/receipt
332 package_entry
333 )
334 fi
335 [ -f $WOK/$i/receipt ] || continue
336 DEPENDS=""
337 . $WOK/$i/receipt
338 [ -n "$DEPENDS" ] && dep_scan "$DEPENDS" "$2 "
339 done
340 }
342 # recursive reverse dependencies scan
343 rdep_scan()
344 {
345 SEARCH=$1
346 case "$SEARCH" in
347 glibc-base|gcc-lib-base) cat <<EOT
348 glibc-base and gcc-lib-base are implicit dependencies,
349 <b>every</b> package is supposed to depend on them.
350 EOT
351 return;;
352 esac
353 for i in $WOK/* ; do
354 DEPENDS=""
355 . $i/receipt
356 echo "$(basename $i) $(echo $DEPENDS)"
357 done | awk -v search=$SEARCH '
358 function show_deps(deps, all_deps, pkg, space)
359 {
360 if (all_deps[pkg] == 1) return
361 all_deps[pkg] = 1
362 if (space != "") printf "%s%s\n",space,pkg
363 for (i = 1; i <= split(deps[pkg], mydeps, " "); i++) {
364 show_deps(deps, all_deps, mydeps[i],"////" space)
365 }
366 }
368 {
369 all_deps[$1] = 0
370 for (i = 2; i <= NF; i++)
371 deps[$i] = deps[$i] " " $1
372 }
374 END {
375 show_deps(deps, all_deps, search, "")
376 }
377 ' | while read pkg; do
378 . $WOK/${pkg##*/}/receipt
379 package_entry
380 cat << _EOT_
381 $(echo ${pkg%/*} | sed 's|/| |g') $(package_entry)
382 _EOT_
383 done
384 }
386 # Check package exists
387 package_exist()
388 {
389 [ -f $WOK/$1/receipt ] && return 0
390 cat << _EOT_
392 <h3>$noresult</h3>
393 <pre class="package">
394 _EOT_
395 return 1
396 }
398 # Display < > &
399 htmlize()
400 {
401 sed -e 's/&/\&/g' -e 's/</\</g' -e 's/>/\>/g'
402 }
404 display_packages_and_files()
405 {
406 last=""
407 while read pkg file; do
408 pkg=${pkg%:}
409 if [ "$pkg" != "$last" ]; then
410 . $WOK/$pkg/receipt
412 package_entry
413 last=$pkg
414 fi
415 echo " $file"
416 done
417 }
419 # Display search form and result if requested.
420 if [ "$REQUEST_METHOD" != "POST" ]; then
421 xhtml_header
422 cat << _EOT_
424 <!-- Content top. -->
425 <div id="content_top">
426 <div class="top_left"></div>
427 <div class="top_right"></div>
428 </div>
430 <!-- Content -->
431 <div id="content">
432 <a name="content"></a>
434 <h1><font color="#3E1220">$package</font></h1>
435 <h2><font color="#DF8F06">$search</font></h2>
436 _EOT_
437 search_form
438 xhtml_footer
439 else
440 xhtml_header
441 cat << _EOT_
443 <!-- Content top. -->
444 <div id="content_top">
445 <div class="top_left"></div>
446 <div class="top_right"></div>
447 </div>
449 <!-- Content -->
450 <div id="content">
451 <a name="content"></a>
453 <h1><font color="#3E1220">$package</font></h1>
454 <h2><font color="#DF8F06">$search</font></h2>
455 _EOT_
456 search_form
457 if [ "$OBJECT" = "Depends" ]; then
458 if package_exist $SEARCH ; then
459 cat << _EOT_
461 <h3>$deptree</h3>
462 <pre class="package">
463 _EOT_
464 ALL_DEPS=""
465 dep_scan $SEARCH ""
466 SUGGESTED=""
467 . $WOK/$SEARCH/receipt
468 if [ -n "$SUGGESTED" ]; then
469 cat << _EOT_
470 </pre>
472 <h3>$deptree (SUGGESTED)</h3>
473 <pre class="package">
474 _EOT_
475 ALL_DEPS=""
476 dep_scan "$SUGGESTED" " "
477 fi
478 cat << _EOT_
479 </pre>
481 <h3>$rdeptree</h3>
482 <pre class="package">
483 _EOT_
484 ALL_DEPS=""
485 rdep_scan $SEARCH
486 cat << _EOT_
487 </pre>
488 _EOT_
489 fi
490 elif [ "$OBJECT" = "BuildDepends" ]; then
491 if package_exist $SEARCH ; then
492 cat << _EOT_
494 <h3>$bdeplist</h3>
495 <pre class="package">
496 _EOT_
497 BUILD_DEPENDS=""
498 . $WOK/$SEARCH/receipt
499 [ -n "$BUILD_DEPENDS" ] && for dep in $BUILD_DEPENDS ; do
500 if [ ! -s $WOK/$dep/receipt ]; then
501 cat << _EOT_
502 $dep: not found !
503 _EOT_
504 continue
505 fi
506 . $WOK/$dep/receipt
507 package_entry
508 done
509 cat << _EOT_
510 </pre>
512 <h3>$rbdeplist</h3>
513 <pre class="package">
514 _EOT_
515 for dep in $(grep -l $SEARCH $WOK/*/receipt); do
516 BUILD_DEPENDS=""
517 . $dep
518 echo " $BUILD_DEPENDS " | grep -q " $SEARCH " &&
519 package_entry
520 done
521 cat << _EOT_
522 </pre>
523 _EOT_
524 fi
525 elif [ "$OBJECT" = "FileOverlap" ]; then
526 if package_exist $SEARCH ; then
527 cat << _EOT_
529 <h3>$overloading $SEARCH</h3>
530 <pre class="package">
531 _EOT_
532 ( unlzma -c $PACKAGES_REPOSITORY/files.list.lzma | grep ^$SEARCH: ;
533 unlzma -c $PACKAGES_REPOSITORY/files.list.lzma | grep -v ^$SEARCH: ) | awk '
534 BEGIN { pkg="" }
535 {
536 if (pkg == "") pkg=$1
537 if ($1 == pkg) file[$2]=$1
538 else if (file[$2] == pkg) print
539 }
540 ' | display_packages_and_files
541 cat << _EOT_
542 </pre>
543 _EOT_
544 fi
545 elif [ "$OBJECT" = "File" ]; then
546 cat << _EOT_
548 <h3>$result</h3>
549 <pre class="package">
550 _EOT_
551 last=""
552 unlzma -c $PACKAGES_REPOSITORY/files.list.lzma \
553 | grep $SEARCH | while read pkg file; do
554 echo "$file" | grep -q $SEARCH || continue
555 if [ "$last" != "${pkg%:}" ]; then
556 last=${pkg%:}
557 (
558 . $WOK/$last/receipt
559 cat << _EOT_
561 <i>$(package_entry)</i>
562 _EOT_
563 )
564 fi
565 echo " $file"
566 done
567 elif [ "$OBJECT" = "File_list" ]; then
568 package_exist $SEARCH && cat << _EOT_
570 <h3>$result</h3>
571 <pre class="package">
572 _EOT_
573 last=""
574 unlzma -c $PACKAGES_REPOSITORY/files.list.lzma \
575 | grep ^$SEARCH: | sed 's/.*: / /' | sort
576 elif [ "$OBJECT" = "Desc" ]; then
577 if [ -f $WOK/$SEARCH/description.txt ]; then
578 cat << _EOT_
580 <h3>$result</h3>
581 <pre class="package">
582 <pre>
583 $(htmlize < $WOK/$SEARCH/description.txt)
584 </pre>
585 _EOT_
586 else
587 cat << _EOT_
589 <h3>$result</h3>
590 <pre class="package">
591 _EOT_
592 last=""
593 grep -i $SEARCH $PACKAGES_REPOSITORY/packages.desc | \
594 sort | while read pkg extras ; do
595 . $WOK/$pkg/receipt
596 package_entry
597 done
598 fi
599 elif [ "$OBJECT" = "Tags" ]; then
600 cat << _EOT_
602 <h3>$result</h3>
603 <pre class="package">
604 _EOT_
605 last=""
606 grep ^TAGS= $WOK/*/receipt | grep -i $SEARCH | \
607 sed "s|$WOK/\(.*\)/receipt:.*|\1|" | sort | while read pkg ; do
608 . $WOK/$pkg/receipt
609 package_entry
610 done
611 elif [ "$OBJECT" = "Receipt" ]; then
612 package_exist $SEARCH && cat << _EOT_
614 <h3>$result</h3>
615 <pre class="package">
616 <pre>
617 $(if [ -f $WOK/$SEARCH/taz/*/receipt ]; then
618 cat $WOK/$SEARCH/taz/*/receipt
619 else
620 cat $WOK/$SEARCH/receipt
621 fi | htmlize)
622 </pre>
623 _EOT_
624 else
625 cat << _EOT_
627 <h3>$result</h3>
628 <pre class="package">
629 _EOT_
630 for pkg in `ls $WOK/ | grep $SEARCH`
631 do
632 . $WOK/$pkg/receipt
633 DESC=" <a href=\"?desc=$pkg\">description</a>"
634 [ -f $WOK/$pkg/description.txt ] || DESC=""
635 cat << _EOT_
636 $(package_entry)$DESC
637 _EOT_
638 done
639 equiv=$PACKAGES_REPOSITORY/packages.equiv
640 vpkgs="$(cat $equiv | cut -d= -f1 | grep $SEARCH)"
641 for vpkg in $vpkgs ; do
642 cat << _EOT_
643 </pre>
645 <h3>$result (package providing $vpkg)</h3>
646 <pre class="package">
647 _EOT_
648 for pkg in $(grep $vpkg= $equiv | sed "s/$vpkg=//"); do
649 . $WOK/${pkg#*:}/receipt
650 package_entry
651 done
652 done
653 fi
654 cat << _EOT_
655 </pre>
656 _EOT_
657 xhtml_footer
658 fi
660 exit 0