wok-next view tazpkg-web/stuff/search.cgi @ rev 10341

screen: Add $CONFIGURE_ARGS.
author Christopher Rogers <slaxemulator@gmail.com>
date Sun May 22 02:29:02 2011 +0000 (2011-05-22)
parents 7057fef5a16a
children
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>
243 <!-- Header -->
244 <div id="header">
245 <!-- Logo -->
246 <a href="http://pkgs.slitaz.org/"><img id="logo"
247 src="/pics/website/logo.png"
248 title="pkgs.slitaz.org" alt="pkgs.slitaz.org" /></a>
249 <p id="titre">#!/Packages</p>
250 </div>
251 _EOF_
252 }
254 # xHTML Footer.
255 xhtml_footer()
256 {
257 cat << _EOT_
258 <center>
259 <i>$(ls $WOK/ | wc -l) packages and $(unlzma -c $PACKAGES_REPOSITORY/files.list.lzma | wc -l) files in $SLITAZ_VERSION database</i>
260 </center>
262 <!-- End of content -->
263 </div>
265 <!-- Footer -->
266 <div id="footer">
267 <div class="right_box">
268 <h4>SliTaz Network</h4>
269 <ul>
270 <li><a href="http://www.slitaz.org/">Main Website</a></li>
271 <li><a href="http://doc.slitaz.org/">Documentation</a></li>
272 <li><a href="http://forum.slitaz.org/">Support Forum</a></li>
273 <li><a href="http://scn.slitaz.org/">Community Network</a></li>
274 <li><a href="http://twitter.com/slitaz">SliTaz on Twitter</a></li>
275 <li><a href="http://distrowatch.com/slitaz">SliTaz on DistroWatch</a></li>
276 </ul>
277 </div>
278 <h4>SliTaz Packages</h4>
279 <ul>
280 <li><a href="#header">Top of the page</a></li>
281 <li>Copyright &copy; <span class="year"></span>
282 <a href="http://www.slitaz.org/">SliTaz</a></li>
283 <li><a href="http://www.slitaz.org/en/about/">About the project</a></li>
284 <li><a href="http://pkgs.slitaz.org/search.cgi">Search packages</a></li>
285 <li>Page modified the _DATE_</li>
286 <li><a href="http://validator.w3.org/check?uri=referer"><img
287 src="http://pkgs.slitaz.org/pics/website/xhtml10.png"
288 title="Code validé XHTML 1.0" alt="Valid XHTML 1.0"
289 style="width: 80px; height: 15px; vertical-align: middle;" /></a></li>
290 </ul>
291 </div>
293 </body>
294 </html>
295 _EOT_
296 }
298 installed_size()
299 {
300 [ $VERBOSE -gt 0 ] &&
301 grep -A 3 "^$1\$" /home/slitaz/$SLITAZ_VERSION/packages/packages.txt | \
302 grep installed | sed 's/.*(\(.*\) installed.*/(\1) /'
303 }
305 package_entry()
306 {
307 if [ -s "$(dirname $0)/$SLITAZ_VERSION/$CATEGORY.html" ]; then
308 cat << _EOT_
309 <a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> $(installed_size $PACKAGE): $SHORT_DESC
310 _EOT_
311 else
312 cat << _EOT_
313 <a href="http://mirror.slitaz.org/packages/$SLITAZ_VERSION/$PACKAGE-$VERSION$EXTRA_VERSION.tazpkg">$PACKAGE</a> $(installed_size $PACKAGE): $SHORT_DESC
314 _EOT_
315 fi
316 }
318 # recursive dependencies scan
319 dep_scan()
320 {
321 for i in $1; do
322 case " $ALL_DEPS " in
323 *\ $i\ *) continue;;
324 esac
325 ALL_DEPS="$ALL_DEPS $i"
326 if [ -n "$2" ]; then
327 echo -n "$2"
328 (
329 . $WOK/$i/receipt
330 package_entry
331 )
332 fi
333 [ -f $WOK/$i/receipt ] || continue
334 DEPENDS=""
335 . $WOK/$i/receipt
336 [ -n "$DEPENDS" ] && dep_scan "$DEPENDS" "$2 "
337 done
338 }
340 # recursive reverse dependencies scan
341 rdep_scan()
342 {
343 SEARCH=$1
344 case "$SEARCH" in
345 glibc-base|gcc-lib-base) cat <<EOT
346 glibc-base and gcc-lib-base are implicit dependencies,
347 <b>every</b> package is supposed to depend on them.
348 EOT
349 return;;
350 esac
351 for i in $WOK/* ; do
352 DEPENDS=""
353 . $i/receipt
354 echo "$(basename $i) $(echo $DEPENDS)"
355 done | awk -v search=$SEARCH '
356 function show_deps(deps, all_deps, pkg, space)
357 {
358 if (all_deps[pkg] == 1) return
359 all_deps[pkg] = 1
360 if (space != "") printf "%s%s\n",space,pkg
361 for (i = 1; i <= split(deps[pkg], mydeps, " "); i++) {
362 show_deps(deps, all_deps, mydeps[i],"////" space)
363 }
364 }
366 {
367 all_deps[$1] = 0
368 for (i = 2; i <= NF; i++)
369 deps[$i] = deps[$i] " " $1
370 }
372 END {
373 show_deps(deps, all_deps, search, "")
374 }
375 ' | while read pkg; do
376 . $WOK/${pkg##*/}/receipt
377 cat << _EOT_
378 $(echo ${pkg%/*} | sed 's|/| |g') $(package_entry)
379 _EOT_
380 done
381 }
383 # Check package exists
384 package_exist()
385 {
386 [ -f $WOK/$1/receipt ] && return 0
387 cat << _EOT_
389 <h3>$noresult</h3>
390 <pre class="package">
391 _EOT_
392 return 1
393 }
395 # Display < > &
396 htmlize()
397 {
398 sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g'
399 }
401 display_packages_and_files()
402 {
403 last=""
404 while read pkg file; do
405 pkg=${pkg%:}
406 if [ "$pkg" != "$last" ]; then
407 . $WOK/$pkg/receipt
409 package_entry
410 last=$pkg
411 fi
412 echo " $file"
413 done
414 }
416 # Display search form and result if requested.
417 if [ "$REQUEST_METHOD" != "POST" ]; then
418 xhtml_header
419 cat << _EOT_
421 <!-- Content -->
422 <div id="content">
424 <h1>$package</h1>
425 <h2>$search</h2>
426 _EOT_
427 search_form
428 xhtml_footer
429 else
430 xhtml_header
431 cat << _EOT_
433 <!-- Content -->
434 <div id="content">
436 <h1>$package</h1>
437 <h2>$search</h2>
438 _EOT_
439 search_form
440 if [ "$OBJECT" = "Depends" ]; then
441 if package_exist $SEARCH ; then
442 cat << _EOT_
444 <h3>$deptree</h3>
445 <pre class="package">
446 _EOT_
447 ALL_DEPS=""
448 dep_scan $SEARCH ""
449 SUGGESTED=""
450 . $WOK/$SEARCH/receipt
451 if [ -n "$SUGGESTED" ]; then
452 cat << _EOT_
453 </pre>
455 <h3>$deptree (SUGGESTED)</h3>
456 <pre class="package">
457 _EOT_
458 ALL_DEPS=""
459 dep_scan "$SUGGESTED" " "
460 fi
461 cat << _EOT_
462 </pre>
464 <h3>$rdeptree</h3>
465 <pre class="package">
466 _EOT_
467 ALL_DEPS=""
468 rdep_scan $SEARCH
469 cat << _EOT_
470 </pre>
471 _EOT_
472 fi
473 elif [ "$OBJECT" = "BuildDepends" ]; then
474 if package_exist $SEARCH ; then
475 cat << _EOT_
477 <h3>$bdeplist</h3>
478 <pre class="package">
479 _EOT_
480 BUILD_DEPENDS=""
481 . $WOK/$SEARCH/receipt
482 [ -n "$BUILD_DEPENDS" ] && for dep in $BUILD_DEPENDS ; do
483 if [ ! -s $WOK/$dep/receipt ]; then
484 cat << _EOT_
485 $dep: not found !
486 _EOT_
487 continue
488 fi
489 . $WOK/$dep/receipt
490 package_entry
491 done
492 cat << _EOT_
493 </pre>
495 <h3>$rbdeplist</h3>
496 <pre class="package">
497 _EOT_
498 for dep in $(grep -l $SEARCH $WOK/*/receipt); do
499 BUILD_DEPENDS=""
500 . $dep
501 echo " $BUILD_DEPENDS " | grep -q " $SEARCH " &&
502 package_entry
503 done
504 cat << _EOT_
505 </pre>
506 _EOT_
507 fi
508 elif [ "$OBJECT" = "FileOverlap" ]; then
509 if package_exist $SEARCH ; then
510 cat << _EOT_
512 <h3>$overloading $SEARCH</h3>
513 <pre class="package">
514 _EOT_
515 ( unlzma -c $PACKAGES_REPOSITORY/files.list.lzma | grep ^$SEARCH: ;
516 unlzma -c $PACKAGES_REPOSITORY/files.list.lzma | grep -v ^$SEARCH: ) | awk '
517 BEGIN { pkg=""; last="x" }
518 {
519 if ($2 == "") next
520 if (index($2,last) == 1 && substr($2,1+length(last),1) == "/")
521 delete file[last]
522 last=$2
523 if (pkg == "") pkg=$1
524 if ($1 == pkg) file[$2]=$1
525 else if (file[$2] == pkg) print
526 }
527 ' | display_packages_and_files
528 cat << _EOT_
529 </pre>
530 _EOT_
531 fi
532 elif [ "$OBJECT" = "File" ]; then
533 cat << _EOT_
535 <h3>$result</h3>
536 <pre class="package">
537 _EOT_
538 last=""
539 unlzma -c $PACKAGES_REPOSITORY/files.list.lzma \
540 | grep $SEARCH | while read pkg file; do
541 echo "$file" | grep -q $SEARCH || continue
542 if [ "$last" != "${pkg%:}" ]; then
543 last=${pkg%:}
544 (
545 . $WOK/$last/receipt
546 cat << _EOT_
548 <i>$(package_entry)</i>
549 _EOT_
550 )
551 fi
552 echo " $file"
553 done
554 elif [ "$OBJECT" = "File_list" ]; then
555 package_exist $SEARCH && cat << _EOT_
557 <h3>$result</h3>
558 <pre class="package">
559 _EOT_
560 last=""
561 unlzma -c $PACKAGES_REPOSITORY/files.list.lzma \
562 | grep ^$SEARCH: | sed 's/.*: / /' | sort
563 elif [ "$OBJECT" = "Desc" ]; then
564 if [ -f $WOK/$SEARCH/description.txt ]; then
565 cat << _EOT_
567 <h3>$result</h3>
568 <pre class="package">
569 <pre>
570 $(htmlize < $WOK/$SEARCH/description.txt)
571 </pre>
572 _EOT_
573 else
574 cat << _EOT_
576 <h3>$result</h3>
577 <pre class="package">
578 _EOT_
579 last=""
580 grep -i $SEARCH $PACKAGES_REPOSITORY/packages.desc | \
581 sort | while read pkg extras ; do
582 . $WOK/$pkg/receipt
583 package_entry
584 done
585 fi
586 elif [ "$OBJECT" = "Tags" ]; then
587 cat << _EOT_
589 <h3>$result</h3>
590 <pre class="package">
591 _EOT_
592 last=""
593 grep ^TAGS= $WOK/*/receipt | grep -i $SEARCH | \
594 sed "s|$WOK/\(.*\)/receipt:.*|\1|" | sort | while read pkg ; do
595 . $WOK/$pkg/receipt
596 package_entry
597 done
598 elif [ "$OBJECT" = "Receipt" ]; then
599 package_exist $SEARCH && cat << _EOT_
601 <h3>$result</h3>
602 <pre class="package">
603 <pre>
604 $(if [ -f $WOK/$SEARCH/taz/*/receipt ]; then
605 cat $WOK/$SEARCH/taz/*/receipt
606 else
607 cat $WOK/$SEARCH/receipt
608 fi | htmlize)
609 </pre>
610 _EOT_
611 else
612 cat << _EOT_
614 <h3>$result</h3>
615 <pre class="package">
616 _EOT_
617 for pkg in `ls $WOK/ | grep $SEARCH`
618 do
619 . $WOK/$pkg/receipt
620 DESC=" <a href=\"?desc=$pkg\">description</a>"
621 [ -f $WOK/$pkg/description.txt ] || DESC=""
622 cat << _EOT_
623 $(package_entry)$DESC
624 _EOT_
625 done
626 equiv=$PACKAGES_REPOSITORY/packages.equiv
627 vpkgs="$(cat $equiv | cut -d= -f1 | grep $SEARCH)"
628 for vpkg in $vpkgs ; do
629 cat << _EOT_
630 </pre>
632 <h3>$result (package providing $vpkg)</h3>
633 <pre class="package">
634 _EOT_
635 for pkg in $(grep $vpkg= $equiv | sed "s/$vpkg=//"); do
636 . $WOK/${pkg#*:}/receipt
637 package_entry
638 done
639 done
640 fi
641 cat << _EOT_
642 </pre>
643 _EOT_
644 xhtml_footer
645 fi
647 exit 0