cookutils view lighttpd/index.cgi @ rev 1002
cook: export CAT for mk_pkg_receipt; lighttpd/index.cgi: rename man2html to man2html.bin for package man2html availability, prepend diff output with vertical bar, improve coloring.
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Mon Nov 06 02:53:05 2017 +0200 (2017-11-06) |
parents | ae3975981d3f |
children | 75b330dd2734 |
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 '/s/<pkg>': show status indicator icon
275 # Can't use ?query - not able to change '+' to '%2B' in the sed rules (see log handler)
277 if [ "$pkg" == 's' ]; then
278 # argument <pkg> is in $cmd variable
280 # find main package
281 main=$(awk -F$'\t' -vpkg=" $cmd " '{
282 if (index(" " $2 " ", pkg)) {print $1; exit}
283 }' $splitdb)
284 # get version
285 ver="$(. $wok/$main/receipt; echo "$VERSION")"
287 echo -en "Content-Type: image/svg+xml\n\n<svg xmlns='http://www.w3.org/2000/svg' height='12' width='8'><path d='"
288 if [ -e $PKGS/$cmd-$ver.tazpkg ]; then
289 echo "m1 2-1 1v8l1 1h6l1-1v-8l-1-1z' fill='#090'/></svg>"
290 else
291 echo "m0 3v8l1 1h6l1-1v-8l-1-1h-6zm3 0h2v5h-2zm0 6h2v2h-2z' fill='#d00'/></svg>"
292 fi
293 exit
294 fi
297 # Query '?theme[=<theme>]': change UI theme
299 if [ -n "$(GET theme)" ]; then
300 theme="$(GET theme)"
301 ref="$(echo "$HTTP_REFERER" | sed 's|:|%3A|g; s|/|%2F|g; s|\?|%3F|g; s|\+|%2B|g;')"
302 case $theme in
303 theme)
304 current=$(COOKIE theme)
305 page_header
306 cat <<EOT
307 <section>
308 <h2>Change theme</h2>
309 <p>Current theme: “${current:-default}”. Select other:</p>
310 <ul>
311 $(
312 for i in default emerald sky goldenrod midnight like2016 terminal; do
313 [ "$i" == "${current:-default}" ] || echo "<li><a href=\"$base/?theme=$i&ref=$ref\">$i</a></li>"
314 done
315 )
316 </ul>
317 </section>
318 EOT
319 page_footer
320 exit 0
321 ;;
322 default|emerald|sky|goldenrod|midnight|like2016|terminal)
323 ref="$(GET ref)"
324 [ -n "$ref" ] || ref="$base/"
325 # Expires in a year
326 expires=$(date -uRd @$(($(date +%s)+31536000)) | sed 's|UTC|GMT|')
327 echo -e "HTTP/1.1 302 Found\nLocation: $ref\nCache-Control: no-cache\nSet-Cookie: theme=$theme; expires=$expires\n\n"
328 exit 0
329 ;;
330 esac
331 fi
334 #case "$QUERY_STRING" in
335 # stuff*)
336 # file="$wok/$(GET stuff)"
337 # manage_modified "$file"
338 # ;;
339 #
340 # pkg=*|receipt=*|description=*|files=*|log=*|man=*|doc=*|info=*)
341 # type=${QUERY_STRING%%=*}
342 # pkg=$(GET $type)
343 # case "$type" in
344 # description)
345 # manage_modified "$wok/$pkg/receipt" 'no-last-modified'
346 # manage_modified "$wok/$pkg/description.txt" 'silently-absent'
347 # ;;
348 # log)
349 # manage_modified "$wok/${pkg%%.log*}/receipt" 'no-last-modified'
350 # manage_modified "$LOGS/$pkg"
351 # ;;
352 # *)
353 # manage_modified "$wok/$pkg/receipt" pkg
354 # ;;
355 # esac
356 # ;;
357 #esac
360 # RSS feed generator
361 # URI: ?rss[&limit={1..100}]
363 if [ -n "$(GET rss)" ]; then
364 limit=$(GET limit); limit="${limit:-12}"; [ "$limit" -gt 100 ] && limit='100'
365 pubdate=$(date -Rur$(ls -t $FEEDS/*.xml | head -n1) | sed 's|UTC|GMT|')
366 cooker_url="http://$HTTP_HOST$base/"
367 cat <<EOT
368 Content-Type: application/rss+xml
370 <?xml version="1.0" encoding="utf-8" ?>
371 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
372 <channel>
373 <title>$title</title>
374 <description>The SliTaz packages cooker feed</description>
375 <link>$cooker_url</link>
376 <lastBuildDate>$pubdate</lastBuildDate>
377 <pubDate>$pubdate</pubDate>
378 <atom:link href="$cooker_url?rss" rel="self" type="application/rss+xml" />
379 EOT
380 for rss in $(ls -t $FEEDS/*.xml | head -n$limit); do
381 sed "s|http[^=]*=|$cooker_url|; s|<guid|& isPermaLink=\"false\"|g; s|</pubDate| GMT&|g" $rss
382 done
383 cat <<EOT
384 </channel>
385 </rss>
386 EOT
387 exit 0
388 fi
391 ### OpenSearch ###
393 # Query '/os.xml': get OpenSearch Description
395 if [ "$pkg" == 'os.xml' ]; then
396 cat <<EOT
397 Content-Type: application/xml; charset=UTF-8
399 <?xml version="1.0" encoding="UTF-8"?>
400 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
401 <ShortName>$title</ShortName>
402 <Description>SliTaz packages search</Description>
403 <Image width="16" height="16" type="image/png">http://$HTTP_HOST/images/logo.png</Image>
404 <Url type="text/html" method="GET" template="http://$HTTP_HOST$base/{searchTerms}"/>
405 <Url type="application/x-suggestions+json" method="GET" template="http://$HTTP_HOST$base/">
406 <Param name="oss" value="{searchTerms}"/>
407 </Url>
408 <SearchForm>http://$HTTP_HOST$base/</SearchForm>
409 <InputEncoding>UTF-8</InputEncoding>
410 </OpenSearchDescription>
411 EOT
412 exit 0
413 fi
415 # Query '?oss[=<term>]': OpenSearch suggestions
417 if [ -n "$(GET oss)" ]; then
418 term="$(GET oss | tr -cd '[:alnum:]+-')"
419 echo -e 'Content-Type: application/x-suggestions+json; charset=UTF-8\n'
420 cd $wok
421 ls | fgrep "$term" | head -n10 | awk -vterm="$term" '
422 BEGIN{printf("[\"%s\",[", term)}
423 {printf("%s\"%s\"", NR != 1 ? "," : "", $0)}
424 END {printf("]]")}
425 '
426 exit 0
427 fi
432 #
433 # Functions
434 #
437 # Unpack to stdout
439 docat() {
440 case "$1" in
441 *gz) zcat ;;
442 *bz2) bzcat ;;
443 *xz) xzcat ;;
444 *) cat
445 esac < $1
446 }
449 # Tiny texinfo converter
451 info2html() {
452 sed \
453 -e 's|&|\&|g; s|<|\<|g; s|>|\>|g' \
454 -e 's|^\* \(.*\)::|* <a href="#\1">\1</a> |' \
455 -e 's|\*note \(.*\)::|<a href="#\1">\1</a>|' \
456 -e '/^File: / s|(dir)|Top|g' \
457 -e '/^File: / s|Next: \([^,]*\)|<a class="button" href="#\1">Next: \1</a>|' \
458 -e '/^File: / s|Prev: \([^,]*\)|<a class="button" href="#\1">Prev: \1</a>|' \
459 -e '/^File: / s|Up: \([^,]*\)|<a class="button" href="#\1">Up: \1</a>|' \
460 -e '/^File: / s|^.* Node: \([^,]*\), *\(.*\)$|<pre id="\1">\2|' \
461 -e '/^<pre id=/ s|^\([^>]*>\)\(<a[^>]*>Next: [^,]*\), *\(<a[^>]*>Prev: [^,]*\), *\(<a[^>]*>Up: .*\)|\1 \3 \4 \2|' \
462 -e '/^Tag Table:$/,/^End Tag Table$/d' \
463 -e '/INFO-DIR/,/^END-INFO-DIR/d' \
464 -e "s|https*://[^>),'\"\`’ ]*|<a href=\"&\">&</a>|g" \
465 -e "s|ftp://[^>),\"\` ]*|<a href=\"&\">&</a>|g" \
466 -e 's|^\* Menu:|<b>Menu:</b>|' \
467 -e "s|^|</pre>|"
468 }
471 # Put some colors into log and DB files.
473 syntax_highlighter() {
474 case $1 in
475 log)
476 # If variables not defined - define them with some rare values
477 : ${_src=#_#_#}
478 : ${_install=#_#_#}
479 : ${_fs=#_#_#}
480 : ${_stuff=#_#_#}
481 # Use one-letter html tags to save some bytes :)
482 # <b>is error (red)</b> <u>is warning (orange)</u> <i>is informative (green)</i>
483 sed \
484 -e 's/&/\&/g; s/</\</g; s/>/\>/g' \
485 -e 's#OK$#<i>OK</i>#' \
486 -e 's#\([Dd]one\)$#<i>\1</i>#' \
487 -e 's#Success$#<i>Success</i>#' \
488 -e 's#\([^a-z]\)ok$#\1<i>ok</i>#' \
489 -e 's#\([^a-z]\)yes$#\1<i>yes</i>#' \
490 -e 's#\([^a-z]\)ON$#\1<i>ON</i>#' \
491 -e 's#\([^a-z]\)no$#\1<u>no</u>#' \
492 -e 's#\([^a-z]\)none$#\1<u>none</u>#' \
493 -e 's#\([^a-z]\)false$#\1<u>false</u>#' \
494 -e 's#\([^a-z]\)OFF$#\1<u>OFF</u>#' \
495 -e 's#\(^checking .*\.\.\. \)\(.*\)$#\1<i>\2</i>#' \
496 \
497 -e 's#\( \[Y[nm/]\?\] n\)$# <u>\1</u>#' \
498 -e 's#\( \[N[ym/]\?\] y\)$# <i>\1</i>#' \
499 -e 's# y$# <i>y</i>#' \
500 -e 's# n$# <u>n</u>#' \
501 -e 's#(NEW) *$#<b>(NEW)</b>#' \
502 \
503 -e 's#.*(pkg/local).*#<i>\0</i>#' \
504 -e 's#.*(web/cache).*#<u>\0</u>#' \
505 \
506 -e 's#\([^a-zA-Z]\)\([Ee]rror\)$#\1<b>\2</b>#' \
507 -e 's#ERROR:#<b>ERROR:</b>#g' \
508 \
509 -e 's#^.*[Ff][Aa][Ii][Ll][Ee][Dd].*#<b>\0</b>#' \
510 -e 's#^.*[Ff]atal.*#<b>\0</b>#' \
511 -e '/non-fatal/ s|</*b>||g' \
512 -e 's#^.*[Nn]ot found.*#<b>\0</b>#' \
513 -e 's#^.*[Nn]o such file.*#<b>\0</b>#' \
514 -e 's#^.*No package .* found.*#<b>\0</b>#' \
515 -e 's#^.*Unable to find.*#<b>\0</b>#' \
516 -e 's#[^a-zA-Z-][Ii]nvalid.*#<b>\0</b>#' \
517 -e 's#\([Nn][Oo][Tt] found\.*\)$#<b>\1</b>#' \
518 -e 's#\(found\.*\)$#<i>\1</i>#' \
519 \
520 -e 's#^.*WARNING:.*#<u>\0</u>#' \
521 -e 's#^.*warning:.*#<u>\0</u>#' \
522 -e 's#^.* [Ee]rror:* .*#<b>\0</b>#' \
523 -e 's#^.*terminated.*#<b>\0</b>#' \
524 -e 's#\(missing\)#<b>\1</b>#g' \
525 -e 's#^.*[Cc]annot find.*#<b>\0</b>#' \
526 -e 's#^.*unrecognized options.*#<u>\0</u>#' \
527 -e 's#^.*does not.*#<u>\0</u>#' \
528 -e 's#^.*[Ii]gnoring.*#<u>\0</u>#' \
529 -e 's#^.*note:.*#<u>\0</u>#' \
530 \
531 -e 's#^.* will not .*#<u>\0</u>#' \
532 -e 's!^Hunk .* succeeded at .*!<u>\0</u>!' \
533 -e 's#^.* Warning: .*#<u>\0</u>#' \
534 \
535 -e "s#^Executing:\([^']*\).#<em>\0</em>#" \
536 -e "s#^Making.*#<em>\0</em>#" \
537 -e "s#^Scanning dependencies of target .*#<em>\0</em>#" \
538 -e "s#^====\([^']*\).#<span class='span-line'>\0</span>#g" \
539 -e "s#^[a-zA-Z0-9]\([^']*\) :: #<span class='span-sky'>\0</span>#g" \
540 -e "s#[fh]tt*ps*://[^ '\"]*#<a href='\0'>\0</a>#g" \
541 \
542 -e 's|^<u>\(.*libtool: warning: relinking.*\)</u>|\1|' \
543 -e 's|^<u>\(.*libtool: warning: .* has not been installed in .*\)</u>|\1|' \
544 -e 's|^<u>\(.*checking for a sed.*\)</u>|\1|' \
545 \
546 -e "s|$_src|<var>\${src}</var>|g;
547 s|$_install|<var>\${install}</var>|g;
548 s|$_fs|<var>\${fs}</var>|g;
549 s|$_stuff|<var>\${stuff}</var>|g" \
550 \
551 -e "s|\[\([01]\);3\([1-7]\)m|<span class='c\2\1'>|g;
552 s|\[\([01]\);0m|<span class='c0\1'>|g;
553 s|\[0m|</span>|g;" \
554 \
555 -e "s|\[9\([1-6]\)m|<span class='c\10'>|;
556 s|\[39m|</span>|;
557 s|\[1m|<strong>|g; s|\[0m|</strong>|g" \
558 -e "s!^|\(+.*\)!|<span class='c20'>\1</span>!;
559 s!^|\(-.*\)!|<span class='c10'>\1</span>!;
560 s!^|\(@@.*@@\)\$!|<span class='c30'>\1</span>!;"
561 \
563 ;;
565 files)
566 # Highlight the Busybox's `ls` output
567 awk '{
568 part1 = substr($0, 0, 16);
569 part2 = substr($0, 17, 9);
570 part3 = substr($0, 26, 9);
571 part4 = substr($0, 35);
572 if (part2 != "root ") part2 = "<span class=\"c11\">" part2 "</span>";
573 if (part3 != "root ") part3 = "<span class=\"c11\">" part3 "</span>";
574 print part1 part2 part3 part4;
575 }' | \
576 sed "s|\[0m/|/\[0m|g;
577 s|\[\([01]\);3\([1-7]\)m|<a class='c\2\1'>|g;
578 s|\[\([01]\);0m|<a class='c0\1'>|g;
579 s|\[0m|</a>|g;
580 s|^\(lrwxrwxrwx\)|<span class='c61'>\1</span>|;
581 s|^\(-rwxr-xr-x\)|<span class='c21'>\1</span>|;
582 s|^\(-rw-r--r--\)|<span class='c31'>\1</span>|;
583 s|^\(drwxr-xr-x\)|<span class='c41'>\1</span>|;
584 s|^\([lrwxs-]*\)|<span class='c11'>\1</span>|;
585 "
586 ;;
587 esac
588 }
591 show_code() {
592 echo -n "<pre><code class=\"language-$1\">"
593 sed 's|&|\&|g; s|<|\<|g; s|>|\>|g'
594 echo '</code></pre>'
595 }
598 datalist() {
599 cut -d$'\t' -f2 $splitdb | tr ' ' '\n' | sort -u | awk '
600 BEGIN{printf("<datalist id=\"packages\">")}
601 {printf("<option>%s",$1)}
602 END {printf("</datalist>")}
603 '
604 }
607 mklog() {
608 awk '
609 BEGIN { printf("<pre class=\"log dog\">\n") }
610 { print }
611 END { print "</pre>" }'
612 }
615 summary() {
616 log="$1"
617 pkg="$(basename ${log%%.log*})"
619 if [ -f "$log" ]; then
620 if grep -q "cook:$pkg$" $command; then
621 show_note i "The Cooker is currently building $pkg"
622 elif fgrep -q "Summary for:" $log; then
623 sed '/^Summary for:/,$!d' $log | awk '
624 BEGIN { print "<section>" }
625 function row(line) {
626 split(line, s, " : ");
627 printf("\t<tr><td>%s</td><td>%s</td></tr>\n", s[1], s[2]);
628 }
629 function row2(line, rowNum) {
630 split(line, s, " : ");
631 if (rowNum == 1) {
632 print "<thead>";
633 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]);
634 print "</thead><tbody>";
635 }
636 else
637 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]);
638 }
639 {
640 if (NR==1) { printf("<h3>%s</h3>\n<table>\n", $0); next }
641 if ($0 ~ "===") { seen++; if (seen == 1) next; else exit; }
642 if ($0 ~ "---") {
643 seen2++;
644 if (seen2 == 1) print "</table>\n\n<table class=\"pkgslist\">"
645 next
646 }
647 if (seen2) row2($0, seen2); else row($0);
648 }
649 END { print "</tbody></table></section>" }
650 '
651 elif fgrep -q "Debug information" $log; then
652 echo -e '<section>\n<h3>Debug information</h3>'
653 sed -e '/^Debug information/,$!d; /^===/d; /^$/d' $log | sed -n '1!p' | \
654 if [ -n "$2" ]; then
655 syntax_highlighter log | sed 's|\([^0-9 ]\)\([0-9][0-9]*\):|\1<a href="#l\2">\2</a>:|'
656 else
657 sed 's|^[0-9][0-9]*:||' | syntax_highlighter log
658 fi | mklog
659 echo '</section>'
660 fi
661 else
662 [ -n "$pkg" -a -d "$wok/$pkg" ] && show_note e "No log for $pkg"
663 fi
664 }
667 active() {
668 [ "$cmd" == "$1" -o "$cmd" == "${2:-$1}" ] && echo -n ' active'
669 }
672 pkg_info() {
673 local log active bpkg short_desc=''
674 log="$LOGS/$pkg.log"
676 echo -n "<h2><a href=\"$base/${requested_pkg:-$pkg}\">${requested_pkg:-$pkg}</a>"
677 # Get short description for existing packages
678 [ -f $PKGS/packages.info ] &&
679 short_desc="$(awk -F$'\t' -vp="${requested_pkg:-$pkg}" '{if ($1 == p) { printf("%s", $4); exit; }}' $PKGS/packages.info)"
680 # If package not exists (not created yet or broken), get short description
681 # (but only for "main" package) from receipt
682 [ -n "$short_desc" ] || short_desc="$(. $wok/$pkg/receipt; echo "$SHORT_DESC")"
683 echo ": $short_desc</h2>"
684 echo '<div id="info">'
685 echo "<a class='button icon receipt$(active receipt stuff)' href='$base/$pkg/receipt'>receipt & stuff</a>"
687 unset WEB_SITE WANTED
688 . $wok/$pkg/receipt
690 [ -n "$WEB_SITE" ] &&
691 echo "<a class='button icon website' href='$WEB_SITE' target='_blank' rel='noopener noreferrer'>web site</a>"
693 [ -f "$wok/$pkg/taz/$PACKAGE-$VERSION/receipt" ] &&
694 echo "<a class='button icon files$(active files)' href='$base/$pkg/files'>files</a>"
696 [ -n "$(ls $wok/$pkg/description*.txt)" ] &&
697 echo "<a class='button icon desc$(active description)' href='$base/$pkg/description'>description</a>"
699 [ -n "$TARBALL" -a -s "$SRC/$TARBALL" -o -d "$wok/$pkg/taz" ] &&
700 echo "<a class='button icon download' href='$base/$pkg/download'>download</a>"
702 echo "<a class='button icon browse' href='$base/$pkg/browse/'>browse</a>"
704 [ -x ./man2html.bin -a -d "$wok/$pkg/install/usr/share/man" ] &&
705 echo "<a class='button icon doc$(active man)' href='$base/$pkg/man/'>man</a>"
707 [ -d "$wok/$pkg/install/usr/share/doc" -o -d "$wok/$pkg/install/usr/share/gtk-doc" ] &&
708 echo "<a class='button icon doc$(active doc)' href='$base/$pkg/doc/'>doc</a>"
710 [ -d "$wok/$pkg/install/usr/share/info" ] &&
711 echo "<a class='button icon doc$(active info)' href='$base/$pkg/info/#Top'>info</a>"
713 if [ -n "$LFS" ]; then
714 printf "<a class='button icon doc' href='%s' target='_blank' rel='noopener noreferrer'>" "$LFS"
715 [ "${LFS/blfs/}" != "$LFS" ] && printf "B"
716 printf "LFS</a>\n"
717 fi
719 [ -s "$log" ] &&
720 echo "<a class='button icon log$(active log)' href='$base/$pkg/log/'>logs</a>"
722 echo '</div>'
723 }
726 mktable() {
727 sed 's# : #|#' | awk -vc="$1" '
728 BEGIN { printf("<table class=\"%s\">\n", c); FS="|" }
729 { printf("<tr><td>%s</td>", $1);
730 if (NF == 2) printf("<td>%s</td>", $2);
731 printf("</tr>\n", $2) }
732 END { print "</table>" }'
733 }
736 section() {
737 local i=$(basename "$1")
738 echo -e '\n\n<section>'
739 [ $(wc -l < $1) -gt $2 ] && echo "<a class='button icon more r' href='?$i'>${3#*|}</a>"
740 echo "<h2>${3%|*}</h2>"
741 mktable "$i"
742 echo '</section>'
743 }
746 show_desc() {
747 echo "<section><h3>Description of “$1”</h3>"
748 if [ -n "$md2html" ]; then
749 $md2html $2
750 else
751 show_code markdown < $2
752 fi
753 echo "</section>"
754 }
757 # Return all the names of packages bundled in this receipt
759 all_names() {
760 local split=" $SPLIT "
761 if [ "${split/ $PACKAGE /}" != "$split" ]; then
762 # $PACKAGE included somewhere in $SPLIT (probably in the end).
763 # We should build packages in the order defined in the $SPLIT.
764 echo $SPLIT
765 else
766 # We'll build the $PACKAGE, then all defined in the $SPLIT.
767 echo $PACKAGE $SPLIT
768 fi
769 }
772 toolchain_version() {
773 echo "<tr><td><a href='$base/$1'>$1</a></td><td>"
774 if [ -e "$WOK/$1/receipt" ]; then
775 grep ^VERSION $WOK/$1/receipt | cut -d '"' -f2
776 echo '</td><td>'
777 grep ^SHORT_DESC $WOK/$1/receipt | cut -d '"' -f2
778 else
779 echo -n '---</td><td>---'
780 fi
781 echo "</td></tr>"
782 }
785 files_header() {
786 echo '<section><h3>Available downloads:</h3>'
787 echo '<table><thead><tr><th>File</th><th>Size</th><th>Description</th></tr></thead><tbody>'
788 }
791 # Update statistics used in web interface.
792 # There is no need to recalculate the statistics every time the page is displayed.
793 # Note, $webstat file must be owned by www, otherwise this function will not be able to do the job.
795 update_webstat() {
796 echo '<div id="waitme">'
797 show_note i 'Please wait while statistics are being collected.'
798 echo "</div>"
800 # for receipts:
801 rtotal=$(ls $WOK/*/arch.$ARCH | wc -l)
802 rcooked=$(ls -d $WOK/*/taz | wc -l)
803 runbuilt=$(($rtotal - $rcooked))
804 rblocked=$(wc -l < $blocked)
805 rbroken=$(wc -l < $broken)
807 # for packages:
808 ptotal=$(cut -d$'\t' -f2 $CACHE/split.db | tr ' ' '\n' | sort -u | wc -l)
809 pcooked=$(ls $PKGS/*.tazpkg | wc -l)
810 punbuilt=$(($ptotal - $pcooked))
811 pblocked=$(
812 while read i; do
813 sed "/^$i\t/!d" $CACHE/split.db
814 done < $blocked | cut -d$'\t' -f2 | tr ' ' '\n' | wc -l)
815 pbroken=$(
816 while read i; do
817 sed "/^$i\t/!d" $CACHE/split.db
818 done < $broken | cut -d$'\t' -f2 | tr ' ' '\n' | wc -l)
820 cat > $webstat <<EOT
821 rtotal="$rtotal"; rcooked="$rcooked"; runbuilt="$runbuilt"; rblocked="$rblocked"; rbroken="$rbroken"
822 ptotal="$ptotal"; pcooked="$pcooked"; punbuilt="$punbuilt"; pblocked="$pblocked"; pbroken="$pbroken"
823 EOT
825 echo '<script>document.getElementById("waitme").remove();</script>'
826 }
831 #
832 # Load requested page
833 #
835 if [ -z "$pkg" ]; then
837 page_header
838 if [ -n "$QUERY_STRING" -a "$QUERY_STRING" != 'debug' ]; then
840 for list in activity cooknotes cooklist; do
841 [ -n "$(GET $list)" ] || continue
842 [ "$list" == 'cooklist' ] && nb="- Packages: $(wc -l < $cooklist)"
843 echo '<section id="content2">'
844 echo "<h2>DB: $list $nb</h2>"
845 tac $CACHE/$list | sed 's|cooker.cgi?pkg=||; s|%2B|+|g;
846 s|\[ Done|<span class="r c20">Done|;
847 s|\[ Failed|<span class="r c10">Failed|;
848 s| \]|</span>|' | mktable $list
849 echo '</section>'
850 done
852 if [ -n "$(GET broken)" ]; then
853 echo '<section id="content2">'
854 echo "<h2>DB: broken - Packages: $(wc -l < $broken)</h2>"
855 sort $CACHE/broken | sed "s|^[^']*|<a href='$base/\0'>\0</a>|g" | mktable
856 echo '</section>'
857 fi
859 case "$QUERY_STRING" in
860 *.log)
861 log=$LOGS/$QUERY_STRING
862 name=$(basename $log)
863 if [ -f "$log" ]; then
864 echo "<h2>Log for: ${name%.log}</h2>"
865 if fgrep -q "Summary" $log; then
866 echo '<pre class="log">'
867 grep -A 20 'Summary' $log | syntax_highlighter log
868 echo '</pre>'
869 fi
870 echo '<pre class="log">'
871 syntax_highlighter log < $log
872 echo '</pre>'
873 if [ "$QUERY_STRING" == 'pkgdb.log' ]; then
874 # Display button only for SliTaz web browser
875 case "$HTTP_USER_AGENT" in
876 *SliTaz*)
877 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
878 if grep -qs '^pkgdb$' $CACHE/recook-packages; then
879 show_note i "The package database has been requested for re-creation"
880 else
881 echo "<a class='button' href='$base/?recook=pkgdb'>Re-create the DB</a>"
882 fi
883 fi
884 ;;
885 esac
886 fi
887 else
888 show_note e "No log file: $log"
889 fi
890 ;;
891 toolchain)
892 cat <<EOT
893 <div id="content2">
894 <section>
895 <h2>SliTaz GNU/Linux toolchain</h2>
897 <table>
898 <tr><td>Build date</td> <td colspan="2">$(sed -n '/^Cook date/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td></tr>
899 <tr><td>Build duration</td> <td colspan="2">$(sed -n '/^Cook time/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td></tr>
900 <tr><td>Architecture</td> <td colspan="2">$ARCH</td></tr>
901 <tr><td>Build system</td> <td colspan="2">$BUILD_SYSTEM</td></tr>
902 <tr><td>Host system</td> <td colspan="2">$HOST_SYSTEM</td></tr>
903 <tr><th>Package</th><th>Version</th><th>Description</th></tr>
904 $(toolchain_version slitaz-toolchain)
905 $(toolchain_version binutils)
906 $(toolchain_version linux-api-headers)
907 $(toolchain_version gcc)
908 $(toolchain_version glibc)
909 </table>
911 <p>Toolchain documentation: <a target="_blank" rel="noopener noreferrer"
912 href="http://doc.slitaz.org/en:cookbook:toolchain">http://doc.slitaz.org/en:cookbook:toolchain</a>
913 </p>
915 </section>
916 </div>
917 EOT
918 ;;
919 esac
920 page_footer
921 exit 0
922 fi
925 # We may have a toolchain.cgi script for cross cooker's
926 if [ -f "toolchain.cgi" ]; then
927 toolchain="toolchain.cgi"
928 else
929 toolchain="?toolchain"
930 fi
932 # Main page with summary. Count only packages included in ARCH,
933 # use 'cooker arch-db' to manually create arch.$ARCH files.
935 cat <<EOT
936 <div id="content2">
938 <section>
939 <form method="get" action="" class="search r">
940 <input type="hidden" name="search" value="pkg"/>
941 <button type="submit" title="Search">Search</button>
942 <input type="search" name="q" placeholder="Package" list="packages" autocorrect="off" autocapitalize="off"/>
943 </form>
945 <h2>Summary</h2>
946 EOT
948 mktable <<EOT
949 Cooker state : $(running_command)
950 Wok revision : <a href='$WOK_URL' target='_blank' rel='noopener noreferrer'>$(cat $wokrev)</a>
951 Commits to cook : $(wc -l < $commits)
952 Current cooklist : $(wc -l < $cooklist)
953 Architecture : $ARCH, <a href="$toolchain">toolchain</a>
954 Server date : <span id='date'>$(date -u '+%F %R %Z')</span>
955 EOT
957 # If command is "cook:*", update gauge and percentage periodically.
958 # If different package is cooking, reload the page (with new settings)
959 cmd="$(cat $command)"
960 case "$cmd" in
961 cook:*)
962 pkg=${cmd#*:}
963 echo "<script>updatePkg = '${pkg//+/%2B}';</script>"
964 ;;
965 esac
967 # Do we need to update the statistics?
968 [ "$webstat" -nt "$activity" ] || update_webstat
969 . $webstat
971 pct=0; [ "$rtotal" -gt 0 ] && pct=$(( ($rcooked * 100) / $rtotal ))
973 cat <<EOT
974 <div class="meter"><progress max="100" value="$pct">${pct}%</progress><span>${pct}%</span></div>
976 <table class="webstat"><thead>
977 <tr><th> </th><th>Total </th><th>Cooked </th><th>Unbuilt </th><th>Blocked </th><th>Broken </th></tr>
978 </thead><tbody>
979 <tr><td>Receipts</td><td>$rtotal</td><td>$rcooked</td><td>$runbuilt</td><td>$rblocked</td><td>$rbroken</td></tr>
980 <tr><td>Packages</td><td>$ptotal</td><td>$pcooked</td><td>$punbuilt</td><td>$pblocked</td><td>$pbroken</td></tr>
981 </tbody></table>
982 EOT
984 if [ -e "$CACHE/cooker-request" -a ! -s $command ]; then
985 if [ "$activity" -nt "$CACHE/cooker-request" ]; then
986 echo '<a class="button icon bell r" href="?poke">Wake up</a>'
987 else
988 show_note i 'Cooker will be launched in the next 5 minutes.'
989 fi
990 fi
992 cat <<EOT
993 <p>
994 Service logs:
995 <a href="?cookorder.log">cookorder</a> ·
996 <a href="?commits.log">commits</a> ·
997 <a href="?pkgdb.log">pkgdb</a>
998 </p>
999 </section>
1000 EOT
1002 tac $activity | head -n12 | sed 's|cooker.cgi?pkg=||;
1003 s|\[ Done|<span class="r c20">Done|;
1004 s|\[ Failed|<span class="r c10">Failed|;
1005 s| \]|</span>|;
1006 s|%2B|\+|g' | \
1007 section $activity 12 "Activity|More activity"
1009 [ -s "$cooknotes" ] && tac $cooknotes | head -n12 | \
1010 section $cooknotes 12 "Cooknotes|More notes"
1012 [ -s "$commits" ] &&
1013 section $commits 20 "Commits|More commits" < $commits
1015 [ -s "$cooklist" ] && head -n 20 $cooklist | \
1016 section $cooklist 20 "Cooklist|Full cooklist"
1018 [ -s "$broken" ] && head -n20 $broken | sed "s|^[^']*|<a href='\0'>\0</a>|g" | \
1019 section $broken 20 "Broken|All broken packages"
1021 [ -s "$blocked" ] && sed "s|^[^']*|<a href='\0'>\0</a>|g" $blocked | \
1022 section $blocked 12 "Blocked|All blocked packages"
1024 cd $PKGS
1025 ls -let *.tazpkg | awk '
1026 (NR<=20){
1027 sub(/:[0-9][0-9]$/, "", $9);
1028 mon = index(" JanFebMarAprMayJunJulAugSepOctNovDec", $7) / 3;
1029 printf("%d-%02d-%02d %s : <a href=\"get/%s\">%s</a>\n", $10, mon, $8, $9, $11, $11);
1030 }' | \
1031 section $activity 1000 "Latest cook"
1033 echo '</div>'
1034 datalist
1035 page_footer
1036 exit 0
1037 fi
1040 case "$cmd" in
1041 '')
1042 page_header
1044 requested_pkg="$pkg"
1045 # Package info.
1046 if [ ! -f "$wok/$pkg/receipt" ]; then
1047 # Let's look at the cases when the package was not found
1049 # Maybe query is the exact name of split package? -> proceed to main package
1050 mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
1051 if (index(" " $2 " ", pkg)) {print $1; exit}
1052 }' $splitdb)
1054 # No, so let's find any matches among packages names (both main and split)
1055 if [ -z "$mainpkg" ]; then
1056 pkgs=$(cut -d$'\t' -f2 $splitdb | tr ' ' '\n' | fgrep "$pkg")
1057 # Nothing matched
1058 if [ -z "$pkgs" ]; then
1059 echo "<h2>Not Found</h2>"
1060 show_note e "The requested package <b>$pkg</b> was not found on this server."
1061 page_footer; exit 0
1062 fi
1063 # Search results page
1064 echo "<section><h2>Package names matching “$pkg”</h2>"
1065 echo "<table><thead><tr><th>Name</th><th>Description</th><th>Category</th></tr></thead><tbody>"
1066 query="$pkg"
1067 for pkg in $pkgs; do
1068 # Find main package
1069 mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
1070 if (index(" " $2 " ", pkg)) {print $1; exit}
1071 }' $splitdb)
1072 unset SHORT_DESC CATEGORY; . $wok/$mainpkg/receipt
1074 unset SHORT_DESC CATEGORY
1075 [ -e "$wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt" ] &&
1076 . $wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt
1078 echo -n "<tr><td><a href="$base/$pkg">${pkg//$query/<mark>$query</mark>}</a>"
1079 [ "$pkg" == "$mainpkg" ] || echo -n " (${mainpkg//$query/<mark>$query</mark>})"
1080 echo -n "</td><td>$SHORT_DESC</td><td>$CATEGORY</td></tr>"
1081 done
1082 echo '</tbody></table></section>'
1083 page_footer; exit 0
1084 fi
1085 pkg="$mainpkg"
1086 fi
1088 log=$LOGS/$pkg.log
1089 pkg_info
1091 # Check for a log file and display summary if it exists.
1092 summary "$log"
1097 # Informal table with dependencies
1098 pkg="$requested_pkg"
1099 inf="$(mktemp -d)"
1101 # 1/3: Build dependencies (from receipt and pkgdb)
1102 for i in $WANTED $BUILD_DEPENDS $(awk -F$'\t' -vp=" $pkg " '{if (index(" " $2 " ", p) && (" " $1 " " != p)) print $1}' $splitdb); do
1103 echo "$i" >> $inf/a
1104 done
1106 # 2/3: Runtime dependencies (from pkgdb)
1107 {
1108 [ -s "$PKGS/packages.info" ] &&
1109 awk -F$'\t' -vp="$pkg" '{
1110 if ($1 == p) print $8
1111 }' "$PKGS/packages.info"
1112 } | tr ' ' '\n' | sort -u > $inf/b
1114 # 3/3: Required by (from pkgdb)
1115 {
1116 for i in $pkg $(awk -F$'\t' -vp="$pkg" '{if ($1 == p) print $2}' $splitdb); do
1117 [ -s "$PKGS/packages.info" ] &&
1118 awk -F$'\t' -vp=" $i " '{
1119 if (index(" " $8 " ", p)) print $1
1120 }' "$PKGS/packages.info"
1122 [ -s "$PKGS/bdeps.txt" ] &&
1123 awk -F$'\t' -vp=" $i " '{
1124 if (index(" " $2 " ", p)) print $1
1125 }' $PKGS/bdeps.txt
1126 done
1127 } | sort -u > $inf/c
1129 cat <<EOT
1130 <section>
1131 <h3>Related packages</h3>
1132 <table class="third">
1133 <thead>
1134 <tr>
1135 <th>Build dependencies</th>
1136 <th>Runtime dependencies</th>
1137 <th>Required by</th>
1138 </tr>
1139 </thead>
1140 <tbody>
1141 EOT
1143 awk -vinf="$inf" -vbase="$base" '
1144 function linki(i) {
1145 if (i) return sprintf("<img src=\"%s/s/%s\"> <a href=\"%s/%s\">%s</a>", base, i, base, i, i);
1146 }
1147 BEGIN{
1148 do {
1149 a = b = c = "";
1150 getline a < inf "/a";
1151 getline b < inf "/b";
1152 getline c < inf "/c";
1153 printf("<tr><td>%s </td><td>%s </td><td>%s </td></tr>", linki(a), linki(b), linki(c));
1154 } while ( a b c )
1155 }'
1156 cat <<EOT
1157 </tbody>
1158 </table>
1159 </section>
1160 EOT
1161 # Clean
1162 rm -r $inf
1167 # Display <Recook> button only for SliTaz web browser
1168 case "$HTTP_USER_AGENT" in
1169 *SliTaz*)
1170 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
1171 if grep -qs "^$pkg$" $CACHE/recook-packages; then
1172 show_note i "The package “$pkg” has been requested for recook"
1173 else
1174 echo "<a class='button' href='$base/?recook=${pkg//+/%2B}'>Recook $pkg</a>"
1175 fi
1176 fi
1177 ;;
1178 esac
1179 ;;
1181 receipt)
1182 page_header
1183 pkg_info
1184 echo "<a class='button receipt' href='$base/$pkg/receipt'>receipt</a>"
1185 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1186 awk -vb="$base/$pkg" '{printf("<a class=\"button\" href=\"%s/%s\">%s</a>\n", b, $0, $0)}'
1188 show_code bash < $wok/$pkg/receipt
1189 ;;
1191 stuff)
1192 page_header
1193 pkg_info
1194 file="$pkg/stuff/$arg"
1195 echo "<a class='button' href='$base/$pkg/receipt'>receipt</a>"
1196 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1197 awk -vb="$base/$pkg" -va="stuff/$arg" '{
1198 printf("<a class=\"button%s\" href=\"%s/%s\">%s</a>\n", a==$0 ? " receipt" : "", b, $0, $0)
1199 }'
1201 if [ -f "$wok/$file" ]; then
1202 case $file in
1203 *.desktop|*.theme) class="ini" ;;
1204 *.patch|*.diff|*.u) class="diff" ;;
1205 *.sh) class="bash" ;;
1206 *.conf*|*.ini)
1207 class="bash"
1208 [ -n "$(cut -c1 < $wok/$file | fgrep '[')" ] && class="ini"
1209 ;;
1210 *.pl) class="perl" ;;
1211 *.c|*.h|*.awk) class="clike" ;;
1212 *.svg) class="svg" ;;
1213 *Makefile*) class="makefile" ;;
1214 *.po|*.pot) class="bash" ;;
1215 *.css) class="css" ;;
1216 *.htm|*.html) class="html" ;;
1217 *.js) class="js" ;;
1218 *.txt) class="asciidoc" ;;
1219 *)
1220 case $(head -n1 $wok/$file) in
1221 *!/bin/sh*|*!/bin/bash*) class="bash" ;;
1222 esac
1223 if [ -z "$class" -a "$(head -n1 $wok/$file | cut -b1)" == '#' ]; then
1224 class="bash"
1225 fi
1226 if [ -z "$class" ]; then
1227 # Follow Busybox restrictions. Search for non-printable chars
1228 if [ $(tr -d '[:alnum:][:punct:][:blank:][:cntrl:]' < "$wok/$file" | wc -c) -gt 0 ]; then
1229 raw="true"
1230 fi
1231 fi
1232 ;;
1233 esac
1235 # Display image
1236 case $file in
1237 *.png|*.svg|*.jpg|*.jpeg|*.ico)
1238 echo "<img src='$base/$pkg/browse/stuff/$arg' style='display: block; max-width: 100%; margin: auto'/>"
1239 ;;
1240 esac
1242 # Display colored listing for all text-based documents (also for *.svg)
1243 case $file in
1244 *.png|*.jpg|*.jpeg|*.ico) ;;
1245 *)
1246 if [ -z "$raw" ]; then
1247 cat $wok/$file | show_code $class
1248 fi
1249 ;;
1250 esac
1252 # Display hex dump for binary files
1253 if [ -n "$raw" ]; then
1254 hexdump -C $wok/$file | show_code #| sed 's|^\([0-9a-f][0-9a-f]*\)|<span class="c2">\1</span>|'
1255 fi
1256 else
1257 show_note e "File “$file” absent!"
1258 fi
1259 ;;
1261 files)
1262 page_header
1263 pkg_info
1265 packaged=$(mktemp)
1267 # find main package
1268 wanted=$(. $wok/$pkg/receipt; echo $WANTED)
1269 main=${wanted:-$pkg}
1271 # identify split packages
1272 split="$main $(. $wok/$main/receipt; echo $SPLIT)"
1273 [ -d "$wok/$main-dev" ] && split="$split $main-dev"
1274 split="$(echo $split | tr ' ' '\n' | sort -u)"
1276 # finally we need the version
1277 if [ -f "$WOK/linux/receipt" ]; then
1278 kvers=$(. $WOK/linux/receipt; echo $VERSION)
1279 kbasevers=$(echo $kvers | cut -d. -f1,2)
1280 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
1281 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
1282 kbasevers=$(echo $kvers | cut -d. -f1,2)
1283 fi
1284 ver=$(. $wok/$main/receipt; echo $VERSION$EXTRAVERSION)
1287 echo "<section><h3>Quick jump:</h3><ul>"
1288 echo "$split" | sed 'p' | xargs printf "<li><a href='#%s'>%s</a></li>\n"
1289 echo "<li id='li-repeats' style='display:none'><a href='#repeats'>repeatedly packaged files</a></li>"
1290 echo "<li id='li-empty' style='display:none'><a href='#empty'>unpackaged empty folders</a></li>"
1291 echo "<li id='li-orphans' style='display:none'><a href='#orphans'>unpackaged files</a>"
1292 echo "<span id='orphansTypes'></span></li>"
1293 echo "</ul></section>"
1295 for p in $split; do
1296 namever="$p-$ver"
1297 if [ -d "$wok/$p/taz/$p-$ver" ]; then
1298 indir=$p
1299 elif [ -d "$wok/$main/taz/$p-$ver" ]; then
1300 indir=$main
1301 fi
1302 dir="$wok/$indir/taz/$p-$ver/fs"
1304 size=$(du -hs $dir | awk '{ sub(/\.0/, ""); print $1 }')
1306 echo "<section><h3 id='$p'>Contents of package “$namever” (${size:-empty}):</h3>"
1307 echo '<pre class="files">'
1308 if [ -s "$wok/$indir/taz/$p-$ver/files.list" ]; then
1309 echo -n '<span class="underline">permissions·lnk·user ·'
1310 echo -en 'group · size·date & time ·name\n</span>'
1311 cd $dir
1312 find . -print0 | sort -z | xargs -0 ls -ldp --color=always | \
1313 syntax_highlighter files | \
1314 sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$indir/browse/taz/$p-$ver/fs\2'>\2\3|;" | \
1315 awk 'BEGIN { FS="\""; }
1316 { gsub("+", "%2B", $2); print; }'
1317 else
1318 echo 'No files'
1319 fi
1320 echo '</pre></section>'
1321 cat $wok/$indir/taz/$p-$ver/files.list >> $packaged
1322 done
1324 # find repeatedly packaged files
1325 repeats="$(sort $packaged | uniq -d)"
1326 if [ -n "$repeats" ]; then
1327 echo '<script>document.getElementById("li-repeats").style.display = "list-item"</script>'
1328 echo -n '<section><h3 id="repeats">Repeatedly packaged files:</h3><pre class="files">'
1329 echo "$repeats" | sed 's|^|<span class="c11">!!!</span> |'
1330 echo "</pre></section>"
1331 fi
1333 # find unpackaged empty folders
1334 emptydirs="$(
1335 cd $wok/$main/install
1336 find -type d | sed 's|\.||' | \
1337 while read d; do
1338 [ -z "$(ls "$wok/$main/install$d")" ] || continue
1339 echo $d
1340 done | \
1341 while read d; do
1342 notfound='yes'
1343 for p in $(cd $wok/$main/taz; ls); do
1344 if [ -d "$wok/$main/taz/$p/fs$d" ]; then
1345 notfound=''
1346 break
1347 fi
1348 done
1349 [ -n "$notfound" ] &&
1350 ls -ldp --color=always .$d | syntax_highlighter files | sed 's|>\./|>/|'
1351 done
1352 )"
1353 if [ -n "$emptydirs" ]; then
1354 echo '<script>document.getElementById("li-empty").style.display = "list-item"</script>'
1355 echo -n '<section><h3 id="empty">Unpackaged empty folders:</h3><pre class="files">'
1356 echo "$emptydirs"
1357 echo "</pre></section>"
1358 fi
1360 # find unpackaged files
1361 all_files=$(mktemp)
1362 cd $wok/$main/install; find ! -type d | sed 's|\.||' > $all_files
1363 orphans="$(sort $all_files $packaged | uniq -u)"
1364 if [ -d "$wok/$main/install" -a -n "$orphans" ]; then
1365 echo '<script>document.getElementById("li-orphans").style.display = "list-item"</script>'
1366 echo '<section><h3 id="orphans">Unpackaged files:</h3>'
1367 table=$(mktemp)
1368 echo "$orphans" | awk -vi="$base/$indir/browse/install" '
1369 function tag(text, color) {
1370 printf("<span class=\"c%s1\">%s</span> ", color, text);
1371 printf("<a class=\"c00\" href=\"%s\">%s</a>\n", i $0, $0);
1372 }
1373 /\/perllocal.pod$/ || /\/\.packlist$/ || /\/share\/bash-completion\// ||
1374 /\/lib\/systemd\// || /\.pyc$/ || /\.pyo$/ || /\/fonts\.scale$/ || /\/fonts\.dir$/ {
1375 tag("---", 0); next }
1376 /\.pod$/ { tag("pod", 5); next }
1377 /\/share\/man\// { tag("man", 5); next }
1378 /\/share\/doc\// || /\/share\/gtk-doc\// || /\/share\/info\// ||
1379 /\/share\/devhelp\// { tag("doc", 5); next }
1380 /\/share\/icons\// { tag("ico", 2); next }
1381 /\/share\/locale\// { tag("loc", 4); next }
1382 /\.h$/ || /\.a$/ || /\.la$/ || /\.pc$/ || /\/bin\/.*-config$/ ||
1383 /\/Makefile.*$/ { tag("dev", 3); next }
1384 /\/share\/help\// || /\/share\/appdata\// { tag("gnm", 6); next }
1385 { tag("???", 1) }
1386 ' > $table
1388 # Summary table
1389 orphans_types='()'
1390 for i in head body; do
1391 case $i in
1392 head) echo -n '<table class="summary"><tr>';;
1393 body) echo -n '<th> </th></tr><tr>';;
1394 esac
1395 for j in '???1' dev3 loc4 ico2 doc5 man5 pod5 gnm6 '---0'; do
1396 tag=${j:0:3}; class="c${j:3:1}0"; [ "$class" == 'c00' ] && class='c01'
1397 case $i in
1398 head) echo -n "<th class='$class'>$tag</th>";;
1399 body)
1400 tagscount="$(grep ">$tag<" $table | wc -l)"
1401 printf '<td>%s</td>' "$tagscount"
1402 [ "$tagscount" -gt 0 ] && orphans_types="${orphans_types/)/ $tag)}"
1403 ;;
1404 esac
1405 done
1406 done
1407 echo '<td> </td></tr></table>'
1408 orphans_types="${orphans_types/( /(}"
1409 [ "$orphans_types" != '()' ] &&
1410 echo "<script>document.getElementById('orphansTypes').innerText = '${orphans_types// /, }';</script>"
1412 echo -n '<pre class="files">'
1413 cat $table
1414 echo '</pre></section>'
1415 rm $table
1416 fi
1417 rm $packaged $all_files
1418 ;;
1420 description)
1421 page_header
1422 pkg_info
1423 descs="$(ls $WOK/$pkg/description*.txt)"
1424 if [ -n "$descs" ]; then
1425 echo '<div id="content2">'
1426 [ -f "$WOK/$pkg/description.txt" ] && show_desc "$pkg" "$WOK/$pkg/description.txt"
1427 for i in $descs; do
1428 case $i in
1429 */description.txt) continue ;;
1430 *) package=$(echo $i | cut -d. -f2) ;;
1431 esac
1432 show_desc "$package" "$i"
1433 done
1434 echo '</div>'
1435 else
1436 show_note w "No description of $pkg"
1437 fi
1438 ;;
1440 log)
1441 page_header
1442 pkg_info
1443 [ -z "$arg" ] && arg=$(stat -c %Y $LOGS/$pkg.log)
1445 echo '<div class="btnList">'
1446 acc='l' # access key for the latest log is 'L'
1447 while read log; do
1448 # for all $pkg.log, $pkg.log.0 .. $pkg.log.9, $pkg-pack.log (if any)
1449 timestamp=$(stat -c %Y $log)
1450 class=''
1451 if [ "$arg" == "$timestamp" ]; then
1452 class=' log'
1453 logfile="$log"
1454 fi
1455 case $log in *-pack.log) acc='p';; esac # access key for the packing log is 'P'
1456 echo -n "<a class='button$class' data-acc='$acc' accesskey='$acc' href='$base/$pkg/log/$timestamp'>"
1457 echo "$(stat -c %y $log | cut -d: -f1,2)</a>"
1458 case $acc in
1459 l) acc=0;;
1460 *) acc=$((acc+1));;
1461 esac
1462 done <<EOT
1463 $(find $LOGS -name "$pkg.log*" | sort)
1464 $(find $LOGS -name "$pkg-pack.log")
1465 EOT
1466 echo '</div>'
1468 if [ -z "$logfile" ]; then
1469 show_note e "Requested log is absent"
1470 page_footer
1471 exit 0
1472 fi
1474 # Define cook variables for syntax highlighter
1475 if [ -s "$WOK/$pkg/receipt" ]; then
1476 . "$WOK/$pkg/receipt"
1477 _wok='/home/slitaz/wok'
1478 _src="$_wok/$pkg/source/$PACKAGE-$VERSION"
1479 _install="$_wok/$pkg/install"
1480 _fs="$_wok/$pkg/taz/$PACKAGE-$VERSION/fs"
1481 _stuff="$_wok/$pkg/stuff"
1482 fi
1484 # if [ ! -f "gzlog/$pkg.$arg" ]; then
1485 # {
1486 # summary "$logfile" links
1487 #
1488 # syntax_highlighter log < $logfile | awk '
1489 # BEGIN { print "<pre class=\"log\">"; }
1490 # { printf("<a name=\"l%d\" href=\"#l%d\">%5d</a> %s\n", NR, NR, NR, $0); }
1491 # END { print "</pre>"; }
1492 # '
1493 #
1494 # page_footer
1495 # } | gzip > gzlog/$pkg.$arg
1496 # fi
1498 blog=$(basename $logfile)
1499 summary "$logfile" links
1501 # disable next `sed` for the 'like2016' theme
1502 theme=$(COOKIE theme); theme=${theme:-default}; [ "$theme" != 'like2016' ] && theme=''
1503 cat $logfile | syntax_highlighter log | \
1504 sed -e "/(pkg\/local$theme):/ s|: \([^<]*\)|<img src='$base/i/$blog/\1'> \1|" | \
1505 awk '
1506 BEGIN { print "<pre class=\"log\">"; }
1507 { printf("<span id=\"l%d\">%s</span><a href=\"#l%d\"></a>\n", NR, $0, NR); }
1508 END { print "</pre>"; }
1509 '
1510 ;;
1513 man|doc|info)
1514 page_header
1515 pkg_info
1516 echo '<div style="max-height: 6.4em; overflow: auto; padding: 0 4px">'
1518 dir="wok/$pkg/install/usr/share/$cmd"
1519 [ "$cmd" == 'doc' ] && dir="$dir wok/$pkg/install/usr/share/gtk-doc"
1520 if [ "$cmd" == 'doc' -a -z "$arg" ]; then
1521 try=$(for i in $dir; do find $i -name 'index.htm*'; done | sed q)
1522 [ -n "$try" ] && arg="$try"
1523 fi
1524 while read i; do
1525 [ -s "$i" ] || continue
1526 case "$i" in
1527 *.jp*g|*.png|*.gif|*.svg|*.css) continue
1528 esac
1529 i=${i#$dir/}
1530 [ -n "$arg" ] || arg="$i"
1531 class=''; [ "$arg" == "$i" ] && class=" doc"
1532 case "$cmd" in
1533 man)
1534 case $i in
1535 man*) lang='';;
1536 *) lang="${i%%/*}: ";;
1537 esac
1538 man=$(basename $i .gz)
1539 echo "<a class='button$class' href='$base/$pkg/man/$i'>$lang${man%.*} (${man##*.})</a>"
1540 ;;
1541 doc)
1542 echo "<a class='button$class' href='$base/$pkg/doc/$i'>$(basename $i .gz)</a>"
1543 ;;
1544 info)
1545 info=$(basename $i)
1546 echo "<a class='button$class' href='$base/$pkg/info/$i#Top'>${info/.info/}</a>"
1547 ;;
1548 esac
1549 done <<EOT
1550 $(for i in $dir; do find $i -type f; done | sort)
1551 EOT
1552 echo '</div>'
1554 [ -f "$arg" ] || arg="$dir/$arg"
1555 if [ -f "$arg" ]; then
1556 tmp="$(mktemp)"
1557 docat "$arg" > $tmp
1558 [ -s "$tmp" ] &&
1559 case "$cmd" in
1560 info)
1561 echo '<div id="content2" class="texinfo"><pre class="first">'
1562 info2html < "$tmp"
1563 echo '</pre></div>'
1564 ;;
1565 doc)
1566 case "$arg" in
1567 *.sgml|*.devhelp2) class='xml';;
1568 *.py) class='python';; # pycurl package
1569 *.css) class='css';;
1570 *.sh) class='bash';;
1571 *)
1572 first=$(head -n1 "$tmp")
1573 if [ "${first:0:1}" == '#' ]; then
1574 class='bash' # first line begins with '#'
1575 else
1576 class='asciidoc'
1577 fi;;
1578 esac
1579 case "$arg" in
1580 *.htm*)
1581 case $arg in
1582 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
1583 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
1584 esac
1585 # make the iframe height so long to contain its contents without scrollbar
1586 echo "<iframe id='idoc' src='$page' width='100%' onload='resizeIframe(this)'></iframe>"
1587 ;;
1588 *.pdf)
1589 case $arg in
1590 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
1591 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
1592 esac
1593 cat <<EOT
1594 <object id="idoc" data="$page" width="100%" height="100%" type="application/pdf" style="min-height: 600px">
1595 $(show_note w "Missing PDF plugin.<br/>Get the file <a href="$page">$(basename "$page")</a>.")
1596 </object>
1597 EOT
1598 ;;
1599 *.md|*.markdown)
1600 echo '<section>'
1601 $md2html "$tmp"
1602 echo '</section>'
1603 ;;
1604 *)
1605 show_code $class < "$tmp"
1606 ;;
1607 esac
1608 ;;
1609 man)
1610 #export TEXTDOMAIN='man2html'
1611 echo "<div id='content2'>"
1613 html=$(./man2html.bin "$tmp" | sed -e '1,/<header>/d' -e '/<footer>/,$d' \
1614 -e 's|<a href="file:///[^>]*>\([^<]*\)</a>|\1|g' \
1615 -e 's|<a href="?[1-9]\+[^>]*>\([^<]*\)</a>|\1|g')
1617 if [ -n "$(echo "$html" | fgrep 'The requested file /tmp/tmp.')" ]; then
1618 # Process the pre-formatted man-cat page
1619 # (for example see sudo package without groff in build dependencies)
1620 sed -i '
1621 s|M-bM-^@M-^S|—|g;
1622 s|M-bM-^@M-^\\|<b>|g;
1623 s|M-bM-^@M-^]|</b>|g
1624 s|M-bM-^@M-^X|<u>|g;
1625 s|M-bM-^@M-^Y|</u>|g;
1626 s|M-BM-||g;
1627 s|++oo|•|g;
1628 s|&|\&|g; s|<|\<|g; s|>|\>|g;
1629 ' "$tmp"
1630 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 \
1631 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 \
1632 0 1 2 3 4 5 6 7 8 9 _ - '\\+' '\.' /; do
1633 sed -i "s|$i$i|<b>$i</b>|g; s|_$i|<u>$i</u>|g" "$tmp"
1634 done
1635 echo '<pre class="catman">'
1636 sed 's|</b><b>||g; s|</u><u>||g; s|</u><b>_</b><u>|_|g; s|</b> <b>| |g;' "$tmp"
1637 echo '</pre>'
1638 else
1639 echo "$html"
1640 fi
1641 echo "</div>"
1642 ;;
1643 esac
1644 rm -f $tmp
1645 else
1646 show_note e "File “$arg” not exists!"
1647 fi
1648 ;;
1650 download)
1651 page_header
1652 pkg_info
1653 show=0
1655 . $wok/$pkg/receipt
1657 if [ -n "$TARBALL" -a -s "$SRC/$TARBALL" ]; then
1658 files_header
1659 echo "<tr><td><a href='$base/src/$TARBALL'>$TARBALL</a></td>"
1660 ls -lh "$SRC/$TARBALL" | awk '{printf("<td>%sB</td>", $5)}'
1661 echo "<td>Sources for building the package “$pkg”</td></tr>"
1662 show=1
1663 fi
1665 if [ -d "$wok/$pkg/taz" ]; then
1666 [ "$show" -eq 1 ] || files_header
1668 for i in $(all_names); do
1669 [ -e "$wok/$pkg/taz/$i-$VERSION$EXTRAVERSION/receipt" ] || continue
1670 . $wok/$pkg/taz/$i-$VERSION$EXTRAVERSION/receipt
1672 for filename in "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg"; do
1673 [ -f "$PKGS/$filename" ] &&
1674 cat <<EOT
1675 <tr>
1676 <td><a href="$base/get/$filename">$filename</a></td>
1677 <td>$(ls -lh ./packages/$filename | awk '{printf("%sB", $5)}')</td>
1678 <td>$SHORT_DESC</td>
1679 </tr>
1680 EOT
1681 done
1682 done
1683 show=1
1684 fi
1686 if [ "$show" -eq 1 ]; then
1687 echo '</tbody></table></section>'
1688 else
1689 show_note w "Sorry, there's nothing to download…"
1690 fi
1691 ;;
1693 esac
1696 page_footer
1697 exit 0