wok-6.x view tazpkg-web/stuff/search.cgi @ rev 4699
Up: gdb-dev (7.0.1)
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Jan 02 11:34:40 2010 +0100 (2010-01-02) |
parents | dbf2180c7325 |
children | 85313fe45f02 |
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 for i in $(echo $REQUEST_URI | sed 's/[?&]/ /g'); do
19 SLITAZ_VERSION=cooking
20 case "$i" in
21 lang=*)
22 LANG=${i#*=};;
23 file=*)
24 SEARCH=${i#*=}
25 OBJECT=File;;
26 desc=*)
27 SEARCH=${i#*=}
28 OBJECT=Desc;;
29 tags=*)
30 SEARCH=${i#*=}
31 OBJECT=Tags;;
32 receipt=*)
33 SEARCH=${i#*=}
34 OBJECT=Receipt;;
35 filelist=*)
36 SEARCH=${i#*=}
37 OBJECT=File_list;;
38 package=*)
39 SEARCH=${i#*=}
40 OBJECT=Package;;
41 depends=*)
42 SEARCH=${i#*=}
43 OBJECT=Depends;;
44 version=s*|version=2*)
45 SLITAZ_VERSION=stable;;
46 version=1*)
47 SLITAZ_VERSION=1.0;;
48 esac
49 done
50 [ -n "$SEARCH" ] && REQUEST_METHOD="POST"
51 fi
53 case "$OBJECT" in
54 File) selected_file="selected";;
55 Desc) selected_desc="selected";;
56 Tags) selected_tags="selected";;
57 Receipt) selected_receipt="selected";;
58 File_list) selected_file_list="selected";;
59 Depends) selected_depends="selected";;
60 esac
62 case "$SLITAZ_VERSION" in
63 1.0) selected_1="selected";;
64 stable) selected_stable="selected";;
65 esac
67 # unescape query
68 SEARCH="$(echo $SEARCH | sed 's/%2B/+/g' | sed 's/%3A/:/g' | sed 's|%2F|/|g')"
70 if [ -z "$LANG" ]; then
71 for i in $(echo $HTTP_ACCEPT_LANGUAGE | sed 's/[,;]/ /g'); do
72 case "$i" in
73 fr|de|pt|cn)
74 LANG=$i
75 break;;
76 esac
77 done
78 fi
80 package="Package"
81 file="File"
82 desc="Description"
83 tags="Tags"
84 receipt="Receipt"
85 file_list="File list"
86 depends="Depends"
87 search="Search"
88 cooking="cooking"
89 stable="stable"
90 result="Result for : $SEARCH"
91 noresult="No package $SEARCH"
92 deptree="Dependency tree for : $SEARCH"
93 rdeptree="Reverse dependency tree for : $SEARCH"
94 charset="ISO-8859-1"
96 case "$LANG" in
98 fr) package="Paquet"
99 receipt="Recette"
100 depends="Dépendances"
101 search="Recherche"
102 result="Recherche de : $SEARCH"
103 noresult="Paquet $SEARCH introuvable"
104 deptree="Arbre des dépendances de $SEARCH"
105 rdeptree="Arbre inversé des dépendances de $SEARCH"
106 file_list="Liste des fichiers"
107 file="Fichier";;
109 de) package="Paket"
110 depends="Abhängigkeiten"
111 desc="Beschreibung"
112 search="Suche"
113 cooking="Cooking"
114 stable="Stable"
115 result="Resultate für : $SEARCH"
116 noresult="Kein Paket für $SEARCH"
117 deptree="Abhängigkeiten von: $SEARCH"
118 rdeptree="Abhängigkeit für: $SEARCH"
119 file_list="Datei liste"
120 file="Datei";;
122 pt) package="Pacote"
123 search="Buscar"
124 cooking="cooking"
125 stable="stable"
126 result="Resultado para : $SEARCH"
127 noresult="Sem resultado: $SEARCH"
128 deptree="Árvore de dependências para: $SEARCH"
129 rdeptree="Árvore de dependências reversa para: $SEARCH"
130 depends="Dependências"
131 desc="Descrição"
132 file_list="Arquivo lista"
133 file="Arquivo";;
135 cn) package="软件包:"
136 cooking="å¼€å‘版"
137 stable="稳定版"
138 desc="æè¿°"
139 tags="æ ‡ç¾"
140 depends="ä¾èµ–"
141 file="文件"
142 file_list="文件列表"
143 search="Search"
144 result="Result for : $SEARCH"
145 noresult="No package $SEARCH"
146 deptree="Dependency tree for : $SEARCH"
147 rdeptree="Reverse dependency tree for : $SEARCH"
148 charset="UTF-8";;
150 *) LANG="en";;
152 esac
154 WOK=/home/slitaz/$SLITAZ_VERSION/wok
155 PACKAGES_REPOSITORY=/home/slitaz/$SLITAZ_VERSION/packages
157 echo Content-type: text/html
158 echo
160 # Search form
161 search_form()
162 {
163 cat << _EOT_
165 <div style="text-align: center; padding: 20px;">
166 <form method="post" action="search.cgi">
167 <input type="hidden" name="lang" value="$LANG" />
168 <select name="object">
169 <option value="Package">$package</option>
170 <option $selected_desc value="Desc">$desc</option>
171 <option $selected_tags value="Tags">$tags</option>
172 <option $selected_receipt value="Receipt">$receipt</option>
173 <option $selected_depends value="Depends">$depends</option>
174 <option $selected_file value="File">$file</option>
175 <option $selected_file_list value="File_list">$file_list</option>
176 </select>
177 <strong>:</strong>
178 <input type="text" name="query" size="32" value="$SEARCH" />
179 <select name="version">
180 <option value="cooking">$cooking</option>
181 <option $selected_stable value="stable">$stable</option>
182 <option $selected_1 value="1.0">1.0</option>
183 </select>
184 <input type="submit" name="search" value="$search" />
185 </form>
186 </div>
187 _EOT_
188 }
190 # xHTML Header.
191 xhtml_header()
192 {
193 cat << _EOF_
194 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
195 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
196 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="$LANG" lang="$LANG">
197 <head>
198 <title>SliTaz Packages - Search $SEARCH</title>
199 <meta http-equiv="content-type" content="text/html; charset=$charset" />
200 <meta name="description" content="Au sujet de SliTaz GNU/Linux mini système d'exploitation" />
201 <meta name="keywords" lang="fr" content="Système, libre, gnu, linux, opensource, livecd" />
202 <meta name="robots" content="index, follow, all" />
203 <meta name="revisit-after" content="7 days" />
204 <meta name="expires" content="never" />
205 <meta name="modified" content="$DATE" />
206 <meta name="author" content="ash, awk, grep, sed and cat"/>
207 <meta name="publisher" content="www.slitaz.org" />
208 <link rel="shortcut icon" href="http://pkgs.slitaz.org/favicon.ico" />
209 <link rel="stylesheet" type="text/css" href="http://pkgs.slitaz.org/slitaz.css" />
210 </head>
211 <body bgcolor="#ffffff">
213 <!-- Header -->
214 <div id="header">
215 <a name="top"></a>
216 <!-- Access -->
217 <div id="access">
218 <a href="http://www.slitaz.org/" title="SliTaz Web site">Website</a> |
219 <a href="http://wiki.slitaz.org/" title="SliTaz Community Wiki">Wiki</a> |
220 <a href="http://labs.slitaz.org/" title="SliTaz laboratories">Labs</a>
221 </div>
222 <a href="http://pkgs.slitaz.org/"><img id="logo"
223 src="http://pkgs.slitaz.org/pics/website/logo.png" title="pkgs.slitaz.org" alt="pkgs.slitaz.org"
224 style="border: 0px solid ; width: 200px; height: 74px;" /></a>
225 <p id="titre">#!/tazpkg/packages</p>
226 </div>
227 _EOF_
228 }
230 # xHTML Footer.
231 xhtml_footer()
232 {
233 cat << _EOT_
234 <center>
235 <i>$(ls $WOK/ | wc -l) packages and $(unlzma -c $PACKAGES_REPOSITORY/files.list.lzma | wc -l) files in $SLITAZ_VERSION database</i>
236 </center>
238 <!-- End of content with round corner -->
239 </div>
240 <div id="content_bottom">
241 <div class="bottom_left"></div>
242 <div class="bottom_right"></div>
243 </div>
245 <!-- Start of footer and copy notice -->
246 <div id="copy">
247 <p>
248 Dernière modification : $DATE -
249 <a href="#top">Top of the page</a>
250 </p>
251 <p>
252 Copyright © 2009 <a href="http://www.slitaz.org/">SliTaz</a> -
253 <a href="http://www.gnu.org/licenses/gpl.html">GNU General Public License</a>
254 </p>
255 <!-- End of copy -->
256 </div>
258 <!-- Bottom and logo's -->
259 <div id="bottom">
260 <p>
261 <a href="http://validator.w3.org/check?uri=referer"><img
262 src="http://pkgs.slitaz.org/pics/website/xhtml10.png" alt="Valid XHTML 1.0"
263 title="Code validé XHTML 1.0"
264 style="width: 80px; height: 15px;" /></a>
265 </p>
266 </div>
268 </body>
269 </html>
270 _EOT_
271 }
273 # recursive dependencies scan
274 dep_scan()
275 {
276 for i in $1; do
277 case " $ALL_DEPS " in
278 *\ $i\ *) continue;;
279 esac
280 ALL_DEPS="$ALL_DEPS $i"
281 if [ -n "$2" ]; then
282 echo -n "$2"
283 (
284 . $WOK/$i/receipt
285 cat << _EOT_
286 <a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> : $SHORT_DESC
287 _EOT_
288 )
289 fi
290 [ -f $WOK/$i/receipt ] || continue
291 DEPENDS=""
292 . $WOK/$i/receipt
293 [ -n "$DEPENDS" ] && dep_scan "$DEPENDS" "$2 "
294 done
295 }
297 # recursive reverse dependencies scan
298 rdep_scan()
299 {
300 SEARCH=$1
301 case "$SEARCH" in
302 glibc-base|gcc-lib-base) cat <<EOT
303 glibc-base and gcc-lib-base are implicit dependencies,
304 <b>every</b> package is supposed to depend on them.
305 EOT
306 return;;
307 esac
308 for i in $WOK/* ; do
309 DEPENDS=""
310 . $i/receipt
311 echo "$(basename $i) $(echo $DEPENDS)"
312 done | awk -v search=$SEARCH '
313 function show_deps(deps, all_deps, pkg, space)
314 {
315 if (all_deps[pkg] == 1) return
316 all_deps[pkg] = 1
317 if (space != "") printf "%s%s\n",space,pkg
318 for (i = 1; i <= split(deps[pkg], mydeps, " "); i++) {
319 show_deps(deps, all_deps, mydeps[i],"////" space)
320 }
321 }
323 {
324 all_deps[$1] = 0
325 for (i = 2; i <= NF; i++)
326 deps[$i] = deps[$i] " " $1
327 }
329 END {
330 show_deps(deps, all_deps, search, "")
331 }
332 ' | while read pkg; do
333 . $WOK/${pkg##*/}/receipt
334 cat << _EOT_
335 $(echo ${pkg%/*} | sed 's|/| |g') <a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> : $SHORT_DESC
336 _EOT_
337 done
338 }
340 # Check package exists
341 package_exist()
342 {
343 [ -f $WOK/$1/receipt ] && return 0
344 cat << _EOT_
346 <h3>$noresult</h3>
347 <pre class="package">
348 _EOT_
349 return 1
350 }
352 # Display < > &
353 htmlize()
354 {
355 sed -e 's/&/\&/g' -e 's/</\</g' -e 's/>/\>/g'
356 }
358 # Display search form and result if requested.
359 if [ "$REQUEST_METHOD" != "POST" ]; then
360 xhtml_header
361 cat << _EOT_
363 <!-- Content top. -->
364 <div id="content_top">
365 <div class="top_left"></div>
366 <div class="top_right"></div>
367 </div>
369 <!-- Content -->
370 <div id="content">
371 <a name="content"></a>
373 <h1><font color="#3E1220">$package</font></h1>
374 <h2><font color="#DF8F06">$search</font></h2>
375 _EOT_
376 search_form
377 xhtml_footer
378 else
379 xhtml_header
380 cat << _EOT_
382 <!-- Content top. -->
383 <div id="content_top">
384 <div class="top_left"></div>
385 <div class="top_right"></div>
386 </div>
388 <!-- Content -->
389 <div id="content">
390 <a name="content"></a>
392 <h1><font color="#3E1220">$package</font></h1>
393 <h2><font color="#DF8F06">$search</font></h2>
394 _EOT_
395 search_form
396 if [ "$OBJECT" = "Depends" ]; then
397 if package_exist $SEARCH ; then
398 cat << _EOT_
400 <h3>$deptree</h3>
401 <pre class="package">
402 _EOT_
403 ALL_DEPS=""
404 dep_scan $SEARCH ""
405 SUGGESTED=""
406 . $WOK/$SEARCH/receipt
407 if [ -n "$SUGGESTED" ]; then
408 cat << _EOT_
409 </pre>
411 <h3>$deptree (SUGGESTED)</h3>
412 <pre class="package">
413 _EOT_
414 ALL_DEPS=""
415 dep_scan "$SUGGESTED" " "
416 fi
417 cat << _EOT_
418 </pre>
420 <h3>$rdeptree</h3>
421 <pre class="package">
422 _EOT_
423 ALL_DEPS=""
424 rdep_scan $SEARCH
425 fi
426 elif [ "$OBJECT" = "File" ]; then
427 cat << _EOT_
429 <h3>$result</h3>
430 <pre class="package">
431 _EOT_
432 last=""
433 unlzma -c $PACKAGES_REPOSITORY/files.list.lzma \
434 | grep $SEARCH | while read pkg file; do
435 echo "$file" | grep -q $SEARCH || continue
436 if [ "$last" != "${pkg%:}" ]; then
437 last=${pkg%:}
438 (
439 . $WOK/$last/receipt
440 cat << _EOT_
442 <i><b><a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a></b> $SHORT_DESC</i>
443 _EOT_
444 )
445 fi
446 echo " $file"
447 done
448 elif [ "$OBJECT" = "File_list" ]; then
449 package_exist $SEARCH && cat << _EOT_
451 <h3>$result</h3>
452 <pre class="package">
453 _EOT_
454 last=""
455 unlzma -c $PACKAGES_REPOSITORY/files.list.lzma \
456 | grep ^$SEARCH: | sed 's/.*: / /' | sort
457 elif [ "$OBJECT" = "Desc" ]; then
458 if [ -f $WOK/$SEARCH/description.txt ]; then
459 cat << _EOT_
461 <h3>$result</h3>
462 <pre class="package">
463 <pre>
464 $(htmlize < $WOK/$SEARCH/description.txt)
465 </pre>
466 _EOT_
467 else
468 cat << _EOT_
470 <h3>$result</h3>
471 <pre class="package">
472 _EOT_
473 last=""
474 grep -i $SEARCH $PACKAGES_REPOSITORY/packages.desc | \
475 sort | while read pkg extras ; do
476 . $WOK/$pkg/receipt
477 cat << _EOT_
478 <a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> : $SHORT_DESC
479 _EOT_
480 done
481 fi
482 elif [ "$OBJECT" = "Tags" ]; then
483 cat << _EOT_
485 <h3>$result</h3>
486 <pre class="package">
487 _EOT_
488 last=""
489 grep ^TAGS= $WOK/*/receipt | grep -i $SEARCH | \
490 sed "s|$WOK/\(.*\)/receipt:.*|\1|" | sort | while read pkg ; do
491 . $WOK/$pkg/receipt
492 cat << _EOT_
493 <a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> : $SHORT_DESC
494 _EOT_
495 done
496 elif [ "$OBJECT" = "Receipt" ]; then
497 package_exist $SEARCH && cat << _EOT_
499 <h3>$result</h3>
500 <pre class="package">
501 <pre>
502 $(if [ -f $WOK/$SEARCH/taz/*/receipt ]; then
503 cat $WOK/$SEARCH/taz/*/receipt
504 else
505 cat $WOK/$SEARCH/receipt
506 fi | htmlize)
507 </pre>
508 _EOT_
509 else
510 cat << _EOT_
512 <h3>$result</h3>
513 <pre class="package">
514 _EOT_
515 for pkg in `ls $WOK | grep $SEARCH`
516 do
517 . $WOK/$pkg/receipt
518 DESC=" <a href=\"?desc=$pkg\">description</a>"
519 [ -f $WOK/$pkg/description.txt ] || DESC=""
520 cat << _EOT_
521 <a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> : $SHORT_DESC$DESC
522 _EOT_
523 done
524 equiv=$PACKAGES_REPOSITORY/packages.equiv
525 vpkgs="$(cat $equiv | cut -d= -f1 | grep $SEARCH)"
526 for vpkg in $vpkgs ; do
527 cat << _EOT_
528 </pre>
530 <h3>$result (package providing $vpkg)</h3>
531 <pre class="package">
532 _EOT_
533 for pkg in $(grep $vpkg= $equiv | sed "s/$vpkg=//"); do
534 . $WOK/${pkg#*:}/receipt
535 cat << _EOT_
536 <a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> : $SHORT_DESC
537 _EOT_
538 done
539 done
540 fi
541 cat << _EOT_
542 </pre>
543 _EOT_
544 xhtml_footer
545 fi
547 exit 0