slitaz-forge view pkgs/search.sh @ rev 697

mirror: remove Swiss academia mirror
See: http://forum.slitaz.org/topic/who-is-responsible-for-the-mirror-list-on-httpslitazorgenget
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon Oct 08 23:27:48 2018 +0300 (7 months ago)
parents acdd1536ea51
children 061a079077a3
line source
1 #!/bin/sh -v
2 #
3 # Tiny CGI search engine for SliTaz packages on http://pkgs.slitaz.org/
4 # Christophe Lincoln <pankso@slitaz.org>
5 # Aleksej Bobylev <al.bobylev@gmail.com>
6 #
8 date_start="$(date -u +%s)"
10 renice -n 19 $$
13 # Parse query string
15 . /etc/slitaz/slitaz.conf
16 . /usr/lib/slitaz/httphelper.sh
17 cache='/var/cache/pkgs'
18 mkdir -p "$cache"
20 _() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; echo; }
21 _n() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; }
22 _p() { local S="$1" P="$2" N="$3"; shift 3; printf "$(ngettext "$S" "$P" "$N")" "$@"; }
25 [ -n "$MIRROR_URL" ] || MIRROR_URL="http://mirror.slitaz.org"
28 # User preferred language
29 # parameter $1 have priority; without parameter $1 - browser language only
30 # if we don't support any of user languages (or only en), then return C locale
32 user_lang() {
33 unset LANG
34 IFS=','
35 for lang in $1 $HTTP_ACCEPT_LANGUAGE; do
36 lang=${lang%;*}; lang=${lang# }; lang=${lang%-*}; lang=${lang%_*}
37 case "$lang" in
38 de) LANG='de_DE';;
39 en) LANG='en_US';;
40 es) LANG='es_ES';;
41 fa) LANG='fa_IR';;
42 fr) LANG='fr_FR';;
43 #it) LANG='it_IT';; # We haven't Italian translations
44 pl) LANG='pl_PL';;
45 pt) LANG='pt_BR';;
46 ru) LANG='ru_RU';;
47 sv) LANG='sv_SE';;
48 uk) LANG='uk_UA';;
49 zh) LANG='zh_TW';;
50 esac
51 [ -n "$LANG" ] && break
52 done
53 unset IFS
54 echo "${LANG:-C}"
55 }
58 # Part of query to indicate current debug mode
60 ifdebug() {
61 ifdebug="$(GET debug)"
62 [ -n "$ifdebug" ] && ifdebug="$1$ifdebug"
63 echo "$ifdebug"
64 }
67 # GET or POST variable
69 GETPOST() {
70 echo "$(POST $1)$(GET $1)"
71 }
74 # Nice URL replacer - to copy URL from address bar
75 # TODO: deal with POST method of form submitting
77 nice_url() {
78 # if user submitted a form
79 if [ "$REQUEST_METHOD" == 'POST' -o -n "$(GET submit)" ]; then
80 OBJECT="$(GETPOST object)"
81 SEARCH="$(GETPOST query)"
82 case $OBJECT in
83 Package) NICE="package=$SEARCH";;
84 Desc) NICE="desc=$SEARCH";;
85 Tags) NICE="tags=$SEARCH";;
86 Arch) NICE="arch=$SEARCH";;
87 Bugs) NICE="bugs=$SEARCH";;
88 Receipt) NICE="receipt=$SEARCH";;
89 Depends) NICE="depends=$SEARCH";;
90 BuildDepends) NICE="builddepends=$SEARCH";;
91 File) NICE="file=$SEARCH";;
92 File_list) NICE="filelist=$SEARCH";;
93 FileOverlap) NICE="fileoverlap=$SEARCH";;
94 Category) NICE="category=$SEARCH";;
95 Maintainer) NICE="maintainer=$SEARCH";;
96 License) NICE="license=$SEARCH";;
97 esac
99 # version, if needed
100 version="$(GETPOST version)"
101 if [ -n "$version" -a "$version" != 'cooking' -a "$version" != 'c' ]; then
102 NICE="$NICE&version=${version:0:1}"
103 fi
105 # lang, if needed
106 query_lang="$(GETPOST lang)"
107 pref_lang="$(user_lang)"
108 browser_lang="${pref_lang%_*}"
109 if [ -n "$query_lang" ]; then
110 COOKIE="lang=$query_lang"
111 else
112 COOKIE=''
113 fi
115 # verbose, if needed
116 verboseq="$(GETPOST verbose)"
117 if [ -n "$verboseq" -a "$verboseq" != '0' ]; then
118 NICE="$NICE&verbose=1"
119 fi
121 # debug, if needed
122 debugq="$(GET debug)"
123 if [ -n "$debugq" -a "$debugq" == 'debug' ]; then
124 NICE="$NICE&debug"
125 fi
127 # redirect
128 if [ -z "$COOKIE" ]; then
129 header "HTTP/1.1 301 Moved Permanently" "Location: ?$NICE"
130 else
131 header "HTTP/1.1 301 Moved Permanently" "Set-Cookie: $COOKIE" "Location: ?$NICE"
132 fi
133 exit 0
134 fi
135 }
138 nice_url
143 # Internationalization
144 . /usr/bin/gettext.sh
145 export TEXTDOMAIN='tazpkg-web'
146 # Translate actions once
147 a_co="$(_ 'Cooker')"
148 a_dl="$(_ 'Download')"
149 a_rc="$(_ 'Receipt')"
154 # Cache icons to fast search
155 # Find the latest update in the "icons" folder
156 unset ICONS_CACHE_REBUILDED
157 iconslast="$cache/icons.$(date -u +%s -r /var/www/pkgs/icons/$(ls -t /var/www/pkgs/icons | head -n1))"
159 if [ ! -f "$iconslast" ]; then
160 find "$cache" -name 'icons.*' -delete
162 (
163 cat icons/packages.icons
164 awk '{printf "%s\tcli\n",$1}' icons/packages-cli.icons
165 awk '{printf "%s\tdoc\n",$1}' icons/packages-doc.icons
166 awk '{printf "%s\tfont\n",$1}' icons/packages-font.icons
167 awk '{printf "%s\ti18n\n",$1}' icons/packages-i18n.icons
168 awk '{printf "%s\tthm\n",$1}' icons/packages-thm.icons
169 awk '{printf "%s\tlib\n",$1}' icons/packages-lib.icons
170 awk '{printf "%s\tpy\n",$1}' icons/packages-py.icons
171 awk '{printf "%s\tperl\n",$1}' icons/packages-perl.icons
172 ls icons/*.png | awk -F/ '{sub(/\.png/,"",$2);printf "%s\t%s\n", $2, $2}'
173 ) | sort > "$iconslast"
174 ICONS_CACHE_REBUILDED='yes'
175 fi
179 unset SEARCH SLITAZ_VERSION
180 VERBOSE=0
181 s='selected'
182 for i in $(echo $QUERY_STRING | sed 's/[?&]/ /g'); do
183 case "$(echo $i | tr [A-Z] [a-z])" in
184 query=*|search=*) [ ${i#*=} == Search ] || SEARCH=${i#*=};;
185 object=*) OBJECT=${i#*=};;
186 verbose=*) VERBOSE=${i#*=};;
187 lang=*) LANG=${i#*=};;
188 file=*) SEARCH=${i#*=}; OBJECT='File'; sel_file=$s;;
189 desc=*) SEARCH=${i#*=}; OBJECT='Desc'; sel_desc=$s;;
190 tags=*) SEARCH=${i#*=}; OBJECT='Tags'; sel_tags=$s;;
191 arch=*) SEARCH=${i#*=}; OBJECT='Arch'; sel_arch=$s;;
192 bugs=*) SEARCH=${i#*=}; OBJECT='Bugs'; sel_bugs=$s;;
193 receipt=*) SEARCH=${i#*=}; OBJECT='Receipt'; sel_rcpt=$s;;
194 filelist=*) SEARCH=${i#*=}; OBJECT='File_list'; sel_flst=$s;;
195 package=*) SEARCH=${i#*=}; OBJECT='Package';;
196 depends=*) SEARCH=${i#*=}; OBJECT='Depends'; sel_deps=$s;;
197 builddepends=*) SEARCH=${i#*=}; OBJECT='BuildDepends'; sel_bdps=$s;;
198 fileoverlap=*) SEARCH=${i#*=}; OBJECT='FileOverlap'; sel_over=$s;;
199 category=*) SEARCH=${i#*=}; OBJECT='Category'; sel_catg=$s;;
200 maintainer=*) SEARCH=${i#*=}; OBJECT='Maintainer'; sel_mtnr=$s;;
201 license=*) SEARCH=${i#*=}; OBJECT='License'; sel_lcns=$s;;
202 version=1*) SLITAZ_VERSION='1.0'; sel_1=$s;;
203 version=2*) SLITAZ_VERSION='2.0'; sel_2=$s;;
204 version=3*) SLITAZ_VERSION='3.0'; sel_3=$s;;
205 version=s*|version=4*) SLITAZ_VERSION='stable'; sel_s=$s;;
206 version=u*) SLITAZ_VERSION='undigest'; sel_u=$s;;
207 version=b*) SLITAZ_VERSION='backports'; sel_b=$s;;
208 version=t*) SLITAZ_VERSION='tiny'; sel_t=$s;;
209 esac
210 done
211 [ -z "$SLITAZ_VERSION" ] && SLITAZ_VERSION='cooking'
212 addver=''; [ "$SLITAZ_VERSION" != 'cooking' ] && addver="&amp;version=$SLITAZ_VERSION"
213 SEARCH="${SEARCH//%20/ }"
215 #
216 # Content negotiation for Gettext
217 #
219 LANG=$(user_lang $(COOKIE lang))
220 lang="${LANG%_*}"
221 export LANG LC_ALL=$LANG
224 #
225 # Unescape query and set vars
226 #
228 SEARCH="$(echo $SEARCH | sed 's|%2B|+|g; s|%3A|:|g; s|%2F|/|g')"
230 SLITAZ_HOME="/home/slitaz"
231 if [ "$SLITAZ_VERSION" == 'cooking' ]; then
232 WOK="$SLITAZ_HOME/wok"
233 else
234 WOK="$SLITAZ_HOME/wok-$SLITAZ_VERSION"
235 fi
237 pkgsrepo="$SLITAZ_HOME/$SLITAZ_VERSION/packages"
238 repoid="$(cat "$pkgsrepo/ID")"
239 filelist="$pkgsrepo/files.list.lzma"
240 pkglist="$pkgsrepo/packages.txt"
241 equiv="$pkgsrepo/packages.equiv"
242 pinfo="$pkgsrepo/packages.info"
244 # Date of the last modification (both packages DB or icons DB)
245 if [ -f "$pkgsrepo/ID" ]; then
246 if [ "$iconslast" -nt "$pkgsrepo/ID" ]; then
247 lastmod="$(date -Rur "$iconslast")"
248 else
249 lastmod="$(date -Rur "$pkgsrepo/ID")"
250 fi
251 lastmod="${lastmod/UTC/GMT}"
252 fi
257 # Search form
258 # TODO: add hint 'You are can search for depends loop, if textfield is empty'...
259 # add progress ticker while page is not complete
261 search_form() {
262 [ -z "$SEARCH$(GET info)" ] && autofocus='autofocus'
264 cat <<EOT
266 <div class="form">
267 <form id="s_form" name="s_form" method="post" action="$(ifdebug '?')">
268 <span class="small">
269 <select name="object">
270 <option value="Package" class="pkg">$(_ 'Package name')</option>
271 <option $sel_desc value="Desc" class="description">$(_ 'Description')</option>
272 <option $sel_tags value="Tags" class="tag">$(_ 'Tag')</option>
273 <option $sel_arch value="Arch" class="arch">$(_ 'Architecture')</option>
274 <option $sel_bugs value="Bugs" class="bugs">$(_ 'Bugs')</option>
275 <option $sel_rcpt value="Receipt" class="receipt">$(_ 'Receipt')</option>
276 <option $sel_deps value="Depends" class="dep">$(_ 'Dependencies')</option>
277 <option $sel_bdps value="BuildDepends" class="dep">$(_ 'Build dependencies')</option>
278 <option $sel_file value="File" class="file">$(_ 'File')</option>
279 <option $sel_flst value="File_list" class="files-list">$(_ 'File list')</option>
280 <option $sel_over value="FileOverlap" class="common">$(_ 'Common files')</option>
281 <option $sel_catg value="Category" class="category">$(_ 'Category')</option>
282 <option $sel_mtnr value="Maintainer" class="avatar">$(_ 'Maintainer')</option>
283 <option $sel_lcns value="License" class="license">$(_ 'License')</option>
284 </select>
285 </span>
286 <span class="stretch">
287 <input $autofocus type="search" name="query" id="query" value="$SEARCH$(GET info)"
288 autocorrect="off" autocapitalize="off" autocomplete="on" spellcheck="false"
289 results="5" autosave="pkgsearch"/>
290 </span>
291 <span class="small">
292 <select name="version" title="$(_ 'SliTaz version')">
293 <option value="cooking">$( _ 'cooking')</option>
294 <option $sel_s value="stable">4.0</option>
295 <option $sel_3 value="3.0">3.0</option>
296 <option $sel_2 value="2.0">2.0</option>
297 <option $sel_1 value="1.0">1.0</option>
298 <option $sel_t value="tiny">$( _ 'tiny')</option>
299 <option $sel_u value="undigest">$( _ 'undigest')</option>
300 <option $sel_b value="backports">$( _ 'backports')</option>
301 </select>
302 </span>
303 <span class="small">
304 <button type="submit">$(_ 'Search')</button>
305 </span>
306 </form>
307 </div>
308 EOT
309 }
312 # xHTML5 Header.
314 xhtml_header() {
315 . lib/header.sh
316 }
319 # FIXME: unused function
321 cat_files_list() {
322 local tmp="/tmp/files.list.$(basename ${1%/packages})"
323 if [ ! -s "$tmp" -o "$1/files.list.lzma" -nt "$tmp" ]; then
324 unlzma < "$1/files.list.lzma" > "$tmp.$$" && mv "$tmp.$$" "$tmp"
325 fi
326 case "$2" in
327 lines)
328 if [ ! -s "$tmp.lines" -o "$tmp" -nt "$tmp.lines" ]; then
329 wc -l < "$tmp" > "$tmp.lines.$$" &&
330 mv "$tmp.lines.$$" "$tmp.lines"
331 fi
332 cat "$tmp.lines"
333 ;;
334 *)
335 cat "$tmp";;
336 esac
337 }
342 # xHTML Footer.
344 xhtml_footer() {
345 # Number of packages in the current repo
346 if [ ! -f "$cache/stat.p.$SLITAZ_VERSION.$repoid" ]; then
347 rm $cache/stat.p.$SLITAZ_VERSION.*
348 ls "$WOK/" | wc -l > "$cache/stat.p.$SLITAZ_VERSION.$repoid"
349 fi
351 # Number of files in the current repo
352 if [ ! -f "$cache/stat.f.$SLITAZ_VERSION.$repoid" ]; then
353 rm $cache/stat.f.$SLITAZ_VERSION.*
354 unlzma < "$filelist" | wc -l > "$cache/stat.f.$SLITAZ_VERSION.$repoid"
355 fi
357 PKGS=$( cat "$cache/stat.p.$SLITAZ_VERSION.$repoid")
358 FILES=$(cat "$cache/stat.f.$SLITAZ_VERSION.$repoid")
359 echo -en '\n<div class="summary">'
360 _p '%s package' '%s packages' "$PKGS" \
361 "$PKGS"
362 _p ' and %s file in %s database' ' and %s files in %s database' "$FILES" \
363 "$FILES" "$SLITAZ_VERSION"
365 # Date of the last update...
366 echo -n ' ('
367 if [ -e "$pkgsrepo/IDs" ]; then
368 # ...based on the value inside IDs
369 date +"%c" -d@$(cut -d' ' -f2 "$pkgsrepo/IDs") | tr -d '\n'
370 elif [ -e "$pkgsrepo/ID" ]; then
371 # ...based on the date of ID
372 date +"%c" -r "$pkgsrepo/ID" | tr -d '\n'
373 else
374 # ...based on the date of the newest file
375 date +"%c" -r "$pkgsrepo/$(ls -Lt "$pkgsrepo" | head -n1)" | tr -d '\n'
376 fi
377 echo -n ')'
379 cat <<EOT
380 </div>
381 </main>
383 EOT
385 local lang="${LANG%_*}"
386 if [ -e "lib/footer.$lang.sh" ]; then
387 echo '<footer>'
388 . lib/footer.$lang.sh
389 else
390 echo '<footer dir="ltr">'
391 . lib/footer.sh
392 fi
394 echo -n '<div class="summary">'
395 gen_time=$(( $(date -u +%s) - $date_start ))
396 _p 'Page generated in %s second.' 'Page generated in %s seconds.' "$gen_time" \
397 "$gen_time"
399 cat <<EOT
400 </div>
401 <img src="style/qr.png" alt="#" onmouseover="this.title = location.href"
402 onclick="this.src = QRCodePNG(location.href, this)"/>
403 </footer>
405 <script>
406 function QRCodePNG(str, obj) {
407 try {
408 obj.height = obj.width += 300;
409 return QRCode.generatePNG(str, {ecclevel: 'H'});
410 }
411 catch (any) {
412 var element = document.createElement("script");
413 element.src = "style/qrcode.min.js";
414 element.type ="text/javascript";
415 element.onload = function() {
416 obj.src = QRCode.generatePNG(str, {ecclevel: 'H'});
417 };
418 document.body.appendChild(element);
419 }
420 }
422 document.getElementById('ticker').style.visibility='hidden';
423 </script>
424 </body>
425 </html>
426 EOT
427 exit 0
428 }
433 # TODO: to remove
435 installed_size() {
436 if [ $VERBOSE -gt 0 ]; then
437 inst=$(grep -A 3 "^$1\$" $pkgslist | grep installed)
438 # size=$(echo $inst | cut -d'(' -f2 | cut -d' ' -f1)
439 echo $inst | sed 's/.*(\(.*\).*/(\1)/'
440 # echo $size
441 # | sed 's/.*(\(.*\) installed.*/(\1) /'
442 fi
443 }
448 # Package icon
450 package_icon() {
451 local icon='pkg'
453 case "$1" in
454 *-dev) icon='dev';;
455 linux-*|linux64-*) icon='linux';;
456 xorg-*) icon='xorg';;
457 *) icon=$(awk -F$'\t' -vp="$1" '$1==p{print $2;exit}' "$iconslast");;
458 esac
459 echo "icons$2/${icon:-pkg}.png"
460 }
465 package_entry() {
467 # Level for packages tree
468 if [ -n "$1" ]; then
469 echo "<tr class=\"l$1\">"
470 else
471 echo '<tr>'
472 fi
474 PACKAGE_URL="$MIRROR_URL/packages/$SLITAZ_VERSION/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg"
476 case "$SLITAZ_VERSION" in
477 cooking)
478 COOKER="<a href=\"http://cook.slitaz.org/cooker.cgi?pkg=$PACKAGE\" class=\"co\" title=\"$a_co\">$a_co</a>"
479 ;;
480 stable|undigest|backports)
481 COOKER="<a href=\"http://cook.slitaz.org/$SLITAZ_VERSION/cooker.cgi?pkg=$PACKAGE\" class=\"co\" title=\"$a_co\">$a_co</a>"
482 ;;
483 *)
484 COOKER=''
485 ;;
486 esac
488 cat <<EOT
489 <td class="first"><a href="?info=$PACKAGE$addver"><img src="$(package_icon $PACKAGE)" alt="$PACKAGE icon"/></a></td>
490 <td><b>$PACKAGE</b><br/>$SHORT_DESC</td>
491 <td class="last">
492 <a class="dl" href="$PACKAGE_URL" title="$a_dl">$a_dl</a>
493 <a class="rc" href="?receipt=$PACKAGE$addver" title="$a_rc">$a_rc</a>
494 $COOKER
495 </td>
496 </tr>
497 EOT
498 }
501 package_entries() {
502 # Input: $1 = [ desc | category | tags | name ]
503 # $2 = query
505 awk -F$'\t' -vtype="$1" -vquery="$2" -vmurl="$MIRROR_URL" -vver="$SLITAZ_VERSION" \
506 -vaco="$a_co" -vadl="$a_dl" -varc="$a_rc" -viconslast="$iconslast" \
507 -vnf="$(_ 'Nothing found')" -vaddver="$addver" '
508 BEGIN {
509 IGNORECASE = 1;
510 print "<table class=\"list\">";
511 notfound = "y";
512 }
514 function cooker() {
515 if (ver!="cooking" && ver!="stable" && ver!="undigest" && ver!="backports") return;
517 printf "\t<a href=\"http://cook.slitaz.org/";
518 if (ver=="stable" || ver=="undigest" || ver=="backports") printf "%s/", ver;
519 printf "cooker.cgi?pkg=%s\" class=\"co\" title=\"%s\">%s</a>", $1, aco, aco;
520 }
522 function icon(pkg) {
523 i="";
524 if (pkg ~ /-dev$/) { return "dev"; }
525 if (pkg ~ /^linux(64)?-/) { return "linux"; }
526 if (pkg ~ /^xorg-/) { return "xorg"; }
527 "awk -vp=\"" pkg "\" \"BEGIN{FS=\\\"\t\\\"}\\\$1==p{print \\\$2;exit}\" " iconslast | getline i;
528 if (i) { return i; }
529 return "pkg";
530 }
532 function tabline() {
533 markname = $1; if (type=="name") gsub(query, "<mark>&</mark>", markname);
534 markdesc = $4; if (type=="desc") gsub(query, "<mark>&</mark>", markdesc);
535 printf "<tr>\n\t<td class=\"first\">"
536 printf "<a href=\"?info=%s%s\">", gensub(/\+/, "%2B", "g", $1), addver;
537 printf "<img src=\"icons/%s.png\" alt=\"%s icon\"/></a></td>\n", icon($1), $1;
538 printf "\t<td><b>%s</b><br/>%s</td>\n", markname, markdesc;
539 printf "\t<td class=\"last\">\n";
540 printf "\t<a class=\"dl\" href=\"%s\" ", murl "/packages/" ver "/" $1 "-" $2 ".tazpkg";
541 printf "title=\"%s\">%s</a>\n", adl, adl;
542 printf "\t<a class=\"rc\" href=\"?receipt=%s%s\" ", $1, addver;
543 printf "title=\"%s\">%s</a>\n", arc, arc;
544 cooker();
545 printf "</td>\n</tr>\n"
546 }
549 {
550 if (type=="name" && match($1, query)) { tabline(); notfound = ""; }
551 if (type=="category" && $3==query) { tabline(); notfound = ""; }
552 if (type=="desc" && match($4, query)) { tabline(); notfound = ""; }
553 if (type=="tags" && match(" "$6" ", " "query" ")) { tabline(); notfound = ""; }
554 }
556 END {
557 if (notfound) printf "<tr><td class=\"first\"><img src=\"icons/notfound.png\" alt="Not found"/></td><td><b>%s</b></td></tr>", nf;
558 print "</table>";
559 }
560 ' "$pinfo";
561 }
566 package_entry_inline() {
567 # if [ -s "$(dirname $0)/$SLITAZ_VERSION/$CATEGORY.html" ]; then
568 # cat << _EOT_
569 #<a href="$SLITAZ_VERSION/$CATEGORY.html#$PACKAGE">$PACKAGE</a> $(installed_size $PACKAGE) : $SHORT_DESC
570 #_EOT_
571 # else
572 PACKAGE_URL="$MIRROR_URL/packages/$SLITAZ_VERSION/$PACKAGE-$VERSION$EXTRA_VERSION.tazpkg"
573 PACKAGE_HREF="<a href=\"$PACKAGE_URL\">$PACKAGE</a>"
574 case "$SLITAZ_VERSION" in
575 cooking)
576 COOKER="<a href=\"http://cook.slitaz.org/cooker.cgi?pkg=$PACKAGE\">$a_co</a>";;
577 stable|undigest|backports)
578 COOKER="<a href=\"http://cook.slitaz.org/$SLITAZ_VERSION/cooker.cgi?pkg=$PACKAGE\">$a_co</a>";;
579 *)
580 COOKER='';;
581 esac
582 cat <<EOT
583 $PACKAGE_HREF $(installed_size $PACKAGE) : $SHORT_DESC \
584 <a href="?receipt=$PACKAGE&amp;version=$SLITAZ_VERSION">$a_rc</a>&nbsp;$COOKER
585 EOT
586 # fi
587 }
590 # Show loop in depends/build_depends chains
592 show_loops() {
593 awk '
594 function chkloop(pkg, i, n)
595 {
596 if (n < 8)
597 for (i = 1; i <= split(deps[pkg],curdep," "); i++) {
598 if (curdep[i] == base || chkloop(curdep[i], 0, n+1)) {
599 split(deps[pkg],curdep," ")
600 p = curdep[i] " " p
601 return 1
602 }
603 }
604 return 0
605 }
606 {
607 for (i = 2; i <= NF; i++)
608 deps[$1] = deps[$1] " " $i
609 }
610 END {
611 for (pkg in deps) {
612 base = pkg
613 p = ""
614 if (chkloop(pkg, 0, 0))
615 print pkg " " p
616 #print pkg " : " p "..."
617 }
618 }' | while read line; do
619 set -- $line
620 case " $last " in
621 *\ $1\ *) continue
622 esac
623 last="$line"
624 pkg=$1
625 shift
626 echo "<strong>$pkg </strong>: $@ ..."
627 done
628 }
631 # recursive dependencies scan
633 dep_scan() {
634 for i in $1; do
635 case " $ALL_DEPS " in
636 *\ $i\ *)
637 continue;;
638 esac
639 ALL_DEPS="$ALL_DEPS $i"
640 if [ -n "$2" ]; then
641 echo -n "$2"
642 (
643 . $WOK/$i/receipt
644 package_entry_inline
645 )
646 fi
647 [ -f $WOK/$i/receipt ] || continue
648 unset BUILD_DEPENDS DEPENDS WANTED
649 . $WOK/$i/receipt
650 if [ -n "$3" ]; then
651 [ -n "$BUILD_DEPENDS$WANTED" ] &&
652 dep_scan "$WANTED $BUILD_DEPENDS" "$2 " $3
653 else
654 [ -n "$DEPENDS" ] && dep_scan "$DEPENDS" "$2 "
655 fi
656 done
657 }
660 # recursive reverse dependencies scan
662 rdep_scan() {
663 SEARCH=$1
664 case "$SEARCH" in
665 glibc-base|gcc-lib-base)
666 _ '"glibc-base" and "gcc-lib-base" are implicit dependencies, <b>every</b> package is supposed to depend on them.'
667 return;;
668 esac
669 for i in $WOK/* ; do
670 unset BUILD_DEPENDS DEPENDS WANTED
671 . $i/receipt
672 if [ -n "$2" ]; then
673 echo "$(basename $i) $(echo $WANTED $BUILD_DEPENDS)"
674 else
675 echo "$(basename $i) $(echo $DEPENDS)"
676 fi
677 done | awk -v search=$SEARCH '
678 function show_deps(deps, all_deps, pkg, space)
679 {
680 if (all_deps[pkg] == 1) return
681 all_deps[pkg] = 1
682 if (space != "") printf "%s%s\n",space,pkg
683 for (i = 1; i <= split(deps[pkg], mydeps, " "); i++) {
684 show_deps(deps, all_deps, mydeps[i],"////" space)
685 }
686 }
688 {
689 all_deps[$1] = 0
690 for (i = 2; i <= NF; i++)
691 deps[$i] = deps[$i] " " $1
692 }
694 END {
695 show_deps(deps, all_deps, search, "")
696 }
697 ' | while read pkg; do
698 . $WOK/${pkg##*/}/receipt
699 cat << _EOT_
700 $(echo ${pkg%/*} | sed 's|/| |g') $(package_entry_inline)
701 _EOT_
702 done
703 }
708 # Check non-empty argument
710 check_n() {
711 if [ -z "$1" ]; then
712 cat <<EOT
713 <div class="err">$(_ 'Please specify name of the package.')</div>
714 <p> <br/> </p>
715 EOT
716 return 1
717 fi
718 }
721 # Check package existence
723 package_exist() {
724 check_n "$1"
726 if [ ! -f "$WOK/$1/receipt" ]; then
727 cat <<EOT
728 <div class="err">$(_ 'Package "%s" was not found' "$1")</div>
729 <p> <br/> </p>
730 EOT
731 return 1
732 fi
734 return 0
735 }
740 # Display < > &
742 htmlize() {
743 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g'
744 }
749 display_packages_and_files() {
750 unset last
751 while read pkg file; do
752 pkg=${pkg%:}
753 if [ "$pkg" != "$last" ]; then
754 . "$WOK/$pkg/receipt"
756 package_entry_inline
757 last="$pkg"
758 fi
759 echo " $file"
760 done
761 }
764 # Syntax highlighting for receipt file - stolen from tazpanel:
765 # '/var/www/tazpanel/lib/libtazpanel' and developed
767 syntax_highlighter() {
768 . $1
769 sed -e "s|\&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s| | |g" \
770 -e "s|@|\&#64;|g; s|~|\&#126;|g" \
771 -e "#literals" \
772 -e "s|'\([^']*\)'|@l\0~|g" \
773 -e 's|"\([^"]*\)"|@l\0~|g' \
774 -e 's|"\([^"]*\)\\|@l\0~|g' \
775 -e 's|\([^"]*\)\"$|@l\0~|g' \
776 -e "#paths" \
777 -e 's|\([ =]\)\([a-zA-Z0-9/-]*/[\$a-zA-Z0-9/\.-]\+\)\([ )]\)|\1@p\2~\3|g' \
778 -e 's|\([ =]\)\([a-zA-Z0-9/-]*/[\$a-zA-Z0-9/\.-]\+$\)|\1@p\2~|g' \
779 -e 's|\(\$[a-zA-Z0-9_\.-]\+\)\(/[\$a-zA-Z0-9_/\.\*-]\+\)\([ )]*\)|@p\1\2~\3|g' \
780 -e "#functions" \
781 -e 's|^\([^()]*\)\(()\)|@f\0~|g' \
782 -e "#single line comments" \
783 -e 's|^\([ ]*\)#\([^#]*$\)|@c\0~|g' \
784 -e "#parameters" \
785 -e 's|\( \)\(-[a-z0-9]\+\)\( *\)|\1@r\2~\3|g' \
786 -e 's|\( \)\(--[a-z0-9\-]\+\)\([= ]\)|\1@r\2~\3|g' \
787 -e "#variables" \
788 -e "s|^\([^=@#' \-]*\)\(=\)|@v\1~\2|g" \
789 -e 's|\([ ^@-]*\)\([a-zA-Z0-9]\+\)\(=\)|\1@v\2~\3|g' \
790 -e "s#\(\$[a-zA-Z0-9_]\+\)#@v\0~#g" \
791 -e "#urls" \
792 -e s"#\"\(http:[^\"\$ ]*\)\"#\"<a @u href=\0>\1</a>\"#"g \
793 -e s"#\"\(ftp:[^\"\$ ]*\)\"#\"<a @u href=\0>\1</a>\"#"g \
794 -e "#commands" \
795 -e s"#^\( \+\)\([^'= @\-]\+\)#\1@m\2~#"g \
796 -e "#simple commands" \
797 -e s"#\([{}\]$\)#@s\0~#"g \
798 -e s"#\( \)\(\&amp;\&amp;\)\( *\)#\1@s\2~\3#"g \
799 -e s"#\(|\)#@s\0~#"g \
800 -e s"#\(\&lt;\)#@s\0~#"g \
801 -e s"#\(\&gt;\&amp;\)#@s\0~#"g \
802 -e s"#\(\&gt;\)#@s\0~#"g \
803 -e s"#\(\[\)#@s\0~#"g \
804 -e s"#\(\]\)#@s\0~#"g \
805 \
806 -e "s|´|'|g; s|›|</span>|g" \
807 -e "s|@c|<span class='r-comment'>|g" \
808 -e "s|@l|<span class='r-literal'>|g" \
809 -e "s|@v|<span class='r-var'>|g" \
810 -e "s|@f|<span class='r-func'>|g" \
811 -e "s|@u|class='r-url' target='_blank'|g" \
812 -e "s|@m|<span class='r-com'>|g" \
813 -e "s|@s|<span class='r-scom'>|g" \
814 -e "s|@p|<span class='r-path'>|g" \
815 -e "s|@r|<span class='r-param'>|g" \
816 -e "s|~|</span>|g" < "$1" | add_url_links
817 }
820 # Create some clickable links
822 add_url_links() {
823 local tarball_url
824 sedit=''
825 case "$SLITAZ_VERSION" in
826 cooking)
827 [ -n "$VERSION" ] &&
828 sedit="$sedit -e 's|\\(>VERSION<[^\"]*\"\\)\\([^\"]*\\)|\\1<a class='r-url' target='_blank' href=\"http://cook.slitaz.org/cooker.cgi?pkg=$PACKAGE\">\\2</a>|}'"
829 ;;
830 stable|undigest|backports)
831 [ -n "$VERSION" ] &&
832 sedit="$sedit -e 's|\\(>VERSION<[^\"]*\"\\)\\([^\"]*\\)|\\1<a class='r-url' target='_blank' href=\"http://cook.slitaz.org/$SLITAZ_VERSION/cooker.cgi?pkg=$PACKAGE\">\\2</a>|}'"
833 ;;
834 esac
835 #[ -n "$WEB_SITE" ] && sedit="$sedit -e '/WEB_SITE/{s|\\($WEB_SITE\\)|<a class='r-url' target='_blank' href=\"\\1\">\\1</a>|}'"
837 [ -n "$WGET_URL" ] &&
838 sedit="$sedit -e 's|\\(>WGET_URL<[^\"]*\"\\)\\([^\"]*\\)|\\1<a class='r-url' target='_blank' href=\"${WGET_URL//|/\\|}\">\\2</a>|}'"
840 [ -n "$MAINTAINER" ] &&
841 sedit="$sedit -e '/MAINTAINER/{s|\\(${MAINTAINER/@/&#64;}\\)|<a class='r-url' target='_blank' href=\"?maintainer=\\1\\&amp;version=$SLITAZ_VERSION\">\\1</a>|}'"
843 [ -n "$CATEGORY" ] &&
844 sedit="$sedit -e '/CATEGORY/{s|\\($CATEGORY\\)|<a class='r-url' target='_blank' href=\"?category=\\1\\&amp;version=$SLITAZ_VERSION\">\\1</a>|}'"
846 [ -f "$WOK/$PACKAGE/description.txt" ] &&
847 sedit="$sedit -e '/SHORT_DESC/{s|\\($SHORT_DESC\\)|<a class='r-url' target='_blank' href=\"?desc=$PACKAGE\\&amp;version=$SLITAZ_VERSION\">\\1</a>|}'"
849 tarball_url=sources/packages-$SLITAZ_VERSION/${TARBALL:0:1}/$TARBALL
850 [ -f /var/www/slitaz/mirror/$tarball_url ] || case "$tarball_url" in
851 *.gz) tarball_url=${tarball_url%gz}lzma ;;
852 *.tgz) tarball_url=${tarball_url%tgz}tar.lzma ;;
853 *.bz2) tarball_url=${tarball_url%bz2}lzma ;;
854 esac
855 [ -f /var/www/slitaz/mirror/$tarball_url ] && sedit="$sedit -e 's|\\(>TARBALL<[^\"]*\"\\)\\([^\"]*\\)|\\1<a class='r-url' target='_blank' href=\"http://mirror.slitaz.org/$tarball_url\">\\2</a>|'"
857 if [ -n "$EXTRA_SOURCE_FILES" ]; then
858 for i in $(echo $EXTRA_SOURCE_FILES) ; do
859 p="sources/packages-$SLITAZ_VERSION/${i:0:1}/$i"
860 [ -f "/var/www/slitaz/mirror/$p" ] || continue
861 #FIXME
862 sedit="$sedit -e 's|\\([\" >]\\)$i\\([\" <\\]\\)|\\1<a class='r-url' target='_blank' href=\"http://mirror.slitaz.org/$p\">$i</a>\\2|'"
863 sedit="$sedit -e 's|^$i\\([\" <\\]\\)|<a class='r-url' target='_blank' href=\"http://mirror.slitaz.org/$p\">$i</a>\\1|'"
864 done
865 fi
866 if [ -n "$DEPENDS$BUILD_DEPENDS$SUGGESTED$PROVIDE$WANTED" ]; then
867 for i in $(echo $DEPENDS $BUILD_DEPENDS $SUGGESTED $PROVIDE $WANTED) ; do
868 sedit="$sedit -e 's|\\([\" >]\\)$i\\([\" <\\]\\)|\\1<a class='r-url' target='_blank' href=\\\"?receipt=$i\\&amp;version=$SLITAZ_VERSION\\\">$i</a>\\2|'"
869 sedit="$sedit -e 's|^$i\\([\" <\\]\\)|<a class='r-url' target='_blank' href=\\\"?receipt=$i\\&amp;version=$SLITAZ_VERSION\\\">$i</a>\\1|'"
870 done
871 fi
872 if [ -n "$LICENSE" ]; then
873 for i in $LICENSE ; do
874 sedit="$sedit -e '/LICENSE/{s|\\($i\\)|<a class='r-url' target='_blank' href=\"?license=\\1\\&amp;version=$SLITAZ_VERSION\">\\1</a>|}'"
875 done
876 fi
877 if [ -n "$HOST_ARCH" ]; then
878 for i in $HOST_ARCH ; do
879 sedit="$sedit -e '/HOST_ARCH/{s|\\([\" ]\\)$i\\([\" ]\\)|\\1<a class='r-url' target='_blank' href=\\\"?arch=$i\\&amp;version=$SLITAZ_VERSION\\\">$i</a>\\2|}'"
880 done
881 fi
882 if [ -n "$TAGS" ]; then
883 for i in $TAGS ; do
884 sedit="$sedit -e '/TAGS/{s|\\([\" ]\\)$i\\([\" ]\\)|\\1<a class='r-url' target='_blank' href=\\\"?tags=$i\\&amp;version=$SLITAZ_VERSION\\\">$i</a>\\2|}'"
885 done
886 fi
887 eval sed $sedit \
888 -e "'s|genpkg_rules|<a class='r-url' target='_blank' href=\"?filelist=$PACKAGE\\&amp;version=$SLITAZ_VERSION\">&</a>|'"
889 }
892 display_cloud() {
893 arg=$1
894 [ -d /tmp/cloud ] || mkdir -p /tmp/cloud
895 [ /tmp/cloud/$arg-$SLITAZ_VERSION -nt $pkglist ] &&
896 cat /tmp/cloud/$arg-$SLITAZ_VERSION ||
897 find $WOK/ -maxdepth 2 -name receipt -exec sed \
898 "/^$1=/!d;s/.*['\"<]\\(..*\\)[>\"'].*/\\1/" {} \; | awk '
899 {
900 for (i = 1; $i != ""; i++)
901 count[$i]++
902 }
903 END {
904 min=10000
905 max=0
906 cnt=0
907 for (i in count) {
908 if (count[i] < min) min = count[i]
909 if (count[i] > max) max = count[i]
910 cnt++
911 }
912 for (i in count)
913 print count[i] " " min " " max " " i
914 print cnt
915 }' | sed 's/[<>]//g' | sort -k 4 | {
916 while read cnt min max tag ; do
917 if [ -z "$min" ]; then
918 count="$cnt"
919 continue
920 fi
921 pct=$(((($cnt-$min)*100)/($max-$min)))
922 pct=$(((10000 - ((100 - $pct)**2))/100))
923 pct=$(((10000 - ((100 - $pct)**2))/100))
924 cat <<EOT
925 <span class="tagn">$cnt</span><a href="?$arg=$tag$addver" class="tag$(($pct/10))">$tag</a>
926 EOT
927 done
928 echo -n '<hr/><p class="lang">'
929 case $arg in
930 HOST_ARCH) _p '%s architecture' '%s architectures' "$count" "$count";;
931 MAINTAINER) _p '%s maintainer' '%s maintainers' "$count" "$count";;
932 LICENSE) _p '%s license' '%s licenses' "$count" "$count";;
933 CATEGORY) _p '%s category' '%s categories' "$count" "$count";;
934 TAGS) _p '%s tag' '%s tags' "$count" "$count";;
935 esac
936 echo '</p>'
937 } | tee /tmp/cloud/$arg-$SLITAZ_VERSION
938 }
941 #
942 # page begins
943 #
945 if [ -n "$HTTP_IF_MODIFIED_SINCE" -a "$HTTP_IF_MODIFIED_SINCE" == "$lastmod" ]; then
946 # When user agent asks if content modified since last seen and it is not modified
947 header "HTTP/1.1 304 Not Modified"
948 exit 0
949 fi
950 if [ -z "$lastmod" ]; then
951 # We don't know last modification date
952 header "HTTP/1.1 200 OK" "Content-type: text/html; charset=UTF-8"
953 else
954 header "HTTP/1.1 200 OK" "Content-type: text/html; charset=UTF-8" "Last-Modified: $lastmod"
955 fi
956 xhtml_header
959 #
960 # Language selector
961 #
963 cat <<EOT
964 <!-- Languages -->
965 <div class="lang"><a class="locale2" href="http://www.slitaz.org/i18n.php"
966 target="_blank"></a><select form="s_form" name="lang" onchange="this.form.submit();">
967 EOT
969 for i in en de es fa fr ja pl pt ru sv uk zh; do
970 case $i in
971 en) c='us'; l='English';;
972 de) c='de'; l='Deutsch';;
973 es) c='es'; l='Español';;
974 fa) c='ir'; l='فارسی';;
975 fr) c='fr'; l='Français';;
976 it) c='it'; l='Italiano';;
977 ja) c='jp'; l='日本語';;
978 pl) c='pl'; l='Polski';;
979 pt) c='br'; l='Português';;
980 ru) c='ru'; l='Русский';;
981 sv) c='se'; l='Svenska';;
982 uk) c='ua'; l='Українська';;
983 zh) c='tw'; l='中文';;
984 esac
986 echo -n "<option class=\"$c\" value=\"$i\""
987 [ "$i" == "${LANG%_*}" ] && echo -n " selected"
988 echo ">$l</option>"
989 done
990 echo '</select></div>'
992 cat <<EOT
993 <!-- Content -->
994 <main>
995 EOT
998 #
999 # Handle GET requests
1002 case " $(GET) " in
1003 *\ debug\ *|*\ debug*)
1004 cat <<EOT
1005 <h2>Debug info</h2>
1007 <pre>$(httpinfo)</pre>
1009 <pre>$(env)</pre>
1011 <pre>LANG="$LANG"
1012 OBJECT="$OBJECT"
1013 SEARCH="$SEARCH"
1014 SLITAZ_VERSION="$SLITAZ_VERSION"
1015 WOK="$WOK"
1016 GET="$(GET)"
1018 HTTP_IF_MODIFIED_SINCE="$HTTP_IF_MODIFIED_SINCE"
1019 lastmod ="$lastmod"
1020 </pre>
1021 EOT
1022 ;;
1023 esac
1028 # Display search form and result if requested.
1030 cat <<EOT
1031 <div id="ticker"><img src="loader.gif" alt="."/></div>
1032 EOT
1033 search_form
1038 # Show links for "info" page
1040 show_info_links() {
1041 if [ -n "$1" ]; then
1042 echo -n "<tr><td class=\"first\"><b>$2</b></td><td class=\"spkg\">"
1044 echo $1 | tr ' ' $'\n' | awk -vt="$3" -vv="$addver" -viconslast="$iconslast" '
1045 function icon(pkg) {
1046 i="";
1047 if (pkg ~ /-dev$/) { return "dev"; }
1048 if (pkg ~ /^linux(64)?-/) { return "linux"; }
1049 if (pkg ~ /^xorg-/) { return "xorg"; }
1050 "awk -vp=\"" pkg "\" \"BEGIN{FS=\\\"\t\\\"}\\\$1==p{print \\\$2;exit}\" " iconslast | getline i;
1051 if (i) { return i; }
1052 return "pkg";
1054 function link(pkg) {
1055 printf "<a href=\"?%s=%s%s\">", t, gensub(/\+/, "%2B", "g", pkg), v;
1056 if (t!="tags") printf "<img src=\"icons-s/%s.png\" alt=\"%s icon\"/>", icon(pkg), pkg;
1057 printf "%s</a>", pkg;
1060 split($1, line, ":");
1061 link(line[1]);
1062 if (line[2]) { printf ":"; link(line[2]); }
1063 printf "  ";
1064 }'
1065 echo "</td></tr>"
1066 fi
1069 # Source for categories names to translate
1071 noop() {
1072 _ 'base-system'; _ 'x-window'; _ 'utilities'; _ 'network'; _ 'graphics';
1073 _ 'multimedia'; _ 'office'; _ 'development'; _ 'system-tools'; _ 'security';
1074 _ 'games'; _ 'misc'; _ 'meta'; _ 'non-free'
1077 case " $(GET) " in
1078 *\ info\ *)
1079 package_exist $(GET info) || xhtml_footer
1080 . "$WOK/$(GET info)/receipt"
1082 cat <<EOT
1083 <table class="info">
1084 <tr>
1085 <td class="first"><b>$(gettext 'Name')</b></td>
1086 <td>$PACKAGE
1087 <div class="appImg" style="background: url($(package_icon $PACKAGE 2))"></div>
1088 </td>
1089 </tr>
1090 EOT
1091 [ -n "$VERSION" ] && cat <<EOT
1092 <tr>
1093 <td class="first"><b>$(gettext 'Version')</b></td>
1094 <td>$VERSION</td>
1095 </tr>
1096 EOT
1097 cat <<EOT
1098 <tr>
1099 <td class="first"><b>$(gettext 'Category')</b></td>
1100 <td><a href="?category=$CATEGORY$addver">$(gettext "$CATEGORY")</a></td>
1101 </tr>
1103 <tr>
1104 <td class="first"><b>$(gettext 'Description')</b></td>
1105 <td>$(echo "$SHORT_DESC" | htmlize)</td>
1106 </tr>
1107 EOT
1108 if [ -n "$MAINTAINER" ]; then
1109 # For form "John Doe <jdoe@example.org>"
1110 M="${MAINTAINER#*<}"; M="${M%>}" # extract address "jdoe@example.org"
1111 MAINTAINER=$(echo $MAINTAINER | htmlize) # escape "<" and ">" for use in HTML
1112 cat <<EOT
1113 <tr>
1114 <td class="first"><b>$(gettext 'Maintainer')</b></td>
1115 <td><a href="?maintainer=$M$addver">${MAINTAINER/@/&#8203;@&#8203;}</a></td>
1116 </tr>
1117 EOT
1118 fi
1119 [ -n "$LICENSE" ] && cat <<EOT
1120 <tr>
1121 <td class="first"><b>$(gettext 'License')</b></td>
1122 <td>$(for license in $LICENSE; do
1123 echo "<a href=\"?license=$license$addver\">$license</a> "
1124 done)</td>
1125 </tr>
1126 EOT
1127 web_site="${WEB_SITE#http://}"
1128 cat <<EOT
1129 <tr>
1130 <td class="first"><b>$(gettext 'Website')</b></td>
1131 <td><a href="$WEB_SITE" target="_blank">${web_site%/}</a></td>
1132 </tr>
1133 EOT
1134 show_info_links "$TAGS" "$(_ 'Tags')" 'tags'
1136 if [ -n "$PACKED_SIZE" ]; then
1137 cat <<EOT
1138 <tr>
1139 <td class="first"><b>$(gettext 'Sizes')</b></td>
1140 <td>${PACKED_SIZE/.0/} / ${UNPACKED_SIZE/.0/}</td>
1141 </tr>
1142 EOT
1143 elif [ -f "$pinfo" ]; then
1144 cat <<EOT
1145 <tr>
1146 <td class="first"><b>$(gettext 'Sizes')</b></td>
1147 <td>$(awk -F$'\t' -vp=$PACKAGE '$1==p{print $7}' "$pinfo" | sed 's| | / |')</td>
1148 </tr>
1149 EOT
1150 fi
1152 show_info_links "$DEPENDS" "$(gettext 'Depends on')" 'info'
1154 show_info_links "$PROVIDE" "$(gettext 'Provides')" 'info'
1156 show_info_links "$SUGGESTED" "$(gettext 'Suggested')" 'info'
1157 cat <<EOT
1158 </table>
1160 EOT
1162 # Actions / screenshot
1163 pkg=${PACKAGE//+/%2B}
1164 pkg_url="$MIRROR_URL/packages/$SLITAZ_VERSION/$pkg-$VERSION$EXTRA_VERSION.tazpkg"
1165 case "$SLITAZ_VERSION" in
1166 cooking)
1167 COOKER="<a class=\"cooker\" href=\"http://cook.slitaz.org/cooker.cgi?pkg=$PACKAGE\">$(gettext 'Show cooking log')</a>";;
1168 stable|undigest|backports)
1169 COOKER="<a class=\"cooker\" href=\"http://cook.slitaz.org/$SLITAZ_VERSION/cooker.cgi?pkg=$PACKAGE\">$(gettext 'Show cooking log')</a>";;
1170 *)
1171 COOKER="<span class=\"cooker\">$(gettext 'N/A')</span>";;
1172 esac
1173 cat <<EOT
1174 <div class="sssb desc center">
1175 <a href="http://screenshots.debian.net/package/$pkg" target="_blank"><img
1176 src="http://screenshots.debian.net/thumbnail/$pkg" alt="$PACKAGE screenshot"/></a>
1177 </div>
1179 <table class="info">
1180 <tr><td><span class="download"></span>
1181 <a href="$pkg_url">$(gettext 'Download package')</a>
1182 </td>
1183 <td rowspan="5" class="last hssc">
1184 <a href="http://screenshots.debian.net/package/$pkg" target="_blank"><img
1185 src="http://screenshots.debian.net/thumbnail/$pkg" alt="$PACKAGE screenshot"/></a>
1186 </td>
1187 </tr>
1188 <tr><td><a class="receipt" href="?receipt=$pkg$addver">$(gettext 'Show receipt')</a></td></tr>
1189 <tr><td><a class="files-list" href="?filelist=$pkg$addver">$(gettext 'Show files list')</a></td></tr>
1190 <tr><td>$COOKER</td></tr>
1191 <tr id="tazpanelButtons" class="hidden">
1192 <td>
1193 <span id="tazpaneli" class="hidden">
1194 <a class="pkgi" href="http://127.0.0.1:82/user/pkgs.cgi?do=Install&amp;pkg=$pkg" target="_blank">$(gettext 'Install package')</a>
1195 </span>
1196 <span id="tazpanelr" class="hidden">
1197 <a class="pkgr" href="http://127.0.0.1:82/user/pkgs.cgi?do=Remove&amp;pkg=$pkg" target="_blank">$(gettext 'Remove package')</a>
1198 </span>
1199 </td>
1200 </tr>
1201 </table>
1203 <script>
1204 function ajaxTazPanel(pkg) {
1205 var req = new XMLHttpRequest();
1206 req.onreadystatechange = function() {
1207 if (req.readyState == XMLHttpRequest.DONE) {
1208 if (req.status == 200) {
1209 if (req.responseText == 'i') {
1210 // Package installed, allow to remove
1211 document.getElementById('tazpanelr').className='';
1212 } else {
1213 // Package not installed, allow to install
1214 document.getElementById('tazpaneli').className='';
1216 document.getElementById('tazpanelButtons').className='';
1220 req.open('GET', 'http://tazpanel:82/pkgs.cgi?status&web=y&pkg=' + pkg, true);
1221 req.send();
1223 ajaxTazPanel('$pkg');
1224 </script>
1225 EOT
1227 # Description
1228 if [ -f "$WOK/$PACKAGE/description.txt" ]; then
1229 cat <<EOT
1230 <h3>$(gettext 'Description')</h3>
1231 <table><tr><td>$(./sundown < "$WOK/$PACKAGE/description.txt")</td></tr></table>
1232 EOT
1233 fi
1235 # Config files
1236 if [ -n "$CONFIG_FILES" ]; then
1237 cat <<EOT
1238 <div class="conf">
1239 <h3>$(gettext 'Configuration files')</h3>
1240 <table><tr><td><ul>
1241 EOT
1242 for file in $CONFIG_FILES; do
1243 cat <<EOT
1244 <li><a href="ftp://cook.slitaz.org/$PACKAGE/taz/$PACKAGE-$VERSION$EXTRAVERSION/fs$file" target="_blank">$file</a></li>
1245 EOT
1246 done
1247 cat <<EOT
1248 </ul></td></tr></table>
1249 </div>
1250 EOT
1251 fi
1253 ;;
1254 esac
1259 case "$OBJECT" in
1262 ### Depends loops; [Reverse] Dependency tree [(SUGGESTED)]
1263 Depends)
1264 if [ -z "$SEARCH" ]; then
1265 cat <<EOT
1266 <h3>$(_ 'Loop dependency')</h3>
1267 <pre class="hard">
1268 EOT
1269 for i in $WOK/*/receipt; do
1270 PACKAGE=
1271 DEPENDS=
1272 . $i
1273 echo "$PACKAGE $(echo $DEPENDS)"
1274 done | show_loops
1275 echo '</pre>'
1277 elif package_exist $SEARCH ; then
1278 cat <<EOT
1279 <h3>$(_ 'Dependency tree for package "%s"' "$SEARCH")</h3>
1280 <pre class="hard">
1281 EOT
1282 unset ALL_DEPS
1283 dep_scan $SEARCH ''
1284 unset SUGGESTED
1285 . $WOK/$SEARCH/receipt
1286 echo '</pre>'
1288 if [ -n "$SUGGESTED" ]; then
1289 cat <<EOT
1290 <h3>$(_ 'Dependency tree for packages suggested by package "%s"' "$SEARCH")</h3>
1291 <pre class="hard">
1292 EOT
1293 unset ALL_DEPS
1294 dep_scan "$SUGGESTED" ' '
1295 echo '</pre>'
1296 fi
1298 cat <<EOT
1299 <h3>$(_ 'Reverse dependency tree for package "%s"' "$SEARCH")</h3>
1300 <pre class="hard">
1301 EOT
1302 unset ALL_DEPS
1303 rdep_scan $SEARCH
1304 echo '</pre>'
1305 fi
1306 ;;
1311 ### Build depends loops; [Reverse] Build dependency tree
1313 BuildDepends)
1314 if [ -z "$SEARCH" ]; then
1315 cat <<EOT
1316 <h3>$(_ 'Loop dependency of build')</h3>
1317 <pre class="hard">
1318 EOT
1319 for i in $WOK/*/receipt; do
1320 PACKAGE=
1321 WANTED=
1322 BUILD_DEPENDS=
1323 . $i
1324 echo "$PACKAGE $WANTED $(echo $BUILD_DEPENDS)"
1325 done | show_loops
1326 echo '</pre>'
1328 elif package_exist $SEARCH ; then
1329 cat <<EOT
1330 <h3>$(_ 'Package "%s" requires next packages to be built' "$SEARCH")</h3>
1331 <pre class="hard">
1332 EOT
1333 unset ALL_DEPS
1334 dep_scan $SEARCH '' build
1335 echo '</pre>'
1337 cat <<EOT
1338 <h3>$(_ 'Next packages require package "%s" to be built' "$SEARCH")</h3>
1339 <pre class="hard">
1340 EOT
1341 unset ALL_DEPS
1342 rdep_scan $SEARCH build
1343 echo '</pre>'
1344 fi
1345 ;;
1350 ### Common files
1352 FileOverlap)
1353 if package_exist $SEARCH; then
1354 cat <<EOT
1356 <h3>$(_ 'Next packages may overwrite files of package "%s"' "$SEARCH")</h3>
1357 <pre class="hard">
1358 EOT
1359 ( unlzma < $filelist | grep ^$SEARCH: ;
1360 unlzma < $filelist | grep -v ^$SEARCH: ) | awk '
1361 BEGIN { pkg=""; last="x" }
1363 if ($2 == "") next
1364 if (index($2, last) == 1 && substr($2, 1+length(last), 1) == "/")
1365 delete file[last]
1366 last=$2
1367 if (pkg == "") pkg=$1
1368 if ($1 == pkg) file[$2]=$1
1369 else if (file[$2] == pkg) print
1371 ' | display_packages_and_files
1372 echo '</pre>'
1373 fi
1374 ;;
1379 ### File search
1381 File)
1382 if [ -n "$SEARCH" ]; then
1383 cat <<EOT
1385 <h3>$(_ 'File names matching "%s"' "$SEARCH")</h3>
1386 <table class="list">
1387 EOT
1388 unset last
1389 unlzma < $filelist | grep -i "$SEARCH" | \
1390 while read pkg file; do
1391 echo "$file" | grep -qi "$SEARCH" || continue
1392 if [ "$last" != "${pkg%:}" ]; then
1393 [ -n "$last" ] && cat <<EOT
1394 </td></tr>
1395 EOT
1396 last=${pkg%:}
1398 . $WOK/$last/receipt
1399 package_entry
1400 cat <<EOT
1401 <tr><td colspan="3" class="pre">
1402 EOT
1404 fi
1405 echo -n "$file" | awk -vquery="$SEARCH" 'BEGIN{IGNORECASE=1}gsub(query, "<mark>&</mark>")'
1406 echo "<br/>"
1407 done
1408 cat <<EOT
1409 </td></tr>
1410 </table>
1411 EOT
1412 fi
1413 ;;
1418 ### List of files
1420 File_list)
1421 if package_exist $SEARCH; then
1422 cat <<EOT
1424 <h3>$(_ 'List of files in the package "%s"' "$SEARCH")</h3>
1425 <pre class="hard">
1426 EOT
1427 unset last
1428 unlzma < $filelist \
1429 | grep ^$SEARCH: | sed 's|.*: | |' | sort
1430 cat <<EOT
1431 </pre>
1432 <pre class="hard">
1433 EOT
1434 filenb=$(unlzma < $filelist | grep ^$SEARCH: | wc -l)
1435 _p '%s file' '%s files' "$filenb" "$filenb"
1436 cat <<EOT
1438 $(busybox sed -n "/^$SEARCH$/{nnnpq}" $pkglist)
1439 </pre>
1440 EOT
1441 fi
1442 ;;
1447 ### Package description
1449 Desc)
1450 if [ -z "$SEARCH" ]; then
1451 cat <<EOT
1452 <div class="err">$(_ 'Please specify name of the package.')</div>
1453 <p> <br/> </p>
1454 EOT
1455 xhtml_footer
1456 exit 0
1457 fi
1459 cat <<EOT
1460 <h3>$(_ 'Descriptions matching "%s"' "$SEARCH")</h3>
1461 EOT
1462 if [ -f "$pinfo" ]; then
1463 package_entries desc "$SEARCH"
1464 else
1465 echo '<table class="list">'
1466 unset last
1467 # FIXME packages.desc should not be used (at least this way)
1468 grep -i "$SEARCH" "$pkgsrepo/packages.desc" | \
1469 sort | while read pkg extras ; do
1470 . "$WOK/$pkg/receipt"
1471 package_entry
1472 done
1473 echo '</table>'
1474 fi
1475 ;;
1480 Bugs)
1481 cat <<EOT
1483 <h3>$(_ 'Known bugs in the packages')</h3>
1485 <table class="bugs list">
1486 EOT
1487 unset last
1488 grep ^BUGS= $WOK/*/receipt | \
1489 sed "s|$WOK/\(.*\)/receipt:.*|\1|" | sort | while read pkg ; do
1490 unset BUGS
1491 . "$WOK/$pkg/receipt"
1492 package_entry
1493 echo -n '<tr><td> </td><td colspan="2">'
1494 echo -n "$BUGS" | htmlize
1495 echo '</td></tr>'
1496 done
1497 echo '</table>'
1498 ;;
1503 ### Arch
1505 Arch)
1506 if [ -n "$SEARCH" ]; then
1507 cat <<EOT
1509 <h3>$(_ 'The list of packages of architecture "%s"' "$SEARCH")</h3>
1510 <pre class="hard">
1511 EOT
1512 unset last
1513 grep ^HOST_ARCH= $WOK/*/receipt | grep -i "$SEARCH" | \
1514 sed "s|$WOK/\(.*\)/receipt:.*|\1|" | sort | while read pkg ; do
1515 unset HOST_ARCH
1516 . "$WOK/$pkg/receipt"
1517 echo " $HOST_ARCH " | grep -iq " $SEARCH " &&
1518 package_entry_inline
1519 done
1520 cat <<EOT
1521 </pre>
1522 EOT
1523 else
1524 # Display arch cloud
1525 display_cloud HOST_ARCH
1526 fi
1527 ;;
1532 ### Maintainer
1534 Maintainer)
1535 if [ -n "$SEARCH" ]; then
1536 cat <<EOT
1538 <h3>$(_n 'The list of packages that <%s> maintains' "$SEARCH" | htmlize)</h3>
1539 <table class="list">
1540 EOT
1541 unset last
1542 grep ^MAINTAINER= $WOK/*/receipt | grep -i "$SEARCH" | \
1543 sed "s|$WOK/\(.*\)/receipt:.*|\1|" | sort | while read pkg ; do
1544 . "$WOK/$pkg/receipt"
1545 package_entry
1546 done
1547 cat <<EOT
1548 </table>
1549 EOT
1550 else
1551 # Display maintainer cloud
1552 display_cloud MAINTAINER
1553 fi
1554 ;;
1559 ### License
1561 License)
1562 if [ -n "$SEARCH" ]; then
1563 cat <<EOT
1564 <h3>$(_ 'Packages with "%s" license' "$SEARCH")</h3>
1565 <table class="list">
1566 EOT
1567 unset last
1568 grep ^LICENSE= $WOK/*/receipt | grep -i "$SEARCH" | \
1569 sed "s|$WOK/\(.*\)/receipt:.*|\1|" | sort | while read pkg ; do
1570 . "$WOK/$pkg/receipt"
1571 package_entry
1572 done
1573 echo '</table>'
1574 else
1575 # Display license cloud
1576 display_cloud LICENSE
1577 fi
1578 ;;
1583 ### Category
1585 Category)
1586 if [ -n "$SEARCH" ]; then
1587 cat <<EOT
1588 <h3>$(_ 'Packages of category "%s"' "$SEARCH")</h3>
1589 EOT
1590 if [ -f "$pinfo" ]; then
1591 package_entries category "$SEARCH"
1592 else
1593 echo '<table class="list">'
1594 unset last
1595 grep ^CATEGORY= $WOK/*/receipt | grep -i "$SEARCH" | \
1596 sed "s|$WOK/\(.*\)/receipt:.*|\1|" | sort | while read pkg ; do
1597 . "$WOK/$pkg/receipt"
1598 package_entry
1599 done
1600 echo '</table>'
1601 fi
1602 else
1603 # Display category cloud
1604 if [ -f "$pinfo" ]; then
1605 tags="$(awk -F$'\t' '{if($3){print $3}}' "$pinfo" | tr ' ' $'\n' | sort | uniq -c)"
1606 max="$(echo "$tags" | awk '{if ($1 > MAX) MAX = $1} END{print MAX}')"
1607 echo "$tags" | awk -vMAX="$max" -vaddver="$addver" '{
1608 printf "<span class=\"tagn\">%s</span>", $1;
1609 printf "<a class=\"tag%s\" ", int($1 * 10 / MAX + 1);
1610 printf "href=\"?category=%s%s\">%s</a> ", $2, addver, $2;
1611 }'
1612 else
1613 display_cloud CATEGORY
1614 fi
1615 fi
1616 ;;
1621 ### Tags
1623 Tags)
1624 if [ -n "$SEARCH" ]; then
1625 cat <<EOT
1626 <h3>$(_ 'The list of packages tagged "%s"' "$SEARCH")</h3>
1627 EOT
1628 if [ -f "$pinfo" ]; then
1629 package_entries tags "$SEARCH"
1630 else
1631 echo '<table class="list">'
1632 unset last
1633 grep ^TAGS= $WOK/*/receipt | grep -i "$SEARCH" | \
1634 sed "s|$WOK/\(.*\)/receipt:.*|\1|" | sort | while read pkg ; do
1635 . "$WOK/$pkg/receipt"
1636 package_entry
1637 done
1638 echo '</table>'
1639 fi
1640 else
1641 # Display tag cloud
1642 if [ -f "$pinfo" ]; then
1643 TAGS="$(awk -F$'\t' '{if($6){print $6}}' "$pinfo" | tr ' ' $'\n' | sort | uniq -c)"
1644 MAX="$(echo "$TAGS" | awk '{if ($1 > MAX) MAX = $1} END{print MAX}')"
1645 echo "$TAGS" | awk -vMAX="$MAX" -vv="$addver" '{
1646 printf "<span class=\"tagn\">%s</span>", $1;
1647 printf "<a class=\"tag%s\" ", int($1 * 10 / MAX + 1);
1648 printf "href=\"?tags=%s%s\">%s</a> ", $2, v, $2;
1649 }'
1650 else
1651 display_cloud TAGS
1652 fi
1653 fi
1654 ;;
1659 ### Package receipt with syntax highlighter
1661 Receipt)
1662 if package_exist "$SEARCH"; then
1663 cat <<EOT
1665 <h3>$(_ 'Receipt for package "%s"' "$SEARCH")</h3>
1666 <pre class="hard">
1667 EOT
1668 if [ -f $WOK/$SEARCH/taz/*/receipt ]; then
1669 syntax_highlighter $WOK/$SEARCH/taz/*/receipt
1670 else
1671 syntax_highlighter $WOK/$SEARCH/receipt
1672 fi
1673 echo '</pre>'
1674 fi
1675 ;;
1680 ### Package
1682 Package)
1683 if check_n "$SEARCH"; then
1684 cat <<EOT
1685 <h3>$(_ 'Package names matching "%s"' "$SEARCH")</h3>
1686 EOT
1688 if [ -f "$pinfo" ]; then
1689 package_entries name "$SEARCH"
1690 else
1691 echo '<table class="list">'
1692 for pkg in $(ls $WOK/ | grep -i "$SEARCH"); do
1693 . "$WOK/$pkg/receipt"
1694 package_entry
1695 done
1696 echo '</table>'
1697 fi
1699 vpkgs="$(cut -d= -f1 < $equiv | grep -i "$SEARCH")"
1700 for vpkg in $vpkgs; do
1701 cat <<EOT
1703 <h3>$(_ 'Packages providing the package "%s"' "$vpkg")</h3>
1705 <table class="list">
1706 EOT
1707 for pkg in $(grep $vpkg= $equiv | sed "s|$vpkg=||"); do
1708 echo " <!-- '$pkg' - '${pkg#*:}' -->"
1709 if [ -e "$WOK/${pkg#*:}/receipt" ]; then
1710 . $WOK/${pkg#*:}/receipt
1711 package_entry
1712 fi
1713 done
1714 echo '</table>'
1715 done
1716 fi
1717 ;;
1718 esac
1720 xhtml_footer
1722 exit 0