cookutils view lighttpd/index.cgi @ rev 1063

lighttpd/index.cgi: load main page parts asynchronously
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon Jun 04 11:27:06 2018 +0300 (2018-06-04)
parents 45a7e146df74
children 0af059297232
line source
1 #!/bin/sh
2 #
3 # SliTaz Cooker CGI + Lighttpd web interface.
4 #
6 # Make request URI relative to the script name
7 base="$(dirname "$SCRIPT_NAME")"; [ "$base" == '/' ] && base=''
8 REQUEST_URI=$(echo "$REQUEST_URI" | sed "s|^$base/*|/|; s|\?.*||")
10 # Split the URI request to /pkg/cmd/arg
11 export pkg=$(echo "$REQUEST_URI" | cut -d/ -f2)
12 export cmd=$(echo "$REQUEST_URI" | cut -d/ -f3)
13 export arg=$(echo "$REQUEST_URI" | sed 's|^/[^/]*/[^/]*/||')
16 . /usr/lib/slitaz/httphelper.sh
18 [ -f "/etc/slitaz/cook.conf" ] && . /etc/slitaz/cook.conf
19 [ -f "./cook.conf" ] && . ./cook.conf
20 wok="$WOK"
21 title=${title:-SliTaz Cooker}
22 # Cooker DB files.
23 activity="$CACHE/activity"
24 commits="$CACHE/commits"
25 cooklist="$CACHE/cooklist"
26 cookorder="$CACHE/cookorder"
27 command="$CACHE/command"; touch $command
28 blocked="$CACHE/blocked"
29 broken="$CACHE/broken"
30 cooknotes="$CACHE/cooknotes"
31 cooktime="$CACHE/cooktime"
32 wokrev="$CACHE/wokrev"
33 webstat="$CACHE/webstat"
34 splitdb="$CACHE/split.db"
36 # Path to markdown to html convertor
37 cmark_opts='--smart -e table -e strikethrough -e autolink -e tagfilter'
38 if [ -n "$(which cmark 2>/dev/null)" ]; then
39 md2html="$(which cmark) $cmark_opts"
40 elif [ -x "./cmark" ]; then
41 md2html="./cmark $cmark_opts"
42 elif [ -n "$(which sundown 2>/dev/null)" ]; then
43 md2html=$(which sundown)
44 elif [ -x "./sundown" ]; then
45 md2html="./sundown"
46 fi
51 # Search form redirection
52 if [ -n "$(GET search)" ]; then
53 echo -e "HTTP/1.1 301 Moved Permanently\nLocation: $base/$(GET q)\n\n"
54 exit 0
55 fi
58 # Show the running command and it's progression
60 running_command() {
61 state="$(cat $command)"
62 local pct=''
63 if [ -n "$state" ];then
64 echo -n "$state</td></tr><tr><td>Completion</td>"
65 set -- $(grep "^$state" $cooktime)
66 [ -n "$1" -a $2 -ne 0 ] && pct=$((($(date +%s)-$3)*100/$2))
67 [ -n "$pct" ] && max="max='100'"
68 echo -n "<td><progress id='gauge' $max value='$pct' title='Click to stop updating' onclick='stopUpdating()'>"
69 echo -n "</progress> <span id='pct'>${pct:-?}%</span>"
70 [ "$2" -gt 60 ] &&
71 echo -n "</td></tr><tr><td>Estimated end time</td><td>$(date +%H:%M -ud @$(($2+$3)))"
72 else
73 echo 'not running'
74 fi
75 }
78 # HTML page header
80 page_header() {
81 local theme t='' css pretitle='' command
82 theme=$(COOKIE theme)
83 [ "$theme" == 'default' ] && theme=''
84 [ -n "$theme" ] && theme="-$theme"
85 css="cooker$theme.css"
87 if [ -n "$pkg" ]; then
88 case "$pkg" in
89 ~) pretitle="Tag \"$cmd\" - ";;
90 *) pretitle="$pkg - ";;
91 esac
92 else
93 command="$(cat $command)"
94 [ -n "$command" ] && pretitle="$command - "
95 fi
96 [ -z "$favicon" ] && favicon='/slitaz-cooker.png'
98 echo -e 'Content-Type: text/html; charset=UTF-8\n'
100 cat <<EOT
101 <!DOCTYPE html>
102 <html lang="en">
103 <head>
104 <title>$pretitle$title</title>
105 <link rel="stylesheet" href="/$css">
106 <link rel="icon" type="image/png" href="$favicon">
107 <link rel="search" href="$base/os.xml" title="$title" type="application/opensearchdescription+xml">
108 <!-- mobile -->
109 <meta name="viewport" content="width=device-width, initial-scale=1.0">
110 <meta name="theme-color" content="#222">
111 <!-- rss -->
112 <link rel="alternate" type="application/rss+xml" title="$title Feed" href="?rss">
113 <script>
114 // Get part of the main page
115 function getPart(part) {
116 var partRequest = new XMLHttpRequest();
117 partRequest.onreadystatechange = function() {
118 if (this.readyState == 4 && this.status == 200) {
119 response = this.responseText;
120 var partElement = document.getElementById(part);
121 if (response !== null) partElement.innerHTML = response;
122 }
123 };
124 partRequest.open('GET', '?part=' + part, true);
125 partRequest.responseType = '';
126 partRequest.send();
127 }
128 </script>
129 </head>
130 <body>
131 <div id="container">
132 <header>
133 <h1><a href="$base/">$title</a></h1>
134 <div class="network">
135 <a href="http://www.slitaz.org/">Home</a>
136 <a href="http://bugs.slitaz.org/">Bugs</a>
137 <a href="http://hg.slitaz.org/wok-next/">Hg</a>
138 <a href="http://roadmap.slitaz.org/">Roadmap</a>
139 <a href="http://pizza.slitaz.me/">Pizza</a>
140 <a href="http://tank.slitaz.org/">Tank</a>
141 |
142 <a href="/cross/">Cross</a>
143 <a href="/i486.cgi">i486</a>
144 <a href="$base/cookiso.cgi">ISO</a>
145 <select onChange="window.location.href=this.value" style="display: none">
146 <option value=".">Go to…</option>
147 <option value="http://www.slitaz.org/">Home</option>
148 <option value="http://bugs.slitaz.org/">Bug tracker</option>
149 <option value="http://hg.slitaz.org/wok/">Hg wok</option>
150 <option value="http://roadmap.slitaz.org/">Roadmap</option>
151 <option value="http://pizza.slitaz.me/">Pizza</option>
152 <option value="http://tank.slitaz.org/">Tank</option>
153 <option disabled>---------</option>
154 <option value="cross/">Cross</option>
155 <option value="i486.cgi">i486</option>
156 <option value="cookiso.cgi">ISO</option>
157 </select>
158 </div>
159 </header>
161 <main>
162 EOT
164 [ -n "$(GET debug)" ] && echo "<pre><code class='language-ini'>$(env | sort)</code></pre>"
165 }
168 # HTML page footer
170 page_footer() {
171 date_now=$(date +%s)
172 sec_now=$(date +%S); sec_now=${sec_now#0} # remove one leading zero
173 wait_sec=$(( 60 - $sec_now ))
174 cat <<EOT
175 </main>
177 <footer>
178 <a href="http://www.slitaz.org/">SliTaz Website</a>
179 <a href="$base/">Cooker</a>
180 <a href="$base/doc/cookutils/cookutils.html">Documentation</a>
181 <a href="$base/?theme">Theme</a>
182 </footer>
183 </div>
184 <script src="/cooker.js"></script>
185 <script>refreshDate(${wait_sec}000, ${date_now}000)</script>
186 </body>
187 </html>
188 EOT
189 }
192 show_note() {
193 echo "<div class='bigicon-$1'>$2</div>"
194 }
197 not_found() {
198 local file="${1#$PKGS/}"; file="${file#$LOGS/}"; file="${file#$WOK/}"
199 echo "HTTP/1.1 404 Not Found"
200 page_header
201 echo "<h2>Not Found</h2>"
202 case $2 in
203 pkg)
204 show_note e "The requested package “$(basename "$(dirname "$file")")” was not found." ;;
205 *)
206 show_note e "The requested file “$file” was not found." ;;
207 esac
208 page_footer
209 }
212 manage_modified() {
213 local file="$1" option="$2" nul day mon year time hh mm ss date_s
214 if [ ! -f "$file" ]; then
215 if [ "$option" == 'silently-absent' ]; then
216 echo "HTTP/1.1 404 Not Found"
217 return
218 else
219 not_found "$file" "$2"
220 exit
221 fi
222 fi
223 [ "$option" == 'no-last-modified' ] && return
224 if [ -n "$HTTP_IF_MODIFIED_SINCE" ]; then
225 echo "$HTTP_IF_MODIFIED_SINCE" | \
226 while read nul day mon year time nul; do
227 case $mon in
228 Jan) mon='01';; Feb) mon='02';; Mar) mon='03';; Apr) mon='04';;
229 May) mon='05';; Jun) mon='06';; Jul) mon='07';; Aug) mon='08';;
230 Sep) mon='09';; Oct) mon='10';; Nov) mon='11';; Dec) mon='12';;
231 esac
232 hh=$(echo $time | cut -d: -f1)
233 mm=$(echo $time | cut -d: -f2)
234 ss=$(echo $time | cut -d: -f3)
235 date_s=$(date -ud "$year$mon$day$hh$mm.$ss" +%s)
236 # if [ "$date_s" -ge "$(date -ur "$file" +%s)" ]; then
237 # echo -e 'HTTP/1.1 304 Not Modified\n'
238 # exit
239 # fi
240 # TODO: improve caching control
241 done
242 fi
243 echo "Last-Modified: $(date -Rur "$file" | sed 's|UTC|GMT|')"
244 echo "Cache-Control: public, max-age=3600"
245 }
248 # Query '?pct=<package>': update percentage
250 if [ -n "$(GET pct)" ]; then
251 pkg="$(GET pct)"
252 state="$(cat $command)"
253 if [ "$state" == "cook:$pkg" ]; then
254 set -- $(grep "^$state" $cooktime)
255 [ -n "$1" ] && pct=$(( ($(date +%s) - $3) * 100 / $2 ))
256 echo "${pct:-?}"
257 else
258 echo 'reload'
259 fi
260 exit 0
261 fi
264 # Query '?poke': poke cooker
266 if [ -n "$(GET poke)" ]; then
267 touch $CACHE/cooker-request
268 echo -e "Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}\n"
269 exit
270 fi
273 # Query '?recook=<package>': query to recook package
275 if [ -n "$(GET recook)" ]; then
276 pkg="$(GET recook)"
277 case "$HTTP_USER_AGENT" in
278 *SliTaz*)
279 grep -qs "^$pkg$" $CACHE/recook-packages ||
280 echo "$pkg" >> $CACHE/recook-packages
281 esac
282 echo -e "Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}\n"
283 exit
284 fi
287 # Query '/i/<log>/<pkg>': show indicator icon
288 # Can't use ?query - not able to change '+' to '%2B' in the sed rules (see log handler)
290 if [ "$pkg" == 'i' ]; then
291 echo -en "Content-Type: image/svg+xml\n\n<svg xmlns='http://www.w3.org/2000/svg' height='12' width='8'><path d='"
292 if [ $LOGS/$cmd -nt $PKGS/$arg.tazpkg ]; then
293 echo "m1 2-1 1v8l1 1h6l1-1v-8l-1-1z' fill='#090'/></svg>"
294 else
295 echo "m0 3v8l1 1h6l1-1v-8l-1-1h-6zm3 0h2v5h-2zm0 6h2v2h-2z' fill='#d00'/></svg>"
296 fi
297 exit
298 fi
301 # Query '/s/<pkg>': show status indicator icon
302 # Can't use ?query - not able to change '+' to '%2B' in the sed rules (see log handler)
304 if [ "$pkg" == 's' ]; then
305 # argument <pkg> is in $cmd variable
306 echo -en "Content-Type: image/svg+xml\n\n<svg xmlns='http://www.w3.org/2000/svg' height='12' width='8'><path d='"
307 # packages.info updates with each new package, so we'll find actual info here
308 if grep -q "^$cmd"$'\t' $PKGS/packages.info; then
309 echo "m1 2-1 1v8l1 1h6l1-1v-8l-1-1z' fill='#090'/></svg>"
310 else
311 echo "m0 3v8l1 1h6l1-1v-8l-1-1h-6zm3 0h2v5h-2zm0 6h2v2h-2z' fill='#d00'/></svg>"
312 fi
313 exit
314 fi
317 # Query '?theme[=<theme>]': change UI theme
319 if [ -n "$(GET theme)" ]; then
320 theme="$(GET theme)"
321 ref="$(echo "$HTTP_REFERER" | sed 's|:|%3A|g; s|/|%2F|g; s|\?|%3F|g; s|\+|%2B|g;')"
322 case $theme in
323 theme)
324 current=$(COOKIE theme)
325 page_header
326 cat <<EOT
327 <section>
328 <h2>Change theme</h2>
329 <p>Current theme: “${current:-default}”. Select other:</p>
330 <ul>
331 $(
332 for i in default emerald sky goldenrod midnight like2016 terminal; do
333 [ "$i" == "${current:-default}" ] || echo "<li><a href=\"$base/?theme=$i&amp;ref=$ref\">$i</a></li>"
334 done
335 )
336 </ul>
337 </section>
338 EOT
339 page_footer
340 exit 0
341 ;;
342 default|emerald|sky|goldenrod|midnight|like2016|terminal)
343 ref="$(GET ref)"
344 [ -n "$ref" ] || ref="$base/"
345 # Expires in a year
346 expires=$(date -uRd @$(($(date +%s)+31536000)) | sed 's|UTC|GMT|')
347 echo -e "HTTP/1.1 302 Found\nLocation: $ref\nCache-Control: no-cache\nSet-Cookie: theme=$theme; expires=$expires\n\n"
348 exit 0
349 ;;
350 esac
351 fi
354 #case "$QUERY_STRING" in
355 # stuff*)
356 # file="$wok/$(GET stuff)"
357 # manage_modified "$file"
358 # ;;
359 #
360 # pkg=*|receipt=*|description=*|files=*|log=*|man=*|doc=*|info=*)
361 # type=${QUERY_STRING%%=*}
362 # pkg=$(GET $type)
363 # case "$type" in
364 # description)
365 # manage_modified "$wok/$pkg/receipt" 'no-last-modified'
366 # manage_modified "$wok/$pkg/description.txt" 'silently-absent'
367 # ;;
368 # log)
369 # manage_modified "$wok/${pkg%%.log*}/receipt" 'no-last-modified'
370 # manage_modified "$LOGS/$pkg"
371 # ;;
372 # *)
373 # manage_modified "$wok/$pkg/receipt" pkg
374 # ;;
375 # esac
376 # ;;
377 #esac
380 # RSS feed generator
381 # URI: ?rss[&limit={1..100}]
383 if [ -n "$(GET rss)" ]; then
384 limit=$(GET limit); limit="${limit:-12}"; [ "$limit" -gt 100 ] && limit='100'
385 pubdate=$(date -Rur$(ls -t $FEEDS/*.xml | head -n1) | sed 's|UTC|GMT|')
386 cooker_url="http://$HTTP_HOST$base/"
387 cat <<EOT
388 Content-Type: application/rss+xml
390 <?xml version="1.0" encoding="utf-8" ?>
391 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
392 <channel>
393 <title>$title</title>
394 <description>The SliTaz packages cooker feed</description>
395 <link>$cooker_url</link>
396 <lastBuildDate>$pubdate</lastBuildDate>
397 <pubDate>$pubdate</pubDate>
398 <atom:link href="$cooker_url?rss" rel="self" type="application/rss+xml" />
399 EOT
400 for rss in $(ls -t $FEEDS/*.xml | head -n$limit); do
401 sed "s|http[^=]*=|$cooker_url|; s|<guid|& isPermaLink=\"false\"|g; s|</pubDate| GMT&|g" $rss
402 done
403 cat <<EOT
404 </channel>
405 </rss>
406 EOT
407 exit 0
408 fi
411 ### OpenSearch ###
413 # Query '/os.xml': get OpenSearch Description
415 if [ "$pkg" == 'os.xml' ]; then
416 cat <<EOT
417 Content-Type: application/xml; charset=UTF-8
419 <?xml version="1.0" encoding="UTF-8"?>
420 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
421 <ShortName>$title</ShortName>
422 <Description>SliTaz packages search</Description>
423 <Image width="16" height="16" type="image/png">http://$HTTP_HOST/images/logo.png</Image>
424 <Url type="text/html" method="GET" template="http://$HTTP_HOST$base/{searchTerms}"/>
425 <Url type="application/x-suggestions+json" method="GET" template="http://$HTTP_HOST$base/">
426 <Param name="oss" value="{searchTerms}"/>
427 </Url>
428 <SearchForm>http://$HTTP_HOST$base/</SearchForm>
429 <InputEncoding>UTF-8</InputEncoding>
430 </OpenSearchDescription>
431 EOT
432 exit 0
433 fi
435 # Query '?oss[=<term>]': OpenSearch suggestions
437 if [ -n "$(GET oss)" ]; then
438 term="$(GET oss | tr -cd '[:alnum:]+-')"
439 echo -e 'Content-Type: application/x-suggestions+json; charset=UTF-8\n'
440 cd $wok
441 ls | fgrep "$term" | head -n10 | awk -vterm="$term" '
442 BEGIN{printf("[\"%s\",[", term)}
443 {printf("%s\"%s\"", NR != 1 ? "," : "", $0)}
444 END {printf("]]")}
445 '
446 exit 0
447 fi
452 #
453 # Functions
454 #
457 # Unpack to stdout
459 docat() {
460 case "$1" in
461 *gz) zcat ;;
462 *bz2) bzcat ;;
463 *xz) xzcat ;;
464 *) cat
465 esac < $1
466 }
469 # Tiny texinfo converter
471 info2html() {
472 sed \
473 -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g' \
474 -e 's|^\* \(.*\)::|* <a href="#\1">\1</a> |' \
475 -e 's|\*note \(.*\)::|<a href="#\1">\1</a>|' \
476 -e '/^File: / s|(dir)|Top|g' \
477 -e '/^File: / s|Next: \([^,]*\)|<a class="button" href="#\1">Next: \1</a>|' \
478 -e '/^File: / s|Prev: \([^,]*\)|<a class="button" href="#\1">Prev: \1</a>|' \
479 -e '/^File: / s|Up: \([^,]*\)|<a class="button" href="#\1">Up: \1</a>|' \
480 -e '/^File: / s|^.* Node: \([^,]*\), *\(.*\)$|<pre id="\1">\2|' \
481 -e '/^<pre id=/ s|^\([^>]*>\)\(<a[^>]*>Next: [^,]*\), *\(<a[^>]*>Prev: [^,]*\), *\(<a[^>]*>Up: .*\)|\1 \3 \4 \2|' \
482 -e '/^Tag Table:$/,/^End Tag Table$/d' \
483 -e '/INFO-DIR/,/^END-INFO-DIR/d' \
484 -e "s|https*://[^>),'\"\`’ ]*|<a href=\"&\">&</a>|g" \
485 -e "s|ftp://[^>),\"\` ]*|<a href=\"&\">&</a>|g" \
486 -e 's|^\* Menu:|<b>Menu:</b>|' \
487 -e "s|^|</pre>|"
488 }
491 # Put some colors into log and DB files.
493 syntax_highlighter() {
494 case $1 in
495 log)
496 # If variables not defined - define them with some rare values
497 : ${_src=#_#_#}
498 : ${_install=#_#_#}
499 : ${_fs=#_#_#}
500 : ${_stuff=#_#_#}
501 # Use one-letter html tags to save some bytes :)
502 # <b>is error (red)</b> <u>is warning (orange)</u> <i>is informative (green)</i>
503 sed \
504 -e 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g' \
505 -e 's#OK$#<i>OK</i>#' \
506 -e 's#\([Dd]one\)$#<i>\1</i>#' \
507 -e 's#Success$#<i>Success</i>#' \
508 -e 's#\([^a-z]\)ok$#\1<i>ok</i>#' \
509 -e 's#\([^a-z]\)yes$#\1<i>yes</i>#' \
510 -e 's#: \(YES.*\)#: <i>\1</i>#' \
511 -e 's#\([^a-z]\)ON$#\1<i>ON</i>#' \
512 -e 's#\(enabled\)$#<i>\1</i>#' \
513 -e 's#\([^a-z]\)no$#\1<u>no</u>#' \
514 -e 's#: \(NO.*\)#: <u>\1</u>#' \
515 -e 's#\([^a-z]\)none$#\1<u>none</u>#' \
516 -e 's#\([^a-z]\)false$#\1<u>false</u>#' \
517 -e 's#\([^a-z]\)OFF$#\1<u>OFF</u>#' \
518 -e 's#\(disabled\)$#<u>\1</u>#' \
519 -e 's#\(^checking .*\.\.\. \)\(.*\)$#\1<i>\2</i>#' \
520 \
521 -e 's#\( \[Y[nm/]\?\] n\)$# <u>\1</u>#' \
522 -e 's#\( \[N[ym/]\?\] y\)$# <i>\1</i>#' \
523 -e 's# y$# <i>y</i>#' \
524 -e 's# n$# <u>n</u>#' \
525 -e 's#(NEW) *$#<b>(NEW)</b>#' \
526 \
527 -e 's#.*(pkg/local).*#<i>\0</i>#' \
528 -e 's#.*(web/cache).*#<u>\0</u>#' \
529 \
530 -e 's#\([^a-zA-Z]\)\([Ee]rror\)$#\1<b>\2</b>#' \
531 -e 's#ERROR:#<b>ERROR:</b>#g' \
532 \
533 -e 's#^.*multiple definition of.*#<b>\0</b>#' \
534 -e 's#^.*[Ff][Aa][Ii][Ll][Ee][Dd].*#<b>\0</b>#' \
535 -e 's#^.*[Ff]atal.*#<b>\0</b>#' \
536 -e '/non-fatal/ s|</*b>||g' \
537 -e 's#^.*[Nn]ot found.*#<b>\0</b>#' \
538 -e 's#^.*[Nn]o such file.*#<b>\0</b>#' \
539 -e 's#^.*No package .* found.*#<b>\0</b>#' \
540 -e 's#^.*Unable to find.*#<b>\0</b>#' \
541 -e 's#[^a-zA-Z-][Ii]nvalid.*#<b>\0</b>#' \
542 -e 's#\([Nn][Oo][Tt] found\.*\)$#<b>\1</b>#' \
543 -e 's#\(found\.*\)$#<i>\1</i>#' \
544 \
545 -e 's#^.*WARNING:.*#<u>\0</u>#' \
546 -e 's#^.*warning:.*#<u>\0</u>#' \
547 -e 's#^.* [Ee]rror:* .*#<b>\0</b>#' \
548 -e 's#^.*terminated.*#<b>\0</b>#' \
549 -e 's#\(missing\)#<b>\1</b>#g' \
550 -e 's#^.*[Cc]annot find.*#<b>\0</b>#' \
551 -e 's#^.*unrecognized options.*#<u>\0</u>#' \
552 -e 's#^.*does not.*#<u>\0</u>#' \
553 -e 's#^.*[Ii]gnoring.*#<u>\0</u>#' \
554 -e 's#^.*note:.*#<u>\0</u>#' \
555 \
556 -e 's#^.* will not .*#<u>\0</u>#' \
557 -e 's!^Hunk .* succeeded at .*!<u>\0</u>!' \
558 -e 's#^.* Warning: .*#<u>\0</u>#' \
559 \
560 -e "s#^Executing:\([^']*\).#<em>\0</em>#" \
561 -e "s#^Making.*#<em>\0</em>#" \
562 -e "s#^Scanning dependencies of target .*#<em>\0</em>#" \
563 -e "s#^====\([^']*\).#<span class='span-line'>\0</span>#g" \
564 -e "s#^[a-zA-Z0-9]\([^']*\) :: #<span class='span-sky'>\0</span>#g" \
565 -e "s#[fh]tt*ps*://[^ '\"]*#<a href='\0'>\0</a>#g" \
566 \
567 -e 's|^<u>\(.*libtool: warning: relinking.*\)</u>|\1|' \
568 -e 's|^<u>\(.*libtool: warning: .* has not been installed in .*\)</u>|\1|' \
569 -e 's|^<u>\(.*checking for a sed.*\)</u>|\1|' \
570 -e 's|^<u><b>\(.*inlining failed.*\)</b></u>|<u>\1</u>|' \
571 \
572 -e "s|$_src|<var>\${src}</var>|g;
573 s|$_install|<var>\${install}</var>|g;
574 s|$_fs|<var>\${fs}</var>|g;
575 s|$_stuff|<var>\${stuff}</var>|g" \
576 \
577 -e "s|\[\([01]\)m\[3\([1-7]\)m|<span class='c\2\1'>|g;
578 s|\[\([01]\);3\([1-7]\)m|<span class='c\2\1'>|g;
579 s|\[3\([1-7]\)m|<span class='c\10'>|g;
580 s|\[\([01]\);0m|<span class='c0\1'>|g;
581 s|\[0m|</span>|g;
582 s|\[m|</span>|g;
583 s|\[0;10m|</span>|g;
584 s|\[K||g;" \
585 \
586 -e "s|\[9\([1-6]\)m|<span class='c\10'>|;
587 s|\[39m|</span>|;
588 #s|\[1m|<span class='c01'>|g;
589 s|\[1m|<span style='font-weight:bold'>|g; s|(B|</span>|g;
590 s|\[m||g;
591 " \
592 -e "s!^|\(+.*\)!|<span class='c20'>\1</span>!;
593 s!^|\(-.*\)!|<span class='c10'>\1</span>!;
594 s!^|\(@@.*@@\)\$!|<span class='c30'>\1</span>!;"
595 \
597 ;;
599 files)
600 # Highlight the Busybox's `ls` output
601 awk '{
602 part1 = substr($0, 0, 16);
603 part2 = substr($0, 17, 9);
604 part3 = substr($0, 26, 9);
605 part4 = substr($0, 35);
606 if (part2 != "root ") part2 = "<span class=\"c11\">" part2 "</span>";
607 if (part3 != "root ") part3 = "<span class=\"c11\">" part3 "</span>";
608 print part1 part2 part3 part4;
609 }' | \
610 sed "s|\[0m/|/\[0m|g;
611 s|\[\([01]\);3\([1-7]\)m|<a class='c\2\1'>|g;
612 s|\[\([01]\);0m|<a class='c0\1'>|g;
613 s|\[0m|</a>|g;
614 s|^\(lrwxrwxrwx\)|<span class='c61'>\1</span>|;
615 s|^\(-rwxr-xr-x\)|<span class='c21'>\1</span>|;
616 s|^\(-rw-r--r--\)|<span class='c31'>\1</span>|;
617 s|^\(drwxr-xr-x\)|<span class='c41'>\1</span>|;
618 s|^\([lrwxs-][lrwxs-]*\)|<span class='c11'>\1</span>|;
619 "
620 ;;
621 esac
622 }
625 show_code() {
626 echo -n "<pre><code class=\"language-$1\">"
627 sed 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g'
628 echo '</code></pre>'
629 }
632 datalist() {
633 cut -d$'\t' -f2 $splitdb | tr ' ' '\n' | sort -u | awk '
634 BEGIN{printf("<datalist id=\"packages\">")}
635 {printf("<option>%s",$1)}
636 END {printf("</datalist>")}
637 '
638 }
641 mklog() {
642 awk '
643 BEGIN { printf("<pre class=\"log dog\">\n") }
644 { print }
645 END { print "</pre>" }'
646 }
649 summary() {
650 log="$1"
651 pkg="$(basename ${log%%.log*})"
653 if [ -f "$log" ]; then
654 if grep -q "cook:$pkg$" $command; then
655 show_note i "The Cooker is currently building $pkg"
656 elif fgrep -q "Summary for:" $log; then
657 sed '/^Summary for:/,$!d' $log | awk '
658 BEGIN { print "<section>" }
659 function row(line) {
660 split(line, s, " : ");
661 printf("\t<tr><td>%s</td><td>%s</td></tr>\n", s[1], s[2]);
662 }
663 function row2(line, rowNum) {
664 split(line, s, " : ");
665 if (rowNum == 1) {
666 print "<thead>";
667 printf("\t<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n", s[1], s[2], s[3], s[4], s[5]);
668 print "</thead><tbody>";
669 }
670 else
671 printf("\t<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n", s[1], s[2], s[3], s[4], s[5]);
672 }
673 {
674 if (NR==1) { printf("<h3>%s</h3>\n<table>\n", $0); next }
675 if ($0 ~ "===") { seen++; if (seen == 1) next; else exit; }
676 if ($0 ~ "---") {
677 seen2++;
678 if (seen2 == 1) print "</table>\n\n<table class=\"pkgslist\">"
679 next
680 }
681 if (seen2) row2($0, seen2); else row($0);
682 }
683 END { print "</tbody></table></section>" }
684 '
685 elif fgrep -q "Debug information" $log; then
686 echo -e '<section>\n<h3>Debug information</h3>'
687 sed -e '/^Debug information/,$!d; /^===/d; /^$/d' $log | sed -n '1!p' | \
688 if [ -n "$2" ]; then
689 syntax_highlighter log | sed 's|\([^0-9 ]\)\([0-9][0-9]*\):|\1<a href="#l\2">\2</a>:|'
690 else
691 sed 's|^[0-9][0-9]*:||' | syntax_highlighter log
692 fi | mklog
693 echo '</section>'
694 fi
695 else
696 [ -n "$pkg" -a -d "$wok/$pkg" ] && show_note e "No log for $pkg"
697 fi
698 }
701 active() {
702 [ "$cmd" == "$1" -o "$cmd" == "${2:-$1}" ] && echo -n ' active'
703 }
706 pkg_info() {
707 local log active bpkg short_desc=''
708 log="$LOGS/$pkg.log"
710 echo -n "<h2><a href=\"$base/${requested_pkg:-$pkg}\">${requested_pkg:-$pkg}</a>"
711 # Get short description for existing packages
712 [ -f $PKGS/packages.info ] &&
713 short_desc="$(awk -F$'\t' -vp="${requested_pkg:-$pkg}" '{if ($1 == p) { printf("%s", $4); exit; }}' $PKGS/packages.info)"
714 # If package does not exist (not created yet or broken), get short description
715 # (but only for "main" package) from receipt
716 [ -n "$short_desc" ] || short_desc="$(. $wok/$pkg/receipt; echo "$SHORT_DESC")"
717 echo ": $short_desc</h2>"
718 echo '<div id="info">'
719 echo "<a class='button icon receipt$(active receipt stuff)' href='$base/$pkg/receipt'>receipt &amp; stuff</a>"
721 # In the receipts $EXTRAVERSION is defined using $kvers, get it here [copy from 'cook' set_paths()]
722 if [ -f "$wok/linux/receipt" ]; then
723 kvers=$(. $wok/linux/receipt; echo $VERSION)
724 kbasevers=$(echo $kvers | cut -d. -f1,2)
725 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
726 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
727 kbasevers=$(echo $kvers | cut -d. -f1,2)
728 fi
730 unset WEB_SITE WANTED
731 . $wok/$pkg/receipt
733 [ -n "$WEB_SITE" ] &&
734 echo "<a class='button icon website' href='$WEB_SITE' target='_blank' rel='noopener noreferrer'>web site</a>"
736 [ -f "$wok/$pkg/taz/$PACKAGE-$VERSION$EXTRAVERSION/receipt" ] &&
737 echo "<a class='button icon files$(active files)' href='$base/$pkg/files'>files</a>"
739 [ -n "$(ls $wok/$pkg/description*.txt)" ] &&
740 echo "<a class='button icon desc$(active description)' href='$base/$pkg/description'>description</a>"
742 [ -n "$TARBALL" -a -s "$SRC/$TARBALL" -o -d "$wok/$pkg/taz" ] &&
743 echo "<a class='button icon download' href='$base/$pkg/download'>download</a>"
745 echo "<a class='button icon browse' href='$base/$pkg/browse/'>browse</a>"
747 [ -x ./man2html.bin -a -d "$wok/$pkg/install/usr/share/man" ] &&
748 echo "<a class='button icon doc$(active man)' href='$base/$pkg/man/'>man</a>"
750 [ -d "$wok/$pkg/install/usr/share/doc" -o -d "$wok/$pkg/install/usr/share/gtk-doc" ] &&
751 echo "<a class='button icon doc$(active doc)' href='$base/$pkg/doc/'>doc</a>"
753 [ -d "$wok/$pkg/install/usr/share/info" ] &&
754 echo "<a class='button icon doc$(active info)' href='$base/$pkg/info/#Top'>info</a>"
756 if [ -n "$LFS" ]; then
757 printf "<a class='button icon doc' href='%s' target='_blank' rel='noopener noreferrer'>" "$LFS"
758 [ "${LFS/blfs/}" != "$LFS" ] && printf "B"
759 printf "LFS</a>\n"
760 fi
762 [ -s "$log" ] &&
763 echo "<a class='button icon log$(active log)' href='$base/$pkg/log/'>logs</a>"
765 echo '</div>'
766 }
769 mktable() {
770 sed 's# : #|#' | awk -vc="$1" '
771 BEGIN { printf("<table class=\"%s\">\n", c); FS="|" }
772 { printf("<tr><td>%s</td>", $1);
773 if (NF == 2) printf("<td>%s</td>", $2);
774 printf("</tr>\n", $2) }
775 END { print "</table>" }'
776 }
779 section() {
780 local i=$(basename "$1")
781 echo -e '\n\n<section>'
782 [ $(wc -l < $1) -gt $2 ] && echo "<a class='button icon more r' href='?$i'>${3#*|}</a>"
783 echo "<h2>${3%|*}</h2>"
784 mktable "$i"
785 echo '</section>'
786 }
789 show_desc() {
790 echo "<section><h3>Description of “$1”</h3>"
791 if [ -n "$md2html" ]; then
792 $md2html $2
793 else
794 show_code markdown < $2
795 fi
796 echo "</section>"
797 }
800 # Return all the names of packages bundled in this receipt
802 all_names() {
803 # Get package names from $SPLIT variable
804 local split=$(echo $SPLIT \
805 | awk '
806 BEGIN { RS = " "; FS = ":"; }
807 { print $1; }' \
808 | tr '\n' ' ')
809 local split_space=" $split "
810 if ! head -n1 $WOK/$pkg/receipt | fgrep -q 'v2'; then
811 # For receipts v1: $SPLIT may present in the $WANTED package,
812 # but split packages have their own receipts
813 echo $PACKAGE
814 elif [ "${split_space/ $PACKAGE /}" != "$split_space" ]; then
815 # $PACKAGE included somewhere in $SPLIT (probably in the end).
816 # We should build packages in the order defined in the $SPLIT.
817 echo $split
818 else
819 # We'll build the $PACKAGE, then all defined in the $SPLIT.
820 echo $PACKAGE $split
821 fi
822 }
825 toolchain_version() {
826 echo "<tr><td><a href='$base/$1'>$1</a></td>"
827 awk -F$'\t' -vpkg="$1" '
828 BEGIN { version = description = "---"; }
829 {
830 if ($1 == pkg) { version = $2; description = $4; }
831 }
832 END { printf("<td>%s</td><td>%s</td></tr>", version, description); }
833 ' $PKGS/packages.info
834 }
837 files_header() {
838 echo '<section><h3>Available downloads:</h3>'
839 echo '<table><thead><tr><th>File</th><th>Size</th><th>Description</th></tr></thead><tbody>'
840 }
843 # Update statistics used in web interface.
844 # There is no need to recalculate the statistics every time the page is displayed.
845 # Note, $webstat file must be owned by www, otherwise this function will not be able to do the job.
847 update_webstat() {
848 # echo '<div id="waitme">'
849 # show_note i 'Please wait while statistics are being collected.'
850 # echo "</div>"
852 # for receipts:
853 rtotal=$(ls $WOK/*/arch.$ARCH | wc -l)
854 rcooked=$(ls -d $WOK/*/taz | wc -l)
855 runbuilt=$(($rtotal - $rcooked))
856 rblocked=$(wc -l < $blocked)
857 rbroken=$(wc -l < $broken)
859 # for packages:
860 ptotal=$(cut -d$'\t' -f2 $CACHE/split.db | tr ' ' '\n' | sort -u | wc -l)
861 pcooked=$(ls $PKGS/*.tazpkg | wc -l)
862 punbuilt=$(($ptotal - $pcooked))
863 pblocked=$(
864 while read i; do
865 sed "/^$i\t/!d" $CACHE/split.db
866 done < $blocked | cut -d$'\t' -f2 | tr ' ' '\n' | wc -l)
867 pbroken=$(
868 while read i; do
869 sed "/^$i\t/!d" $CACHE/split.db
870 done < $broken | cut -d$'\t' -f2 | tr ' ' '\n' | wc -l)
872 cat > $webstat <<EOT
873 rtotal="$rtotal"; rcooked="$rcooked"; runbuilt="$runbuilt"; rblocked="$rblocked"; rbroken="$rbroken"
874 ptotal="$ptotal"; pcooked="$pcooked"; punbuilt="$punbuilt"; pblocked="$pblocked"; pbroken="$pbroken"
875 EOT
877 echo '<script>document.getElementById("waitme").remove();</script>'
878 }
881 # Generate part of the main page
883 part() {
884 if [ -z "$nojs" ]; then
885 echo "<div id='$1'></div><script>getPart('$1')</script>"
886 return
887 fi
889 echo '<div>'
890 case $1 in
891 summary)
892 echo '<h2>Summary</h2>'
894 mktable <<EOT
895 Cooker state : $(running_command)
896 Wok revision : <a href='$WOK_URL' target='_blank' rel='noopener noreferrer'>$(cat $wokrev)</a>
897 Commits to cook : $(wc -l < $commits)
898 Current cooklist : $(wc -l < $cooklist)
899 Architecture : $ARCH, <a href="$toolchain">toolchain</a>
900 Server date : <span id='date'>$(date -u '+%F %R %Z')</span>
901 EOT
903 # If command is "cook:*", update gauge and percentage periodically.
904 # If different package is cooking, reload the page (with new settings)
905 cmd="$(cat $command)"
906 case "$cmd" in
907 cook:*)
908 pkg=${cmd#*:}
909 echo "<script>updatePkg = '${pkg//+/%2B}';</script>"
910 ;;
911 esac
912 ;;
913 webstat)
914 # Do we need to update the statistics?
915 [ "$webstat" -nt "$activity" ] || update_webstat
916 . $webstat
918 pct=0; [ "$rtotal" -gt 0 ] && pct=$(( ($rcooked * 100) / $rtotal ))
920 cat <<EOT
921 <div class="meter"><progress max="100" value="$pct">${pct}%</progress><span>${pct}%</span></div>
923 <table class="webstat"><thead>
924 <tr><th> </th><th>Total </th><th>Cooked </th><th>Unbuilt </th><th>Blocked </th><th>Broken </th></tr>
925 </thead><tbody>
926 <tr><td>Receipts</td><td>$rtotal</td><td>$rcooked</td><td>$runbuilt</td><td>$rblocked</td><td>$rbroken</td></tr>
927 <tr><td>Packages</td><td>$ptotal</td><td>$pcooked</td><td>$punbuilt</td><td>$pblocked</td><td>$pbroken</td></tr>
928 </tbody></table>
929 EOT
930 ;;
931 activity)
932 tac $activity | head -n12 | sed 's|cooker.cgi?pkg=||;
933 s|\[ Done|<span class="r c20">Done|;
934 s|\[ Failed|<span class="r c10">Failed|;
935 s|\[ -Failed|<span class="r c10"><del>Failed</del>|;
936 s| \]|</span>|;
937 s|%2B|\+|g' | \
938 section $activity 12 "Activity|More activity"
939 ;;
940 cooknotes)
941 [ -s "$cooknotes" ] && tac $cooknotes | head -n12 | \
942 section $cooknotes 12 "Cooknotes|More notes"
943 ;;
944 commits)
945 [ -s "$commits" ] && head -n20 $commits | \
946 section $commits 20 "Commits|More commits"
947 ;;
948 cooklist)
949 [ -s "$cooklist" ] && head -n 20 $cooklist | \
950 section $cooklist 20 "Cooklist|Full cooklist"
951 ;;
952 broken)
953 [ -s "$broken" ] && head -n20 $broken | sed "s|^[^']*|<a href='\0'>\0</a>|g" | \
954 section $broken 20 "Broken|All broken packages"
955 ;;
956 blocked)
957 [ -s "$blocked" ] && sed "s|^[^']*|<a href='\0'>\0</a>|g" $blocked | \
958 section $blocked 12 "Blocked|All blocked packages"
959 ;;
960 pkgs)
961 cd $PKGS
962 # About BusyBox's `ls`
963 # On the Tank server: BusyBox v1.18.4 (2012-03-14 03:32:25 CET) multi-call binary.
964 # It supported the option `-e`, output with `-let` options like this:
965 # -rw-r--r-- 1 user group 100000 Fri Nov 3 10:00:00 2017 filename
966 # 1 2 3 4 5 6 7 8 9 10 11
967 # Newer BusyBox v1.27.2 doesn't support option `-e` and has no configs to
968 # configure it or return the option back. It supported the long option
969 # `--full-time` instead, but output is different:
970 # -rw-r--r-- 1 user group 100000 2017-11-03 10:00:00 +0200 filename
971 # 1 2 3 4 5 6 7 8 9
972 if ls -let >/dev/null 2>&1; then
973 ls -let *.tazpkg \
974 | awk '
975 (NR<=20){
976 sub(/:[0-9][0-9]$/, "", $9);
977 mon = index(" JanFebMarAprMayJunJulAugSepOctNovDec", $7) / 3;
978 printf("%d-%02d-%02d %s : <a href=\"get/%s\">%s</a>\n", $10, mon, $8, $9, $11, $11);
979 }' \
980 | section $activity 1000 "Latest cook"
981 else
982 ls -lt --full-time *.tazpkg \
983 | awk '
984 (NR<=20){
985 sub(/:[0-9][0-9]$/, "", $7);
986 printf("%s %s : <a href=\"get/%s\">%s</a>\n", $6, $7, $9, $9);
987 }' \
988 | section $activity 1000 "Latest cook"
989 fi
990 ;;
991 esac
992 echo '</div>'
993 }
996 # Query '?part=<part>': get part of the main page
998 if [ -n "$(GET part)" ]; then
999 part="$(GET part)"
1000 case $part in
1001 summary|webstat|activity|cooknotes|commits|cooklist|broken|blocked|pkgs)
1002 nojs='yes'
1003 part $part
1004 ;;
1005 esac
1006 exit 0
1007 fi
1013 # Load requested page
1016 if [ -z "$pkg" ]; then
1018 page_header
1019 if [ -n "$QUERY_STRING" -a "$QUERY_STRING" != 'debug' ]; then
1021 for list in activity cooknotes cooklist; do
1022 [ -n "$(GET $list)" ] || continue
1023 [ "$list" == 'cooklist' ] && nb="- Packages: $(wc -l < $cooklist)"
1024 echo '<section id="content2">'
1025 echo "<h2>DB: $list $nb</h2>"
1026 tac $CACHE/$list | sed 's|cooker.cgi?pkg=||; s|%2B|+|g;
1027 s|\[ Done|<span class="r c20">Done|;
1028 s|\[ Failed|<span class="r c10">Failed|;
1029 s|\[ -Failed|<span class="r c10"><del>Failed</del>|;
1030 s| \]|</span>|' | mktable $list
1031 echo '</section>'
1032 done
1034 if [ -n "$(GET broken)" ]; then
1035 echo '<section id="content2">'
1036 echo "<h2>DB: broken - Packages: $(wc -l < $broken)</h2>"
1037 sort $CACHE/broken | sed "s|^[^']*|<a href='$base/\0'>\0</a>|g" | mktable
1038 echo '</section>'
1039 fi
1041 case "$QUERY_STRING" in
1042 *.log)
1043 log=$LOGS/$QUERY_STRING
1044 name=$(basename $log)
1045 if [ -f "$log" ]; then
1046 echo "<h2>Log for: ${name%.log}</h2>"
1047 if fgrep -q "Summary" $log; then
1048 echo '<pre class="log">'
1049 grep -A 20 'Summary' $log | syntax_highlighter log
1050 echo '</pre>'
1051 fi
1052 echo '<pre class="log">'
1053 syntax_highlighter log < $log
1054 echo '</pre>'
1055 if [ "$QUERY_STRING" == 'pkgdb.log' ]; then
1056 # Display button only for SliTaz web browser
1057 case "$HTTP_USER_AGENT" in
1058 *SliTaz*)
1059 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
1060 if grep -qs '^pkgdb$' $CACHE/recook-packages; then
1061 show_note i "The package database has been requested for re-creation"
1062 else
1063 echo "<a class='button' href='$base/?recook=pkgdb'>Re-create the DB</a>"
1064 fi
1065 fi
1066 ;;
1067 esac
1068 fi
1069 else
1070 show_note e "No log file: $log"
1071 fi
1072 ;;
1073 toolchain)
1074 cat <<EOT
1075 <div id="content2">
1076 <section>
1077 <h2>SliTaz GNU/Linux toolchain</h2>
1079 <table>
1080 <tr><td>Build date</td> <td colspan="2">$(sed -n '/^Cook date/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td></tr>
1081 <tr><td>Build duration</td> <td colspan="2">$(sed -n '/^Cook time/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td></tr>
1082 <tr><td>Architecture</td> <td colspan="2">$ARCH</td></tr>
1083 <tr><td>Host system</td> <td colspan="2">$BUILD_SYSTEM</td></tr>
1084 <tr><td>Target system</td> <td colspan="2">$HOST_SYSTEM</td></tr>
1085 <tr><th>Package</th><th>Version</th><th>Description</th></tr>
1086 $(toolchain_version slitaz-toolchain)
1087 $(toolchain_version binutils)
1088 $(toolchain_version linux-api-headers)
1089 $(toolchain_version gcc)
1090 $(toolchain_version glibc)
1091 </table>
1093 <p>Toolchain documentation: <a target="_blank" rel="noopener noreferrer"
1094 href="http://doc.slitaz.org/en:cookbook:toolchain">http://doc.slitaz.org/en:cookbook:toolchain</a>
1095 </p>
1097 </section>
1098 </div>
1099 EOT
1100 ;;
1101 esac
1102 page_footer
1103 exit 0
1104 fi
1107 # We may have a toolchain.cgi script for cross cooker's
1108 if [ -f "toolchain.cgi" ]; then
1109 toolchain="toolchain.cgi"
1110 else
1111 toolchain="?toolchain"
1112 fi
1114 # Main page with summary. Count only packages included in ARCH,
1115 # use 'cooker arch-db' to manually create arch.$ARCH files.
1117 cat <<EOT
1118 <div id="content2">
1120 <section>
1121 <form method="get" action="" class="search r">
1122 <input type="hidden" name="search" value="pkg"/>
1123 <button type="submit" title="Search">Search</button>
1124 <input type="search" name="q" placeholder="Package" list="packages" autocorrect="off" autocapitalize="off"/>
1125 </form>
1126 EOT
1128 part summary
1129 part webstat
1131 if [ -e "$CACHE/cooker-request" -a ! -s $command ]; then
1132 if [ "$activity" -nt "$CACHE/cooker-request" ]; then
1133 echo '<a class="button icon bell r" href="?poke">Wake up</a>'
1134 else
1135 show_note i 'Cooker will be launched in the next 5 minutes.'
1136 fi
1137 fi
1139 cat <<EOT
1140 <p>
1141 Service logs:
1142 <a href="?cookorder.log">cookorder</a> ·
1143 <a href="?commits.log">commits</a> ·
1144 <a href="?pkgdb.log">pkgdb</a>
1145 </p>
1146 </section>
1147 EOT
1149 part activity
1150 part cooknotes
1151 part commits
1152 part cooklist
1153 part broken
1154 part blocked
1155 part pkgs
1157 echo '</div>'
1158 datalist
1159 page_footer
1160 exit 0
1161 fi
1164 # show tag
1166 if [ "$pkg" == '~' -a -n "$cmd" ]; then
1167 tag="$cmd"
1168 page_header
1169 cat <<EOT
1170 <div id="content2">
1171 <section>
1172 <h2>Tag “$tag”</h2>
1174 <table>
1175 <thead>
1176 <tr><th>Name</th><th>Description</th><th>Category</th></tr>
1177 </thead>
1178 <tbody>
1179 EOT
1180 sort $PKGS/packages.info \
1181 | awk -F$'\t' -vtag=" $tag " -vbase="$base" '{
1182 if (index(" " $6 " ", tag)) {
1183 url = base "/" $1 "/";
1184 gsub("+", "%2B", url);
1185 printf("<tr><td><img src=\"%s/s/%s\"> ", base, $1);
1186 printf("<a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", url, $1, $4, $3);
1188 }'
1189 echo '</tbody></table></section></div>'
1190 page_footer
1191 exit 0
1192 fi
1195 case "$cmd" in
1196 '')
1197 page_header
1199 requested_pkg="$pkg"
1200 # Package info.
1201 if [ ! -f "$wok/$pkg/receipt" ]; then
1202 # Let's look at the cases when the package was not found
1204 # Maybe query is the exact name of split package? -> proceed to main package
1205 mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
1206 if (index(" " $2 " ", pkg)) {print $1; exit}
1207 }' $splitdb)
1209 # No, so let's find any matches among packages names (both main and split)
1210 if [ -z "$mainpkg" ]; then
1211 pkgs=$(cut -d$'\t' -f2 $splitdb | tr ' ' '\n' | fgrep "$pkg")
1212 # Nothing matched
1213 if [ -z "$pkgs" ]; then
1214 echo "<h2>Not Found</h2>"
1215 show_note e "The requested package <b>$pkg</b> was not found on this server."
1216 page_footer; exit 0
1217 fi
1218 # Search results page
1219 echo "<section><h2>Package names matching “$pkg”</h2>"
1220 echo "<table><thead><tr><th>Name</th><th>Description</th><th>Category</th></tr></thead><tbody>"
1221 query="$pkg"
1222 for pkg in $pkgs; do
1223 # Find main package
1224 mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
1225 if (index(" " $2 " ", pkg)) {print $1; exit}
1226 }' $splitdb)
1227 unset SHORT_DESC CATEGORY; . $wok/$mainpkg/receipt
1229 unset SHORT_DESC CATEGORY
1230 [ -e "$wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt" ] &&
1231 . $wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt
1233 echo -n "<tr><td><a href="$base/$pkg">${pkg//$query/<mark>$query</mark>}</a>"
1234 [ "$pkg" == "$mainpkg" ] || echo -n " (${mainpkg//$query/<mark>$query</mark>})"
1235 echo -n "</td><td>$SHORT_DESC</td><td>$CATEGORY</td></tr>"
1236 done
1237 echo '</tbody></table></section>'
1238 page_footer; exit 0
1239 fi
1240 pkg="$mainpkg"
1241 fi
1243 log=$LOGS/$pkg.log
1244 pkg_info
1246 # Check for a log file and display summary if it exists.
1247 summary "$log"
1250 # Show tag list
1251 taglist=$(
1252 for i in $pkg $(awk -F$'\t' -vp="$pkg" '{if ($1 == p) print $2}' $splitdb); do
1253 [ -s "$PKGS/packages.info" ] &&
1254 awk -F$'\t' -vpkg="$i" '{
1255 if ($1 == pkg) { print $6; exit; }
1256 }' "$PKGS/packages.info"
1257 done \
1258 | tr ' ' '\n' \
1259 | sort -u
1261 if [ -n "$taglist" ]; then
1262 echo -n '<section><h3>Tags</h3><p>'
1263 lasttag=$(echo "$taglist" | tail -n1)
1264 for tag in $taglist; do
1265 echo -n "<a href=\"$base/~/${tag//+/%2B}\">$tag</a>"
1266 [ "$tag" != "$lasttag" ] && echo -n " · "
1267 done
1268 echo '</p></section>'
1269 fi
1272 # Informational table with dependencies
1273 pkg="$requested_pkg"
1274 inf="$(mktemp -d)"
1276 # 1/3: Build dependencies (from receipt and pkgdb)
1277 for i in $WANTED $BUILD_DEPENDS $(awk -F$'\t' -vp=" $pkg " '{if (index(" " $2 " ", p) && (" " $1 " " != p)) print $1}' $splitdb); do
1278 echo "$i" >> $inf/a
1279 done
1281 # 2/3: Runtime dependencies (from pkgdb)
1283 [ -s "$PKGS/packages.info" ] &&
1284 awk -F$'\t' -vp="$pkg" '{
1285 if ($1 == p) print $8
1286 }' "$PKGS/packages.info"
1287 } | tr ' ' '\n' | sort -u > $inf/b
1289 # 3/3: Required by (from pkgdb)
1291 for i in $pkg $(awk -F$'\t' -vp="$pkg" '{if ($1 == p) print $2}' $splitdb); do
1292 [ -s "$PKGS/packages.info" ] &&
1293 awk -F$'\t' -vp=" $i " '{
1294 if (index(" " $8 " ", p)) print $1
1295 }' "$PKGS/packages.info"
1297 [ -s "$PKGS/bdeps.txt" ] &&
1298 awk -F$'\t' -vp=" $i " '{
1299 if (index(" " $2 " ", p)) print $1
1300 }' $PKGS/bdeps.txt
1301 done
1302 } | sort -u > $inf/c
1304 cat <<EOT
1305 <section>
1306 <h3>Related packages</h3>
1307 <table class="third">
1308 <thead>
1309 <tr>
1310 <th>Build dependencies</th>
1311 <th>Runtime dependencies</th>
1312 <th>Required by</th>
1313 </tr>
1314 </thead>
1315 <tbody>
1316 EOT
1318 awk -vinf="$inf" -vbase="$base" '
1319 function linki(i) {
1320 if (i) return sprintf("<img src=\"%s/s/%s\"> <a href=\"%s/%s\">%s</a>", base, i, base, i, i);
1322 BEGIN{
1323 do {
1324 a = b = c = "";
1325 getline a < inf "/a";
1326 getline b < inf "/b";
1327 getline c < inf "/c";
1328 printf("<tr><td>%s </td><td>%s </td><td>%s </td></tr>", linki(a), linki(b), linki(c));
1329 } while ( a b c )
1330 }'
1331 cat <<EOT
1332 </tbody>
1333 </table>
1334 </section>
1335 EOT
1336 # Clean
1337 rm -r $inf
1342 # Display <Recook> button only for SliTaz web browser
1343 case "$HTTP_USER_AGENT" in
1344 *SliTaz*)
1345 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
1346 if grep -qs "^$pkg$" $CACHE/recook-packages; then
1347 show_note i "The package “$pkg” has been requested for recook"
1348 else
1349 echo "<a class='button' href='$base/?recook=${pkg//+/%2B}'>Recook $pkg</a>"
1350 fi
1351 fi
1352 ;;
1353 esac
1354 ;;
1356 receipt)
1357 page_header
1358 pkg_info
1359 echo "<a class='button receipt' href='$base/$pkg/receipt'>receipt</a>"
1360 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1361 awk -vb="$base/$pkg" '{printf("<a class=\"button\" href=\"%s/%s\">%s</a>\n", b, $0, $0)}'
1363 show_code bash < $wok/$pkg/receipt
1364 ;;
1366 stuff)
1367 page_header
1368 pkg_info
1369 file="$pkg/stuff/$arg"
1370 echo "<a class='button' href='$base/$pkg/receipt'>receipt</a>"
1371 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1372 awk -vb="$base/$pkg" -va="stuff/$arg" '{
1373 printf("<a class=\"button%s\" href=\"%s/%s\">%s</a>\n", a==$0 ? " receipt" : "", b, $0, $0)
1374 }'
1376 if [ -f "$wok/$file" ]; then
1377 case $file in
1378 *.desktop|*.theme) class="ini" ;;
1379 *.patch|*.diff|*.u) class="diff" ;;
1380 *.sh) class="bash" ;;
1381 *.conf*|*.ini)
1382 class="bash"
1383 [ -n "$(cut -c1 < $wok/$file | fgrep '[')" ] && class="ini"
1384 ;;
1385 *.pl) class="perl" ;;
1386 *.c|*.h|*.awk) class="clike" ;;
1387 *.svg) class="svg" ;;
1388 *Makefile*) class="makefile" ;;
1389 *.po|*.pot) class="bash" ;;
1390 *.css) class="css" ;;
1391 *.htm|*.html) class="html" ;;
1392 *.js) class="js" ;;
1393 *.txt) class="asciidoc" ;;
1394 *)
1395 case $(head -n1 $wok/$file) in
1396 *!/bin/sh*|*!/bin/bash*) class="bash" ;;
1397 esac
1398 if [ -z "$class" -a "$(head -n1 $wok/$file | cut -b1)" == '#' ]; then
1399 class="bash"
1400 fi
1401 if [ -z "$class" ]; then
1402 # Follow Busybox restrictions. Search for non-printable chars
1403 if [ $(tr -d '[:alnum:][:punct:][:blank:][:cntrl:]' < "$wok/$file" | wc -c) -gt 0 ]; then
1404 raw="true"
1405 fi
1406 fi
1407 ;;
1408 esac
1410 # Display image
1411 case $file in
1412 *.png|*.svg|*.jpg|*.jpeg|*.ico)
1413 echo "<img src='$base/$pkg/browse/stuff/$arg' style='display: block; max-width: 100%; margin: auto'/>"
1414 ;;
1415 esac
1417 # Display colored listing for all text-based documents (also for *.svg)
1418 case $file in
1419 *.png|*.jpg|*.jpeg|*.ico) ;;
1420 *)
1421 if [ -z "$raw" ]; then
1422 cat $wok/$file | show_code $class
1423 fi
1424 ;;
1425 esac
1427 # Display hex dump for binary files
1428 if [ -n "$raw" ]; then
1429 hexdump -C $wok/$file | show_code #| sed 's|^\([0-9a-f][0-9a-f]*\)|<span class="c2">\1</span>|'
1430 fi
1431 else
1432 show_note e "File “$file” absent!"
1433 fi
1434 ;;
1436 files)
1437 page_header
1438 pkg_info
1440 # find main package
1441 wanted=$(. $wok/$pkg/receipt; echo $WANTED)
1442 main=${wanted:-$pkg}
1443 devpkg=''; [ -d "$wok/$main-dev" ] && devpkg="$main-dev"
1445 splitsets=$(echo $SPLIT" " \
1446 | awk '
1447 BEGIN { RS = " "; FS = ":"; }
1448 { print $2; }' \
1449 | sort -u \
1450 | tr '\n' ' ' \
1451 | sed 's|^ *||; s| *$||')
1453 splitpkgs=$(echo $SPLIT" " \
1454 | awk '
1455 BEGIN { RS = " "; FS = ":"; }
1456 { print $1; }' \
1457 | tr '\n' ' ' \
1458 | sed 's|^ *||; s| *$||')
1460 # we need the version
1461 if [ -f "$WOK/linux/receipt" ]; then
1462 kvers=$(. $WOK/linux/receipt; echo $VERSION)
1463 kbasevers=$(echo $kvers | cut -d. -f1,2)
1464 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
1465 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
1466 kbasevers=$(echo $kvers | cut -d. -f1,2)
1467 fi
1468 ver=$(. $wok/$main/receipt; echo $VERSION$EXTRAVERSION)
1470 echo "<section><h3>Quick jump:</h3>"
1473 for part in head body; do
1475 for set in '' $splitsets; do
1476 pkgsofset=$(echo $SPLIT" " \
1477 | awk -vset="$set" -vmain="$main" -vdev="$devpkg" '
1478 BEGIN {
1479 RS = " "; FS = ":";
1480 if (!set) print main;
1481 if (!set && dev) print dev;
1484 if ($2 == set) print $1;
1485 }' \
1486 | sort -u)
1488 set_description=''
1489 [ -n "$splitsets" ] &&
1490 case "$set" in
1491 '')
1492 set_description=' (default set)'
1493 set_title='Default set'
1494 ;;
1495 *)
1496 set_description=" (set “$set”)"
1497 set_title="Set “$set”"
1498 ;;
1499 esac
1501 install="$wok/$main/install"
1502 [ -n "$set" ] && install="$install-$set"
1504 case $part in
1505 head)
1506 [ -n "$splitsets" ] &&
1507 case "$set" in
1508 '') echo "<ul><li>Default set:";;
1509 *) echo "<li>Set “$set”:";;
1510 esac
1511 echo -e '\t<ul>'
1512 echo "$pkgsofset" | sed 'p' | xargs printf "\t\t<li><a href='#%s'>%s</a></li>\n"
1513 cat <<EOT
1514 <li id='li-repeats$set' style='display:none'>
1515 <a href='#repeats$set'>repeatedly packaged files</a></li>
1516 <li id='li-empty$set' style='display:none'>
1517 <a href='#empty$set'>unpackaged empty folders</a></li>
1518 <li id='li-outoftree$set' style='display:none'>
1519 <a href='#outoftree$set'>out-of-tree files</a></li>
1520 <li id='li-orphans$set' style='display:none'>
1521 <a href='#orphans$set'>unpackaged files</a>
1522 <span id='orphansTypes$set'></span></li>
1523 EOT
1524 echo -e '\t</ul>'
1525 [ -n "$splitsets" ] && echo "</li>"
1526 ;;
1527 body)
1528 all_files=$(mktemp)
1529 cd $install; find ! -type d | sed 's|\.||' > $all_files
1531 # ------------------------------------------------------
1532 # Packages content
1533 # ------------------------------------------------------
1534 packaged=$(mktemp)
1535 for p in $pkgsofset; do
1536 namever="$(awk -F$'\t' -vp="$p" '{
1537 if ($1==p) {printf("%s-%s\n", $1, $2); exit}
1538 }' $PKGS/packages.info)"
1539 if [ -d "$wok/$p/taz/$p-$ver" ]; then
1540 indir=$p
1541 elif [ -d "$wok/$main/taz/$p-$ver" ]; then
1542 indir=$main
1543 fi
1544 dir="$wok/$indir/taz/$p-$ver/fs"
1546 size=$(du -hs $dir | awk '{ sub(/\.0/, ""); print $1 }')
1548 echo
1549 echo "<section id='$p'>"
1550 echo " <h3>Contents of package “$namever” (${size:-empty}):</h3>"
1551 echo ' <pre class="files">'
1552 if [ -s "$wok/$indir/taz/$p-$ver/files.list" ]; then
1553 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
1554 cd $dir
1555 find . -print0 \
1556 | sort -z \
1557 | xargs -0 ls -ldp --color=always \
1558 | syntax_highlighter files \
1559 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$indir/browse/taz/$p-$ver/fs\2'>\2\3|;" \
1560 | awk 'BEGIN { FS="\""; }
1561 { gsub("+", "%2B", $2); print; }'
1562 else
1563 echo 'No files'
1564 fi
1565 echo '</pre>'
1566 echo '</section>'
1568 cat $wok/$indir/taz/$p-$ver/files.list >> $packaged
1569 done
1570 # ------------------------------------------------------
1571 # /Packages content
1572 # ------------------------------------------------------
1574 # ------------------------------------------------------
1575 # Repeatedly packaged files
1576 # ------------------------------------------------------
1577 repeats=$(mktemp)
1578 sort $packaged | uniq -d > $repeats
1579 if [ -s "$repeats" ]; then
1580 echo
1581 echo "<script>document.getElementById('li-repeats$set').style.display = 'list-item'</script>"
1582 echo "<section id='repeats$set'>"
1583 echo " <h3>Repeatedly packaged files$set_description:</h3>"
1584 cd $install
1586 IFS=$'\n'
1587 echo -n ' <pre class="files">'
1588 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
1589 while read i; do
1590 find .$i -exec ls -ldp --color=always '{}' \; \
1591 | syntax_highlighter files \
1592 | sed 's|>\./|>/|'
1593 done < $repeats
1594 echo '</pre>'
1595 echo '</section>'
1596 unset IFS
1597 fi
1598 rm $repeats
1599 # ------------------------------------------------------
1600 # /Repeatedly packaged files
1601 # ------------------------------------------------------
1603 # ------------------------------------------------------
1604 # Unpackaged empty folders
1605 # ------------------------------------------------------
1606 emptydirs=$(mktemp)
1607 cd $install
1608 IFS=$'\n'
1609 find -type d \
1610 | sed 's|\.||' \
1611 | while read d; do
1612 [ -z "$(ls "$install$d")" ] || continue
1613 # empty dir determined by empty `ls`
1614 echo $d
1615 done \
1616 | while read d; do
1617 notfound='yes'
1618 for p in $(cd $wok/$main/taz; ls); do
1619 if [ -d "$wok/$main/taz/$p/fs$d" ]; then
1620 notfound=''
1621 break
1622 fi
1623 done
1624 [ -n "$notfound" ] &&
1625 ls -ldp --color=always .$d \
1626 | syntax_highlighter files \
1627 | sed 's|>\./|>/|'
1628 done > $emptydirs
1629 unset IFS
1630 if [ -s "$emptydirs" ]; then
1631 echo
1632 echo "<script>document.getElementById('li-empty$set').style.display = 'list-item'</script>"
1633 echo "<section id='empty$set'>"
1634 echo " <h3>Unpackaged empty folders$set_description:</h3>"
1635 echo -n ' <pre class="files">'
1636 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
1637 cat $emptydirs
1638 echo '</pre>'
1639 echo '</section>'
1640 fi
1641 rm $emptydirs
1642 # ------------------------------------------------------
1643 # /Unpackaged empty folders
1644 # ------------------------------------------------------
1646 # ------------------------------------------------------
1647 # Out-of-tree files
1648 # ------------------------------------------------------
1649 outoftree=$(mktemp)
1650 awk -F$'\n' -vall="$all_files" '
1652 if (FILENAME == all) files_all[$1] = "1";
1653 else files_pkg[$1] = "1";
1655 END {
1656 for (i in files_pkg) {
1657 if (! files_all[i]) print i;
1660 ' "$all_files" "$packaged" > $outoftree
1662 if [ -d "$install" -a -s "$outoftree" ]; then
1663 echo
1664 echo "<script>document.getElementById('li-outoftree$set').style.display = 'list-item'</script>"
1665 echo "<section id='outoftree$set'>"
1666 echo " <h3>Out-of-tree files$set_description:</h3>"
1667 echo -n ' <pre class="files">'
1668 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
1669 IFS=$'\n'
1670 while read outoftree_line; do
1671 # Find the package out-of-tree file belongs to
1672 for i in $pkgsofset; do
1673 if grep -q "^$outoftree_line$" $wok/$main/taz/$i-$ver/files.list; then
1674 cd $wok/$main/taz/$i-$ver/fs
1675 ls -ldp --color=always ".$outoftree_line" \
1676 | syntax_highlighter files \
1677 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$main/browse/taz/$i-$ver/fs\2'>\2\3|;" \
1678 | awk 'BEGIN { FS="\""; }
1679 { gsub("+", "%2B", $2); print; }'
1680 fi
1681 done
1682 done < $outoftree
1683 unset IFS
1684 echo '</pre>'
1685 echo '</section>'
1686 fi
1687 rm $outoftree
1688 # ------------------------------------------------------
1689 # /Out-of-tree files
1690 # ------------------------------------------------------
1692 # ------------------------------------------------------
1693 # Unpackaged files
1694 # ------------------------------------------------------
1695 orphans=$(mktemp)
1696 awk -F$'\n' -vall="$all_files" '
1698 if (FILENAME == all) files_all[$1] = "1";
1699 else files_pkg[$1] = "1";
1701 END {
1702 for (i in files_all) {
1703 if (! files_pkg[i]) print i;
1706 ' "$all_files" "$packaged" | sort > $orphans
1707 if [ -d "$install" -a -s "$orphans" ]; then
1708 echo
1709 echo "<script>document.getElementById('li-orphans$set').style.display = 'list-item'</script>"
1710 echo "<section id='orphans$set'>"
1711 echo " <h3>Unpackaged files$set_description:</h3>"
1712 table=$(mktemp)
1713 awk '
1714 function tag(text, color) {
1715 printf("<span class=\"c%s1\">%s</span> ", color, text);
1716 printf("%s\n", $0);
1718 /\/perllocal\.pod$/ || /\/\.packlist$/ ||
1719 /\/share\/bash-completion\// || /\/etc\/bash_completion\.d\// ||
1720 /\/lib\/systemd\// || /\.pyc$/ || /\.pyo$/ ||
1721 /\/fonts\.scale$/ || /\/fonts\.dir$/ || /\.la$/ {
1722 tag("---", 0); next }
1723 /\.pod$/ { tag("pod", 5); next }
1724 /\/share\/man\// { tag("man", 5); next }
1725 /\/share\/doc\// || /\/share\/gtk-doc\// || /\/share\/info\// ||
1726 /\/share\/devhelp\// { tag("doc", 5); next }
1727 /\/share\/icons\// { tag("ico", 2); next }
1728 /\/share\/locale\// { tag("loc", 4); next }
1729 /\.h$/ || /\.a$/ || /\.pc$/ || /\/bin\/.*-config$/ ||
1730 /\/Makefile.*$/ { tag("dev", 3); next }
1731 /\/share\/help\// || /\/share\/appdata\// { tag("gnm", 6); next }
1732 { tag("???", 1) }
1733 ' "$orphans" > $table
1735 # Summary table
1736 orphans_types='()'
1737 for i in head body; do
1738 case $i in
1739 head) echo -n '<table class="summary"><tr>';;
1740 body) echo -n '<th> </th></tr><tr>';;
1741 esac
1742 for j in '???1' dev3 loc4 ico2 doc5 man5 pod5 gnm6 '---0'; do
1743 tag=${j:0:3}; class="c${j:3:1}0"; [ "$class" == 'c00' ] && class='c01'
1744 case $i in
1745 head) echo -n "<th class='$class'>$tag</th>";;
1746 body)
1747 tagscount="$(grep ">$tag<" $table | wc -l)"
1748 printf '<td>%s</td>' "$tagscount"
1749 [ "$tagscount" -gt 0 ] && orphans_types="${orphans_types/)/ $tag)}"
1750 ;;
1751 esac
1752 done
1753 done
1754 echo '<td> </td></tr></table>'
1755 orphans_types="${orphans_types/( /(}"
1756 [ "$orphans_types" != '()' ] &&
1757 echo "<script>document.getElementById('orphansTypes$set').innerText = '${orphans_types// /, }';</script>"
1759 suffix=''; [ -n "$set" ] && suffix="-$set"
1760 echo -n ' <pre class="files">'
1761 echo -en '<span class="underline">tag·permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
1762 IFS=$'\n'
1763 while read orphan_line; do
1764 echo -n "${orphan_line/span> */span>} "
1765 cd $install
1766 ls -ldp --color=always ".${orphan_line#*</span> }" \
1767 | syntax_highlighter files \
1768 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$main/browse/install$suffix\2'>\2\3|;" \
1769 | awk 'BEGIN { FS="\""; }
1770 { gsub("+", "%2B", $2); print; }'
1771 done < $table
1772 unset IFS
1773 echo '</pre>'
1774 echo '</section>'
1775 rm $table
1776 fi
1777 rm $orphans
1778 # ------------------------------------------------------
1779 # /Unpackaged files
1780 # ------------------------------------------------------
1782 rm $all_files $packaged
1783 ;;
1784 esac
1785 done # /set
1787 case "$part" in
1788 head)
1789 [ -n "$splitsets" ] && echo "</ul>"
1790 echo "</section>"
1791 ;;
1792 esac
1793 done # /part
1795 ;;
1797 description)
1798 page_header
1799 pkg_info
1800 descs="$(ls $WOK/$pkg/description*.txt)"
1801 if [ -n "$descs" ]; then
1802 echo '<div id="content2">'
1803 [ -f "$WOK/$pkg/description.txt" ] && show_desc "$pkg" "$WOK/$pkg/description.txt"
1804 for i in $descs; do
1805 case $i in
1806 */description.txt) continue ;;
1807 *) package=$(echo $i | cut -d. -f2) ;;
1808 esac
1809 show_desc "$package" "$i"
1810 done
1811 echo '</div>'
1812 else
1813 show_note w "No description of $pkg"
1814 fi
1815 ;;
1817 log)
1818 page_header
1819 pkg_info
1820 [ -z "$arg" ] && arg=$(stat -c %Y $LOGS/$pkg.log)
1822 echo '<div class="btnList">'
1823 acc='l' # access key for the latest log is 'L'
1824 while read log; do
1825 # for all $pkg.log, $pkg.log.0 .. $pkg.log.9, $pkg-pack.log (if any)
1826 timestamp=$(stat -c %Y $log)
1827 class=''
1828 if [ "$arg" == "$timestamp" ]; then
1829 class=' log'
1830 logfile="$log"
1831 fi
1832 case $log in *-pack.log) acc='p';; esac # access key for the packing log is 'P'
1833 echo -n "<a class='button$class' data-acc='$acc' accesskey='$acc' href='$base/$pkg/log/$timestamp'>"
1834 echo "$(stat -c %y $log | cut -d: -f1,2)</a>"
1835 case $acc in
1836 l) acc=0;;
1837 *) acc=$((acc+1));;
1838 esac
1839 done <<EOT
1840 $(find $LOGS -name "$pkg.log*" | sort)
1841 $(find $LOGS -name "$pkg-pack.log")
1842 EOT
1843 echo '</div>'
1845 if [ -z "$logfile" ]; then
1846 show_note e "Requested log is absent"
1847 page_footer
1848 exit 0
1849 fi
1851 # Define cook variables for syntax highlighter
1852 if [ -s "$WOK/$pkg/receipt" ]; then
1853 . "$WOK/$pkg/receipt"
1854 _wok='/home/slitaz/wok'
1855 _src="$_wok/$pkg/source/$PACKAGE-$VERSION"
1856 _install="$_wok/$pkg/install"
1857 _fs="$_wok/$pkg/taz/$PACKAGE-$VERSION/fs"
1858 _stuff="$_wok/$pkg/stuff"
1859 fi
1861 # if [ ! -f "gzlog/$pkg.$arg" ]; then
1862 # {
1863 # summary "$logfile" links
1865 # syntax_highlighter log < $logfile | awk '
1866 # BEGIN { print "<pre class=\"log\">"; }
1867 # { printf("<a name=\"l%d\" href=\"#l%d\">%5d</a> %s\n", NR, NR, NR, $0); }
1868 # END { print "</pre>"; }
1869 # '
1871 # page_footer
1872 # } | gzip > gzlog/$pkg.$arg
1873 # fi
1875 blog=$(basename $logfile)
1876 summary "$logfile" links
1878 # disable next `sed` for the 'like2016' theme
1879 theme=$(COOKIE theme); theme=${theme:-default}; [ "$theme" != 'like2016' ] && theme=''
1880 cat $logfile | syntax_highlighter log | \
1881 sed -e "/(pkg\/local$theme):/ s|: \([^<]*\)|<img src='$base/i/$blog/\1'> \1|" | \
1882 awk '
1883 BEGIN { print "<pre class=\"log\">"; }
1884 { printf("<span id=\"l%d\">%s</span><a href=\"#l%d\"></a>\n", NR, $0, NR); }
1885 END { print "</pre>"; }
1887 ;;
1890 man|doc|info)
1891 page_header
1892 pkg_info
1893 echo '<div style="max-height: 6.4em; overflow: auto; padding: 0 4px">'
1895 dir="wok/$pkg/install/usr/share/$cmd"
1896 [ "$cmd" == 'doc' ] && dir="$dir wok/$pkg/install/usr/share/gtk-doc"
1897 if [ "$cmd" == 'doc' -a -z "$arg" ]; then
1898 try=$(for i in $dir; do find $i -name 'index.htm*'; done | sed q)
1899 [ -n "$try" ] && arg="$try"
1900 fi
1901 while read i; do
1902 [ -s "$i" ] || continue
1903 case "$i" in
1904 *.jp*g|*.png|*.gif|*.svg|*.css) continue
1905 esac
1906 i=${i#$dir/}
1907 [ -n "$arg" ] || arg="$i"
1908 class=''; [ "$arg" == "$i" ] && class=" doc"
1909 case "$cmd" in
1910 man)
1911 case $i in
1912 man*) lang='';;
1913 *) lang="${i%%/*}: ";;
1914 esac
1915 man=$(basename $i .gz)
1916 echo "<a class='button$class' href='$base/$pkg/man/$i'>$lang${man%.*} (${man##*.})</a>"
1917 ;;
1918 doc)
1919 echo "<a class='button$class' href='$base/$pkg/doc/$i'>$(basename $i .gz)</a>"
1920 ;;
1921 info)
1922 info=$(basename $i)
1923 echo "<a class='button$class' href='$base/$pkg/info/$i#Top'>${info/.info/}</a>"
1924 ;;
1925 esac
1926 done <<EOT
1927 $(for i in $dir; do find $i -type f; done | sort)
1928 EOT
1929 echo '</div>'
1931 [ -f "$arg" ] || arg="$dir/$arg"
1932 if [ -f "$arg" ]; then
1933 tmp="$(mktemp)"
1934 docat "$arg" > $tmp
1935 [ -s "$tmp" ] &&
1936 case "$cmd" in
1937 info)
1938 echo '<div id="content2" class="texinfo"><pre class="first">'
1939 info2html < "$tmp"
1940 echo '</pre></div>'
1941 ;;
1942 doc)
1943 case "$arg" in
1944 *.sgml|*.devhelp2) class='xml';;
1945 *.py) class='python';; # pycurl package
1946 *.css) class='css';;
1947 *.sh) class='bash';;
1948 *)
1949 first=$(head -n1 "$tmp")
1950 if [ "${first:0:1}" == '#' ]; then
1951 class='bash' # first line begins with '#'
1952 else
1953 class='asciidoc'
1954 fi;;
1955 esac
1956 case "$arg" in
1957 *.htm*)
1958 case $arg in
1959 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
1960 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
1961 esac
1962 # make the iframe height so long to contain its contents without scrollbar
1963 echo "<iframe id='idoc' src='$page' width='100%' onload='resizeIframe(this)'></iframe>"
1964 ;;
1965 *.pdf)
1966 case $arg in
1967 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
1968 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
1969 esac
1970 cat <<EOT
1971 <object id="idoc" data="$page" width="100%" height="100%" type="application/pdf" style="min-height: 600px">
1972 $(show_note w "Missing PDF plugin.<br/>Get the file <a href="$page">$(basename "$page")</a>.")
1973 </object>
1974 EOT
1975 ;;
1976 *.md|*.markdown)
1977 echo '<section>'
1978 $md2html "$tmp"
1979 echo '</section>'
1980 ;;
1981 *)
1982 show_code $class < "$tmp"
1983 ;;
1984 esac
1985 ;;
1986 man)
1987 #export TEXTDOMAIN='man2html'
1988 echo "<div id='content2'>"
1990 html=$(./man2html.bin "$tmp" | sed -e '1,/<header>/d' -e '/<footer>/,$d' \
1991 -e 's|<a href="file:///[^>]*>\([^<]*\)</a>|\1|g' \
1992 -e 's|<a href="?[1-9]\+[^>]*>\([^<]*\)</a>|\1|g')
1994 if [ -n "$(echo "$html" | fgrep 'The requested file /tmp/tmp.')" ]; then
1995 # Process the pre-formatted man-cat page
1996 # (for example see sudo package without groff in build dependencies)
1997 sed -i '
1998 s|M-bM-^@M-^S|—|g;
1999 s|M-bM-^@M-^\\|<b>|g;
2000 s|M-bM-^@M-^]|</b>|g
2001 s|M-bM-^@M-^X|<u>|g;
2002 s|M-bM-^@M-^Y|</u>|g;
2003 s|M-BM-||g;
2004 s|++oo|•|g;
2005 s|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g;
2006 ' "$tmp"
2007 for i in a b c d e f g h i j k l m n o p q r s t u v w x y z \
2008 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \
2009 0 1 2 3 4 5 6 7 8 9 _ - '\\+' '\.' /; do
2010 sed -i "s|$i$i|<b>$i</b>|g; s|_$i|<u>$i</u>|g" "$tmp"
2011 done
2012 echo '<pre class="catman">'
2013 sed 's|</b><b>||g; s|</u><u>||g; s|</u><b>_</b><u>|_|g; s|</b> <b>| |g;' "$tmp"
2014 echo '</pre>'
2015 else
2016 echo "$html"
2017 fi
2018 echo "</div>"
2019 ;;
2020 esac
2021 rm -f $tmp
2022 else
2023 show_note e "File “$arg” does not exist!"
2024 fi
2025 ;;
2027 download)
2028 page_header
2029 pkg_info
2030 show=0
2032 . $wok/$pkg/receipt
2034 if [ -n "$TARBALL" -a -s "$SRC/$TARBALL" ]; then
2035 files_header
2036 echo "<tr><td><a href='$base/src/$TARBALL'>$TARBALL</a></td>"
2037 ls -lh "$SRC/$TARBALL" | awk '{printf("<td>%sB</td>", $5)}'
2038 echo "<td>Sources for building the package “$pkg”</td></tr>"
2039 show=1
2040 fi
2042 if [ -d "$wok/$pkg/taz" ]; then
2043 [ "$show" -eq 1 ] || files_header
2045 common_version=$VERSION
2046 for i in $(all_names); do
2047 [ -e "$wok/$pkg/taz/$i-$common_version$EXTRAVERSION/receipt" ] || continue
2048 . $wok/$pkg/taz/$i-$common_version$EXTRAVERSION/receipt
2050 for filename in "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg"; do
2051 [ -f "$PKGS/$filename" ] &&
2052 cat <<EOT
2053 <tr>
2054 <td><a href="$base/get/$filename">$filename</a></td>
2055 <td>$(ls -lh ./packages/$filename | awk '{printf("%sB", $5)}')</td>
2056 <td>$SHORT_DESC</td>
2057 </tr>
2058 EOT
2059 done
2060 done
2061 show=1
2062 fi
2064 if [ "$show" -eq 1 ]; then
2065 echo '</tbody></table></section>'
2066 else
2067 show_note w "Sorry, there's nothing to download…"
2068 fi
2069 ;;
2071 esac
2074 page_footer
2075 exit 0