wok-current view tazpkg-web/stuff/search.cgi @ rev 7862

tazpkg-web: exclude path from common files
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Jan 01 21:01:35 2011 +0100 (2011-01-01)
parents dd533bb4feda
children 7057fef5a16a
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 &copy; $(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/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/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=""; last="x" }
537 {
538 if ($2 == "") next
539 if (index($2,last) == 1) delete file[last]
540 last=$2
541 if (pkg == "") pkg=$1
542 if ($1 == pkg) file[$2]=$1
543 else if (file[$2] == pkg) print
544 }
545 ' | display_packages_and_files
546 cat << _EOT_
547 </pre>
548 _EOT_
549 fi
550 elif [ "$OBJECT" = "File" ]; then
551 cat << _EOT_
553 <h3>$result</h3>
554 <pre class="package">
555 _EOT_
556 last=""
557 unlzma -c $PACKAGES_REPOSITORY/files.list.lzma \
558 | grep $SEARCH | while read pkg file; do
559 echo "$file" | grep -q $SEARCH || continue
560 if [ "$last" != "${pkg%:}" ]; then
561 last=${pkg%:}
562 (
563 . $WOK/$last/receipt
564 cat << _EOT_
566 <i>$(package_entry)</i>
567 _EOT_
568 )
569 fi
570 echo " $file"
571 done
572 elif [ "$OBJECT" = "File_list" ]; then
573 package_exist $SEARCH && cat << _EOT_
575 <h3>$result</h3>
576 <pre class="package">
577 _EOT_
578 last=""
579 unlzma -c $PACKAGES_REPOSITORY/files.list.lzma \
580 | grep ^$SEARCH: | sed 's/.*: / /' | sort
581 elif [ "$OBJECT" = "Desc" ]; then
582 if [ -f $WOK/$SEARCH/description.txt ]; then
583 cat << _EOT_
585 <h3>$result</h3>
586 <pre class="package">
587 <pre>
588 $(htmlize < $WOK/$SEARCH/description.txt)
589 </pre>
590 _EOT_
591 else
592 cat << _EOT_
594 <h3>$result</h3>
595 <pre class="package">
596 _EOT_
597 last=""
598 grep -i $SEARCH $PACKAGES_REPOSITORY/packages.desc | \
599 sort | while read pkg extras ; do
600 . $WOK/$pkg/receipt
601 package_entry
602 done
603 fi
604 elif [ "$OBJECT" = "Tags" ]; then
605 cat << _EOT_
607 <h3>$result</h3>
608 <pre class="package">
609 _EOT_
610 last=""
611 grep ^TAGS= $WOK/*/receipt | grep -i $SEARCH | \
612 sed "s|$WOK/\(.*\)/receipt:.*|\1|" | sort | while read pkg ; do
613 . $WOK/$pkg/receipt
614 package_entry
615 done
616 elif [ "$OBJECT" = "Receipt" ]; then
617 package_exist $SEARCH && cat << _EOT_
619 <h3>$result</h3>
620 <pre class="package">
621 <pre>
622 $(if [ -f $WOK/$SEARCH/taz/*/receipt ]; then
623 cat $WOK/$SEARCH/taz/*/receipt
624 else
625 cat $WOK/$SEARCH/receipt
626 fi | htmlize)
627 </pre>
628 _EOT_
629 else
630 cat << _EOT_
632 <h3>$result</h3>
633 <pre class="package">
634 _EOT_
635 for pkg in `ls $WOK/ | grep $SEARCH`
636 do
637 . $WOK/$pkg/receipt
638 DESC=" <a href=\"?desc=$pkg\">description</a>"
639 [ -f $WOK/$pkg/description.txt ] || DESC=""
640 cat << _EOT_
641 $(package_entry)$DESC
642 _EOT_
643 done
644 equiv=$PACKAGES_REPOSITORY/packages.equiv
645 vpkgs="$(cat $equiv | cut -d= -f1 | grep $SEARCH)"
646 for vpkg in $vpkgs ; do
647 cat << _EOT_
648 </pre>
650 <h3>$result (package providing $vpkg)</h3>
651 <pre class="package">
652 _EOT_
653 for pkg in $(grep $vpkg= $equiv | sed "s/$vpkg=//"); do
654 . $WOK/${pkg#*:}/receipt
655 package_entry
656 done
657 done
658 fi
659 cat << _EOT_
660 </pre>
661 _EOT_
662 xhtml_footer
663 fi
665 exit 0