slitaz-forge annotate pkgs/mirror-search.sh @ rev 316

Add pkgs/mirror-search.sh: mirror.slitaz.org fork from tank.slitaz.org, needs conciliation
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Jul 15 09:25:01 2012 +0200 (2012-07-15)
parents
children 26343c8fe3a2
rev   line source
pascal@316 1 #!/bin/sh
pascal@316 2 # Tiny CGI search engine for SliTaz packages on http://pkgs.slitaz.org/
pascal@316 3 # Christophe Lincoln <pankso@slitaz.org>
pascal@316 4 # Aleksej Bobylev <al.bobylev@gmail.com>
pascal@316 5 #
pascal@316 6
pascal@316 7 # Parse query string
pascal@316 8 . /usr/lib/slitaz/httphelper.sh
pascal@316 9
pascal@316 10
pascal@316 11 # User preferred language
pascal@316 12 # parameter $1 have priority; without parameter $1 - browser language only
pascal@316 13 # if we don't support any of user languages (or only en), then return C locale
pascal@316 14 user_lang() {
pascal@316 15 LANG="C"
pascal@316 16 IFS=","
pascal@316 17 for lang in $1 $HTTP_ACCEPT_LANGUAGE
pascal@316 18 do
pascal@316 19 lang=${lang%;*} lang=${lang# } lang=${lang%-*} lang=${lang%_*}
pascal@316 20 case "$lang" in
pascal@316 21 de) LANG="de_DE" ;;
pascal@316 22 es) LANG="es_ES" ;;
pascal@316 23 fr) LANG="fr_FR" ;;
pascal@316 24 it) LANG="it_IT" ;;
pascal@316 25 pt) LANG="pt_BR" ;;
pascal@316 26 ru) LANG="ru_RU" ;;
pascal@316 27 zh) LANG="zh_TW" ;;
pascal@316 28 esac
pascal@316 29 if echo "de en fr pt ru zh" | fgrep -q "$lang"; then
pascal@316 30 break
pascal@316 31 fi
pascal@316 32 done
pascal@316 33 unset IFS
pascal@316 34 echo "$LANG"
pascal@316 35 }
pascal@316 36
pascal@316 37 # Short 2-letter lang code from ll_CC
pascal@316 38 ll_lang() {
pascal@316 39 ll_CC="$1"
pascal@316 40 echo ${ll_CC%_*}
pascal@316 41 }
pascal@316 42
pascal@316 43 # Nice URL replacer - to copy url from address bar
pascal@316 44 # TODO: deal with POST method of form submitting
pascal@316 45 nice_url() {
pascal@316 46 # if user submitted a form
pascal@316 47 if [ ! -z $(GET submit) ]; then
pascal@316 48 OBJECT="$(GET object)"
pascal@316 49 SEARCH="$(GET query)"
pascal@316 50 case $OBJECT in
pascal@316 51 Package) NICE="package=$SEARCH";;
pascal@316 52 Desc) NICE="desc=$SEARCH";;
pascal@316 53 Tags) NICE="tags=$SEARCH";;
pascal@316 54 Receipt) NICE="receipt=$SEARCH";;
pascal@316 55 Depends) NICE="depends=$SEARCH";;
pascal@316 56 BuildDepends) NICE="builddepends=$SEARCH";;
pascal@316 57 File) NICE="file=$SEARCH";;
pascal@316 58 File_list) NICE="filelist=$SEARCH";;
pascal@316 59 FileOverlap) NICE="fileoverlap=$SEARCH";;
pascal@316 60 esac
pascal@316 61 # version, if needed
pascal@316 62 version="$(GET version)"
pascal@316 63 if [ ! -z "$version" -a "$version" != "cooking" ]; then
pascal@316 64 NICE="${NICE}&version=${version:0:1}"
pascal@316 65 fi
pascal@316 66 # lang, if needed
pascal@316 67 query_lang="$(GET lang)"
pascal@316 68 pref_lang="$(user_lang)"
pascal@316 69 browser_lang="$(ll_lang $pref_lang)"
pascal@316 70 if [ ! -z "$query_lang" -a "$query_lang" != "$browser_lang" ]; then
pascal@316 71 NICE="${NICE}&lang=$query_lang"
pascal@316 72 fi
pascal@316 73 # verbose, if needed
pascal@316 74 verboseq="$(GET verbose)"
pascal@316 75 if [ ! -z "$verboseq" -a "$verboseq" != "0" ]; then
pascal@316 76 NICE="${NICE}&verbose=1"
pascal@316 77 fi
pascal@316 78 # redirect
pascal@316 79 # TODO: implement HTTP 301 Redirect
pascal@316 80 cat << EOT
pascal@316 81 Content-type: text/html
pascal@316 82
pascal@316 83 <!DOCTYPE html>
pascal@316 84 <html><head><meta http-equiv="refresh" content="0;url=$SCRIPT_NAME?$NICE" />
pascal@316 85 <title>Redirect</title></head></html>
pascal@316 86 EOT
pascal@316 87 # echo "Location: $SCRIPT_NAME?$NICE"
pascal@316 88 # echo
pascal@316 89 exit 0
pascal@316 90 fi
pascal@316 91 }
pascal@316 92
pascal@316 93 nice_url
pascal@316 94
pascal@316 95
pascal@316 96
pascal@316 97 OBJECT="$(GET object)"
pascal@316 98 SEARCH="$(GET query)"
pascal@316 99 SLITAZ_VERSION="$(GET version)"
pascal@316 100 VERBOSE="$(GET verbose)"
pascal@316 101
pascal@316 102 # Internal variables
pascal@316 103 #DATE=$(date +%Y-%m-%d\ %H:%M:%S)
pascal@316 104
pascal@316 105 # Internationalization
pascal@316 106 . /usr/bin/gettext.sh
pascal@316 107 export TEXTDOMAIN='tazpkg-web'
pascal@316 108
pascal@316 109 SEARCH=""
pascal@316 110 VERBOSE=0
pascal@316 111 for i in $(echo $QUERY_STRING | sed 's/[?&]/ /g'); do
pascal@316 112 # SLITAZ_VERSION=cooking
pascal@316 113 case "$(echo $i | tr [A-Z] [a-z])" in
pascal@316 114 query=*|search=*) [ ${i#*=} == Search ] || SEARCH=${i#*=};;
pascal@316 115 object=*) OBJECT=${i#*=};;
pascal@316 116 verbose=*) VERBOSE=${i#*=};;
pascal@316 117 lang=*) LANG=${i#*=};;
pascal@316 118 file=*) SEARCH=${i#*=}; OBJECT=File;;
pascal@316 119 desc=*) SEARCH=${i#*=}; OBJECT=Desc;;
pascal@316 120 tags=*) SEARCH=${i#*=}; OBJECT=Tags;;
pascal@316 121 receipt=*) SEARCH=${i#*=}; OBJECT=Receipt;;
pascal@316 122 filelist=*) SEARCH=${i#*=}; OBJECT=File_list;;
pascal@316 123 package=*) SEARCH=${i#*=}; OBJECT=Package;;
pascal@316 124 depends=*) SEARCH=${i#*=}; OBJECT=Depends;;
pascal@316 125 builddepends=*) SEARCH=${i#*=}; OBJECT=BuildDepends;;
pascal@316 126 fileoverlap=*) SEARCH=${i#*=}; OBJECT=FileOverlap;;
pascal@316 127 category=*) SEARCH=${i#*=}; OBJECT=Category;;
pascal@316 128 maintainer=*) SEARCH=${i#*=}; OBJECT=Maintainer;;
pascal@316 129 version=[1-9]*) i=${i%%.*}; SLITAZ_VERSION=${i#*=}.0;;
pascal@316 130 version=s*|version=4*) SLITAZ_VERSION=stable;;
pascal@316 131 version=u*) SLITAZ_VERSION=undigest;;
pascal@316 132 version=t*) SLITAZ_VERSION=tiny;;
pascal@316 133 esac
pascal@316 134 done
pascal@316 135 [ -z "$SLITAZ_VERSION" ] && SLITAZ_VERSION=cooking
pascal@316 136 #[ -n "$SEARCH" ] && REQUEST_METHOD="POST"
pascal@316 137 #[ "$SEARCH" == "." ] && SEARCH=
pascal@316 138
pascal@316 139
pascal@316 140 # Content negotiation for Gettext
pascal@316 141 LANG=$(user_lang $(GET lang))
pascal@316 142 lang="$(ll_lang $LANG)"
pascal@316 143 export LANG LC_ALL=$LANG
pascal@316 144
pascal@316 145
pascal@316 146 case "$OBJECT" in
pascal@316 147 File) selected_file="selected";;
pascal@316 148 Desc) selected_desc="selected";;
pascal@316 149 Tags) selected_tags="selected";;
pascal@316 150 Receipt) selected_receipt="selected";;
pascal@316 151 File_list) selected_file_list="selected";;
pascal@316 152 Depends) selected_depends="selected";;
pascal@316 153 BuildDepends) selected_build_depends="selected";;
pascal@316 154 FileOverlap) selected_overlap="selected";;
pascal@316 155 esac
pascal@316 156
pascal@316 157 case "$SLITAZ_VERSION" in
pascal@316 158 tiny) selected_tiny="selected";;
pascal@316 159 1.0) selected_1="selected";;
pascal@316 160 2.0) selected_2="selected";;
pascal@316 161 3.0) selected_3="selected";;
pascal@316 162 stable) selected_stable="selected";;
pascal@316 163 undigest) selected_undigest="selected";;
pascal@316 164 esac
pascal@316 165
pascal@316 166 # unescape query
pascal@316 167 SEARCH="$(echo $SEARCH | sed 's/%2B/+/g; s/%3A/:/g; s|%2F|/|g')"
pascal@316 168
pascal@316 169 WOK=/home/slitaz/$SLITAZ_VERSION/wok
pascal@316 170 PACKAGES_REPOSITORY=/home/slitaz/$SLITAZ_VERSION/packages
pascal@316 171
pascal@316 172
pascal@316 173 # TODO: header function from httphelper
pascal@316 174 echo "Content-type: text/html"
pascal@316 175 echo
pascal@316 176
pascal@316 177 # Search form
pascal@316 178 # TODO: implement POST method
pascal@316 179 # ... method="post" enctype="multipart/form-data" ...
pascal@316 180 # TODO: add hint 'You are can search for depends loop, if textfield is empty'...
pascal@316 181 # add progress ticker while page is not complete
pascal@316 182 search_form()
pascal@316 183 {
pascal@316 184 cat << _EOT_
pascal@316 185
pascal@316 186 <form id="s_form" method="get" action="$SCRIPT_NAME">
pascal@316 187 <input type="hidden" name="lang" value="$lang" />
pascal@316 188 <select name="object">
pascal@316 189 <option value="Package">$(gettext "Package")</option>
pascal@316 190 <option $selected_desc value="Desc">$(gettext "Description")</option>
pascal@316 191 <option $selected_tags value="Tags">$(gettext "Tags")</option>
pascal@316 192 <option $selected_receipt value="Receipt">$(gettext "Receipt")</option>
pascal@316 193 <option $selected_depends value="Depends">$(gettext "Depends")</option>
pascal@316 194 <option $selected_build_depends value="BuildDepends">$(gettext "Build depends")</option>
pascal@316 195 <option $selected_file value="File">$(gettext "File")</option>
pascal@316 196 <option $selected_file_list value="File_list">$(gettext "File list")</option>
pascal@316 197 <option $selected_overlap value="FileOverlap">$(gettext "common files")</option>
pascal@316 198 </select>
pascal@316 199 <input type="text" name="query" id="query" size="20" value="$SEARCH" />
pascal@316 200 <select name="version">
pascal@316 201 <option value="cooking">$(gettext "cooking")</option>
pascal@316 202 <option $selected_stable value="stable">4.0</option>
pascal@316 203 <option $selected_3 value="3.0">3.0</option>
pascal@316 204 <option $selected_2 value="2.0">2.0</option>
pascal@316 205 <option $selected_1 value="1.0">1.0</option>
pascal@316 206 <option $selected_tiny value="tiny">$(gettext "tiny")</option>
pascal@316 207 <option $selected_undigest value="undigest">$(gettext "undigest")</option>
pascal@316 208 </select>
pascal@316 209 <input type="submit" name="submit" value="$(gettext 'Search')" />
pascal@316 210 </form>
pascal@316 211 _EOT_
pascal@316 212 }
pascal@316 213
pascal@316 214 # xHTML5 Header.
pascal@316 215 xhtml_header() {
pascal@316 216 . lib/header.sh
pascal@316 217 }
pascal@316 218
pascal@316 219 # xHTML Footer.
pascal@316 220 # TODO: caching the summary for 5 minutes
pascal@316 221 xhtml_footer() {
pascal@316 222 PKGS=$(ls $WOK/ | wc -l)
pascal@316 223 FILES=$(unlzma -c $PACKAGES_REPOSITORY/files.list.lzma | wc -l)
pascal@316 224 . lib/footer.sh
pascal@316 225 }
pascal@316 226
pascal@316 227 installed_size()
pascal@316 228 {
pascal@316 229 if [ $VERBOSE -gt 0 ]; then
pascal@316 230 inst=$(grep -A 3 "^$1\$" $PACKAGES_REPOSITORY/packages.txt | grep installed)
pascal@316 231 # size=$(echo $inst | cut -d'(' -f2 | cut -d' ' -f1)
pascal@316 232 echo $inst | sed 's/.*(\(.*\).*/(\1)/'
pascal@316 233 # echo $size
pascal@316 234 # | sed 's/.*(\(.*\) installed.*/(\1) /'
pascal@316 235 fi
pascal@316 236 }
pascal@316 237
pascal@316 238 package_entry()
pascal@316 239 {
pascal@316 240 if [ -s "$(dirname $0)/$SLITAZ_VERSION/$CATEGORY.html" ]; then
pascal@316 241 cat << _EOT_
pascal@316 242 <a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> $(installed_size $PACKAGE): $SHORT_DESC
pascal@316 243 _EOT_
pascal@316 244 else
pascal@316 245 PACKAGE_HREF="<u>$PACKAGE</u>"
pascal@316 246 PACKAGE_URL="http://mirror.slitaz.org/packages/$SLITAZ_VERSION/$PACKAGE-$VERSION$EXTRA_VERSION.tazpkg"
pascal@316 247 nslookup mirror.slitaz.org | grep -q 127.0.0.1 &&
pascal@316 248 [ -d /var/www/slitaz/mirror/packages/$SLITAZ_VERSION/$PACKAGE-$VERSION ] &&
pascal@316 249 PACKAGE_URL="http://mirror.slitaz.org/packages/$SLITAZ_VERSION/$PACKAGE-$VERSION" ||
pascal@316 250 PACKAGE_URL="http://mirror.slitaz.org/packages/$SLITAZ_VERSION/$(cd /var/www/slitaz/mirror/packages/$SLITAZ_VERSION ; ls $PACKAGE-$VERSION*.tazpkg)"
pascal@316 251 busybox wget -s $PACKAGE_URL 2> /dev/null &&
pascal@316 252 PACKAGE_HREF="<a href=\"$PACKAGE_URL\">$PACKAGE</a>"
pascal@316 253 cat << _EOT_
pascal@316 254 $PACKAGE_HREF $(installed_size $PACKAGE): $SHORT_DESC
pascal@316 255 _EOT_
pascal@316 256 fi
pascal@316 257 [ -n "$(GET debug)" ] && cat << _EOT_
pascal@316 258 <pre>
pascal@316 259 PACKAGE=$PACKAGE
pascal@316 260 VERSION=$VERSION
pascal@316 261 EXTRAVERSION=$EXTRAVERSION
pascal@316 262 SLITAZ_VERSION=$SLITAZ_VERSION
pascal@316 263 PACKAGE_URL=$PACKAGE_URL
pascal@316 264 $(cd /var/www/slitaz/mirror/packages/$SLITAZ_VERSION ; ls -l $PACKAGE*)
pascal@316 265 </pre>
pascal@316 266 _EOT_
pascal@316 267 }
pascal@316 268
pascal@316 269 # Show loop in depends/build_depends chains
pascal@316 270 show_loops()
pascal@316 271 {
pascal@316 272 awk '
pascal@316 273 function chkloop(pkg, i, n)
pascal@316 274 {
pascal@316 275 if (n < 8)
pascal@316 276 for (i = 1; i <= split(deps[pkg],curdep," "); i++) {
pascal@316 277 if (curdep[i] == base || chkloop(curdep[i], 0, n+1)) {
pascal@316 278 split(deps[pkg],curdep," ")
pascal@316 279 p = curdep[i] " " p
pascal@316 280 return 1
pascal@316 281 }
pascal@316 282 }
pascal@316 283 return 0
pascal@316 284 }
pascal@316 285 {
pascal@316 286 for (i = 2; i <= NF; i++)
pascal@316 287 deps[$1] = deps[$1] " " $i
pascal@316 288 }
pascal@316 289 END {
pascal@316 290 for (pkg in deps) {
pascal@316 291 base = pkg
pascal@316 292 p = ""
pascal@316 293 if (chkloop(pkg, 0, 0))
pascal@316 294 print pkg " " p
pascal@316 295 #print pkg " : " p "..."
pascal@316 296 }
pascal@316 297 }' | while read line; do
pascal@316 298 set -- $line
pascal@316 299 case " $last " in
pascal@316 300 *\ $1\ *) continue
pascal@316 301 esac
pascal@316 302 last="$line"
pascal@316 303 pkg=$1
pascal@316 304 shift
pascal@316 305 echo "<strong>$pkg </strong>: $@ ..."
pascal@316 306 done
pascal@316 307 }
pascal@316 308
pascal@316 309 # recursive dependencies scan
pascal@316 310 dep_scan()
pascal@316 311 {
pascal@316 312 for i in $1; do
pascal@316 313 case " $ALL_DEPS " in
pascal@316 314 *\ $i\ *) continue;;
pascal@316 315 esac
pascal@316 316 ALL_DEPS="$ALL_DEPS $i"
pascal@316 317 if [ -n "$2" ]; then
pascal@316 318 echo -n "$2"
pascal@316 319 (
pascal@316 320 . $WOK/$i/receipt
pascal@316 321 package_entry
pascal@316 322 )
pascal@316 323 fi
pascal@316 324 [ -f $WOK/$i/receipt ] || continue
pascal@316 325 DEPENDS=""
pascal@316 326 BUILD_DEPENDS=""
pascal@316 327 WANTED=""
pascal@316 328 . $WOK/$i/receipt
pascal@316 329 if [ -n "$3" ]; then
pascal@316 330 [ -n "$BUILD_DEPENDS$WANTED" ] &&
pascal@316 331 dep_scan "$WANTED $BUILD_DEPENDS" "$2 " $3
pascal@316 332 else
pascal@316 333 [ -n "$DEPENDS" ] && dep_scan "$DEPENDS" "$2 "
pascal@316 334 fi
pascal@316 335 done
pascal@316 336 }
pascal@316 337
pascal@316 338 # recursive reverse dependencies scan
pascal@316 339 rdep_scan()
pascal@316 340 {
pascal@316 341 SEARCH=$1
pascal@316 342 case "$SEARCH" in
pascal@316 343 glibc-base|gcc-lib-base)
pascal@316 344 $(gettext " glibc-base and gcc-lib-base are implicit dependencies,
pascal@316 345 <b>every</b> package is supposed to depend on them."); echo
pascal@316 346 return;;
pascal@316 347 esac
pascal@316 348 for i in $WOK/* ; do
pascal@316 349 DEPENDS=""
pascal@316 350 BUILD_DEPENDS=""
pascal@316 351 WANTED=""
pascal@316 352 . $i/receipt
pascal@316 353 if [ -n "$2" ]; then
pascal@316 354 echo "$(basename $i) $(echo $WANTED $BUILD_DEPENDS)"
pascal@316 355 else
pascal@316 356 echo "$(basename $i) $(echo $DEPENDS)"
pascal@316 357 fi
pascal@316 358 done | awk -v search=$SEARCH '
pascal@316 359 function show_deps(deps, all_deps, pkg, space)
pascal@316 360 {
pascal@316 361 if (all_deps[pkg] == 1) return
pascal@316 362 all_deps[pkg] = 1
pascal@316 363 if (space != "") printf "%s%s\n",space,pkg
pascal@316 364 for (i = 1; i <= split(deps[pkg], mydeps, " "); i++) {
pascal@316 365 show_deps(deps, all_deps, mydeps[i],"////" space)
pascal@316 366 }
pascal@316 367 }
pascal@316 368
pascal@316 369 {
pascal@316 370 all_deps[$1] = 0
pascal@316 371 for (i = 2; i <= NF; i++)
pascal@316 372 deps[$i] = deps[$i] " " $1
pascal@316 373 }
pascal@316 374
pascal@316 375 END {
pascal@316 376 show_deps(deps, all_deps, search, "")
pascal@316 377 }
pascal@316 378 ' | while read pkg; do
pascal@316 379 . $WOK/${pkg##*/}/receipt
pascal@316 380 cat << _EOT_
pascal@316 381 $(echo ${pkg%/*} | sed 's|/| |g') $(package_entry)
pascal@316 382 _EOT_
pascal@316 383 done
pascal@316 384 }
pascal@316 385
pascal@316 386 # Check package exists
pascal@316 387 package_exist()
pascal@316 388 {
pascal@316 389 [ -f $WOK/$1/receipt ] && return 0
pascal@316 390 cat << _EOT_
pascal@316 391
pascal@316 392 <h3>$(eval_gettext "No package \$SEARCH")</h3>
pascal@316 393 _EOT_
pascal@316 394 return 1
pascal@316 395 }
pascal@316 396
pascal@316 397 # Display < > &
pascal@316 398 htmlize()
pascal@316 399 {
pascal@316 400 sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g'
pascal@316 401 }
pascal@316 402
pascal@316 403 display_packages_and_files()
pascal@316 404 {
pascal@316 405 last=""
pascal@316 406 while read pkg file; do
pascal@316 407 pkg=${pkg%:}
pascal@316 408 if [ "$pkg" != "$last" ]; then
pascal@316 409 . $WOK/$pkg/receipt
pascal@316 410 package_entry
pascal@316 411 last=$pkg
pascal@316 412 fi
pascal@316 413 echo " $file"
pascal@316 414 done
pascal@316 415 }
pascal@316 416
pascal@316 417 build_cloud_cache()
pascal@316 418 {
pascal@316 419 grep -l ^$1= $WOK/*/receipt | while read file; do
pascal@316 420 eval $1=
pascal@316 421 . $file
pascal@316 422 eval echo \$$1
pascal@316 423 done | sed "$2" | awk '
pascal@316 424 {
pascal@316 425 for (i = 1; $i != ""; i++) {
pascal@316 426 count[$i]++
pascal@316 427 }
pascal@316 428 }
pascal@316 429 END {
pascal@316 430 min=10000
pascal@316 431 max=0
pascal@316 432 for (i in count) {
pascal@316 433 if (count[i] < min) min = count[i]
pascal@316 434 if (count[i] > max) max = count[i]
pascal@316 435 }
pascal@316 436 for (i in count)
pascal@316 437 print count[i] " " int((count[i] - min)*100/(max - min)) " " i
pascal@316 438 }' | sort -k 3
pascal@316 439 }
pascal@316 440
pascal@316 441 display_cloud()
pascal@316 442 {
pascal@316 443 echo "<p>"
pascal@316 444 while read cnt pct item ; do
pascal@316 445 cat <<EOT
pascal@316 446 <span style="color:#99f; font-size:9pt; padding-left:5px; padding-right:2px;">\
pascal@316 447 $cnt</span><a href="?$1=$item&amp;version=$SLITAZ_VERSION" style="\
pascal@316 448 font-size:$((8+($pct/10)))pt; font-weight:bold; \
pascal@316 449 color:black; text-decoration:none">$(echo $item | sed 's/-/\&minus;/g')</a>
pascal@316 450 EOT
pascal@316 451 done
pascal@316 452 echo "</p>"
pascal@316 453 }
pascal@316 454
pascal@316 455 xhtml_header
pascal@316 456
pascal@316 457 #
pascal@316 458 # Handle GET requests
pascal@316 459 #
pascal@316 460 case " $(GET) " in
pascal@316 461 *\ debug\ *|*\ debug*)
pascal@316 462 cat << EOT
pascal@316 463 <h2>Debug info</h2>
pascal@316 464 <pre>$(httpinfo)</pre>
pascal@316 465 <pre>LANG=$LANG;
pascal@316 466 OBJECT=$OBJECT;
pascal@316 467 SEARCH=$SEARCH;
pascal@316 468 SLITAZ_VERSION=$SLITAZ_VERSION;
pascal@316 469 WOK=$WOK;
pascal@316 470 </pre>
pascal@316 471 EOT
pascal@316 472 #$(xhtml_footer)
pascal@316 473 #EOT
pascal@316 474 # exit 0
pascal@316 475 ;;
pascal@316 476 esac
pascal@316 477
pascal@316 478 # Display search form and result if requested.
pascal@316 479 #xhtml_header
pascal@316 480 echo "<h2>$(gettext 'Search for packages')</h2>"
pascal@316 481 search_form
pascal@316 482
pascal@316 483 case "$OBJECT" in
pascal@316 484
pascal@316 485
pascal@316 486 ### Depends loops; [Reverse] Dependency tree [(SUGGESTED)]
pascal@316 487 Depends)
pascal@316 488 if [ -z "$SEARCH" ]; then
pascal@316 489 cat << _EOT_
pascal@316 490
pascal@316 491 <h3>$(gettext "Depends loops")</h3>
pascal@316 492 <pre>
pascal@316 493 _EOT_
pascal@316 494 for i in $WOK/*/receipt; do
pascal@316 495 PACKAGE=
pascal@316 496 DEPENDS=
pascal@316 497 . $i
pascal@316 498 echo "$PACKAGE $(echo $DEPENDS)"
pascal@316 499 done | show_loops
pascal@316 500 cat << _EOT_
pascal@316 501 </pre>
pascal@316 502 _EOT_
pascal@316 503 elif package_exist $SEARCH ; then
pascal@316 504 cat << _EOT_
pascal@316 505
pascal@316 506 <h3>$(eval_gettext "Dependency tree for: \$SEARCH")</h3>
pascal@316 507 <pre>
pascal@316 508 _EOT_
pascal@316 509 ALL_DEPS=""
pascal@316 510 dep_scan $SEARCH ""
pascal@316 511 SUGGESTED=""
pascal@316 512 . $WOK/$SEARCH/receipt
pascal@316 513 if [ -n "$SUGGESTED" ]; then
pascal@316 514 cat << _EOT_
pascal@316 515 </pre>
pascal@316 516
pascal@316 517 <h3>$(eval_gettext "Dependency tree for: \$SEARCH (SUGGESTED)")</h3>
pascal@316 518 <pre>
pascal@316 519 _EOT_
pascal@316 520 ALL_DEPS=""
pascal@316 521 dep_scan "$SUGGESTED" " "
pascal@316 522 fi
pascal@316 523 cat << _EOT_
pascal@316 524 </pre>
pascal@316 525
pascal@316 526 <h3>$(eval_gettext "Reverse dependency tree for: \$SEARCH")</h3>
pascal@316 527 <pre>
pascal@316 528 _EOT_
pascal@316 529 ALL_DEPS=""
pascal@316 530 rdep_scan $SEARCH
pascal@316 531 cat << _EOT_
pascal@316 532 </pre>
pascal@316 533 _EOT_
pascal@316 534 fi
pascal@316 535 ;;
pascal@316 536
pascal@316 537
pascal@316 538 ### Build depends loops; [Reverse] Build dependency tree
pascal@316 539 BuildDepends)
pascal@316 540 if [ -z "$SEARCH" ]; then
pascal@316 541 cat << _EOT_
pascal@316 542
pascal@316 543 <h3>$(gettext "Build depends loops")</h3>
pascal@316 544 <pre>
pascal@316 545 _EOT_
pascal@316 546 for i in $WOK/*/receipt; do
pascal@316 547 PACKAGE=
pascal@316 548 WANTED=
pascal@316 549 BUILD_DEPENDS=
pascal@316 550 . $i
pascal@316 551 echo "$PACKAGE $WANTED $(echo $BUILD_DEPENDS)"
pascal@316 552 done | show_loops
pascal@316 553 cat << _EOT_
pascal@316 554 </pre>
pascal@316 555 _EOT_
pascal@316 556 elif package_exist $SEARCH ; then
pascal@316 557 cat << _EOT_
pascal@316 558
pascal@316 559 <h3>$(eval_gettext "\$SEARCH needs these packages to be built")</h3>
pascal@316 560 <pre>
pascal@316 561 _EOT_
pascal@316 562 ALL_DEPS=""
pascal@316 563 dep_scan $SEARCH "" build
pascal@316 564 cat << _EOT_
pascal@316 565 </pre>
pascal@316 566
pascal@316 567 <h3>$(eval_gettext "Packages who need \$SEARCH to be built")</h3>
pascal@316 568 <pre>
pascal@316 569 _EOT_
pascal@316 570 ALL_DEPS=""
pascal@316 571 rdep_scan $SEARCH build
pascal@316 572 cat << _EOT_
pascal@316 573 </pre>
pascal@316 574 _EOT_
pascal@316 575 fi
pascal@316 576 ;;
pascal@316 577
pascal@316 578
pascal@316 579 ### Common files
pascal@316 580 FileOverlap)
pascal@316 581 if [ package_exist $SEARCH ]; then
pascal@316 582 cat << _EOT_
pascal@316 583
pascal@316 584 <h3>$(eval_gettext "These packages may overload files of \$SEARCH")</h3>
pascal@316 585 <pre>
pascal@316 586 _EOT_
pascal@316 587 ( unlzma -c $PACKAGES_REPOSITORY/files.list.lzma | grep ^$SEARCH: ;
pascal@316 588 unlzma -c $PACKAGES_REPOSITORY/files.list.lzma | grep -v ^$SEARCH: ) | awk '
pascal@316 589 BEGIN { pkg=""; last="x" }
pascal@316 590 {
pascal@316 591 if ($2 == "") next
pascal@316 592 if (index($2,last) == 1 && substr($2,1+length(last),1) == "/")
pascal@316 593 delete file[last]
pascal@316 594 last=$2
pascal@316 595 if (pkg == "") pkg=$1
pascal@316 596 if ($1 == pkg) file[$2]=$1
pascal@316 597 else if (file[$2] == pkg) print
pascal@316 598 }
pascal@316 599 ' | display_packages_and_files
pascal@316 600 cat << _EOT_
pascal@316 601 </pre>
pascal@316 602 _EOT_
pascal@316 603 fi
pascal@316 604 ;;
pascal@316 605
pascal@316 606
pascal@316 607 ### File search
pascal@316 608 File)
pascal@316 609 if [ -n "$SEARCH" ]; then
pascal@316 610 cat << _EOT_
pascal@316 611
pascal@316 612 <h3>$(eval_gettext "Result for: \$SEARCH")</h3>
pascal@316 613 <pre>
pascal@316 614 _EOT_
pascal@316 615 last=""
pascal@316 616 unlzma -c $PACKAGES_REPOSITORY/files.list.lzma \
pascal@316 617 | grep "$SEARCH" | while read pkg file; do
pascal@316 618 echo "$file" | grep -q "$SEARCH" || continue
pascal@316 619 if [ "$last" != "${pkg%:}" ]; then
pascal@316 620 last=${pkg%:}
pascal@316 621 (
pascal@316 622 . $WOK/$last/receipt
pascal@316 623 cat << _EOT_
pascal@316 624
pascal@316 625 <i>$(package_entry)</i>
pascal@316 626 _EOT_
pascal@316 627 )
pascal@316 628 fi
pascal@316 629 echo " $file"
pascal@316 630 done
pascal@316 631 cat << _EOT_
pascal@316 632 </pre>
pascal@316 633 _EOT_
pascal@316 634 fi
pascal@316 635 ;;
pascal@316 636
pascal@316 637
pascal@316 638 ### List of files
pascal@316 639 File_list)
pascal@316 640 if package_exist $SEARCH; then
pascal@316 641 cat << _EOT_
pascal@316 642
pascal@316 643 <h3>$(eval_gettext "Result for: \$SEARCH")</h3>
pascal@316 644 <pre>
pascal@316 645 _EOT_
pascal@316 646 last=""
pascal@316 647 unlzma -c $PACKAGES_REPOSITORY/files.list.lzma \
pascal@316 648 | grep ^$SEARCH: | sed 's/.*: / /' | sort
pascal@316 649 cat << _EOT_
pascal@316 650 </pre>
pascal@316 651 <pre>
pascal@316 652 _EOT_
pascal@316 653 filenb=$(unlzma -c $PACKAGES_REPOSITORY/files.list.lzma | grep ^$SEARCH: | wc -l)
pascal@316 654 eval_ngettext "\$filenb file" "\$filenb files" $filenb
pascal@316 655 cat << _EOT_
pascal@316 656 \
pascal@316 657 $(busybox sed -n "/^$SEARCH$/{nnnpq}" $PACKAGES_REPOSITORY/packages.txt)
pascal@316 658 </pre>
pascal@316 659 _EOT_
pascal@316 660 fi
pascal@316 661 ;;
pascal@316 662
pascal@316 663
pascal@316 664 ### Package description
pascal@316 665 Desc)
pascal@316 666 if [ -f $WOK/$SEARCH/description.txt ]; then
pascal@316 667 cat << _EOT_
pascal@316 668
pascal@316 669 <h3>$(eval_gettext "Result for: \$SEARCH")</h3>
pascal@316 670 <pre>
pascal@316 671 $(htmlize < $WOK/$SEARCH/description.txt)
pascal@316 672 </pre>
pascal@316 673 _EOT_
pascal@316 674 else
pascal@316 675 cat << _EOT_
pascal@316 676
pascal@316 677 <h3>$(eval_gettext "Result for: \$SEARCH")</h3>
pascal@316 678 <pre>
pascal@316 679 _EOT_
pascal@316 680 last=""
pascal@316 681 grep -i "$SEARCH" $PACKAGES_REPOSITORY/packages.desc | \
pascal@316 682 sort | while read pkg extras ; do
pascal@316 683 . $WOK/$pkg/receipt
pascal@316 684 package_entry
pascal@316 685 done
pascal@316 686 cat << _EOT_
pascal@316 687 </pre>
pascal@316 688 _EOT_
pascal@316 689 fi
pascal@316 690 ;;
pascal@316 691
pascal@316 692
pascal@316 693 ### Tags
pascal@316 694 Tags)
pascal@316 695 if [ -n "$SEARCH" ]; then
pascal@316 696 cat << _EOT_
pascal@316 697
pascal@316 698 <h3>$(eval_gettext "Result for: \$SEARCH")</h3>
pascal@316 699 <pre>
pascal@316 700 _EOT_
pascal@316 701 last=""
pascal@316 702 grep ^TAGS= $WOK/*/receipt | grep -i "$SEARCH" | \
pascal@316 703 sed "s|$WOK/\(.*\)/receipt:.*|\1|" | sort | while read pkg ; do
pascal@316 704 TAGS=
pascal@316 705 . $WOK/$pkg/receipt
pascal@316 706 echo " $TAGS " | grep -iq " $SEARCH " &&
pascal@316 707 package_entry
pascal@316 708 done
pascal@316 709 cat << _EOT_
pascal@316 710 </pre>
pascal@316 711 _EOT_
pascal@316 712 else
pascal@316 713 # Display clouds
pascal@316 714 while read var arg title filter; do
pascal@316 715 file=/tmp/$arg-$SLITAZ_VERSION
pascal@316 716 echo "<a name=\"$arg\"></a>"
pascal@316 717 echo "<h3>$title</h3>"
pascal@316 718 [ ! -e $file -o \
pascal@316 719 $PACKAGES_REPOSITORY/packages.txt -nt $file ] &&
pascal@316 720 build_cloud_cache $var "$filter" > $file.$$ &&
pascal@316 721 mv $file.$$ $file
pascal@316 722 display_cloud $arg < $file
pascal@316 723 done << EOT
pascal@316 724 TAGS tags Tag\ cloud
pascal@316 725 CATEGORY category Category\ cloud
pascal@316 726 MAINTAINER maintainer Maintainer\ cloud s/.*<//;s/.*\ //;s/>//
pascal@316 727 EOT
pascal@316 728 fi
pascal@316 729 ;;
pascal@316 730
pascal@316 731
pascal@316 732 ### Package receipt
pascal@316 733 # TODO: add style highlighting
pascal@316 734 Receipt)
pascal@316 735 package_exist $SEARCH && cat << _EOT_
pascal@316 736
pascal@316 737 <h3>$(eval_gettext "Result for: \$SEARCH")</h3>
pascal@316 738 <pre>
pascal@316 739 $(if [ -f $WOK/$SEARCH/taz/*/receipt ]; then
pascal@316 740 cat $WOK/$SEARCH/taz/*/receipt
pascal@316 741 else
pascal@316 742 cat $WOK/$SEARCH/receipt
pascal@316 743 fi | htmlize)
pascal@316 744 </pre>
pascal@316 745 _EOT_
pascal@316 746 ;;
pascal@316 747
pascal@316 748
pascal@316 749 ### Package
pascal@316 750 Package)
pascal@316 751 #WHY# if package_exist $SEARCH; then
pascal@316 752 cat << _EOT_
pascal@316 753
pascal@316 754 <h3>$(eval_gettext "Result for: \$SEARCH")</h3>
pascal@316 755 <pre>
pascal@316 756 _EOT_
pascal@316 757 for pkg in `ls $WOK/ | grep "$SEARCH"`
pascal@316 758 do
pascal@316 759 . $WOK/$pkg/receipt
pascal@316 760 DESC=" <a href=\"?object=Desc&query=$pkg&lang=$lang&version=$SLITAZ_VERSION&submit=go\">$(gettext description)</a>"
pascal@316 761 [ -f $WOK/$pkg/description.txt ] || DESC=""
pascal@316 762 cat << _EOT_
pascal@316 763 $(package_entry)$DESC
pascal@316 764 _EOT_
pascal@316 765 done
pascal@316 766 equiv=$PACKAGES_REPOSITORY/packages.equiv
pascal@316 767 vpkgs="$(cat $equiv | cut -d= -f1 | grep $SEARCH)"
pascal@316 768 for vpkg in $vpkgs ; do
pascal@316 769 cat << _EOT_
pascal@316 770 </pre>
pascal@316 771
pascal@316 772 <h3>$(eval_gettext "Result for: \$SEARCH (package providing \$vpkg)")</h3>
pascal@316 773 <pre>
pascal@316 774 _EOT_
pascal@316 775 for pkg in $(grep $vpkg= $equiv | sed "s/$vpkg=//"); do
pascal@316 776 . $WOK/${pkg#*:}/receipt
pascal@316 777 package_entry
pascal@316 778 done
pascal@316 779 done
pascal@316 780 cat << _EOT_
pascal@316 781 </pre>
pascal@316 782 _EOT_
pascal@316 783 #WHY# fi
pascal@316 784 ;;
pascal@316 785
pascal@316 786 ### Category
pascal@316 787 Category)
pascal@316 788 cat << _EOT_
pascal@316 789
pascal@316 790 <h3>$(eval_gettext "Result for: \$SEARCH")</h3>
pascal@316 791 <pre>
pascal@316 792 _EOT_
pascal@316 793 for pkg in `ls $WOK/`
pascal@316 794 do
pascal@316 795 CATEGORY=
pascal@316 796 . $WOK/$pkg/receipt
pascal@316 797 DESC=" <a href=\"?object=Desc&query=$pkg&lang=$lang&version=$SLITAZ_VERSION&submit=go\">$(gettext description)</a>"
pascal@316 798 [ -f $WOK/$pkg/description.txt ] || DESC=""
pascal@316 799 [ "$CATEGORY" == "$SEARCH" ] && cat << _EOT_
pascal@316 800 $(package_entry)$DESC
pascal@316 801 _EOT_
pascal@316 802 done
pascal@316 803 ;;
pascal@316 804
pascal@316 805 ### Maintainer
pascal@316 806 Maintainer)
pascal@316 807 cat << _EOT_
pascal@316 808
pascal@316 809 <h3>$(eval_gettext "Result for: \$SEARCH")</h3>
pascal@316 810 <pre>
pascal@316 811 _EOT_
pascal@316 812 for pkg in `ls $WOK/`
pascal@316 813 do
pascal@316 814 MAINTAINER=
pascal@316 815 . $WOK/$pkg/receipt
pascal@316 816 DESC=" <a href=\"?object=Desc&query=$pkg&lang=$lang&version=$SLITAZ_VERSION&submit=go\">$(gettext description)</a>"
pascal@316 817 [ -f $WOK/$pkg/description.txt ] || DESC=""
pascal@316 818 [ "$MAINTAINER" == "$SEARCH" ] && cat << _EOT_
pascal@316 819 $(package_entry)$DESC
pascal@316 820 _EOT_
pascal@316 821 done
pascal@316 822 ;;
pascal@316 823 esac
pascal@316 824
pascal@316 825 xhtml_footer
pascal@316 826
pascal@316 827 exit 0