slitaz-forge annotate pkgs/search.sh @ rev 336

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