cookutils view lighttpd/index.cgi @ rev 932

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