wok-stable view tazpkg-web/stuff/search.cgi @ rev 6033

No more http://wiki.slitaz.org/
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Aug 16 12:43:11 2010 +0200 (2010-08-16)
parents f7b4acf937ec
children dd533bb4feda
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://doc.slitaz.org/" title="SliTaz Community Documentation">Doc</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 &copy; $(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 cat << _EOT_
380 $(echo ${pkg%/*} | sed 's|/| |g') $(package_entry)
381 _EOT_
382 done
383 }
385 # Check package exists
386 package_exist()
387 {
388 [ -f $WOK/$1/receipt ] && return 0
389 cat << _EOT_
391 <h3>$noresult</h3>
392 <pre class="package">
393 _EOT_
394 return 1
395 }
397 # Display < > &
398 htmlize()
399 {
400 sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g'
401 }
403 display_packages_and_files()
404 {
405 last=""
406 while read pkg file; do
407 pkg=${pkg%:}
408 if [ "$pkg" != "$last" ]; then
409 . $WOK/$pkg/receipt
411 package_entry
412 last=$pkg
413 fi
414 echo " $file"
415 done
416 }
418 # Display search form and result if requested.
419 if [ "$REQUEST_METHOD" != "POST" ]; then
420 xhtml_header
421 cat << _EOT_
423 <!-- Content top. -->
424 <div id="content_top">
425 <div class="top_left"></div>
426 <div class="top_right"></div>
427 </div>
429 <!-- Content -->
430 <div id="content">
431 <a name="content"></a>
433 <h1><font color="#3E1220">$package</font></h1>
434 <h2><font color="#DF8F06">$search</font></h2>
435 _EOT_
436 search_form
437 xhtml_footer
438 else
439 xhtml_header
440 cat << _EOT_
442 <!-- Content top. -->
443 <div id="content_top">
444 <div class="top_left"></div>
445 <div class="top_right"></div>
446 </div>
448 <!-- Content -->
449 <div id="content">
450 <a name="content"></a>
452 <h1><font color="#3E1220">$package</font></h1>
453 <h2><font color="#DF8F06">$search</font></h2>
454 _EOT_
455 search_form
456 if [ "$OBJECT" = "Depends" ]; then
457 if package_exist $SEARCH ; then
458 cat << _EOT_
460 <h3>$deptree</h3>
461 <pre class="package">
462 _EOT_
463 ALL_DEPS=""
464 dep_scan $SEARCH ""
465 SUGGESTED=""
466 . $WOK/$SEARCH/receipt
467 if [ -n "$SUGGESTED" ]; then
468 cat << _EOT_
469 </pre>
471 <h3>$deptree (SUGGESTED)</h3>
472 <pre class="package">
473 _EOT_
474 ALL_DEPS=""
475 dep_scan "$SUGGESTED" " "
476 fi
477 cat << _EOT_
478 </pre>
480 <h3>$rdeptree</h3>
481 <pre class="package">
482 _EOT_
483 ALL_DEPS=""
484 rdep_scan $SEARCH
485 cat << _EOT_
486 </pre>
487 _EOT_
488 fi
489 elif [ "$OBJECT" = "BuildDepends" ]; then
490 if package_exist $SEARCH ; then
491 cat << _EOT_
493 <h3>$bdeplist</h3>
494 <pre class="package">
495 _EOT_
496 BUILD_DEPENDS=""
497 . $WOK/$SEARCH/receipt
498 [ -n "$BUILD_DEPENDS" ] && for dep in $BUILD_DEPENDS ; do
499 if [ ! -s $WOK/$dep/receipt ]; then
500 cat << _EOT_
501 $dep: not found !
502 _EOT_
503 continue
504 fi
505 . $WOK/$dep/receipt
506 package_entry
507 done
508 cat << _EOT_
509 </pre>
511 <h3>$rbdeplist</h3>
512 <pre class="package">
513 _EOT_
514 for dep in $(grep -l $SEARCH $WOK/*/receipt); do
515 BUILD_DEPENDS=""
516 . $dep
517 echo " $BUILD_DEPENDS " | grep -q " $SEARCH " &&
518 package_entry
519 done
520 cat << _EOT_
521 </pre>
522 _EOT_
523 fi
524 elif [ "$OBJECT" = "FileOverlap" ]; then
525 if package_exist $SEARCH ; then
526 cat << _EOT_
528 <h3>$overloading $SEARCH</h3>
529 <pre class="package">
530 _EOT_
531 ( unlzma -c $PACKAGES_REPOSITORY/files.list.lzma | grep ^$SEARCH: ;
532 unlzma -c $PACKAGES_REPOSITORY/files.list.lzma | grep -v ^$SEARCH: ) | awk '
533 BEGIN { pkg="" }
534 {
535 if (pkg == "") pkg=$1
536 if ($1 == pkg) file[$2]=$1
537 else if (file[$2] == pkg) print
538 }
539 ' | display_packages_and_files
540 cat << _EOT_
541 </pre>
542 _EOT_
543 fi
544 elif [ "$OBJECT" = "File" ]; then
545 cat << _EOT_
547 <h3>$result</h3>
548 <pre class="package">
549 _EOT_
550 last=""
551 unlzma -c $PACKAGES_REPOSITORY/files.list.lzma \
552 | grep $SEARCH | while read pkg file; do
553 echo "$file" | grep -q $SEARCH || continue
554 if [ "$last" != "${pkg%:}" ]; then
555 last=${pkg%:}
556 (
557 . $WOK/$last/receipt
558 cat << _EOT_
560 <i>$(package_entry)</i>
561 _EOT_
562 )
563 fi
564 echo " $file"
565 done
566 elif [ "$OBJECT" = "File_list" ]; then
567 package_exist $SEARCH && cat << _EOT_
569 <h3>$result</h3>
570 <pre class="package">
571 _EOT_
572 last=""
573 unlzma -c $PACKAGES_REPOSITORY/files.list.lzma \
574 | grep ^$SEARCH: | sed 's/.*: / /' | sort
575 elif [ "$OBJECT" = "Desc" ]; then
576 if [ -f $WOK/$SEARCH/description.txt ]; then
577 cat << _EOT_
579 <h3>$result</h3>
580 <pre class="package">
581 <pre>
582 $(htmlize < $WOK/$SEARCH/description.txt)
583 </pre>
584 _EOT_
585 else
586 cat << _EOT_
588 <h3>$result</h3>
589 <pre class="package">
590 _EOT_
591 last=""
592 grep -i $SEARCH $PACKAGES_REPOSITORY/packages.desc | \
593 sort | while read pkg extras ; do
594 . $WOK/$pkg/receipt
595 package_entry
596 done
597 fi
598 elif [ "$OBJECT" = "Tags" ]; then
599 cat << _EOT_
601 <h3>$result</h3>
602 <pre class="package">
603 _EOT_
604 last=""
605 grep ^TAGS= $WOK/*/receipt | grep -i $SEARCH | \
606 sed "s|$WOK/\(.*\)/receipt:.*|\1|" | sort | while read pkg ; do
607 . $WOK/$pkg/receipt
608 package_entry
609 done
610 elif [ "$OBJECT" = "Receipt" ]; then
611 package_exist $SEARCH && cat << _EOT_
613 <h3>$result</h3>
614 <pre class="package">
615 <pre>
616 $(if [ -f $WOK/$SEARCH/taz/*/receipt ]; then
617 cat $WOK/$SEARCH/taz/*/receipt
618 else
619 cat $WOK/$SEARCH/receipt
620 fi | htmlize)
621 </pre>
622 _EOT_
623 else
624 cat << _EOT_
626 <h3>$result</h3>
627 <pre class="package">
628 _EOT_
629 for pkg in `ls $WOK/ | grep $SEARCH`
630 do
631 . $WOK/$pkg/receipt
632 DESC=" <a href=\"?desc=$pkg\">description</a>"
633 [ -f $WOK/$pkg/description.txt ] || DESC=""
634 cat << _EOT_
635 $(package_entry)$DESC
636 _EOT_
637 done
638 equiv=$PACKAGES_REPOSITORY/packages.equiv
639 vpkgs="$(cat $equiv | cut -d= -f1 | grep $SEARCH)"
640 for vpkg in $vpkgs ; do
641 cat << _EOT_
642 </pre>
644 <h3>$result (package providing $vpkg)</h3>
645 <pre class="package">
646 _EOT_
647 for pkg in $(grep $vpkg= $equiv | sed "s/$vpkg=//"); do
648 . $WOK/${pkg#*:}/receipt
649 package_entry
650 done
651 done
652 fi
653 cat << _EOT_
654 </pre>
655 _EOT_
656 xhtml_footer
657 fi
659 exit 0