wok view tazpkg-web/stuff/search.cgi @ rev 3529
tazbb: Dont clean-up on each commit (only once a night on Tank)
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Mon Jun 22 02:07:46 2009 +0200 (2009-06-22) |
parents | c075da96e08a |
children | b831574060d2 |
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
156 echo Content-type: text/html
157 echo
159 # Search form
160 search_form()
161 {
162 cat << _EOT_
164 <div style="text-align: center; padding: 20px;">
165 <form method="post" action="search.cgi">
166 <input type="hidden" name="lang" value="$LANG" />
167 <select name="object">
168 <option value="Package">$package</option>
169 <option $selected_desc value="Desc">$desc</option>
170 <option $selected_tags value="Tags">$tags</option>
171 <option $selected_receipt value="Receipt">$receipt</option>
172 <option $selected_depends value="Depends">$depends</option>
173 <option $selected_file value="File">$file</option>
174 <option $selected_file_list value="File_list">$file_list</option>
175 </select>
176 <strong>:</strong>
177 <input type="text" name="query" size="32" value="$SEARCH" />
178 <select name="version">
179 <option value="cooking">$cooking</option>
180 <option $selected_stable value="stable">$stable</option>
181 <option $selected_1 value="1.0">1.0</option>
182 </select>
183 <input type="submit" name="search" value="$search" />
184 </form>
185 </div>
186 _EOT_
187 }
189 # xHTML Header.
190 xhtml_header()
191 {
192 cat << _EOF_
193 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
194 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
195 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="$LANG" lang="$LANG">
196 <head>
197 <title>SliTaz Packages - Search $SEARCH</title>
198 <meta http-equiv="content-type" content="text/html; charset=$charset" />
199 <meta name="description" content="Au sujet de SliTaz GNU/Linux mini système d'exploitation" />
200 <meta name="keywords" lang="fr" content="Système, libre, gnu, linux, opensource, livecd" />
201 <meta name="robots" content="index, follow, all" />
202 <meta name="revisit-after" content="7 days" />
203 <meta name="expires" content="never" />
204 <meta name="modified" content="$DATE" />
205 <meta name="author" content="ash, awk, grep, sed and cat"/>
206 <meta name="publisher" content="www.slitaz.org" />
207 <link rel="shortcut icon" href="http://pkgs.slitaz.org/favicon.ico" />
208 <link rel="stylesheet" type="text/css" href="http://pkgs.slitaz.org/slitaz.css" />
209 </head>
210 <body bgcolor="#ffffff">
212 <!-- Header -->
213 <div id="header">
214 <a name="top"></a>
215 <!-- Access -->
216 <div id="access">
217 <a href="http://www.slitaz.org/" title="SliTaz Web site">Website</a> |
218 <a href="http://wiki.slitaz.org/" title="SliTaz Community Wiki">Wiki</a> |
219 <a href="http://labs.slitaz.org/" title="SliTaz laboratories">Labs</a>
220 </div>
221 <a href="http://pkgs.slitaz.org/"><img id="logo"
222 src="http://pkgs.slitaz.org/pics/website/logo.png" title="pkgs.slitaz.org" alt="pkgs.slitaz.org"
223 style="border: 0px solid ; width: 200px; height: 74px;" /></a>
224 <p id="titre">#!/tazpkg/packages</p>
225 </div>
226 _EOF_
227 }
229 # xHTML Footer.
230 xhtml_footer()
231 {
232 cat << _EOT_
233 <center>
234 <i>$(ls /home/slitaz/$SLITAZ_VERSION/wok | wc -l) packages and $(unlzma -c /home/slitaz/$SLITAZ_VERSION/packages/files.list.lzma | wc -l) files in $SLITAZ_VERSION database</i>
235 </center>
237 <!-- End of content with round corner -->
238 </div>
239 <div id="content_bottom">
240 <div class="bottom_left"></div>
241 <div class="bottom_right"></div>
242 </div>
244 <!-- Start of footer and copy notice -->
245 <div id="copy">
246 <p>
247 Dernière modification : $DATE -
248 <a href="#top">Top of the page</a>
249 </p>
250 <p>
251 Copyright © 2009 <a href="http://www.slitaz.org/">SliTaz</a> -
252 <a href="http://www.gnu.org/licenses/gpl.html">GNU General Public License</a>
253 </p>
254 <!-- End of copy -->
255 </div>
257 <!-- Bottom and logo's -->
258 <div id="bottom">
259 <p>
260 <a href="http://validator.w3.org/check?uri=referer"><img
261 src="http://pkgs.slitaz.org/pics/website/xhtml10.png" alt="Valid XHTML 1.0"
262 title="Code validé XHTML 1.0"
263 style="width: 80px; height: 15px;" /></a>
264 </p>
265 </div>
267 </body>
268 </html>
269 _EOT_
270 }
272 # recursive dependencies scan
273 dep_scan()
274 {
275 for i in $1; do
276 case " $ALL_DEPS " in
277 *\ $i\ *) continue;;
278 esac
279 ALL_DEPS="$ALL_DEPS $i"
280 if [ -n "$2" ]; then
281 echo -n "$2"
282 (
283 . $WOK/$i/receipt
284 cat << _EOT_
285 <a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> : $SHORT_DESC
286 _EOT_
287 )
288 fi
289 [ -f $WOK/$i/receipt ] || continue
290 DEPENDS=""
291 . $WOK/$i/receipt
292 [ -n "$DEPENDS" ] && dep_scan "$DEPENDS" "$2 "
293 done
294 }
296 # recursive reverse dependencies scan
297 rdep_scan()
298 {
299 SEARCH=$1
300 case "$SEARCH" in
301 glibc-base|gcc-lib-base) cat <<EOT
302 glibc-base and gcc-lib-base are implicit dependencies,
303 <b>every</b> package is supposed to depend on them.
304 EOT
305 return;;
306 esac
307 for i in $WOK/* ; do
308 DEPENDS=""
309 . $i/receipt
310 echo "$(basename $i) $(echo $DEPENDS)"
311 done | awk -v search=$SEARCH '
312 function show_deps(deps, all_deps, pkg, space)
313 {
314 if (all_deps[pkg] == 1) return
315 all_deps[pkg] = 1
316 if (space != "") printf "%s%s\n",space,pkg
317 for (i = 1; i <= split(deps[pkg], mydeps, " "); i++) {
318 show_deps(deps, all_deps, mydeps[i],"////" space)
319 }
320 }
322 {
323 all_deps[$1] = 0
324 for (i = 2; i <= NF; i++)
325 deps[$i] = deps[$i] " " $1
326 }
328 END {
329 show_deps(deps, all_deps, search, "")
330 }
331 ' | while read pkg; do
332 . $WOK/${pkg##*/}/receipt
333 cat << _EOT_
334 $(echo ${pkg%/*} | sed 's|/| |g') <a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> : $SHORT_DESC
335 _EOT_
336 done
337 }
339 # Check package exists
340 package_exist()
341 {
342 [ -f $WOK/$1/receipt ] && return 0
343 cat << _EOT_
345 <h3>$noresult</h3>
346 <pre class="package">
347 _EOT_
348 return 1
349 }
351 # Display search form and result if requested.
352 if [ "$REQUEST_METHOD" != "POST" ]; then
353 xhtml_header
354 cat << _EOT_
356 <!-- Content top. -->
357 <div id="content_top">
358 <div class="top_left"></div>
359 <div class="top_right"></div>
360 </div>
362 <!-- Content -->
363 <div id="content">
364 <a name="content"></a>
366 <h1><font color="#3E1220">$package</font></h1>
367 <h2><font color="#DF8F06">$search</font></h2>
368 _EOT_
369 search_form
370 xhtml_footer
371 else
372 xhtml_header
373 cat << _EOT_
375 <!-- Content top. -->
376 <div id="content_top">
377 <div class="top_left"></div>
378 <div class="top_right"></div>
379 </div>
381 <!-- Content -->
382 <div id="content">
383 <a name="content"></a>
385 <h1><font color="#3E1220">$package</font></h1>
386 <h2><font color="#DF8F06">$search</font></h2>
387 _EOT_
388 search_form
389 if [ "$OBJECT" = "Depends" ]; then
390 if package_exist $SEARCH ; then
391 cat << _EOT_
393 <h3>$deptree</h3>
394 <pre class="package">
395 _EOT_
396 ALL_DEPS=""
397 dep_scan $SEARCH ""
398 SUGGESTED=""
399 . $WOK/$SEARCH/receipt
400 if [ -n "$SUGGESTED" ]; then
401 cat << _EOT_
402 </pre>
404 <h3>$deptree (SUGGESTED)</h3>
405 <pre class="package">
406 _EOT_
407 ALL_DEPS=""
408 dep_scan "$SUGGESTED" " "
409 fi
410 cat << _EOT_
411 </pre>
413 <h3>$rdeptree</h3>
414 <pre class="package">
415 _EOT_
416 ALL_DEPS=""
417 rdep_scan $SEARCH
418 fi
419 elif [ "$OBJECT" = "File" ]; then
420 cat << _EOT_
422 <h3>$result</h3>
423 <pre class="package">
424 _EOT_
425 last=""
426 unlzma -c /home/slitaz/$SLITAZ_VERSION/packages/files.list.lzma \
427 | grep $SEARCH | while read pkg file; do
428 echo "$file" | grep -q $SEARCH || continue
429 if [ "$last" != "${pkg%:}" ]; then
430 last=${pkg%:}
431 (
432 . $WOK/$last/receipt
433 cat << _EOT_
435 <i><b><a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a></b> $SHORT_DESC</i>
436 _EOT_
437 )
438 fi
439 echo " $file"
440 done
441 elif [ "$OBJECT" = "File_list" ]; then
442 package_exist $SEARCH && cat << _EOT_
444 <h3>$result</h3>
445 <pre class="package">
446 _EOT_
447 last=""
448 unlzma -c /home/slitaz/$SLITAZ_VERSION/packages/files.list.lzma \
449 | grep ^$SEARCH: | sed 's/.*: / /' | sort
450 elif [ "$OBJECT" = "Desc" ]; then
451 cat << _EOT_
453 <h3>$result</h3>
454 <pre class="package">
455 _EOT_
456 last=""
457 grep -i $SEARCH /home/slitaz/$SLITAZ_VERSION/packages/packages.desc | \
458 sort | while read pkg extras ; do
459 . $WOK/$pkg/receipt
460 cat << _EOT_
461 <a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> : $SHORT_DESC
462 _EOT_
463 done
464 elif [ "$OBJECT" = "Tags" ]; then
465 cat << _EOT_
467 <h3>$result</h3>
468 <pre class="package">
469 _EOT_
470 last=""
471 grep ^TAGS= $WOK/*/receipt | grep -i $SEARCH | \
472 sed "s|$WOK/\(.*\)/receipt:.*|\1|" | sort | while read pkg ; do
473 . $WOK/$pkg/receipt
474 cat << _EOT_
475 <a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> : $SHORT_DESC
476 _EOT_
477 done
478 elif [ "$OBJECT" = "Receipt" ]; then
479 package_exist $SEARCH && cat << _EOT_
481 <h3>$result</h3>
482 <pre class="package">
483 <pre>
484 $(if [ -f $WOK/$SEARCH/taz/*/receipt ]; then
485 cat $WOK/$SEARCH/taz/*/receipt
486 else
487 cat $WOK/$SEARCH//receipt
488 fi | sed -e 's/&/\&/g' -e 's/</\</g' -e 's/>/\>/g')
489 </pre>
490 _EOT_
491 else
492 cat << _EOT_
494 <h3>$result</h3>
495 <pre class="package">
496 _EOT_
497 for pkg in `ls $WOK | grep $SEARCH`
498 do
499 . $WOK/$pkg/receipt
500 cat << _EOT_
501 <a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> : $SHORT_DESC
502 _EOT_
503 done
504 equiv=/home/slitaz/$SLITAZ_VERSION/packages/packages.equiv
505 vpkgs="$(cat $equiv | cut -d= -f1 | grep $SEARCH)"
506 for vpkg in $vpkgs ; do
507 cat << _EOT_
508 </pre>
510 <h3>$result (package providing $vpkg)</h3>
511 <pre class="package">
512 _EOT_
513 for pkg in $(grep $vpkg= $equiv | sed "s/$vpkg=//"); do
514 . $WOK/${pkg#*:}/receipt
515 cat << _EOT_
516 <a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> : $SHORT_DESC
517 _EOT_
518 done
519 done
520 fi
521 cat << _EOT_
522 </pre>
523 _EOT_
524 xhtml_footer
525 fi
527 exit 0