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