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