cookutils view lighttpd/index.cgi @ rev 979

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