cookutils view lighttpd/index.cgi @ rev 933

cook: fix commands --clean, --getsrc, --block, --unblock; lighttpd/index.cgi: add rich statistics on main page.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sun Jun 18 15:13:29 2017 +0300 (2017-06-18)
parents 51eafb844ec4
children 49ff02f8d304
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"
35 # Path to markdown to html convertor
36 cmark_opts='--smart -e table -e strikethrough -e autolink -e tagfilter'
37 if [ -n "$(which cmark 2>/dev/null)" ]; then
38 md2html="$(which cmark) $cmark_opts"
39 elif [ -x "./cmark" ]; then
40 md2html="./cmark $cmark_opts"
41 elif [ -n "$(which sundown 2>/dev/null)" ]; then
42 md2html=$(which sundown)
43 elif [ -x "./sundown" ]; then
44 md2html="./sundown"
45 fi
50 # Search form redirection
51 if [ -n "$(GET search)" ]; then
52 echo -e "HTTP/1.1 301 Moved Permanently\nLocation: $base/$(GET q)\n\n"
53 exit 0
54 fi
57 # Show the running command and it's progression
59 running_command() {
60 state="$(cat $command)"
61 local pct=''
62 if [ -n "$state" ];then
63 echo -n "$state</td></tr><tr><td>Completion</td>"
64 set -- $(grep "^$state" $cooktime)
65 [ -n "$1" -a $2 -ne 0 ] && pct=$((($(date +%s)-$3)*100/$2))
66 [ -n "$pct" ] && max="max='100'"
67 echo -n "<td><progress id='gauge' $max value='$pct' title='Click to stop updating' onclick='stopUpdating()'>"
68 echo -n "</progress> <span id='pct'>${pct:-?}%</span>"
69 [ "$2" -gt 60 ] &&
70 echo -n "</td></tr><tr><td>Estimated end time</td><td>$(date +%H:%M -ud @$(($2+$3)))"
71 else
72 echo 'not running'
73 fi
74 }
77 # HTML page header
79 page_header() {
80 local theme t='' css
81 theme=$(COOKIE theme)
82 [ "$theme" == 'default' ] && theme=''
83 [ -n "$theme" ] && theme="-$theme"
84 css="cooker$theme.css"
86 echo -e 'Content-Type: text/html; charset=UTF-8\n'
88 cat <<EOT
89 <!DOCTYPE html>
90 <html lang="en">
91 <head>
92 <title>$([ -n "$pkg" ] && echo "$pkg - ")$title</title>
93 <link rel="stylesheet" href="/$css">
94 <link rel="icon" type="image/png" href="/slitaz-cooker.png">
95 <link rel="search" href="$base/os.xml" title="$title" type="application/opensearchdescription+xml">
96 <!-- mobile -->
97 <meta name="viewport" content="width=device-width, initial-scale=1.0">
98 <meta name="theme-color" content="#222">
99 <!-- rss -->
100 <link rel="alternate" type="application/rss+xml" title="$title Feed" href="?rss">
101 </head>
102 <body>
103 <div id="container">
104 <header>
105 <h1><a href="$base/">$title</a></h1>
106 <div class="network">
107 <a href="http://www.slitaz.org/">Home</a>
108 <a href="http://bugs.slitaz.org/">Bugs</a>
109 <a href="http://hg.slitaz.org/wok-next/">Hg</a>
110 <a href="http://roadmap.slitaz.org/">Roadmap</a>
111 <a href="http://pizza.slitaz.me/">Pizza</a>
112 <a href="http://tank.slitaz.org/">Tank</a>
113 |
114 <a href="$base/cross/">Cross</a>
115 <a href="$base/i486.cgi">i486</a>
116 <a href="$base/cookiso.cgi">ISO</a>
117 <select onChange="window.location.href=this.value" style="display: none">
118 <option value=".">Go to…</option>
119 <option value="http://www.slitaz.org/">Home</option>
120 <option value="http://bugs.slitaz.org/">Bug tracker</option>
121 <option value="http://hg.slitaz.org/wok/">Hg wok</option>
122 <option value="http://roadmap.slitaz.org/">Roadmap</option>
123 <option value="http://pizza.slitaz.me/">Pizza</option>
124 <option value="http://tank.slitaz.org/">Tank</option>
125 <option disabled>---------</option>
126 <option value="cross/">Cross</option>
127 <option value="i486.cgi">i486</option>
128 <option value="cookiso.cgi">ISO</option>
129 </select>
130 </div>
131 </header>
133 <main>
134 EOT
136 [ -n "$(GET debug)" ] && echo "<pre><code class='language-ini'>$(env | sort)</code></pre>"
137 }
140 # HTML page footer
142 page_footer() {
143 date_now=$(date +%s)
144 sec_now=$(date +%S); sec_now=${sec_now#0} # remove one leading zero
145 wait_sec=$(( 60 - $sec_now ))
146 cat <<EOT
147 </main>
149 <footer>
150 <a href="http://www.slitaz.org/">SliTaz Website</a>
151 <a href="$base/">Cooker</a>
152 <a href="$base/doc/cookutils/cookutils.html">Documentation</a>
153 <a href="$base/?theme">Theme</a>
154 </footer>
155 </div>
156 <script src="/cooker.js"></script>
157 <script>refreshDate(${wait_sec}000, ${date_now}000)</script>
158 </body>
159 </html>
160 EOT
161 }
164 show_note() {
165 echo "<div class='bigicon-$1'>$2</div>"
166 }
169 not_found() {
170 local file="${1#$PKGS/}"; file="${file#$LOGS/}"; file="${file#$WOK/}"
171 echo "HTTP/1.1 404 Not Found"
172 page_header
173 echo "<h2>Not Found</h2>"
174 case $2 in
175 pkg)
176 show_note e "The requested package “$(basename "$(dirname "$file")")” was not found." ;;
177 *)
178 show_note e "The requested file “$file” was not found." ;;
179 esac
180 page_footer
181 }
184 manage_modified() {
185 local file="$1" option="$2" nul day mon year time hh mm ss date_s
186 if [ ! -f "$file" ]; then
187 if [ "$option" == 'silently-absent' ]; then
188 echo "HTTP/1.1 404 Not Found"
189 return
190 else
191 not_found "$file" "$2"
192 exit
193 fi
194 fi
195 [ "$option" == 'no-last-modified' ] && return
196 if [ -n "$HTTP_IF_MODIFIED_SINCE" ]; then
197 echo "$HTTP_IF_MODIFIED_SINCE" | \
198 while read nul day mon year time nul; do
199 case $mon in
200 Jan) mon='01';; Feb) mon='02';; Mar) mon='03';; Apr) mon='04';;
201 May) mon='05';; Jun) mon='06';; Jul) mon='07';; Aug) mon='08';;
202 Sep) mon='09';; Oct) mon='10';; Nov) mon='11';; Dec) mon='12';;
203 esac
204 hh=$(echo $time | cut -d: -f1)
205 mm=$(echo $time | cut -d: -f2)
206 ss=$(echo $time | cut -d: -f3)
207 date_s=$(date -ud "$year$mon$day$hh$mm.$ss" +%s)
208 # if [ "$date_s" -ge "$(date -ur "$file" +%s)" ]; then
209 # echo -e 'HTTP/1.1 304 Not Modified\n'
210 # exit
211 # fi
212 # TODO: improve caching control
213 done
214 fi
215 echo "Last-Modified: $(date -Rur "$file" | sed 's|UTC|GMT|')"
216 echo "Cache-Control: public, max-age=3600"
217 }
220 # Query '?pct=<package>': update percentage
222 if [ -n "$(GET pct)" ]; then
223 pkg="$(GET pct)"
224 state="$(cat $command)"
225 if [ "$state" == "cook:$pkg" ]; then
226 set -- $(grep "^$state" $cooktime)
227 [ -n "$1" ] && pct=$(( ($(date +%s) - $3) * 100 / $2 ))
228 echo "${pct:-?}"
229 else
230 echo 'reload'
231 fi
232 exit 0
233 fi
236 # Query '?poke': poke cooker
238 if [ -n "$(GET poke)" ]; then
239 touch $CACHE/cooker-request
240 echo -e "Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}\n"
241 exit
242 fi
245 # Query '?recook=<package>': query to recook package
247 if [ -n "$(GET recook)" ]; then
248 pkg="$(GET recook)"
249 case "$HTTP_USER_AGENT" in
250 *SliTaz*)
251 grep -qs "^$pkg$" $CACHE/recook-packages ||
252 echo "$pkg" >> $CACHE/recook-packages
253 esac
254 echo -e "Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}\n"
255 exit
256 fi
259 # Query '/i/<log>/<pkg>': show indicator icon
260 # Can't use ?query - not able to change '+' to '%2B' in the sed rules (see log handler)
262 if [ "$pkg" == 'i' ]; then
263 echo -en "Content-Type: image/svg+xml\n\n<svg xmlns='http://www.w3.org/2000/svg' height='12' width='8'><path d='"
264 if [ $LOGS/$cmd -nt $PKGS/$arg.tazpkg ]; then
265 echo "m1 2-1 1v8l1 1h6l1-1v-8l-1-1z' fill='#090'/></svg>"
266 else
267 echo "m0 3v8l1 1h6l1-1v-8l-1-1h-6zm3 0h2v5h-2zm0 6h2v2h-2z' fill='#d00'/></svg>"
268 fi
269 exit
270 fi
273 # Query '?theme[=<theme>]': change UI theme
275 if [ -n "$(GET theme)" ]; then
276 theme="$(GET theme)"
277 ref="$(echo "$HTTP_REFERER" | sed 's|:|%3A|g; s|/|%2F|g; s|\?|%3F|g; s|\+|%2B|g;')"
278 case $theme in
279 theme)
280 current=$(COOKIE theme)
281 page_header
282 cat <<EOT
283 <section>
284 <h2>Change theme</h2>
285 <p>Current theme: “${current:-default}”. Select other:</p>
286 <ul>
287 $(
288 for i in default emerald sky goldenrod midnight like2016 terminal; do
289 [ "$i" == "${current:-default}" ] || echo "<li><a href=\"$base/?theme=$i&amp;ref=$ref\">$i</a></li>"
290 done
291 )
292 </ul>
293 </section>
294 EOT
295 page_footer
296 exit 0
297 ;;
298 default|emerald|sky|goldenrod|midnight|like2016|terminal)
299 ref="$(GET ref)"
300 [ -n "$ref" ] || ref="$base/"
301 # Expires in a year
302 expires=$(date -uRd @$(($(date +%s)+31536000)) | sed 's|UTC|GMT|')
303 echo -e "HTTP/1.1 302 Found\nLocation: $ref\nCache-Control: no-cache\nSet-Cookie: theme=$theme; expires=$expires\n\n"
304 exit 0
305 ;;
306 esac
307 fi
310 #case "$QUERY_STRING" in
311 # stuff*)
312 # file="$wok/$(GET stuff)"
313 # manage_modified "$file"
314 # ;;
315 #
316 # pkg=*|receipt=*|description=*|files=*|log=*|man=*|doc=*|info=*)
317 # type=${QUERY_STRING%%=*}
318 # pkg=$(GET $type)
319 # case "$type" in
320 # description)
321 # manage_modified "$wok/$pkg/receipt" 'no-last-modified'
322 # manage_modified "$wok/$pkg/description.txt" 'silently-absent'
323 # ;;
324 # log)
325 # manage_modified "$wok/${pkg%%.log*}/receipt" 'no-last-modified'
326 # manage_modified "$LOGS/$pkg"
327 # ;;
328 # *)
329 # manage_modified "$wok/$pkg/receipt" pkg
330 # ;;
331 # esac
332 # ;;
333 #esac
336 # RSS feed generator
337 # URI: ?rss[&limit={1..100}]
339 if [ -n "$(GET rss)" ]; then
340 limit=$(GET limit); limit="${limit:-12}"; [ "$limit" -gt 100 ] && limit='100'
341 pubdate=$(date -Rur$(ls -t $FEEDS/*.xml | head -n1) | sed 's|UTC|GMT|')
342 cooker_url="http://$HTTP_HOST$base/"
343 cat <<EOT
344 Content-Type: application/rss+xml
346 <?xml version="1.0" encoding="utf-8" ?>
347 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
348 <channel>
349 <title>$title</title>
350 <description>The SliTaz packages cooker feed</description>
351 <link>$cooker_url</link>
352 <lastBuildDate>$pubdate</lastBuildDate>
353 <pubDate>$pubdate</pubDate>
354 <atom:link href="$cooker_url?rss" rel="self" type="application/rss+xml" />
355 EOT
356 for rss in $(ls -t $FEEDS/*.xml | head -n$limit); do
357 sed "s|http[^=]*=|$cooker_url|; s|<guid|& isPermaLink=\"false\"|g; s|</pubDate| GMT&|g" $rss
358 done
359 cat <<EOT
360 </channel>
361 </rss>
362 EOT
363 exit 0
364 fi
367 ### OpenSearch ###
369 # Query '/os.xml': get OpenSearch Description
371 if [ "$pkg" == 'os.xml' ]; then
372 cat <<EOT
373 Content-Type: application/xml; charset=UTF-8
375 <?xml version="1.0" encoding="UTF-8"?>
376 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
377 <ShortName>$title</ShortName>
378 <Description>SliTaz packages search</Description>
379 <Image width="16" height="16" type="image/png">http://$HTTP_HOST/images/logo.png</Image>
380 <Url type="text/html" method="GET" template="http://$HTTP_HOST$base/{searchTerms}"/>
381 <Url type="application/x-suggestions+json" method="GET" template="http://$HTTP_HOST$base/">
382 <Param name="oss" value="{searchTerms}"/>
383 </Url>
384 <SearchForm>http://$HTTP_HOST$base/</SearchForm>
385 <InputEncoding>UTF-8</InputEncoding>
386 </OpenSearchDescription>
387 EOT
388 exit 0
389 fi
391 # Query '?oss[=<term>]': OpenSearch suggestions
393 if [ -n "$(GET oss)" ]; then
394 term="$(GET oss | tr -cd '[:alnum:]+-')"
395 echo -e 'Content-Type: application/x-suggestions+json; charset=UTF-8\n'
396 cd $wok
397 ls | fgrep "$term" | head -n10 | awk -vterm="$term" '
398 BEGIN{printf("[\"%s\",[", term)}
399 {printf("%s\"%s\"", NR != 1 ? "," : "", $0)}
400 END {printf("]]")}
401 '
402 exit 0
403 fi
408 #
409 # Functions
410 #
413 # Unpack to stdout
415 docat() {
416 case "$1" in
417 *gz) zcat ;;
418 *bz2) bzcat ;;
419 *xz) xzcat ;;
420 *) cat
421 esac < $1
422 }
425 # Tiny texinfo converter
427 info2html() {
428 sed \
429 -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g' \
430 -e 's|^\* \(.*\)::|* <a href="#\1">\1</a> |' \
431 -e 's|\*note \(.*\)::|<a href="#\1">\1</a>|' \
432 -e '/^File: / s|(dir)|Top|g' \
433 -e '/^File: / s|Next: \([^,]*\)|<a class="button" href="#\1">Next: \1</a>|' \
434 -e '/^File: / s|Prev: \([^,]*\)|<a class="button" href="#\1">Prev: \1</a>|' \
435 -e '/^File: / s|Up: \([^,]*\)|<a class="button" href="#\1">Up: \1</a>|' \
436 -e '/^File: / s|^.* Node: \([^,]*\), *\(.*\)$|<pre id="\1">\2|' \
437 -e '/^<pre id=/ s|^\([^>]*>\)\(<a[^>]*>Next: [^,]*\), *\(<a[^>]*>Prev: [^,]*\), *\(<a[^>]*>Up: .*\)|\1 \3 \4 \2|' \
438 -e '/^Tag Table:$/,/^End Tag Table$/d' \
439 -e '/INFO-DIR/,/^END-INFO-DIR/d' \
440 -e "s|https*://[^>),'\"\`’ ]*|<a href=\"&\">&</a>|g" \
441 -e "s|ftp://[^>),\"\` ]*|<a href=\"&\">&</a>|g" \
442 -e 's|^\* Menu:|<b>Menu:</b>|' \
443 -e "s|^|</pre>|"
444 }
447 # Put some colors into log and DB files.
449 syntax_highlighter() {
450 case $1 in
451 log)
452 # If variables not defined - define them with some rare values
453 : ${_src=#_#_#}
454 : ${_install=#_#_#}
455 : ${_fs=#_#_#}
456 : ${_stuff=#_#_#}
457 # Use one-letter html tags to save some bytes :)
458 # <b>is error (red)</b> <u>is warning (orange)</u> <i>is informal (green)</i>
459 sed -e 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g' \
460 -e 's#OK$#<i>OK</i>#' \
461 -e 's#\([Dd]one\)$#<i>\1</i>#' \
462 -e 's#Success$#<i>Success</i>#' \
463 -e 's#\([^a-z]\)ok$#\1<i>ok</i>#' \
464 -e 's#\([^a-z]\)yes$#\1<i>yes</i>#' \
465 -e 's#\([^a-z]\)ON$#\1<i>ON</i>#' \
466 -e 's#\([^a-z]\)no$#\1<u>no</u>#' \
467 -e 's#\([^a-z]\)none$#\1<u>none</u>#' \
468 -e 's#\([^a-z]\)false$#\1<u>false</u>#' \
469 -e 's#\([^a-z]\)OFF$#\1<u>OFF</u>#' \
470 -e 's#\(^checking .*\.\.\. \)\(.*\)$#\1<i>\2</i>#' \
471 \
472 -e 's#\( \[Y[nm/]\?\] n\)$# <u>\1</u>#' \
473 -e 's#\( \[N[ym/]\?\] y\)$# <i>\1</i>#' \
474 -e 's# y$# <i>y</i>#' \
475 -e 's# n$# <u>n</u>#' \
476 -e 's#(NEW) *$#<b>(NEW)</b>#' \
477 \
478 -e 's#.*(pkg/local).*#<i>\0</i>#' \
479 -e 's#.*(web/cache).*#<u>\0</u>#' \
480 \
481 -e 's#\([^a-zA-Z]\)\([Ee]rror\)$#\1<b>\2</b>#' \
482 -e 's#ERROR:#<b>ERROR:</b>#g' \
483 \
484 -e 's#^.*[Ff][Aa][Ii][Ll][Ee][Dd].*#<b>\0</b>#' \
485 -e 's#^.*[Ff]atal.*#<b>\0</b>#' \
486 -e 's#^.*[Nn]ot found.*#<b>\0</b>#' \
487 -e 's#^.*[Nn]o such file.*#<b>\0</b>#' \
488 -e 's#^.*No package .* found.*#<b>\0</b>#' \
489 -e 's#^.*Unable to find.*#<b>\0</b>#' \
490 -e 's#^.*[Ii]nvalid.*#<b>\0</b>#' \
491 -e 's#\([Nn][Oo][Tt] found\.*\)$#<b>\1</b>#' \
492 -e 's#\(found\.*\)$#<i>\1</i>#' \
493 \
494 -e 's#^.*WARNING:.*#<u>\0</u>#' \
495 -e 's#^.*warning:.*#<u>\0</u>#' \
496 -e 's#^.* [Ee]rror:* .*#<b>\0</b>#' \
497 -e 's#^.*terminated.*#<b>\0</b>#' \
498 -e 's#\(missing\)#<b>\1</b>#g' \
499 -e 's#^.*[Cc]annot find.*#<b>\0</b>#' \
500 -e 's#^.*unrecognized options.*#<u>\0</u>#' \
501 -e 's#^.*does not.*#<u>\0</u>#' \
502 -e 's#^.*[Ii]gnoring.*#<u>\0</u>#' \
503 -e 's#^.*note:.*#<u>\0</u>#' \
504 \
505 -e 's#^.* will not .*#<u>\0</u>#' \
506 -e 's!^Hunk .* succeeded at .*!<u>\0</u>!' \
507 -e 's#^.* Warning: .*#<u>\0</u>#' \
508 \
509 -e "s#^Executing:\([^']*\).#<em>\0</em>#" \
510 -e "s#^Making.*#<em>\0</em>#" \
511 -e "s#^Scanning dependencies of target .*#<em>\0</em>#" \
512 -e "s#^====\([^']*\).#<span class='span-line'>\0</span>#g" \
513 -e "s#^[a-zA-Z0-9]\([^']*\) :: #<span class='span-sky'>\0</span>#g" \
514 -e "s#[fh]tt*ps*://[^ '\"]*#<a href='\0'>\0</a>#g" \
515 \
516 -e "s|$_src|<span class='var'>\${src}</span>|g;
517 s|$_install|<span class='var'>\${install}</span>|g;
518 s|$_fs|<span class='var'>\${fs}</span>|g;
519 s|$_stuff|<span class='var'>\${stuff}</span>|g" \
520 -e "s|\[9\([1-6]\)m|<span class='c\10'>|;
521 s|\[39m|</span>|;"
522 ;;
524 files)
525 # Highlight the Busybox's `ls` output
526 awk '{
527 part1 = substr($0, 0, 16);
528 part2 = substr($0, 17, 9);
529 part3 = substr($0, 26, 9);
530 part4 = substr($0, 35);
531 if (part2 != "root ") part2 = "<span class=\"c11\">" part2 "</span>";
532 if (part3 != "root ") part3 = "<span class=\"c11\">" part3 "</span>";
533 print part1 part2 part3 part4;
534 }' | \
535 sed "s|\[0m/|/\[0m|g;
536 s|\[\([01]\);3\([1-7]\)m|<a class='c\2\1'>|g;
537 s|\[\([01]\);0m|<a class='c0\1'>|g;
538 s|\[0m|</a>|g;
539 s|^\(lrwxrwxrwx\)|<span class='c61'>\1</span>|;
540 s|^\(-rwxr-xr-x\)|<span class='c21'>\1</span>|;
541 s|^\(-rw-r--r--\)|<span class='c31'>\1</span>|;
542 s|^\(drwxr-xr-x\)|<span class='c41'>\1</span>|;
543 s|^\([lrwxs-]*\)|<span class='c11'>\1</span>|;
544 "
545 ;;
546 esac
547 }
550 show_code() {
551 echo -n "<pre><code class=\"language-$1\">"
552 sed 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g'
553 echo '</code></pre>'
554 }
557 datalist() {
558 (
559 cd $wok
561 ls | awk '
562 BEGIN{printf("<datalist id=\"packages\">")}
563 {printf("<option>%s</option>",$1)}
564 END {printf("</datalist>")}
565 '
566 )
567 }
570 mklog() {
571 awk '
572 BEGIN { printf("<pre class=\"log dog\">\n") }
573 { print }
574 END { print "</pre>" }'
575 }
578 summary() {
579 log="$1"
580 pkg="$(basename ${log%%.log*})"
582 if [ -f "$log" ]; then
583 if grep -q "cook:$pkg$" $command; then
584 show_note i "The Cooker is currently building $pkg"
585 elif fgrep -q "Summary for:" $log; then
586 sed '/^Summary for:/,$!d' $log | awk '
587 BEGIN { print "<section>" }
588 function row(line) {
589 split(line, s, " : ");
590 printf("\t<tr><td>%s</td><td>%s</td></tr>\n", s[1], s[2]);
591 }
592 function row2(line, rowNum) {
593 split(line, s, " : ");
594 if (rowNum == 1)
595 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]);
596 else
597 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]);
598 }
599 {
600 if (NR==1) { printf("<h3>%s</h3>\n<table>\n", $0); next }
601 if ($0 ~ "===") { seen++; if (seen == 1) next; else exit; }
602 if ($0 ~ "---") {
603 seen2++;
604 if (seen2 == 1) printf("</table>\n<table class=\"pkgslist\">\n")
605 next
606 }
607 if (seen2) row2($0, seen2); else row($0);
608 }
609 END { print "</table></section>" }
610 '
611 elif fgrep -q "Debug information" $log; then
612 echo -e '<section>\n<h3>Debug information</h3>'
613 sed -e '/^Debug information/,$!d; /^===/d; /^$/d' $log | sed -n '1!p' | \
614 if [ -n "$2" ]; then
615 syntax_highlighter log | sed 's|\([0-9][0-9]*\):|<a href="#l\1">\1</a>:|'
616 else
617 sed 's|^[0-9][0-9]*:||' | syntax_highlighter log
618 fi | mklog
619 echo '</section>'
620 fi
621 else
622 [ -n "$pkg" -a -d "$wok/$pkg" ] && show_note e "No log for $pkg"
623 fi
624 }
627 active() {
628 [ "$cmd" == "$1" -o "$cmd" == "${2:-$1}" ] && echo -n ' active'
629 }
632 pkg_info() {
633 local log active bpkg
634 log="$LOGS/$pkg.log"
636 echo "<h2><a href=\"$base/$pkg\">$pkg</a></h2>"
637 echo '<div id="info">'
638 echo "<a class='button icon receipt$(active receipt stuff)' href='$base/$pkg/receipt'>receipt &amp; stuff</a>"
640 unset WEB_SITE WANTED
641 . $wok/$pkg/receipt
643 [ -n "$WEB_SITE" ] &&
644 echo "<a class='button icon website' href='$WEB_SITE' target='_blank' rel='noopener noreferrer'>web site</a>"
646 [ -f "$wok/$pkg/taz/$PACKAGE-$VERSION/receipt" ] &&
647 echo "<a class='button icon files$(active files)' href='$base/$pkg/files'>files</a>"
649 [ -n "$(ls $wok/$pkg/description*.txt)" ] &&
650 echo "<a class='button icon desc$(active description)' href='$base/$pkg/description'>description</a>"
652 [ -n "$TARBALL" -a -s "$SRC/$TARBALL" -o -d "$wok/$pkg/taz" ] &&
653 echo "<a class='button icon download' href='$base/$pkg/download'>download</a>"
655 echo "<a class='button icon browse' href='$base/$pkg/browse/'>browse</a>"
657 [ -x ./man2html -a -d "$wok/$pkg/install/usr/share/man" ] &&
658 echo "<a class='button icon doc$(active man)' href='$base/$pkg/man/'>man</a>"
660 [ -d "$wok/$pkg/install/usr/share/doc" -o -d "$wok/$pkg/install/usr/share/gtk-doc" ] &&
661 echo "<a class='button icon doc$(active doc)' href='$base/$pkg/doc/'>doc</a>"
663 [ -d "$wok/$pkg/install/usr/share/info" ] &&
664 echo "<a class='button icon doc$(active info)' href='$base/$pkg/info/#Top'>info</a>"
666 [ -s "$log" ] &&
667 echo "<a class='button icon log$(active log)' href='$base/$pkg/log/'>logs</a>"
669 echo '</div>'
670 }
673 mktable() {
674 sed 's# : #|#' | awk -vc="$1" '
675 BEGIN { printf("<table class=\"%s\">\n", c); FS="|" }
676 { printf("<tr><td>%s</td>", $1);
677 if (NF == 2) printf("<td>%s</td>", $2);
678 printf("</tr>\n", $2) }
679 END { print "</table>" }'
680 }
683 section() {
684 local i=$(basename "$1")
685 echo -e '\n\n<section>'
686 [ $(wc -l < $1) -gt $2 ] && echo "<a class='button icon more r' href='?$i'>${3#*|}</a>"
687 echo "<h2>${3%|*}</h2>"
688 mktable "$i"
689 echo '</section>'
690 }
693 show_desc() {
694 echo "<section><h3>Description of “$1”</h3>"
695 if [ -n "$md2html" ]; then
696 $md2html $2
697 else
698 show_code markdown < $2
699 fi
700 echo "</section>"
701 }
704 # Return all the names of packages bundled in this receipt
706 all_names() {
707 local split=" $SPLIT "
708 if [ "${split/ $PACKAGE /}" != "$split" ]; then
709 # $PACKAGE included somewhere in $SPLIT (probably in the end).
710 # We should build packages in the order defined in the $SPLIT.
711 echo $SPLIT
712 else
713 # We'll build the $PACKAGE, then all defined in the $SPLIT.
714 echo $PACKAGE $SPLIT
715 fi
716 }
719 toolchain_version() {
720 echo "<tr><td><a href='$base/$1'>$1</a></td><td>"
721 if [ -e "$WOK/$1/receipt" ]; then
722 grep ^VERSION $WOK/$1/receipt | cut -d '"' -f2
723 echo '</td><td>'
724 grep ^SHORT_DESC $WOK/$1/receipt | cut -d '"' -f2
725 else
726 echo -n '---</td><td>---'
727 fi
728 echo "</td></tr>"
729 }
732 files_header() {
733 echo '<section><h3>Available downloads:</h3>'
734 echo '<table><thead><tr><th>File</th><th>Size</th><th>Description</th></tr></thead><tbody>'
735 }
738 # Update statistics used in web interface.
739 # There is no need to recalculate the statistics every time the page is displayed.
741 update_webstat() {
742 # for receipts:
743 rtotal=$(ls $WOK/*/arch.$ARCH | wc -l)
744 rcooked=$(ls -d $WOK/*/taz | wc -l)
745 runbuilt=$(($rtotal - $rcooked))
746 rblocked=$(wc -l < $blocked)
747 rbroken=$(wc -l < $broken)
749 # for packages:
750 ptotal=$(cut -d$'\t' -f2 $CACHE/split.db | tr ' ' '\n' | wc -l)
751 pcooked=$(ls $PKGS/*.tazpkg | wc -l)
752 punbuilt=$(($ptotal - $pcooked))
753 pblocked=$(
754 while read i; do
755 sed "/^$i\t/!d" $CACHE/split.db
756 done < $blocked | cut -d$'\t' -f2 | tr ' ' '\n' | wc -l)
757 pbroken=$(
758 while read i; do
759 sed "/^$i\t/!d" $CACHE/split.db
760 done < $broken | cut -d$'\t' -f2 | tr ' ' '\n' | wc -l)
762 cat > $webstat <<EOT
763 rtotal="$rtotal"; rcooked="$rcooked"; runbuilt="$runbuilt"; rblocked="$rblocked"; rbroken="$rbroken"
764 ptotal="$ptotal"; pcooked="$pcooked"; punbuilt="$punbuilt"; pblocked="$pblocked"; pbroken="$pbroken"
765 EOT
766 }
771 #
772 # Load requested page
773 #
775 if [ -z "$pkg" ]; then
777 page_header
778 if [ -n "$QUERY_STRING" -a "$QUERY_STRING" != 'debug' ]; then
780 for list in activity cooknotes cooklist; do
781 [ -n "$(GET $list)" ] || continue
782 [ "$list" == 'cooklist' ] && nb="- Packages: $(wc -l < $cooklist)"
783 echo '<section id="content2">'
784 echo "<h2>DB: $list $nb</h2>"
785 tac $CACHE/$list | sed 's|cooker.cgi?pkg=||; s|%2B|+|g;
786 s|\[ Done|<span class="r c20">Done|;
787 s|\[ Failed|<span class="r c10">Failed|;
788 s| \]|</span>|' | mktable $list
789 echo '</section>'
790 done
792 if [ -n "$(GET broken)" ]; then
793 echo '<div id="content2">'
794 echo "<h2>DB: broken - Packages: $(wc -l < $broken)</h2>"
795 sort $CACHE/broken | sed "s|^[^']*|<a href='$base/\0'>\0</a>|g" | mktable
796 echo '</div>'
797 fi
799 case "$QUERY_STRING" in
800 *.log)
801 log=$LOGS/$QUERY_STRING
802 name=$(basename $log)
803 if [ -f "$log" ]; then
804 echo "<h2>Log for: ${name%.log}</h2>"
805 if fgrep -q "Summary" $log; then
806 echo '<pre class="log">'
807 grep -A 20 '^Summary' $log | syntax_highlighter log
808 echo '</pre>'
809 fi
810 echo '<pre class="log">'
811 syntax_highlighter log < $log
812 echo '</pre>'
813 else
814 show_note e "No log file: $log"
815 fi
816 ;;
817 toolchain)
818 cat <<EOT
819 <div id="content2">
820 <section>
821 <h2>SliTaz GNU/Linux toolchain</h2>
823 <table>
824 <tr><td>Build date</td> <td colspan="2">$(sed -n '/^Cook date/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td></tr>
825 <tr><td>Build duration</td> <td colspan="2">$(sed -n '/^Cook time/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td></tr>
826 <tr><td>Architecture</td> <td colspan="2">$ARCH</td></tr>
827 <tr><td>Build system</td> <td colspan="2">$BUILD_SYSTEM</td></tr>
828 <tr><td>Host system</td> <td colspan="2">$HOST_SYSTEM</td></tr>
829 <tr><th>Package</th><th>Version</th><th>Description</th></tr>
830 $(toolchain_version slitaz-toolchain)
831 $(toolchain_version binutils)
832 $(toolchain_version linux-api-headers)
833 $(toolchain_version gcc)
834 $(toolchain_version glibc)
835 </table>
837 <p>Toolchain documentation: <a target="_blank" rel="noopener noreferrer"
838 href="http://doc.slitaz.org/en:cookbook:toolchain">http://doc.slitaz.org/en:cookbook:toolchain</a>
839 </p>
841 </section>
842 </div>
843 EOT
844 ;;
845 esac
846 page_footer
847 exit 0
848 fi
851 # We may have a toolchain.cgi script for cross cooker's
852 if [ -f "toolchain.cgi" ]; then
853 toolchain="toolchain.cgi"
854 else
855 toolchain="?toolchain"
856 fi
858 # Main page with summary. Count only packages included in ARCH,
859 # use 'cooker arch-db' to manually create arch.$ARCH files.
861 cat <<EOT
862 <div id="content2">
864 <section>
865 <form method="get" action="" class="search r">
866 <input type="hidden" name="search" value="pkg"/>
867 <button type="submit" title="Search">Search</button>
868 <input type="search" name="q" placeholder="Package" list="packages" autocorrect="off" autocapitalize="off"/>
869 </form>
871 <h2>Summary</h2>
872 EOT
874 mktable <<EOT
875 Cooker state : $(running_command)
876 Wok revision : <a href='$WOK_URL' target='_blank' rel='noopener noreferrer'>$(cat $wokrev)</a>
877 Commits to cook : $(wc -l < $commits)
878 Current cooklist : $(wc -l < $cooklist)
879 Architecture : $ARCH, <a href="$toolchain">toolchain</a>
880 Server date : <span id='date'>$(date -u '+%F %R %Z')</span>
881 EOT
883 # If command is "cook:*", update gauge and percentage periodically.
884 # If different package is cooking, reload the page (with new settings)
885 cmd="$(cat $command)"
886 case "$cmd" in
887 cook:*)
888 pkg=${cmd#*:}
889 echo "<script>updatePkg = '${pkg//+/%2B}';</script>"
890 ;;
891 esac
893 # Do we need to update the statistics?
894 [ "$webstat" -nt "$activity" ] || update_webstat
895 . $webstat
897 pct=0; [ "$rtotal" -gt 0 ] && pct=$(( ($rcooked * 100) / $rtotal ))
899 cat <<EOT
900 <div class="meter"><progress max="100" value="$pct">${pct}%</progress><span>${pct}%</span></div>
902 <table class="webstat"><thead>
903 <tr><th> </th><th>Total </th><th>Cooked </th><th>Unbuilt </th><th>Blocked </th><th>Broken </th></tr>
904 </thead><tbody>
905 <tr><td>Receipts</td><td>$rtotal</td><td>$rcooked</td><td>$runbuilt</td><td>$rblocked</td><td>$rbroken</td></tr>
906 <tr><td>Packages</td><td>$ptotal</td><td>$pcooked</td><td>$punbuilt</td><td>$pblocked</td><td>$pbroken</td></tr>
907 </tbody></table>
908 EOT
910 if [ -e "$CACHE/cooker-request" -a ! -s $command ]; then
911 if [ "$activity" -nt "$CACHE/cooker-request" ]; then
912 echo '<a class="button icon bell r" href="?poke">Wake up</a>'
913 else
914 show_note i 'Cooker will be launched in the next 5 minutes.'
915 fi
916 fi
918 cat <<EOT
919 <p>
920 Service logs:
921 <a href="?cookorder.log">cookorder</a> ·
922 <a href="?commits.log">commits</a> ·
923 <a href="?pkgdb.log">pkgdb</a>
924 </p>
925 </section>
926 EOT
928 tac $activity | head -n12 | sed 's|cooker.cgi?pkg=||;
929 s|\[ Done|<span class="r c20">Done|;
930 s|\[ Failed|<span class="r c10">Failed|;
931 s| \]|</span>|;
932 s|%2B|\+|g' | \
933 section $activity 12 "Activity|More activity"
935 [ -s "$cooknotes" ] && tac $cooknotes | head -n12 | \
936 section $cooknotes 12 "Cooknotes|More notes"
938 [ -s "$commits" ] &&
939 section $commits 20 "Commits|More commits" < $commits
941 [ -s "$cooklist" ] && head -n 20 $cooklist | \
942 section $cooklist 20 "Cooklist|Full cooklist"
944 [ -s "$broken" ] && head -n20 $broken | sed "s|^[^']*|<a href='\0'>\0</a>|g" | \
945 section $broken 20 "Broken|All broken packages"
947 [ -s "$blocked" ] && sed "s|^[^']*|<a href='\0'>\0</a>|g" $blocked | \
948 section $blocked 12 "Blocked|All blocked packages"
950 cd $PKGS
951 ls -let *.tazpkg | awk '
952 (NR<=20){
953 sub(/:[0-9][0-9]$/, "", $9);
954 mon = index(" JanFebMarAprMayJunJulAugSepOctNovDec", $7) / 3;
955 printf("%d-%02d-%02d %s : <a href=\"get/%s\">%s</a>\n", $10, mon, $8, $9, $11, $11);
956 }' | \
957 section $activity 1000 "Latest cook"
959 echo '</div>'
960 datalist
961 page_footer
962 exit 0
963 fi
966 case "$cmd" in
967 '')
968 page_header
969 log=$LOGS/$pkg.log
971 # Package info.
972 if [ -f "$wok/$pkg/receipt" ]; then
973 pkg_info
974 else
975 if [ $(ls $wok/*$pkg*/receipt 2>/dev/null | wc -l) -eq 0 ]; then
976 echo "<h2>Not Found</h2>"
977 show_note e "The requested package <b>$pkg</b> was not found on this server."
978 else
979 # Search page
980 echo "<section><h2>Package names matching “$pkg”</h2>"
981 echo "<table><thead><tr><th>Name</th><th>Description</th><th>Category</th></tr></thead><tbody>"
982 for i in $(cd $wok; ls *$pkg*/receipt); do
983 pkg=$(dirname $i)
984 unset SHORT_DESC CATEGORY
985 . $wok/$pkg/receipt
986 echo -n "<tr><td><a href="$base/$pkg">$pkg</a></td>"
987 echo -n "<td>$SHORT_DESC</td><td>$CATEGORY</td></tr>"
988 done
989 echo '</tbody></table></section>'
990 unset pkg
991 fi
992 page_footer
993 exit 0
994 fi
996 # Check for a log file and display summary if it exists.
997 summary "$log"
999 # Display <Recook> button only for SliTaz web browser
1000 if [ -f "$log" ]; then
1001 case "$HTTP_USER_AGENT" in
1002 *SliTaz*)
1003 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
1004 if grep -qs "^$pkg$" $CACHE/recook-packages; then
1005 show_note i "The package “$pkg” has been requested for recook"
1006 else
1007 echo "<a class='button' href='$base/?recook=${pkg//+/%2B}'>Recook $pkg</a>"
1008 fi
1009 fi
1010 ;;
1011 esac
1012 fi
1013 ;;
1015 receipt)
1016 page_header
1017 pkg_info
1018 echo "<a class='button receipt' href='$base/$pkg/receipt'>receipt</a>"
1019 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1020 awk -vb="$base/$pkg" '{printf("<a class=\"button\" href=\"%s/%s\">%s</a>\n", b, $0, $0)}'
1022 show_code bash < $wok/$pkg/receipt
1023 ;;
1025 stuff)
1026 page_header
1027 pkg_info
1028 file="$pkg/stuff/$arg"
1029 echo "<a class='button' href='$base/$pkg/receipt'>receipt</a>"
1030 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1031 awk -vb="$base/$pkg" -va="stuff/$arg" '{
1032 printf("<a class=\"button%s\" href=\"%s/%s\">%s</a>\n", a==$0 ? " receipt" : "", b, $0, $0)
1033 }'
1035 if [ -f "$wok/$file" ]; then
1036 case $file in
1037 *.desktop|*.theme) class="ini" ;;
1038 *.patch|*.diff|*.u) class="diff" ;;
1039 *.sh) class="bash" ;;
1040 *.conf*|*.ini)
1041 class="bash"
1042 [ -n "$(cut -c1 < $wok/$file | fgrep '[')" ] && class="ini"
1043 ;;
1044 *.pl) class="perl" ;;
1045 *.c|*.h|*.awk) class="clike" ;;
1046 *.svg) class="svg" ;;
1047 *Makefile*) class="makefile" ;;
1048 *.po|*.pot) class="bash" ;;
1049 *.css) class="css" ;;
1050 *.htm|*.html) class="html" ;;
1051 *.js) class="js" ;;
1052 *.txt) class="asciidoc" ;;
1053 *)
1054 case $(head -n1 $wok/$file) in
1055 *!/bin/sh*|*!/bin/bash*) class="bash" ;;
1056 esac
1057 if [ -z "$class" -a "$(head -n1 $wok/$file | cut -b1)" == '#' ]; then
1058 class="bash"
1059 fi
1060 if [ -z "$class" ]; then
1061 # Follow Busybox restrictions. Search for non-printable chars
1062 if [ $(tr -d '[:alnum:][:punct:][:blank:][:cntrl:]' < "$wok/$file" | wc -c) -gt 0 ]; then
1063 raw="true"
1064 fi
1065 fi
1066 ;;
1067 esac
1069 # Display image
1070 case $file in
1071 *.png|*.svg|*.jpg|*.jpeg|*.ico)
1072 echo "<img src='$base/$pkg/browse/stuff/$arg' style='display: block; max-width: 100%; margin: auto'/>"
1073 ;;
1074 esac
1076 # Display colored listing for all text-based documents (also for *.svg)
1077 case $file in
1078 *.png|*.jpg|*.jpeg|*.ico) ;;
1079 *)
1080 if [ -z "$raw" ]; then
1081 cat $wok/$file | show_code $class
1082 fi
1083 ;;
1084 esac
1086 # Display hex dump for binary files
1087 if [ -n "$raw" ]; then
1088 hexdump -C $wok/$file | show_code #| sed 's|^\([0-9a-f][0-9a-f]*\)|<span class="c2">\1</span>|'
1089 fi
1090 else
1091 show_note e "File “$file” absent!"
1092 fi
1093 ;;
1095 files)
1096 page_header
1097 pkg_info
1099 packaged=$(mktemp)
1101 # find main package
1102 wanted=$(. $wok/$pkg/receipt; echo $WANTED)
1103 main=${wanted:-$pkg}
1105 # identify split packages
1106 split="$main $(. $wok/$main/receipt; echo $SPLIT)"
1107 [ -d "$wok/$main-dev" ] && split="$split $main-dev"
1108 split="$(echo $split | tr ' ' '\n' | sort -u)"
1110 # finally we need the version
1111 if [ -f "$WOK/linux/receipt" ]; then
1112 kvers=$(. $WOK/linux/receipt; echo $VERSION)
1113 kbasevers=$(echo $kvers | cut -d. -f1,2)
1114 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
1115 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
1116 kbasevers=$(echo $kvers | cut -d. -f1,2)
1117 fi
1118 ver=$(. $wok/$main/receipt; echo $VERSION$EXTRAVERSION)
1121 echo "<section><h3>Quick jump:</h3><ul>"
1122 echo "$split" | sed 'p' | xargs printf "<li><a href='#id-%s'>%s</a></li>\n"
1123 echo "<li id='li-repeats' style='display:none'><a href='#id-repeats'>repeatedly packaged files</a></li>"
1124 echo "<li id='li-orphans' style='display:none'><a href='#id-orphans'>unpackaged files</a></li>"
1125 echo "</ul></section>"
1127 for p in $split; do
1128 namever="$p-$ver"
1129 if [ -d "$wok/$p/taz/$p-$ver" ]; then
1130 indir=$p
1131 elif [ -d "$wok/$main/taz/$p-$ver" ]; then
1132 indir=$main
1133 fi
1134 dir="$wok/$indir/taz/$p-$ver/fs"
1136 size=$(du -hs $dir | awk '{ sub(/\.0/, ""); print $1 }')
1138 echo "<section><h3 id='id-$p'>Contents of package “$namever” (${size:-empty}):</h3>"
1139 echo '<pre class="files">'
1140 if [ -s "$wok/$indir/taz/$p-$ver/files.list" ]; then
1141 echo -n '<span class="underline">permissions·lnk·user ·'
1142 echo -en 'group · size·date &amp; time ·name\n</span>'
1143 cd $dir
1144 find . -print0 | sort -z | xargs -0 ls -ldp --color=always | \
1145 syntax_highlighter files | \
1146 sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$indir/browse/taz/$p-$ver/fs\2'>\2\3|;" | \
1147 awk 'BEGIN { FS="\""; }
1148 { gsub("+", "%2B", $2); print; }'
1149 else
1150 echo 'No files'
1151 fi
1152 echo '</pre></section>'
1153 cat $wok/$indir/taz/$p-$ver/files.list >> $packaged
1154 done
1156 # find repeatedly packaged files
1157 repeats="$(sort $packaged | uniq -d)"
1158 if [ -n "$repeats" ]; then
1159 echo '<script>document.getElementById("li-repeats").style.display = "list-item"</script>'
1160 echo -n '<section><h3 id="id-repeats">Repeatedly packaged files:</h3><pre class="files">'
1161 echo "$repeats" | sed 's|^|<span class="c11">!!!</span> |'
1162 echo "</pre></section>"
1163 fi
1165 # find unpackaged files
1166 all_files=$(mktemp)
1167 cd $wok/$main/install; find ! -type d | sed 's|\.||' > $all_files
1168 orphans="$(sort $all_files $packaged | uniq -u)"
1169 if [ -d "$wok/$main/install" -a -n "$orphans" ]; then
1170 echo '<script>document.getElementById("li-orphans").style.display = "list-item"</script>'
1171 echo '<section><h3 id="id-orphans">Unpackaged files:</h3>'
1172 table=$(mktemp)
1173 echo "$orphans" | awk -vi="$base/$indir/browse/install" '
1174 function tag(text, color) {
1175 printf("<span class=\"c%s1\">%s</span> ", color, text);
1176 printf("<a class=\"c00\" href=\"%s\">%s</a>\n", i $0, $0);
1178 /\/perllocal.pod$/ || /\/\.packlist$/ || /\/share\/bash-completion\// ||
1179 /\/lib\/systemd\// || /\.pyc$/ || /\.pyo$/ { tag("---", 0); next }
1180 /\.pod$/ { tag("pod", 5); next }
1181 /\/share\/man\// { tag("man", 5); next }
1182 /\/share\/doc\// || /\/share\/gtk-doc\// || /\/share\/info\// ||
1183 /\/share\/devhelp\// { tag("doc", 5); next }
1184 /\/share\/icons\// { tag("ico", 2); next }
1185 /\/share\/locale\// { tag("loc", 4); next }
1186 /\.h$/ || /\.a$/ || /\.la$/ || /\.pc$/ || /\/bin\/.*-config$/ ||
1187 /\/Makefile.*$/ { tag("dev", 3); next }
1188 { tag("???", 1) }
1189 ' > $table
1191 # Summary table
1192 for i in head body; do
1193 case $i in
1194 head) echo -n '<table class="summary"><tr>';;
1195 body) echo -n '<th> </th></tr><tr>';;
1196 esac
1197 for j in '???1' dev3 loc4 ico2 doc5 man5 pod5 '---0'; do
1198 tag=${j:0:3}; class="c${j:3:1}0"; [ "$class" == 'c00' ] && class='c01'
1199 case $i in
1200 head) echo -n "<th class='$class'>$tag</th>";;
1201 body) printf '<td>%s</td>' "$(grep ">$tag<" $table | wc -l)";;
1202 esac
1203 done
1204 done
1205 echo '<td> </td></tr></table>'
1207 echo -n '<pre class="files">'
1208 cat $table
1209 echo '</pre></section>'
1210 rm $table
1211 fi
1212 rm $packaged $all_files
1213 ;;
1215 description)
1216 page_header
1217 pkg_info
1218 descs="$(ls $WOK/$pkg/description*.txt)"
1219 if [ -n "$descs" ]; then
1220 echo '<div id="content2">'
1221 [ -f "$WOK/$pkg/description.txt" ] && show_desc "$pkg" "$WOK/$pkg/description.txt"
1222 for i in $descs; do
1223 case $i in
1224 */description.txt) continue ;;
1225 *) package=$(echo $i | cut -d. -f2) ;;
1226 esac
1227 show_desc "$package" "$i"
1228 done
1229 echo '</div>'
1230 else
1231 show_note w "No description of $pkg"
1232 fi
1233 ;;
1235 log)
1236 page_header
1237 pkg_info
1238 [ -z "$arg" ] && arg=$(stat -c %Y $LOGS/$pkg.log)
1240 echo '<div class="btnList">'
1241 acc='l' # access key for the latest log is 'L'
1242 while read log; do
1243 # for all $pkg.log, $pkg.log.0 .. $pkg.log.9, $pkg-pack.log (if any)
1244 timestamp=$(stat -c %Y $log)
1245 class=''
1246 if [ "$arg" == "$timestamp" ]; then
1247 class=' log'
1248 logfile="$log"
1249 fi
1250 case $log in *-pack.log) acc='p';; esac # access key for the packing log is 'P'
1251 echo -n "<a class='button$class' data-acc='$acc' accesskey='$acc' href='$base/$pkg/log/$timestamp'>"
1252 echo "$(stat -c %y $log | cut -d: -f1,2)</a>"
1253 case $acc in
1254 l) acc=0;;
1255 *) acc=$((acc+1));;
1256 esac
1257 done <<EOT
1258 $(find $LOGS -name "$pkg.log*" | sort)
1259 $(find $LOGS -name "$pkg-pack.log")
1260 EOT
1261 echo '</div>'
1263 if [ -z "$logfile" ]; then
1264 show_note e "Requested log is absent"
1265 page_footer
1266 exit 0
1267 fi
1269 # Define cook variables for syntax highlighter
1270 if [ -s "$WOK/$pkg/receipt" ]; then
1271 . "$WOK/$pkg/receipt"
1272 _wok='/home/slitaz/wok'
1273 _src="$_wok/$pkg/source/$PACKAGE-$VERSION"
1274 _install="$_wok/$pkg/install"
1275 _fs="$_wok/$pkg/taz/$PACKAGE-$VERSION/fs"
1276 _stuff="$_wok/$pkg/stuff"
1277 fi
1279 # if [ ! -f "gzlog/$pkg.$arg" ]; then
1280 # {
1281 # summary "$logfile" links
1283 # syntax_highlighter log < $logfile | awk '
1284 # BEGIN { print "<pre class=\"log\">"; }
1285 # { printf("<a name=\"l%d\" href=\"#l%d\">%5d</a> %s\n", NR, NR, NR, $0); }
1286 # END { print "</pre>"; }
1287 # '
1289 # page_footer
1290 # } | gzip > gzlog/$pkg.$arg
1291 # fi
1293 blog=$(basename $logfile)
1294 summary "$logfile" links
1296 # disable next `sed` for the 'like2016' theme
1297 theme=$(COOKIE theme); theme=${theme:-default}; [ "$theme" != 'like2016' ] && theme=''
1298 cat $logfile | syntax_highlighter log | \
1299 sed -e "/(pkg\/local$theme):/ s|: \([^<]*\)|<img src='$base/i/$blog/\1'> \1|" | \
1300 awk '
1301 BEGIN { print "<pre class=\"log\">"; }
1302 { printf("<a name=\"l%d\" href=\"#l%d\">%5d</a> %s\n", NR, NR, NR, $0); }
1303 END { print "</pre>"; }
1305 ;;
1308 man|doc|info)
1309 page_header
1310 pkg_info
1311 echo '<div style="max-height: 6.4em; overflow: auto; padding: 0 4px">'
1313 dir="wok/$pkg/install/usr/share/$cmd"
1314 [ "$cmd" == 'doc' ] && dir="$dir wok/$pkg/install/usr/share/gtk-doc"
1315 if [ "$cmd" == 'doc' -a -z "$arg" ]; then
1316 try=$(for i in $dir; do find $i -name 'index.htm*'; done | sed q)
1317 [ -n "$try" ] && arg="$try"
1318 fi
1319 while read i; do
1320 [ -s "$i" ] || continue
1321 case "$i" in
1322 *.jp*g|*.png|*.gif|*.svg|*.css) continue
1323 esac
1324 i=${i#$dir/}
1325 [ -n "$arg" ] || arg="$i"
1326 class=''; [ "$arg" == "$i" ] && class=" doc"
1327 case "$cmd" in
1328 man)
1329 case $i in
1330 man*) lang='';;
1331 *) lang="${i%%/*}: ";;
1332 esac
1333 man=$(basename $i .gz)
1334 echo "<a class='button$class' href='$base/$pkg/man/$i'>$lang${man%.*} (${man##*.})</a>"
1335 ;;
1336 doc)
1337 echo "<a class='button$class' href='$base/$pkg/doc/$i'>$(basename $i .gz)</a>"
1338 ;;
1339 info)
1340 info=$(basename $i)
1341 echo "<a class='button$class' href='$base/$pkg/info/$i#Top'>${info/.info/}</a>"
1342 ;;
1343 esac
1344 done <<EOT
1345 $(for i in $dir; do find $i -type f; done | sort)
1346 EOT
1347 echo '</div>'
1349 [ -f "$arg" ] || arg="$dir/$arg"
1350 if [ -f "$arg" ]; then
1351 tmp="$(mktemp)"
1352 docat "$arg" > $tmp
1353 [ -s "$tmp" ] &&
1354 case "$cmd" in
1355 info)
1356 echo '<div id="content2" class="texinfo"><pre class="first">'
1357 info2html < "$tmp"
1358 echo '</pre></div>'
1359 ;;
1360 doc)
1361 case "$arg" in
1362 *.sgml|*.devhelp2) class='xml';;
1363 *.py) class='python';; # pycurl package
1364 *.css) class='css';;
1365 *) class='asciidoc';;
1366 esac
1367 case "$arg" in
1368 *.htm*)
1369 case $arg in
1370 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
1371 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
1372 esac
1373 # make the iframe height so long to contain its contents without scrollbar
1374 echo "<iframe id='idoc' src='$page' width='100%' onload='resizeIframe(this)'></iframe>"
1375 ;;
1376 *.pdf)
1377 case $arg in
1378 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
1379 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
1380 esac
1381 cat <<EOT
1382 <object id="idoc" data="$page" width="100%" height="100%" type="application/pdf" style="min-height: 600px">
1383 $(show_note w "Missing PDF plugin.<br/>Get the file <a href="$page">$(basename "$page")</a>.")
1384 </object>
1385 EOT
1386 ;;
1387 *)
1388 show_code $class < "$tmp"
1389 ;;
1390 esac
1391 ;;
1392 man)
1393 #export TEXTDOMAIN='man2html'
1394 echo "<div id='content2'>"
1396 html=$(./man2html "$tmp" | sed -e '1,/<header>/d' -e '/<footer>/,$d' \
1397 -e 's|<a href="file:///[^>]*>\([^<]*\)</a>|\1|g' \
1398 -e 's|<a href="?[1-9]\+[^>]*>\([^<]*\)</a>|\1|g')
1400 if [ -n "$(echo "$html" | fgrep 'The requested file /tmp/tmp.')" ]; then
1401 # Process the pre-formatted man-cat page
1402 # (for example see sudo package without groff in build dependencies)
1403 sed -i '
1404 s|M-bM-^@M-^S|—|g;
1405 s|M-bM-^@M-^\\|<b>|g;
1406 s|M-bM-^@M-^]|</b>|g
1407 s|M-bM-^@M-^X|<u>|g;
1408 s|M-bM-^@M-^Y|</u>|g;
1409 s|M-BM-||g;
1410 s|++oo|•|g;
1411 s|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g;
1412 ' "$tmp"
1413 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 \
1414 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 \
1415 0 1 2 3 4 5 6 7 8 9 _ - '\\+' '\.' /; do
1416 sed -i "s|$i$i|<b>$i</b>|g; s|_$i|<u>$i</u>|g" "$tmp"
1417 done
1418 echo '<pre class="catman">'
1419 sed 's|</b><b>||g; s|</u><u>||g; s|</u><b>_</b><u>|_|g; s|</b> <b>| |g;' "$tmp"
1420 echo '</pre>'
1421 else
1422 echo "$html"
1423 fi
1424 echo "</div>"
1425 ;;
1426 esac
1427 rm -f $tmp
1428 else
1429 show_note e "File “$arg” not exists!"
1430 fi
1431 ;;
1433 download)
1434 page_header
1435 pkg_info
1436 show=0
1438 . $wok/$pkg/receipt
1440 if [ -n "$TARBALL" -a -s "$SRC/$TARBALL" ]; then
1441 files_header
1442 echo "<tr><td><a href='$base/src/$TARBALL'>$TARBALL</a></td>"
1443 ls -lh "$SRC/$TARBALL" | awk '{printf("<td>%sB</td>", $5)}'
1444 echo "<td>Sources for building the package “$pkg”</td></tr>"
1445 show=1
1446 fi
1448 if [ -d "$wok/$pkg/taz" ]; then
1449 [ "$show" -eq 1 ] || files_header
1451 for i in $(all_names); do
1452 [ -e "$wok/$pkg/taz/$i-$VERSION$EXTRAVERSION/receipt" ] || continue
1453 . $wok/$pkg/taz/$i-$VERSION$EXTRAVERSION/receipt
1455 for filename in "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg"; do
1456 [ -f "$PKGS/$filename" ] &&
1457 cat <<EOT
1458 <tr>
1459 <td><a href="$base/get/$filename">$filename</a></td>
1460 <td>$(ls -lh ./packages/$filename | awk '{printf("%sB", $5)}')</td>
1461 <td>$SHORT_DESC</td>
1462 </tr>
1463 EOT
1464 done
1465 done
1466 show=1
1467 fi
1469 if [ "$show" -eq 1 ]; then
1470 echo '</tbody></table></section>'
1471 else
1472 show_note w "Sorry, there's nothing to download…"
1473 fi
1474 ;;
1476 esac
1479 page_footer
1480 exit 0