wok-4.x rev 3242
mirror-tools: add search.cgi from pkgs.slitaz.org
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat May 30 11:53:39 2009 +0200 (2009-05-30) |
parents | b0788eda3c6e |
children | 0193bd5b5e89 |
files | mirror-tools/stuff/var/www/pkgs/search.cgi |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mirror-tools/stuff/var/www/pkgs/search.cgi Sat May 30 11:53:39 2009 +0200 1.3 @@ -0,0 +1,472 @@ 1.4 +#!/bin/sh 1.5 +# Tiny CGI search engine for SliTaz packages on http://pkgs.slitaz.org/ 1.6 +# Christophe Lincoln <pankso@slitaz.org> 1.7 +# 1.8 + 1.9 +read QUERY_STRING 1.10 +for i in $(echo $QUERY_STRING | sed 's/&/ /g'); do 1.11 + eval $i 1.12 +done 1.13 +LANG=$lang 1.14 +SEARCH=$query 1.15 +SLITAZ_VERSION=$version 1.16 +OBJECT=$object 1.17 +DATE=`date +%Y-%m-%d\ \%H:%M:%S` 1.18 +VERSION=cooking 1.19 +if [ "$REQUEST_METHOD" = "GET" ]; then 1.20 + SEARCH="" 1.21 + for i in $(echo $REQUEST_URI | sed 's/[?&]/ /g'); do 1.22 + SLITAZ_VERSION=cooking 1.23 + case "$i" in 1.24 + lang=*) 1.25 + LANG=${i#*=};; 1.26 + file=*) 1.27 + SEARCH=${i#*=} 1.28 + OBJECT=File;; 1.29 + desc=*) 1.30 + SEARCH=${i#*=} 1.31 + OBJECT=Desc;; 1.32 + tags=*) 1.33 + SEARCH=${i#*=} 1.34 + OBJECT=Tags;; 1.35 + filelist=*) 1.36 + SEARCH=${i#*=} 1.37 + OBJECT=File_list;; 1.38 + package=*) 1.39 + SEARCH=${i#*=} 1.40 + OBJECT=Package;; 1.41 + depends=*) 1.42 + SEARCH=${i#*=} 1.43 + OBJECT=Depends;; 1.44 + version=s*|version=2*) 1.45 + SLITAZ_VERSION=stable;; 1.46 + version=1*) 1.47 + SLITAZ_VERSION=1.0;; 1.48 + esac 1.49 + done 1.50 + [ -n "$SEARCH" ] && REQUEST_METHOD="POST" 1.51 +fi 1.52 + 1.53 +case "$OBJECT" in 1.54 +File) selected_file="selected";; 1.55 +Desc) selected_desc="selected";; 1.56 +Tags) selected_tags="selected";; 1.57 +File_list) selected_file_list="selected";; 1.58 +Depends) selected_depends="selected";; 1.59 +esac 1.60 + 1.61 +case "$SLITAZ_VERSION" in 1.62 +1.0) selected_1="selected";; 1.63 +stable) selected_stable="selected";; 1.64 +esac 1.65 + 1.66 +# unescape query 1.67 +SEARCH="$(echo $SEARCH | sed 's/%2B/+/g' | sed 's/%3A/:/g' | sed 's|%2F|/|g')" 1.68 + 1.69 +package="Package" 1.70 +file="File" 1.71 +desc="Description" 1.72 +tags="Tags" 1.73 +file_list="File list" 1.74 +depends="Depends" 1.75 +search="Search" 1.76 +cooking="cooking" 1.77 +stable="stable" 1.78 +result="Result for : $SEARCH" 1.79 +noresult="No package $SEARCH" 1.80 +deptree="Dependency tree for : $SEARCH" 1.81 +rdeptree="Reverse dependency tree for : $SEARCH" 1.82 +charset="ISO-8859-1" 1.83 +case "$LANG" in 1.84 +fr) package="Paquet" 1.85 + depends="Dépendances" 1.86 + search="Recherche" 1.87 + result="Recherche de : $SEARCH" 1.88 + noresult="Paquet $SEARCH introuvable" 1.89 + deptree="Arbre des dépendances de $SEARCH" 1.90 + rdeptree="Arbre inversé des dépendances de $SEARCH" 1.91 + file_list="Liste des fichiers" 1.92 + file="Fichier";; 1.93 +de) package="Paket" 1.94 + depends="Abhängigkeiten" 1.95 + search="Suche" 1.96 + cooking="Cooking" 1.97 + stable="Stable" 1.98 + result="Resultate für : $SEARCH" 1.99 + noresult="Kein Paket für $SEARCH" 1.100 + deptree="Abhängigkeiten von: $SEARCH" 1.101 + rdeptree="Abhängigkeit für: $SEARCH" 1.102 + file_list="Datei liste" 1.103 + file="Datei";; 1.104 +pt) package="Pacote" 1.105 + search="Buscar" 1.106 + cooking="cooking" 1.107 + stable="stable" 1.108 + result="Resultado para : $SEARCH" 1.109 + noresult="Sem resultado: $SEARCH" 1.110 + deptree="Árvore de dependências para: $SEARCH" 1.111 + rdeptree="Árvore de dependências reversa para: $SEARCH" 1.112 + depends="Dependências" 1.113 + file_list="Arquivo lista" 1.114 + file="Arquivo";; 1.115 +cn) package="软件包:" 1.116 + cooking="å¼€å‘版" 1.117 + stable="稳定版" 1.118 + charset="UTF-8";; 1.119 +*) LANG="en";; 1.120 +esac 1.121 +WOK=/home/slitaz/$SLITAZ_VERSION/wok 1.122 + 1.123 + 1.124 +echo Content-type: text/html 1.125 +echo 1.126 + 1.127 +# Search form 1.128 +search_form() 1.129 +{ 1.130 + cat << _EOT_ 1.131 + 1.132 +<div style="text-align: center; padding: 20px;"> 1.133 +<form method="POST" action="search.cgi"> 1.134 + <input type="hidden" name="lang" value="$LANG"> 1.135 + <select name="object"> 1.136 + <option value="Package">$package</option> 1.137 + <option $selected_desc value="Desc">$desc</option> 1.138 + <option $selected_tags value="Tags">$tags</option> 1.139 + <option $selected_depends value="Depends">$depends</option> 1.140 + <option $selected_file value="File">$file</option> 1.141 + <option $selected_file_list value="File_list">$file_list</option> 1.142 + </select> 1.143 + <strong>:</strong> 1.144 + <input type="text" name="query" size="32" value="$SEARCH"> 1.145 + <select name="version"> 1.146 + <option value="cooking">$cooking</option> 1.147 + <option $selected_stable value="stable">$stable</option> 1.148 + <option $selected_1 value="1.0">1.0</option> 1.149 + </select> 1.150 + <input type="submit" name="search" value="$search"> 1.151 +</form> 1.152 +</div> 1.153 +_EOT_ 1.154 +} 1.155 + 1.156 +# xHTML Header. 1.157 +xhtml_header() 1.158 +{ 1.159 + cat << _EOF_ 1.160 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 1.161 + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 1.162 +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="$LANG" lang="$LANG"> 1.163 +<head> 1.164 + <title>SliTaz Packages - Search $SEARCH</title> 1.165 + <meta http-equiv="content-type" content="text/html; charset=$charset" /> 1.166 + <meta name="description" content="Au sujet de SliTaz GNU/Linux mini système d'exploitation" /> 1.167 + <meta name="keywords" lang="fr" content="Système, libre, gnu, linux, opensource, livecd" /> 1.168 + <meta name="robots" content="index, follow, all" /> 1.169 + <meta name="revisit-after" content="7 days" /> 1.170 + <meta name="expires" content="never" /> 1.171 + <meta name="modified" content="$DATE" /> 1.172 + <meta name="author" content="ash, grep, sed and cat"/> 1.173 + <meta name="publisher" content="www.slitaz.org" /> 1.174 + <link rel="shortcut icon" href="http://pkgs.slitaz.org/favicon.ico" /> 1.175 + <link rel="stylesheet" type="text/css" href="http://pkgs.slitaz.org/slitaz.css" /> 1.176 +</head> 1.177 +<body bgcolor="#ffffff"> 1.178 + 1.179 +<!-- Header --> 1.180 +<div id="header"> 1.181 + <a name="top"></a> 1.182 +<!-- Access --> 1.183 +<div id="access"> 1.184 + <a href="http://www.slitaz.org/" title="SliTaz Web site">Website</a> | 1.185 + <a href="http://wiki.slitaz.org/" title="SliTaz Community Wiki">Wiki</a> | 1.186 + <a href="http://labs.slitaz.org/" title="SliTaz laboratories">Labs</a> 1.187 +</div> 1.188 + <a href="http://pkgs.slitaz.org/"><img id="logo" 1.189 + src="http://pkgs.slitaz.org/pics/website/logo.png" title="pkgs.slitaz.org" alt="pkgs.slitaz.org" 1.190 + style="border: 0px solid ; width: 200px; height: 74px;" /></a> 1.191 + <p id="titre">#!/tazpkg/packages</p> 1.192 +</div> 1.193 +_EOF_ 1.194 +} 1.195 + 1.196 +# xHTML Footer. 1.197 +xhtml_footer() 1.198 +{ 1.199 + cat << _EOT_ 1.200 +<center> 1.201 +<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> 1.202 +</center> 1.203 + 1.204 +<!-- End of content with round corner --> 1.205 +</div> 1.206 +<div id="content_bottom"> 1.207 +<div class="bottom_left"></div> 1.208 +<div class="bottom_right"></div> 1.209 +</div> 1.210 + 1.211 +<!-- Start of footer and copy notice --> 1.212 +<div id="copy"> 1.213 +<p> 1.214 +Dernière modification : $DATE - 1.215 +<a href="#top">Top of the page</a> 1.216 +</p> 1.217 +<p> 1.218 +Copyright © 2009 <a href="http://www.slitaz.org/">SliTaz</a> - 1.219 +<a href="http://www.gnu.org/licenses/gpl.html">GNU General Public License</a> 1.220 +</p> 1.221 +<!-- End of copy --> 1.222 +</div> 1.223 + 1.224 +<!-- Bottom and logo's --> 1.225 +<div id="bottom"> 1.226 +<p> 1.227 +<a href="http://validator.w3.org/check?uri=referer"><img 1.228 + src="http://pkgs.slitaz.org/pics/website/xhtml10.png" alt="Valid XHTML 1.0" 1.229 + title="Code validé XHTML 1.0" 1.230 + style="width: 80px; height: 15px;" /></a> 1.231 +</p> 1.232 +</div> 1.233 + 1.234 +</body> 1.235 +</html> 1.236 +_EOT_ 1.237 +} 1.238 + 1.239 +# recursive dependencies scan 1.240 +dep_scan() 1.241 +{ 1.242 +for i in $1; do 1.243 + case " $ALL_DEPS " in 1.244 + *\ $i\ *) continue;; 1.245 + esac 1.246 + ALL_DEPS="$ALL_DEPS $i" 1.247 + if [ -n "$2" ]; then 1.248 + echo -n "$2" 1.249 + ( 1.250 + . $WOK/$i/receipt 1.251 + cat << _EOT_ 1.252 +<a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> : $SHORT_DESC 1.253 +_EOT_ 1.254 + ) 1.255 + fi 1.256 + [ -f $WOK/$i/receipt ] || continue 1.257 + DEPENDS="" 1.258 + . $WOK/$i/receipt 1.259 + [ -n "$DEPENDS" ] && dep_scan "$DEPENDS" "$2 " 1.260 +done 1.261 +} 1.262 + 1.263 +# recursive reverse dependencies scan 1.264 +rdep_scan() 1.265 +{ 1.266 +SEARCH=$1 1.267 +case "$SEARCH" in 1.268 +glibc-base|gcc-lib-base) cat <<EOT 1.269 + glibc-base and gcc-lib-base are implicit dependencies 1.270 + <b>every</b> packages are supposed to depend on them. 1.271 +EOT 1.272 + return;; 1.273 +esac 1.274 +for i in $WOK/* ; do 1.275 + DEPENDS="" 1.276 + . $i/receipt 1.277 + echo "$(basename $i) $(echo $DEPENDS)" 1.278 +done | awk -v search=$SEARCH ' 1.279 +function show_deps(deps, all_deps, pkg, space) 1.280 +{ 1.281 + if (all_deps[pkg] == 1) return 1.282 + all_deps[pkg] = 1 1.283 + if (space != "") printf "%s%s\n",space,pkg 1.284 + for (i = 1; i <= split(deps[pkg], mydeps, " "); i++) { 1.285 + show_deps(deps, all_deps, mydeps[i],"////" space) 1.286 + } 1.287 +} 1.288 + 1.289 +{ 1.290 + all_deps[$1] = 0 1.291 + for (i = 2; i <= NF; i++) 1.292 + deps[$i] = deps[$i] " " $1 1.293 +} 1.294 + 1.295 +END { 1.296 + show_deps(deps, all_deps, search, "") 1.297 +} 1.298 +' | while read pkg; do 1.299 + . $WOK/${pkg##*/}/receipt 1.300 + cat << _EOT_ 1.301 +$(echo ${pkg%/*} | sed 's|/| |g') <a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> : $SHORT_DESC 1.302 +_EOT_ 1.303 +done 1.304 +} 1.305 + 1.306 +# Display search form and result if requested. 1.307 +if [ "$REQUEST_METHOD" != "POST" ]; then 1.308 + xhtml_header 1.309 + cat << _EOT_ 1.310 + 1.311 +<!-- Content top. --> 1.312 +<div id="content_top"> 1.313 +<div class="top_left"></div> 1.314 +<div class="top_right"></div> 1.315 +</div> 1.316 + 1.317 +<!-- Content --> 1.318 +<div id="content"> 1.319 +<a name="content"></a> 1.320 + 1.321 +<h1><font color="#3E1220">$package</font></h1> 1.322 +<h2><font color="#DF8F06">$search</font></h2> 1.323 +_EOT_ 1.324 + search_form 1.325 + xhtml_footer 1.326 +else 1.327 + xhtml_header 1.328 + cat << _EOT_ 1.329 + 1.330 +<!-- Content top. --> 1.331 +<div id="content_top"> 1.332 +<div class="top_left"></div> 1.333 +<div class="top_right"></div> 1.334 +</div> 1.335 + 1.336 +<!-- Content --> 1.337 +<div id="content"> 1.338 +<a name="content"></a> 1.339 + 1.340 +<h1><font color="#3E1220">$package</font></h1> 1.341 +<h2><font color="#DF8F06">$search</font></h2> 1.342 +_EOT_ 1.343 + search_form 1.344 + if [ "$OBJECT" = "Depends" ]; then 1.345 + if [ -f $WOK/$SEARCH/receipt ]; then 1.346 + cat << _EOT_ 1.347 + 1.348 +<h3>$deptree</h3> 1.349 +<pre class="package"> 1.350 +_EOT_ 1.351 + ALL_DEPS="" 1.352 + dep_scan $SEARCH "" 1.353 + SUGGESTED="" 1.354 + . $WOK/$SEARCH/receipt 1.355 + if [ -n "$SUGGESTED" ]; then 1.356 + cat << _EOT_ 1.357 +</pre> 1.358 + 1.359 +<h3>$deptree (SUGGESTED)</h3> 1.360 +<pre class="package"> 1.361 +_EOT_ 1.362 + ALL_DEPS="" 1.363 + dep_scan "$SUGGESTED" " " 1.364 + fi 1.365 + cat << _EOT_ 1.366 +</pre> 1.367 + 1.368 +<h3>$rdeptree</h3> 1.369 +<pre class="package"> 1.370 +_EOT_ 1.371 + ALL_DEPS="" 1.372 + rdep_scan $SEARCH 1.373 + else 1.374 + cat << _EOT_ 1.375 + 1.376 +<h3>$noresult</h3> 1.377 +<pre class="package"> 1.378 +_EOT_ 1.379 + fi 1.380 + elif [ "$OBJECT" = "File" ]; then 1.381 + cat << _EOT_ 1.382 + 1.383 +<h3>$result</h3> 1.384 +<pre class="package"> 1.385 +_EOT_ 1.386 + last="" 1.387 + unlzma -c /home/slitaz/$SLITAZ_VERSION/packages/files.list.lzma \ 1.388 + | grep $SEARCH | while read pkg file; do 1.389 + echo "$file" | grep -q $SEARCH || continue 1.390 + if [ "$last" != "${pkg%:}" ]; then 1.391 + last=${pkg%:} 1.392 + ( 1.393 + . $WOK/$last/receipt 1.394 + cat << _EOT_ 1.395 + 1.396 +<i><b><a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a></b> $SHORT_DESC</i> 1.397 +_EOT_ 1.398 + ) 1.399 + fi 1.400 + echo " $file" 1.401 + done 1.402 + elif [ "$OBJECT" = "File_list" ]; then 1.403 + cat << _EOT_ 1.404 + 1.405 +<h3>$result</h3> 1.406 +<pre class="package"> 1.407 +_EOT_ 1.408 + last="" 1.409 + unlzma -c /home/slitaz/$SLITAZ_VERSION/packages/files.list.lzma \ 1.410 + | grep ^$SEARCH: | sed 's/.*: / /' | sort 1.411 + elif [ "$OBJECT" = "Desc" ]; then 1.412 + cat << _EOT_ 1.413 + 1.414 +<h3>$result</h3> 1.415 +<pre class="package"> 1.416 +_EOT_ 1.417 + last="" 1.418 + grep -i $SEARCH /home/slitaz/$SLITAZ_VERSION/packages/packages.desc | \ 1.419 + sort | while read pkg extras ; do 1.420 + . $WOK/$pkg/receipt 1.421 + cat << _EOT_ 1.422 +<a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> : $SHORT_DESC 1.423 +_EOT_ 1.424 + done 1.425 + elif [ "$OBJECT" = "Tags" ]; then 1.426 + cat << _EOT_ 1.427 + 1.428 +<h3>$result</h3> 1.429 +<pre class="package"> 1.430 +_EOT_ 1.431 + last="" 1.432 + grep ^TAGS= $WOK/*/receipt | grep -i $SEARCH | \ 1.433 + sed "s|$WOK/\(.*\)/receipt:.*|\1|" | sort | while read pkg ; do 1.434 + . $WOK/$pkg/receipt 1.435 + cat << _EOT_ 1.436 +<a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> : $SHORT_DESC 1.437 +_EOT_ 1.438 + done 1.439 + else 1.440 + cat << _EOT_ 1.441 + 1.442 +<h3>$result</h3> 1.443 +<pre class="package"> 1.444 +_EOT_ 1.445 + for pkg in `ls $WOK | grep $SEARCH` 1.446 + do 1.447 + . $WOK/$pkg/receipt 1.448 + cat << _EOT_ 1.449 +<a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> : $SHORT_DESC 1.450 +_EOT_ 1.451 + done 1.452 + equiv=/home/slitaz/$SLITAZ_VERSION/packages/packages.equiv 1.453 + vpkgs="$(cat $equiv | cut -d= -f1 | grep $SEARCH)" 1.454 + for vpkg in $vpkgs ; do 1.455 + cat << _EOT_ 1.456 +</pre> 1.457 + 1.458 +<h3>$result (package providing $vpkg)</h3> 1.459 +<pre class="package"> 1.460 +_EOT_ 1.461 + for pkg in $(grep $vpkg= $equiv | sed "s/$vpkg=//"); do 1.462 + . $WOK/${pkg#*:}/receipt 1.463 + cat << _EOT_ 1.464 +<a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> : $SHORT_DESC 1.465 +_EOT_ 1.466 + done 1.467 + done 1.468 + fi 1.469 + cat << _EOT_ 1.470 +</pre> 1.471 +_EOT_ 1.472 + xhtml_footer 1.473 +fi 1.474 + 1.475 +exit 0