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

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