cookutils view lighttpd/index.cgi @ rev 938

Tiny edits.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue Jun 20 03:52:01 2017 +0300 (2017-06-20)
parents 49ff02f8d304
children 81f33cdb5a66
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#[^a-zA-Z-][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 print "<thead>";
596 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]);
597 print "</thead><tbody>";
598 }
599 else
600 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]);
601 }
602 {
603 if (NR==1) { printf("<h3>%s</h3>\n<table>\n", $0); next }
604 if ($0 ~ "===") { seen++; if (seen == 1) next; else exit; }
605 if ($0 ~ "---") {
606 seen2++;
607 if (seen2 == 1) print "</table>\n\n<table class=\"pkgslist\">"
608 next
609 }
610 if (seen2) row2($0, seen2); else row($0);
611 }
612 END { print "</tbody></table></section>" }
613 '
614 elif fgrep -q "Debug information" $log; then
615 echo -e '<section>\n<h3>Debug information</h3>'
616 sed -e '/^Debug information/,$!d; /^===/d; /^$/d' $log | sed -n '1!p' | \
617 if [ -n "$2" ]; then
618 syntax_highlighter log | sed 's|\([0-9][0-9]*\):|<a href="#l\1">\1</a>:|'
619 else
620 sed 's|^[0-9][0-9]*:||' | syntax_highlighter log
621 fi | mklog
622 echo '</section>'
623 fi
624 else
625 [ -n "$pkg" -a -d "$wok/$pkg" ] && show_note e "No log for $pkg"
626 fi
627 }
630 active() {
631 [ "$cmd" == "$1" -o "$cmd" == "${2:-$1}" ] && echo -n ' active'
632 }
635 pkg_info() {
636 local log active bpkg
637 log="$LOGS/$pkg.log"
639 echo "<h2><a href=\"$base/$pkg\">$pkg</a></h2>"
640 echo '<div id="info">'
641 echo "<a class='button icon receipt$(active receipt stuff)' href='$base/$pkg/receipt'>receipt &amp; stuff</a>"
643 unset WEB_SITE WANTED
644 . $wok/$pkg/receipt
646 [ -n "$WEB_SITE" ] &&
647 echo "<a class='button icon website' href='$WEB_SITE' target='_blank' rel='noopener noreferrer'>web site</a>"
649 [ -f "$wok/$pkg/taz/$PACKAGE-$VERSION/receipt" ] &&
650 echo "<a class='button icon files$(active files)' href='$base/$pkg/files'>files</a>"
652 [ -n "$(ls $wok/$pkg/description*.txt)" ] &&
653 echo "<a class='button icon desc$(active description)' href='$base/$pkg/description'>description</a>"
655 [ -n "$TARBALL" -a -s "$SRC/$TARBALL" -o -d "$wok/$pkg/taz" ] &&
656 echo "<a class='button icon download' href='$base/$pkg/download'>download</a>"
658 echo "<a class='button icon browse' href='$base/$pkg/browse/'>browse</a>"
660 [ -x ./man2html -a -d "$wok/$pkg/install/usr/share/man" ] &&
661 echo "<a class='button icon doc$(active man)' href='$base/$pkg/man/'>man</a>"
663 [ -d "$wok/$pkg/install/usr/share/doc" -o -d "$wok/$pkg/install/usr/share/gtk-doc" ] &&
664 echo "<a class='button icon doc$(active doc)' href='$base/$pkg/doc/'>doc</a>"
666 [ -d "$wok/$pkg/install/usr/share/info" ] &&
667 echo "<a class='button icon doc$(active info)' href='$base/$pkg/info/#Top'>info</a>"
669 [ -s "$log" ] &&
670 echo "<a class='button icon log$(active log)' href='$base/$pkg/log/'>logs</a>"
672 echo '</div>'
673 }
676 mktable() {
677 sed 's# : #|#' | awk -vc="$1" '
678 BEGIN { printf("<table class=\"%s\">\n", c); FS="|" }
679 { printf("<tr><td>%s</td>", $1);
680 if (NF == 2) printf("<td>%s</td>", $2);
681 printf("</tr>\n", $2) }
682 END { print "</table>" }'
683 }
686 section() {
687 local i=$(basename "$1")
688 echo -e '\n\n<section>'
689 [ $(wc -l < $1) -gt $2 ] && echo "<a class='button icon more r' href='?$i'>${3#*|}</a>"
690 echo "<h2>${3%|*}</h2>"
691 mktable "$i"
692 echo '</section>'
693 }
696 show_desc() {
697 echo "<section><h3>Description of “$1”</h3>"
698 if [ -n "$md2html" ]; then
699 $md2html $2
700 else
701 show_code markdown < $2
702 fi
703 echo "</section>"
704 }
707 # Return all the names of packages bundled in this receipt
709 all_names() {
710 local split=" $SPLIT "
711 if [ "${split/ $PACKAGE /}" != "$split" ]; then
712 # $PACKAGE included somewhere in $SPLIT (probably in the end).
713 # We should build packages in the order defined in the $SPLIT.
714 echo $SPLIT
715 else
716 # We'll build the $PACKAGE, then all defined in the $SPLIT.
717 echo $PACKAGE $SPLIT
718 fi
719 }
722 toolchain_version() {
723 echo "<tr><td><a href='$base/$1'>$1</a></td><td>"
724 if [ -e "$WOK/$1/receipt" ]; then
725 grep ^VERSION $WOK/$1/receipt | cut -d '"' -f2
726 echo '</td><td>'
727 grep ^SHORT_DESC $WOK/$1/receipt | cut -d '"' -f2
728 else
729 echo -n '---</td><td>---'
730 fi
731 echo "</td></tr>"
732 }
735 files_header() {
736 echo '<section><h3>Available downloads:</h3>'
737 echo '<table><thead><tr><th>File</th><th>Size</th><th>Description</th></tr></thead><tbody>'
738 }
741 # Update statistics used in web interface.
742 # There is no need to recalculate the statistics every time the page is displayed.
744 update_webstat() {
745 echo '<div id="waitme">'
746 show_note i 'Please wait while statistics are being collected.'
747 echo "</div>"
749 # for receipts:
750 rtotal=$(ls $WOK/*/arch.$ARCH | wc -l)
751 rcooked=$(ls -d $WOK/*/taz | wc -l)
752 runbuilt=$(($rtotal - $rcooked))
753 rblocked=$(wc -l < $blocked)
754 rbroken=$(wc -l < $broken)
756 # for packages:
757 ptotal=$(cut -d$'\t' -f2 $CACHE/split.db | tr ' ' '\n' | sort -u | wc -l)
758 pcooked=$(ls $PKGS/*.tazpkg | wc -l)
759 punbuilt=$(($ptotal - $pcooked))
760 pblocked=$(
761 while read i; do
762 sed "/^$i\t/!d" $CACHE/split.db
763 done < $blocked | cut -d$'\t' -f2 | tr ' ' '\n' | wc -l)
764 pbroken=$(
765 while read i; do
766 sed "/^$i\t/!d" $CACHE/split.db
767 done < $broken | cut -d$'\t' -f2 | tr ' ' '\n' | wc -l)
769 cat > $webstat <<EOT
770 rtotal="$rtotal"; rcooked="$rcooked"; runbuilt="$runbuilt"; rblocked="$rblocked"; rbroken="$rbroken"
771 ptotal="$ptotal"; pcooked="$pcooked"; punbuilt="$punbuilt"; pblocked="$pblocked"; pbroken="$pbroken"
772 EOT
774 echo '<script>document.getElementById("waitme").remove();</script>'
775 }
780 #
781 # Load requested page
782 #
784 if [ -z "$pkg" ]; then
786 page_header
787 if [ -n "$QUERY_STRING" -a "$QUERY_STRING" != 'debug' ]; then
789 for list in activity cooknotes cooklist; do
790 [ -n "$(GET $list)" ] || continue
791 [ "$list" == 'cooklist' ] && nb="- Packages: $(wc -l < $cooklist)"
792 echo '<section id="content2">'
793 echo "<h2>DB: $list $nb</h2>"
794 tac $CACHE/$list | sed 's|cooker.cgi?pkg=||; s|%2B|+|g;
795 s|\[ Done|<span class="r c20">Done|;
796 s|\[ Failed|<span class="r c10">Failed|;
797 s| \]|</span>|' | mktable $list
798 echo '</section>'
799 done
801 if [ -n "$(GET broken)" ]; then
802 echo '<section id="content2">'
803 echo "<h2>DB: broken - Packages: $(wc -l < $broken)</h2>"
804 sort $CACHE/broken | sed "s|^[^']*|<a href='$base/\0'>\0</a>|g" | mktable
805 echo '</section>'
806 fi
808 case "$QUERY_STRING" in
809 *.log)
810 log=$LOGS/$QUERY_STRING
811 name=$(basename $log)
812 if [ -f "$log" ]; then
813 echo "<h2>Log for: ${name%.log}</h2>"
814 if fgrep -q "Summary" $log; then
815 echo '<pre class="log">'
816 grep -A 20 '^Summary' $log | syntax_highlighter log
817 echo '</pre>'
818 fi
819 echo '<pre class="log">'
820 syntax_highlighter log < $log
821 echo '</pre>'
822 else
823 show_note e "No log file: $log"
824 fi
825 ;;
826 toolchain)
827 cat <<EOT
828 <div id="content2">
829 <section>
830 <h2>SliTaz GNU/Linux toolchain</h2>
832 <table>
833 <tr><td>Build date</td> <td colspan="2">$(sed -n '/^Cook date/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td></tr>
834 <tr><td>Build duration</td> <td colspan="2">$(sed -n '/^Cook time/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td></tr>
835 <tr><td>Architecture</td> <td colspan="2">$ARCH</td></tr>
836 <tr><td>Build system</td> <td colspan="2">$BUILD_SYSTEM</td></tr>
837 <tr><td>Host system</td> <td colspan="2">$HOST_SYSTEM</td></tr>
838 <tr><th>Package</th><th>Version</th><th>Description</th></tr>
839 $(toolchain_version slitaz-toolchain)
840 $(toolchain_version binutils)
841 $(toolchain_version linux-api-headers)
842 $(toolchain_version gcc)
843 $(toolchain_version glibc)
844 </table>
846 <p>Toolchain documentation: <a target="_blank" rel="noopener noreferrer"
847 href="http://doc.slitaz.org/en:cookbook:toolchain">http://doc.slitaz.org/en:cookbook:toolchain</a>
848 </p>
850 </section>
851 </div>
852 EOT
853 ;;
854 esac
855 page_footer
856 exit 0
857 fi
860 # We may have a toolchain.cgi script for cross cooker's
861 if [ -f "toolchain.cgi" ]; then
862 toolchain="toolchain.cgi"
863 else
864 toolchain="?toolchain"
865 fi
867 # Main page with summary. Count only packages included in ARCH,
868 # use 'cooker arch-db' to manually create arch.$ARCH files.
870 cat <<EOT
871 <div id="content2">
873 <section>
874 <form method="get" action="" class="search r">
875 <input type="hidden" name="search" value="pkg"/>
876 <button type="submit" title="Search">Search</button>
877 <input type="search" name="q" placeholder="Package" list="packages" autocorrect="off" autocapitalize="off"/>
878 </form>
880 <h2>Summary</h2>
881 EOT
883 mktable <<EOT
884 Cooker state : $(running_command)
885 Wok revision : <a href='$WOK_URL' target='_blank' rel='noopener noreferrer'>$(cat $wokrev)</a>
886 Commits to cook : $(wc -l < $commits)
887 Current cooklist : $(wc -l < $cooklist)
888 Architecture : $ARCH, <a href="$toolchain">toolchain</a>
889 Server date : <span id='date'>$(date -u '+%F %R %Z')</span>
890 EOT
892 # If command is "cook:*", update gauge and percentage periodically.
893 # If different package is cooking, reload the page (with new settings)
894 cmd="$(cat $command)"
895 case "$cmd" in
896 cook:*)
897 pkg=${cmd#*:}
898 echo "<script>updatePkg = '${pkg//+/%2B}';</script>"
899 ;;
900 esac
902 # Do we need to update the statistics?
903 [ "$webstat" -nt "$activity" ] || update_webstat
904 . $webstat
906 pct=0; [ "$rtotal" -gt 0 ] && pct=$(( ($rcooked * 100) / $rtotal ))
908 cat <<EOT
909 <div class="meter"><progress max="100" value="$pct">${pct}%</progress><span>${pct}%</span></div>
911 <table class="webstat"><thead>
912 <tr><th> </th><th>Total </th><th>Cooked </th><th>Unbuilt </th><th>Blocked </th><th>Broken </th></tr>
913 </thead><tbody>
914 <tr><td>Receipts</td><td>$rtotal</td><td>$rcooked</td><td>$runbuilt</td><td>$rblocked</td><td>$rbroken</td></tr>
915 <tr><td>Packages</td><td>$ptotal</td><td>$pcooked</td><td>$punbuilt</td><td>$pblocked</td><td>$pbroken</td></tr>
916 </tbody></table>
917 EOT
919 if [ -e "$CACHE/cooker-request" -a ! -s $command ]; then
920 if [ "$activity" -nt "$CACHE/cooker-request" ]; then
921 echo '<a class="button icon bell r" href="?poke">Wake up</a>'
922 else
923 show_note i 'Cooker will be launched in the next 5 minutes.'
924 fi
925 fi
927 cat <<EOT
928 <p>
929 Service logs:
930 <a href="?cookorder.log">cookorder</a> ·
931 <a href="?commits.log">commits</a> ·
932 <a href="?pkgdb.log">pkgdb</a>
933 </p>
934 </section>
935 EOT
937 tac $activity | head -n12 | sed 's|cooker.cgi?pkg=||;
938 s|\[ Done|<span class="r c20">Done|;
939 s|\[ Failed|<span class="r c10">Failed|;
940 s| \]|</span>|;
941 s|%2B|\+|g' | \
942 section $activity 12 "Activity|More activity"
944 [ -s "$cooknotes" ] && tac $cooknotes | head -n12 | \
945 section $cooknotes 12 "Cooknotes|More notes"
947 [ -s "$commits" ] &&
948 section $commits 20 "Commits|More commits" < $commits
950 [ -s "$cooklist" ] && head -n 20 $cooklist | \
951 section $cooklist 20 "Cooklist|Full cooklist"
953 [ -s "$broken" ] && head -n20 $broken | sed "s|^[^']*|<a href='\0'>\0</a>|g" | \
954 section $broken 20 "Broken|All broken packages"
956 [ -s "$blocked" ] && sed "s|^[^']*|<a href='\0'>\0</a>|g" $blocked | \
957 section $blocked 12 "Blocked|All blocked packages"
959 cd $PKGS
960 ls -let *.tazpkg | awk '
961 (NR<=20){
962 sub(/:[0-9][0-9]$/, "", $9);
963 mon = index(" JanFebMarAprMayJunJulAugSepOctNovDec", $7) / 3;
964 printf("%d-%02d-%02d %s : <a href=\"get/%s\">%s</a>\n", $10, mon, $8, $9, $11, $11);
965 }' | \
966 section $activity 1000 "Latest cook"
968 echo '</div>'
969 datalist
970 page_footer
971 exit 0
972 fi
975 case "$cmd" in
976 '')
977 page_header
978 log=$LOGS/$pkg.log
980 # Package info.
981 if [ -f "$wok/$pkg/receipt" ]; then
982 pkg_info
983 else
984 if [ $(ls $wok/*$pkg*/receipt 2>/dev/null | wc -l) -eq 0 ]; then
985 echo "<h2>Not Found</h2>"
986 show_note e "The requested package <b>$pkg</b> was not found on this server."
987 else
988 # Search page
989 echo "<section><h2>Package names matching “$pkg”</h2>"
990 echo "<table><thead><tr><th>Name</th><th>Description</th><th>Category</th></tr></thead><tbody>"
991 for i in $(cd $wok; ls *$pkg*/receipt); do
992 pkg=$(dirname $i)
993 unset SHORT_DESC CATEGORY
994 . $wok/$pkg/receipt
995 echo -n "<tr><td><a href="$base/$pkg">$pkg</a></td>"
996 echo -n "<td>$SHORT_DESC</td><td>$CATEGORY</td></tr>"
997 done
998 echo '</tbody></table></section>'
999 unset pkg
1000 fi
1001 page_footer
1002 exit 0
1003 fi
1005 # Check for a log file and display summary if it exists.
1006 summary "$log"
1008 # Display <Recook> button only for SliTaz web browser
1009 if [ -f "$log" ]; then
1010 case "$HTTP_USER_AGENT" in
1011 *SliTaz*)
1012 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
1013 if grep -qs "^$pkg$" $CACHE/recook-packages; then
1014 show_note i "The package “$pkg” has been requested for recook"
1015 else
1016 echo "<a class='button' href='$base/?recook=${pkg//+/%2B}'>Recook $pkg</a>"
1017 fi
1018 fi
1019 ;;
1020 esac
1021 fi
1022 ;;
1024 receipt)
1025 page_header
1026 pkg_info
1027 echo "<a class='button receipt' href='$base/$pkg/receipt'>receipt</a>"
1028 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1029 awk -vb="$base/$pkg" '{printf("<a class=\"button\" href=\"%s/%s\">%s</a>\n", b, $0, $0)}'
1031 show_code bash < $wok/$pkg/receipt
1032 ;;
1034 stuff)
1035 page_header
1036 pkg_info
1037 file="$pkg/stuff/$arg"
1038 echo "<a class='button' href='$base/$pkg/receipt'>receipt</a>"
1039 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1040 awk -vb="$base/$pkg" -va="stuff/$arg" '{
1041 printf("<a class=\"button%s\" href=\"%s/%s\">%s</a>\n", a==$0 ? " receipt" : "", b, $0, $0)
1042 }'
1044 if [ -f "$wok/$file" ]; then
1045 case $file in
1046 *.desktop|*.theme) class="ini" ;;
1047 *.patch|*.diff|*.u) class="diff" ;;
1048 *.sh) class="bash" ;;
1049 *.conf*|*.ini)
1050 class="bash"
1051 [ -n "$(cut -c1 < $wok/$file | fgrep '[')" ] && class="ini"
1052 ;;
1053 *.pl) class="perl" ;;
1054 *.c|*.h|*.awk) class="clike" ;;
1055 *.svg) class="svg" ;;
1056 *Makefile*) class="makefile" ;;
1057 *.po|*.pot) class="bash" ;;
1058 *.css) class="css" ;;
1059 *.htm|*.html) class="html" ;;
1060 *.js) class="js" ;;
1061 *.txt) class="asciidoc" ;;
1062 *)
1063 case $(head -n1 $wok/$file) in
1064 *!/bin/sh*|*!/bin/bash*) class="bash" ;;
1065 esac
1066 if [ -z "$class" -a "$(head -n1 $wok/$file | cut -b1)" == '#' ]; then
1067 class="bash"
1068 fi
1069 if [ -z "$class" ]; then
1070 # Follow Busybox restrictions. Search for non-printable chars
1071 if [ $(tr -d '[:alnum:][:punct:][:blank:][:cntrl:]' < "$wok/$file" | wc -c) -gt 0 ]; then
1072 raw="true"
1073 fi
1074 fi
1075 ;;
1076 esac
1078 # Display image
1079 case $file in
1080 *.png|*.svg|*.jpg|*.jpeg|*.ico)
1081 echo "<img src='$base/$pkg/browse/stuff/$arg' style='display: block; max-width: 100%; margin: auto'/>"
1082 ;;
1083 esac
1085 # Display colored listing for all text-based documents (also for *.svg)
1086 case $file in
1087 *.png|*.jpg|*.jpeg|*.ico) ;;
1088 *)
1089 if [ -z "$raw" ]; then
1090 cat $wok/$file | show_code $class
1091 fi
1092 ;;
1093 esac
1095 # Display hex dump for binary files
1096 if [ -n "$raw" ]; then
1097 hexdump -C $wok/$file | show_code #| sed 's|^\([0-9a-f][0-9a-f]*\)|<span class="c2">\1</span>|'
1098 fi
1099 else
1100 show_note e "File “$file” absent!"
1101 fi
1102 ;;
1104 files)
1105 page_header
1106 pkg_info
1108 packaged=$(mktemp)
1110 # find main package
1111 wanted=$(. $wok/$pkg/receipt; echo $WANTED)
1112 main=${wanted:-$pkg}
1114 # identify split packages
1115 split="$main $(. $wok/$main/receipt; echo $SPLIT)"
1116 [ -d "$wok/$main-dev" ] && split="$split $main-dev"
1117 split="$(echo $split | tr ' ' '\n' | sort -u)"
1119 # finally we need the version
1120 if [ -f "$WOK/linux/receipt" ]; then
1121 kvers=$(. $WOK/linux/receipt; echo $VERSION)
1122 kbasevers=$(echo $kvers | cut -d. -f1,2)
1123 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
1124 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
1125 kbasevers=$(echo $kvers | cut -d. -f1,2)
1126 fi
1127 ver=$(. $wok/$main/receipt; echo $VERSION$EXTRAVERSION)
1130 echo "<section><h3>Quick jump:</h3><ul>"
1131 echo "$split" | sed 'p' | xargs printf "<li><a href='#id-%s'>%s</a></li>\n"
1132 echo "<li id='li-repeats' style='display:none'><a href='#id-repeats'>repeatedly packaged files</a></li>"
1133 echo "<li id='li-orphans' style='display:none'><a href='#id-orphans'>unpackaged files</a></li>"
1134 echo "</ul></section>"
1136 for p in $split; do
1137 namever="$p-$ver"
1138 if [ -d "$wok/$p/taz/$p-$ver" ]; then
1139 indir=$p
1140 elif [ -d "$wok/$main/taz/$p-$ver" ]; then
1141 indir=$main
1142 fi
1143 dir="$wok/$indir/taz/$p-$ver/fs"
1145 size=$(du -hs $dir | awk '{ sub(/\.0/, ""); print $1 }')
1147 echo "<section><h3 id='id-$p'>Contents of package “$namever” (${size:-empty}):</h3>"
1148 echo '<pre class="files">'
1149 if [ -s "$wok/$indir/taz/$p-$ver/files.list" ]; then
1150 echo -n '<span class="underline">permissions·lnk·user ·'
1151 echo -en 'group · size·date &amp; time ·name\n</span>'
1152 cd $dir
1153 find . -print0 | sort -z | xargs -0 ls -ldp --color=always | \
1154 syntax_highlighter files | \
1155 sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$indir/browse/taz/$p-$ver/fs\2'>\2\3|;" | \
1156 awk 'BEGIN { FS="\""; }
1157 { gsub("+", "%2B", $2); print; }'
1158 else
1159 echo 'No files'
1160 fi
1161 echo '</pre></section>'
1162 cat $wok/$indir/taz/$p-$ver/files.list >> $packaged
1163 done
1165 # find repeatedly packaged files
1166 repeats="$(sort $packaged | uniq -d)"
1167 if [ -n "$repeats" ]; then
1168 echo '<script>document.getElementById("li-repeats").style.display = "list-item"</script>'
1169 echo -n '<section><h3 id="id-repeats">Repeatedly packaged files:</h3><pre class="files">'
1170 echo "$repeats" | sed 's|^|<span class="c11">!!!</span> |'
1171 echo "</pre></section>"
1172 fi
1174 # find unpackaged files
1175 all_files=$(mktemp)
1176 cd $wok/$main/install; find ! -type d | sed 's|\.||' > $all_files
1177 orphans="$(sort $all_files $packaged | uniq -u)"
1178 if [ -d "$wok/$main/install" -a -n "$orphans" ]; then
1179 echo '<script>document.getElementById("li-orphans").style.display = "list-item"</script>'
1180 echo '<section><h3 id="id-orphans">Unpackaged files:</h3>'
1181 table=$(mktemp)
1182 echo "$orphans" | awk -vi="$base/$indir/browse/install" '
1183 function tag(text, color) {
1184 printf("<span class=\"c%s1\">%s</span> ", color, text);
1185 printf("<a class=\"c00\" href=\"%s\">%s</a>\n", i $0, $0);
1187 /\/perllocal.pod$/ || /\/\.packlist$/ || /\/share\/bash-completion\// ||
1188 /\/lib\/systemd\// || /\.pyc$/ || /\.pyo$/ { tag("---", 0); next }
1189 /\.pod$/ { tag("pod", 5); next }
1190 /\/share\/man\// { tag("man", 5); next }
1191 /\/share\/doc\// || /\/share\/gtk-doc\// || /\/share\/info\// ||
1192 /\/share\/devhelp\// { tag("doc", 5); next }
1193 /\/share\/icons\// { tag("ico", 2); next }
1194 /\/share\/locale\// { tag("loc", 4); next }
1195 /\.h$/ || /\.a$/ || /\.la$/ || /\.pc$/ || /\/bin\/.*-config$/ ||
1196 /\/Makefile.*$/ { tag("dev", 3); next }
1197 { tag("???", 1) }
1198 ' > $table
1200 # Summary table
1201 for i in head body; do
1202 case $i in
1203 head) echo -n '<table class="summary"><tr>';;
1204 body) echo -n '<th> </th></tr><tr>';;
1205 esac
1206 for j in '???1' dev3 loc4 ico2 doc5 man5 pod5 '---0'; do
1207 tag=${j:0:3}; class="c${j:3:1}0"; [ "$class" == 'c00' ] && class='c01'
1208 case $i in
1209 head) echo -n "<th class='$class'>$tag</th>";;
1210 body) printf '<td>%s</td>' "$(grep ">$tag<" $table | wc -l)";;
1211 esac
1212 done
1213 done
1214 echo '<td> </td></tr></table>'
1216 echo -n '<pre class="files">'
1217 cat $table
1218 echo '</pre></section>'
1219 rm $table
1220 fi
1221 rm $packaged $all_files
1222 ;;
1224 description)
1225 page_header
1226 pkg_info
1227 descs="$(ls $WOK/$pkg/description*.txt)"
1228 if [ -n "$descs" ]; then
1229 echo '<div id="content2">'
1230 [ -f "$WOK/$pkg/description.txt" ] && show_desc "$pkg" "$WOK/$pkg/description.txt"
1231 for i in $descs; do
1232 case $i in
1233 */description.txt) continue ;;
1234 *) package=$(echo $i | cut -d. -f2) ;;
1235 esac
1236 show_desc "$package" "$i"
1237 done
1238 echo '</div>'
1239 else
1240 show_note w "No description of $pkg"
1241 fi
1242 ;;
1244 log)
1245 page_header
1246 pkg_info
1247 [ -z "$arg" ] && arg=$(stat -c %Y $LOGS/$pkg.log)
1249 echo '<div class="btnList">'
1250 acc='l' # access key for the latest log is 'L'
1251 while read log; do
1252 # for all $pkg.log, $pkg.log.0 .. $pkg.log.9, $pkg-pack.log (if any)
1253 timestamp=$(stat -c %Y $log)
1254 class=''
1255 if [ "$arg" == "$timestamp" ]; then
1256 class=' log'
1257 logfile="$log"
1258 fi
1259 case $log in *-pack.log) acc='p';; esac # access key for the packing log is 'P'
1260 echo -n "<a class='button$class' data-acc='$acc' accesskey='$acc' href='$base/$pkg/log/$timestamp'>"
1261 echo "$(stat -c %y $log | cut -d: -f1,2)</a>"
1262 case $acc in
1263 l) acc=0;;
1264 *) acc=$((acc+1));;
1265 esac
1266 done <<EOT
1267 $(find $LOGS -name "$pkg.log*" | sort)
1268 $(find $LOGS -name "$pkg-pack.log")
1269 EOT
1270 echo '</div>'
1272 if [ -z "$logfile" ]; then
1273 show_note e "Requested log is absent"
1274 page_footer
1275 exit 0
1276 fi
1278 # Define cook variables for syntax highlighter
1279 if [ -s "$WOK/$pkg/receipt" ]; then
1280 . "$WOK/$pkg/receipt"
1281 _wok='/home/slitaz/wok'
1282 _src="$_wok/$pkg/source/$PACKAGE-$VERSION"
1283 _install="$_wok/$pkg/install"
1284 _fs="$_wok/$pkg/taz/$PACKAGE-$VERSION/fs"
1285 _stuff="$_wok/$pkg/stuff"
1286 fi
1288 # if [ ! -f "gzlog/$pkg.$arg" ]; then
1289 # {
1290 # summary "$logfile" links
1292 # syntax_highlighter log < $logfile | awk '
1293 # BEGIN { print "<pre class=\"log\">"; }
1294 # { printf("<a name=\"l%d\" href=\"#l%d\">%5d</a> %s\n", NR, NR, NR, $0); }
1295 # END { print "</pre>"; }
1296 # '
1298 # page_footer
1299 # } | gzip > gzlog/$pkg.$arg
1300 # fi
1302 blog=$(basename $logfile)
1303 summary "$logfile" links
1305 # disable next `sed` for the 'like2016' theme
1306 theme=$(COOKIE theme); theme=${theme:-default}; [ "$theme" != 'like2016' ] && theme=''
1307 cat $logfile | syntax_highlighter log | \
1308 sed -e "/(pkg\/local$theme):/ s|: \([^<]*\)|<img src='$base/i/$blog/\1'> \1|" | \
1309 awk '
1310 BEGIN { print "<pre class=\"log\">"; }
1311 { printf("<a name=\"l%d\" href=\"#l%d\">%5d</a> %s\n", NR, NR, NR, $0); }
1312 END { print "</pre>"; }
1314 ;;
1317 man|doc|info)
1318 page_header
1319 pkg_info
1320 echo '<div style="max-height: 6.4em; overflow: auto; padding: 0 4px">'
1322 dir="wok/$pkg/install/usr/share/$cmd"
1323 [ "$cmd" == 'doc' ] && dir="$dir wok/$pkg/install/usr/share/gtk-doc"
1324 if [ "$cmd" == 'doc' -a -z "$arg" ]; then
1325 try=$(for i in $dir; do find $i -name 'index.htm*'; done | sed q)
1326 [ -n "$try" ] && arg="$try"
1327 fi
1328 while read i; do
1329 [ -s "$i" ] || continue
1330 case "$i" in
1331 *.jp*g|*.png|*.gif|*.svg|*.css) continue
1332 esac
1333 i=${i#$dir/}
1334 [ -n "$arg" ] || arg="$i"
1335 class=''; [ "$arg" == "$i" ] && class=" doc"
1336 case "$cmd" in
1337 man)
1338 case $i in
1339 man*) lang='';;
1340 *) lang="${i%%/*}: ";;
1341 esac
1342 man=$(basename $i .gz)
1343 echo "<a class='button$class' href='$base/$pkg/man/$i'>$lang${man%.*} (${man##*.})</a>"
1344 ;;
1345 doc)
1346 echo "<a class='button$class' href='$base/$pkg/doc/$i'>$(basename $i .gz)</a>"
1347 ;;
1348 info)
1349 info=$(basename $i)
1350 echo "<a class='button$class' href='$base/$pkg/info/$i#Top'>${info/.info/}</a>"
1351 ;;
1352 esac
1353 done <<EOT
1354 $(for i in $dir; do find $i -type f; done | sort)
1355 EOT
1356 echo '</div>'
1358 [ -f "$arg" ] || arg="$dir/$arg"
1359 if [ -f "$arg" ]; then
1360 tmp="$(mktemp)"
1361 docat "$arg" > $tmp
1362 [ -s "$tmp" ] &&
1363 case "$cmd" in
1364 info)
1365 echo '<div id="content2" class="texinfo"><pre class="first">'
1366 info2html < "$tmp"
1367 echo '</pre></div>'
1368 ;;
1369 doc)
1370 case "$arg" in
1371 *.sgml|*.devhelp2) class='xml';;
1372 *.py) class='python';; # pycurl package
1373 *.css) class='css';;
1374 *) class='asciidoc';;
1375 esac
1376 case "$arg" in
1377 *.htm*)
1378 case $arg in
1379 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
1380 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
1381 esac
1382 # make the iframe height so long to contain its contents without scrollbar
1383 echo "<iframe id='idoc' src='$page' width='100%' onload='resizeIframe(this)'></iframe>"
1384 ;;
1385 *.pdf)
1386 case $arg in
1387 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
1388 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
1389 esac
1390 cat <<EOT
1391 <object id="idoc" data="$page" width="100%" height="100%" type="application/pdf" style="min-height: 600px">
1392 $(show_note w "Missing PDF plugin.<br/>Get the file <a href="$page">$(basename "$page")</a>.")
1393 </object>
1394 EOT
1395 ;;
1396 *)
1397 show_code $class < "$tmp"
1398 ;;
1399 esac
1400 ;;
1401 man)
1402 #export TEXTDOMAIN='man2html'
1403 echo "<div id='content2'>"
1405 html=$(./man2html "$tmp" | sed -e '1,/<header>/d' -e '/<footer>/,$d' \
1406 -e 's|<a href="file:///[^>]*>\([^<]*\)</a>|\1|g' \
1407 -e 's|<a href="?[1-9]\+[^>]*>\([^<]*\)</a>|\1|g')
1409 if [ -n "$(echo "$html" | fgrep 'The requested file /tmp/tmp.')" ]; then
1410 # Process the pre-formatted man-cat page
1411 # (for example see sudo package without groff in build dependencies)
1412 sed -i '
1413 s|M-bM-^@M-^S|—|g;
1414 s|M-bM-^@M-^\\|<b>|g;
1415 s|M-bM-^@M-^]|</b>|g
1416 s|M-bM-^@M-^X|<u>|g;
1417 s|M-bM-^@M-^Y|</u>|g;
1418 s|M-BM-||g;
1419 s|++oo|•|g;
1420 s|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g;
1421 ' "$tmp"
1422 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 \
1423 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 \
1424 0 1 2 3 4 5 6 7 8 9 _ - '\\+' '\.' /; do
1425 sed -i "s|$i$i|<b>$i</b>|g; s|_$i|<u>$i</u>|g" "$tmp"
1426 done
1427 echo '<pre class="catman">'
1428 sed 's|</b><b>||g; s|</u><u>||g; s|</u><b>_</b><u>|_|g; s|</b> <b>| |g;' "$tmp"
1429 echo '</pre>'
1430 else
1431 echo "$html"
1432 fi
1433 echo "</div>"
1434 ;;
1435 esac
1436 rm -f $tmp
1437 else
1438 show_note e "File “$arg” not exists!"
1439 fi
1440 ;;
1442 download)
1443 page_header
1444 pkg_info
1445 show=0
1447 . $wok/$pkg/receipt
1449 if [ -n "$TARBALL" -a -s "$SRC/$TARBALL" ]; then
1450 files_header
1451 echo "<tr><td><a href='$base/src/$TARBALL'>$TARBALL</a></td>"
1452 ls -lh "$SRC/$TARBALL" | awk '{printf("<td>%sB</td>", $5)}'
1453 echo "<td>Sources for building the package “$pkg”</td></tr>"
1454 show=1
1455 fi
1457 if [ -d "$wok/$pkg/taz" ]; then
1458 [ "$show" -eq 1 ] || files_header
1460 for i in $(all_names); do
1461 [ -e "$wok/$pkg/taz/$i-$VERSION$EXTRAVERSION/receipt" ] || continue
1462 . $wok/$pkg/taz/$i-$VERSION$EXTRAVERSION/receipt
1464 for filename in "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg"; do
1465 [ -f "$PKGS/$filename" ] &&
1466 cat <<EOT
1467 <tr>
1468 <td><a href="$base/get/$filename">$filename</a></td>
1469 <td>$(ls -lh ./packages/$filename | awk '{printf("%sB", $5)}')</td>
1470 <td>$SHORT_DESC</td>
1471 </tr>
1472 EOT
1473 done
1474 done
1475 show=1
1476 fi
1478 if [ "$show" -eq 1 ]; then
1479 echo '</tbody></table></section>'
1480 else
1481 show_note w "Sorry, there's nothing to download…"
1482 fi
1483 ;;
1485 esac
1488 page_footer
1489 exit 0