wok view tazpkg-web/stuff/search.cgi @ rev 3602
libglu-mesa fix VERSION + libkrb5 Dependencies loop
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sun Jun 28 22:49:30 2009 +0200 (2009-06-28) |
parents | b831574060d2 |
children | bc37eb38a4f4 |
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 search form and result if requested.
353 if [ "$REQUEST_METHOD" != "POST" ]; then
354 xhtml_header
355 cat << _EOT_
357 <!-- Content top. -->
358 <div id="content_top">
359 <div class="top_left"></div>
360 <div class="top_right"></div>
361 </div>
363 <!-- Content -->
364 <div id="content">
365 <a name="content"></a>
367 <h1><font color="#3E1220">$package</font></h1>
368 <h2><font color="#DF8F06">$search</font></h2>
369 _EOT_
370 search_form
371 xhtml_footer
372 else
373 xhtml_header
374 cat << _EOT_
376 <!-- Content top. -->
377 <div id="content_top">
378 <div class="top_left"></div>
379 <div class="top_right"></div>
380 </div>
382 <!-- Content -->
383 <div id="content">
384 <a name="content"></a>
386 <h1><font color="#3E1220">$package</font></h1>
387 <h2><font color="#DF8F06">$search</font></h2>
388 _EOT_
389 search_form
390 if [ "$OBJECT" = "Depends" ]; then
391 if package_exist $SEARCH ; then
392 cat << _EOT_
394 <h3>$deptree</h3>
395 <pre class="package">
396 _EOT_
397 ALL_DEPS=""
398 dep_scan $SEARCH ""
399 SUGGESTED=""
400 . $WOK/$SEARCH/receipt
401 if [ -n "$SUGGESTED" ]; then
402 cat << _EOT_
403 </pre>
405 <h3>$deptree (SUGGESTED)</h3>
406 <pre class="package">
407 _EOT_
408 ALL_DEPS=""
409 dep_scan "$SUGGESTED" " "
410 fi
411 cat << _EOT_
412 </pre>
414 <h3>$rdeptree</h3>
415 <pre class="package">
416 _EOT_
417 ALL_DEPS=""
418 rdep_scan $SEARCH
419 fi
420 elif [ "$OBJECT" = "File" ]; then
421 cat << _EOT_
423 <h3>$result</h3>
424 <pre class="package">
425 _EOT_
426 last=""
427 unlzma -c $PACKAGES_REPOSITORY/files.list.lzma \
428 | grep $SEARCH | while read pkg file; do
429 echo "$file" | grep -q $SEARCH || continue
430 if [ "$last" != "${pkg%:}" ]; then
431 last=${pkg%:}
432 (
433 . $WOK/$last/receipt
434 cat << _EOT_
436 <i><b><a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a></b> $SHORT_DESC</i>
437 _EOT_
438 )
439 fi
440 echo " $file"
441 done
442 elif [ "$OBJECT" = "File_list" ]; then
443 package_exist $SEARCH && cat << _EOT_
445 <h3>$result</h3>
446 <pre class="package">
447 _EOT_
448 last=""
449 unlzma -c $PACKAGES_REPOSITORY/files.list.lzma \
450 | grep ^$SEARCH: | sed 's/.*: / /' | sort
451 elif [ "$OBJECT" = "Desc" ]; then
452 cat << _EOT_
454 <h3>$result</h3>
455 <pre class="package">
456 _EOT_
457 last=""
458 grep -i $SEARCH $PACKAGES_REPOSITORY/packages.desc | \
459 sort | while read pkg extras ; do
460 . $WOK/$pkg/receipt
461 cat << _EOT_
462 <a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> : $SHORT_DESC
463 _EOT_
464 done
465 elif [ "$OBJECT" = "Tags" ]; then
466 cat << _EOT_
468 <h3>$result</h3>
469 <pre class="package">
470 _EOT_
471 last=""
472 grep ^TAGS= $WOK/*/receipt | grep -i $SEARCH | \
473 sed "s|$WOK/\(.*\)/receipt:.*|\1|" | sort | while read pkg ; do
474 . $WOK/$pkg/receipt
475 cat << _EOT_
476 <a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> : $SHORT_DESC
477 _EOT_
478 done
479 elif [ "$OBJECT" = "Receipt" ]; then
480 package_exist $SEARCH && cat << _EOT_
482 <h3>$result</h3>
483 <pre class="package">
484 <pre>
485 $(if [ -f $WOK/$SEARCH/taz/*/receipt ]; then
486 cat $WOK/$SEARCH/taz/*/receipt
487 else
488 cat $WOK/$SEARCH//receipt
489 fi | sed -e 's/&/\&/g' -e 's/</\</g' -e 's/>/\>/g')
490 </pre>
491 _EOT_
492 else
493 cat << _EOT_
495 <h3>$result</h3>
496 <pre class="package">
497 _EOT_
498 for pkg in `ls $WOK | grep $SEARCH`
499 do
500 . $WOK/$pkg/receipt
501 cat << _EOT_
502 <a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> : $SHORT_DESC
503 _EOT_
504 done
505 equiv=$PACKAGES_REPOSITORY/packages.equiv
506 vpkgs="$(cat $equiv | cut -d= -f1 | grep $SEARCH)"
507 for vpkg in $vpkgs ; do
508 cat << _EOT_
509 </pre>
511 <h3>$result (package providing $vpkg)</h3>
512 <pre class="package">
513 _EOT_
514 for pkg in $(grep $vpkg= $equiv | sed "s/$vpkg=//"); do
515 . $WOK/${pkg#*:}/receipt
516 cat << _EOT_
517 <a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> : $SHORT_DESC
518 _EOT_
519 done
520 done
521 fi
522 cat << _EOT_
523 </pre>
524 _EOT_
525 xhtml_footer
526 fi
528 exit 0