cookutils view lighttpd/index.cgi @ rev 1077

lighttpd/cooker.css: revert main h2 line height, carry this style to #hdr h2 only; lighttpd/index.cgi: add link to Tank RRD Stats in the footer; package -> files: display SUID files in violet color
author Aleksej Bobylev <al.bobylev@gmail.com>
date Wed Jun 13 14:14:45 2018 +0300 (2018-06-13)
parents 1641fc593494
children 1463d32f6f90
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 case $QUERY_STRING in
19 *debug*)
20 debug='yes'
21 QUERY_STRING="$(echo "$QUERY_STRING" | sed 's|debug||; s|^&||; s|&&|\&|; s|&$||')"
22 ;;
23 esac
25 [ -f "/etc/slitaz/cook.conf" ] && . /etc/slitaz/cook.conf
26 [ -f "./cook.conf" ] && . ./cook.conf
27 wok="$WOK"
28 title=${title:-SliTaz Cooker}
29 # Cooker DB files.
30 activity="$CACHE/activity"
31 commits="$CACHE/commits"
32 cooklist="$CACHE/cooklist"
33 cookorder="$CACHE/cookorder"
34 command="$CACHE/command"; touch $command
35 blocked="$CACHE/blocked"
36 broken="$CACHE/broken"
37 cooknotes="$CACHE/cooknotes"
38 cooktime="$CACHE/cooktime"
39 wokrev="$CACHE/wokrev"
40 webstat="$CACHE/webstat"
41 splitdb="$CACHE/split.db"
43 # Path to markdown to html convertor
44 cmark_opts='--smart -e table -e strikethrough -e autolink -e tagfilter'
45 if [ -n "$(which cmark 2>/dev/null)" ]; then
46 md2html="$(which cmark) $cmark_opts"
47 elif [ -x "./cmark" ]; then
48 md2html="./cmark $cmark_opts"
49 elif [ -n "$(which sundown 2>/dev/null)" ]; then
50 md2html=$(which sundown)
51 elif [ -x "./sundown" ]; then
52 md2html="./sundown"
53 fi
58 # Search form redirection
59 if [ -n "$(GET search)" ]; then
60 echo -e "HTTP/1.1 301 Moved Permanently\nLocation: $base/$(GET q)\n\n"
61 exit 0
62 fi
65 # Show the running command and it's progression
67 running_command() {
68 state="$(cat $command)"
69 local pct=''
70 if [ -n "$state" ];then
71 echo -n "$state</td></tr><tr><td>Completion</td>"
72 set -- $(grep "^$state" $cooktime)
73 [ -n "$1" -a $2 -ne 0 ] && pct=$((($(date +%s)-$3)*100/$2))
74 [ -n "$pct" ] && max="max='100'"
75 echo -n "<td><progress id='gauge' $max value='$pct' title='Click to stop updating' onclick='stopUpdating()'>"
76 echo -n "</progress> <span id='pct'>${pct:-?}%</span>"
77 [ "$2" -gt 60 ] &&
78 echo -n "</td></tr><tr><td>Estimated end time</td><td>$(date +%H:%M -ud @$(($2+$3)))"
79 else
80 echo 'not running'
81 fi
82 }
85 # HTML page header
87 page_header() {
88 local theme t='' css pretitle='' command
89 theme=$(COOKIE theme)
90 [ "$theme" == 'default' ] && theme=''
91 [ -n "$theme" ] && theme="-$theme"
92 css="cooker$theme.css"
94 if [ -n "$pkg" ]; then
95 case "$pkg" in
96 ~) pretitle="Tag \"$cmd\" - ";;
97 *) pretitle="$pkg - ";;
98 esac
99 else
100 command="$(cat $command)"
101 [ -n "$command" ] && pretitle="$command - "
102 fi
103 [ -z "$favicon" ] && favicon='/slitaz-cooker.png'
105 echo -e 'Content-Type: text/html; charset=UTF-8\n'
107 cat <<EOT
108 <!DOCTYPE html>
109 <html lang="en">
110 <head>
111 <title>$pretitle$title</title>
112 <link rel="stylesheet" href="/$css">
113 <link rel="icon" type="image/png" href="$favicon">
114 <link rel="search" href="$base/os.xml" title="$title" type="application/opensearchdescription+xml">
115 <!-- mobile -->
116 <meta name="viewport" content="width=device-width, initial-scale=1.0">
117 <meta name="theme-color" content="#222">
118 <!-- rss -->
119 <link rel="alternate" type="application/rss+xml" title="$title Feed" href="?rss">
120 <script>
121 // Get part of the main page
122 function getPart(part) {
123 var partRequest = new XMLHttpRequest();
124 partRequest.onreadystatechange = function() {
125 if (this.readyState == 4 && this.status == 200) {
126 response = this.responseText;
127 var partElement = document.getElementById(part);
128 if (response !== null) partElement.innerHTML = response;
129 }
130 };
131 partRequest.open('GET', '?part=' + part, true);
132 partRequest.responseType = '';
133 partRequest.send();
134 }
135 </script>
136 </head>
137 <body>
138 <div id="container">
139 <header>
140 <h1><a href="$base/">$title</a></h1>
141 <div class="network">
142 <a href="http://www.slitaz.org/">Home</a>
143 <a href="http://bugs.slitaz.org/">Bugs</a>
144 <a href="http://hg.slitaz.org/wok-next/">Hg</a>
145 <a href="http://roadmap.slitaz.org/">Roadmap</a>
146 <a href="http://pizza.slitaz.me/">Pizza</a>
147 <a href="http://tank.slitaz.org/">Tank</a>
148 |
149 <a href="/cross/">Cross</a>
150 <a href="/i486.cgi">i486</a>
151 <a href="$base/cookiso.cgi">ISO</a>
152 <select onChange="window.location.href=this.value" style="display: none">
153 <option value=".">Go to…</option>
154 <option value="http://www.slitaz.org/">Home</option>
155 <option value="http://bugs.slitaz.org/">Bug tracker</option>
156 <option value="http://hg.slitaz.org/wok/">Hg wok</option>
157 <option value="http://roadmap.slitaz.org/">Roadmap</option>
158 <option value="http://pizza.slitaz.me/">Pizza</option>
159 <option value="http://tank.slitaz.org/">Tank</option>
160 <option disabled>---------</option>
161 <option value="cross/">Cross</option>
162 <option value="i486.cgi">i486</option>
163 <option value="cookiso.cgi">ISO</option>
164 </select>
165 </div>
166 </header>
168 <main>
169 EOT
171 [ -n "$debug" ] && echo "<pre><code class='language-ini'>$(env | sort)</code></pre>"
172 }
175 # HTML page footer
177 page_footer() {
178 date_now=$(date +%s)
179 sec_now=$(date +%S); sec_now=${sec_now#0} # remove one leading zero
180 wait_sec=$(( 60 - $sec_now ))
181 cat <<EOT
182 </main>
184 <footer>
185 <a href="http://www.slitaz.org/">SliTaz Website</a>
186 <a href="http://tank.slitaz.org/graphs.php">Server status</a>
187 <a href="$base/doc/cookutils/cookutils.html">Documentation</a>
188 <a href="$base/?theme">Theme</a>
189 </footer>
190 </div>
191 <script src="/cooker.js"></script>
192 <script>refreshDate(${wait_sec}000, ${date_now}000)</script>
193 </body>
194 </html>
195 EOT
196 }
199 show_note() {
200 echo "<div class='bigicon-$1'>$2</div>"
201 }
204 not_found() {
205 local file="${1#$PKGS/}"; file="${file#$LOGS/}"; file="${file#$WOK/}"
206 echo "HTTP/1.1 404 Not Found"
207 page_header
208 echo "<h2>Not Found</h2>"
209 case $2 in
210 pkg)
211 show_note e "The requested package “$(basename "$(dirname "$file")")” was not found." ;;
212 *)
213 show_note e "The requested file “$file” was not found." ;;
214 esac
215 page_footer
216 }
219 manage_modified() {
220 local file="$1" option="$2" nul day mon year time hh mm ss date_s
221 if [ ! -f "$file" ]; then
222 if [ "$option" == 'silently-absent' ]; then
223 echo "HTTP/1.1 404 Not Found"
224 return
225 else
226 not_found "$file" "$2"
227 exit
228 fi
229 fi
230 [ "$option" == 'no-last-modified' ] && return
231 if [ -n "$HTTP_IF_MODIFIED_SINCE" ]; then
232 echo "$HTTP_IF_MODIFIED_SINCE" | \
233 while read nul day mon year time nul; do
234 case $mon in
235 Jan) mon='01';; Feb) mon='02';; Mar) mon='03';; Apr) mon='04';;
236 May) mon='05';; Jun) mon='06';; Jul) mon='07';; Aug) mon='08';;
237 Sep) mon='09';; Oct) mon='10';; Nov) mon='11';; Dec) mon='12';;
238 esac
239 hh=$(echo $time | cut -d: -f1)
240 mm=$(echo $time | cut -d: -f2)
241 ss=$(echo $time | cut -d: -f3)
242 date_s=$(date -ud "$year$mon$day$hh$mm.$ss" +%s)
243 # if [ "$date_s" -ge "$(date -ur "$file" +%s)" ]; then
244 # echo -e 'HTTP/1.1 304 Not Modified\n'
245 # exit
246 # fi
247 # TODO: improve caching control
248 done
249 fi
250 echo "Last-Modified: $(date -Rur "$file" | sed 's|UTC|GMT|')"
251 echo "Cache-Control: public, max-age=3600"
252 }
255 # Query '?pct=<package>': update percentage
257 if [ -n "$(GET pct)" ]; then
258 pkg="$(GET pct)"
259 state="$(cat $command)"
260 if [ "$state" == "cook:$pkg" ]; then
261 set -- $(grep "^$state" $cooktime)
262 [ -n "$1" ] && pct=$(( ($(date +%s) - $3) * 100 / $2 ))
263 echo "${pct:-?}"
264 else
265 echo 'reload'
266 fi
267 exit 0
268 fi
271 # Query '?poke': poke cooker
273 if [ -n "$(GET poke)" ]; then
274 touch $CACHE/cooker-request
275 echo -e "Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}\n"
276 exit
277 fi
280 # Query '?recook=<package>': query to recook package
282 if [ -n "$(GET recook)" ]; then
283 pkg="$(GET recook)"
284 case "$HTTP_USER_AGENT" in
285 *SliTaz*)
286 grep -qs "^$pkg$" $CACHE/recook-packages ||
287 echo "$pkg" >> $CACHE/recook-packages
288 esac
289 echo -e "Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}\n"
290 exit
291 fi
294 # Query '/i/<log>/<pkg>': show indicator icon
295 # Can't use ?query - not able to change '+' to '%2B' in the sed rules (see log handler)
297 if [ "$pkg" == 'i' ]; then
298 echo -en "Content-Type: image/svg+xml\n\n<svg xmlns='http://www.w3.org/2000/svg' height='12' width='8'><path d='"
299 if [ $LOGS/$cmd -nt $PKGS/$arg.tazpkg ]; then
300 echo "m1 2-1 1v8l1 1h6l1-1v-8l-1-1z' fill='#090'/></svg>"
301 else
302 echo "m0 3v8l1 1h6l1-1v-8l-1-1h-6zm3 0h2v5h-2zm0 6h2v2h-2z' fill='#d00'/></svg>"
303 fi
304 exit
305 fi
308 # Query '/s/<pkg>': show status indicator icon
309 # Can't use ?query - not able to change '+' to '%2B' in the sed rules (see log handler)
311 if [ "$pkg" == 's' ]; then
312 # argument <pkg> is in $cmd variable
313 echo -en "Content-Type: image/svg+xml\n\n<svg xmlns='http://www.w3.org/2000/svg' height='12' width='8'><path d='"
314 # packages.info updates with each new package, so we'll find actual info here
315 if grep -q "^$cmd"$'\t' $PKGS/packages.info; then
316 echo "m1 2-1 1v8l1 1h6l1-1v-8l-1-1z' fill='#090'/></svg>"
317 else
318 echo "m0 3v8l1 1h6l1-1v-8l-1-1h-6zm3 0h2v5h-2zm0 6h2v2h-2z' fill='#d00'/></svg>"
319 fi
320 exit
321 fi
324 # Query '?theme[=<theme>]': change UI theme
326 if [ -n "$(GET theme)" ]; then
327 theme="$(GET theme)"
328 ref="$(echo "$HTTP_REFERER" | sed 's|:|%3A|g; s|/|%2F|g; s|\?|%3F|g; s|\+|%2B|g;')"
329 case $theme in
330 theme)
331 current=$(COOKIE theme)
332 page_header
333 cat <<EOT
334 <section>
335 <h2>Change theme</h2>
336 <p>Current theme: “${current:-default}”. Select other:</p>
337 <ul>
338 $(
339 for i in default emerald sky goldenrod midnight like2016 terminal; do
340 [ "$i" == "${current:-default}" ] || echo "<li><a href=\"$base/?theme=$i&amp;ref=$ref\">$i</a></li>"
341 done
342 )
343 </ul>
344 </section>
345 EOT
346 page_footer
347 exit 0
348 ;;
349 default|emerald|sky|goldenrod|midnight|like2016|terminal)
350 ref="$(GET ref)"
351 [ -n "$ref" ] || ref="$base/"
352 # Expires in a year
353 expires=$(date -uRd @$(($(date +%s)+31536000)) | sed 's|UTC|GMT|')
354 echo -e "HTTP/1.1 302 Found\nLocation: $ref\nCache-Control: no-cache\nSet-Cookie: theme=$theme; expires=$expires\n\n"
355 exit 0
356 ;;
357 esac
358 fi
361 #case "$QUERY_STRING" in
362 # stuff*)
363 # file="$wok/$(GET stuff)"
364 # manage_modified "$file"
365 # ;;
366 #
367 # pkg=*|receipt=*|description=*|files=*|log=*|man=*|doc=*|info=*)
368 # type=${QUERY_STRING%%=*}
369 # pkg=$(GET $type)
370 # case "$type" in
371 # description)
372 # manage_modified "$wok/$pkg/receipt" 'no-last-modified'
373 # manage_modified "$wok/$pkg/description.txt" 'silently-absent'
374 # ;;
375 # log)
376 # manage_modified "$wok/${pkg%%.log*}/receipt" 'no-last-modified'
377 # manage_modified "$LOGS/$pkg"
378 # ;;
379 # *)
380 # manage_modified "$wok/$pkg/receipt" pkg
381 # ;;
382 # esac
383 # ;;
384 #esac
387 # RSS feed generator
388 # URI: ?rss[&limit={1..100}]
390 if [ -n "$(GET rss)" ]; then
391 limit=$(GET limit); limit="${limit:-12}"; [ "$limit" -gt 100 ] && limit='100'
392 pubdate=$(date -Rur$(ls -t $FEEDS/*.xml | head -n1) | sed 's|UTC|GMT|')
393 cooker_url="http://$HTTP_HOST$base/"
394 cat <<EOT
395 Content-Type: application/rss+xml
397 <?xml version="1.0" encoding="utf-8" ?>
398 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
399 <channel>
400 <title>$title</title>
401 <description>The SliTaz packages cooker feed</description>
402 <link>$cooker_url</link>
403 <lastBuildDate>$pubdate</lastBuildDate>
404 <pubDate>$pubdate</pubDate>
405 <atom:link href="$cooker_url?rss" rel="self" type="application/rss+xml" />
406 EOT
407 for rss in $(ls -t $FEEDS/*.xml | head -n$limit); do
408 sed "s|http[^=]*=|$cooker_url|; s|<guid|& isPermaLink=\"false\"|g; s|</pubDate| GMT&|g" $rss
409 done
410 cat <<EOT
411 </channel>
412 </rss>
413 EOT
414 exit 0
415 fi
418 ### OpenSearch ###
420 # Query '/os.xml': get OpenSearch Description
422 if [ "$pkg" == 'os.xml' ]; then
423 cat <<EOT
424 Content-Type: application/xml; charset=UTF-8
426 <?xml version="1.0" encoding="UTF-8"?>
427 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
428 <ShortName>$title</ShortName>
429 <Description>SliTaz packages search</Description>
430 <Image width="16" height="16" type="image/png">http://$HTTP_HOST/images/logo.png</Image>
431 <Url type="text/html" method="GET" template="http://$HTTP_HOST$base/{searchTerms}"/>
432 <Url type="application/x-suggestions+json" method="GET" template="http://$HTTP_HOST$base/">
433 <Param name="oss" value="{searchTerms}"/>
434 </Url>
435 <SearchForm>http://$HTTP_HOST$base/</SearchForm>
436 <InputEncoding>UTF-8</InputEncoding>
437 </OpenSearchDescription>
438 EOT
439 exit 0
440 fi
442 # Query '?oss[=<term>]': OpenSearch suggestions
444 if [ -n "$(GET oss)" ]; then
445 term="$(GET oss | tr -cd '[:alnum:]+-')"
446 echo -e 'Content-Type: application/x-suggestions+json; charset=UTF-8\n'
447 cd $wok
448 ls | fgrep "$term" | head -n10 | awk -vterm="$term" '
449 BEGIN{printf("[\"%s\",[", term)}
450 {printf("%s\"%s\"", NR != 1 ? "," : "", $0)}
451 END {printf("]]")}
452 '
453 exit 0
454 fi
459 #
460 # Functions
461 #
464 # Unpack to stdout
466 docat() {
467 case "$1" in
468 *gz) zcat ;;
469 *bz2) bzcat ;;
470 *xz) xzcat ;;
471 *) cat
472 esac < $1
473 }
476 # Tiny texinfo converter
478 info2html() {
479 sed \
480 -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g' \
481 -e 's|^\* \(.*\)::|* <a href="#\1">\1</a> |' \
482 -e 's|\*note \(.*\)::|<a href="#\1">\1</a>|' \
483 -e '/^File: / s|(dir)|Top|g' \
484 -e '/^File: / s|Next: \([^,]*\)|<a class="button" href="#\1">Next: \1</a>|' \
485 -e '/^File: / s|Prev: \([^,]*\)|<a class="button" href="#\1">Prev: \1</a>|' \
486 -e '/^File: / s|Up: \([^,]*\)|<a class="button" href="#\1">Up: \1</a>|' \
487 -e '/^File: / s|^.* Node: \([^,]*\), *\(.*\)$|<pre id="\1">\2|' \
488 -e '/^<pre id=/ s|^\([^>]*>\)\(<a[^>]*>Next: [^,]*\), *\(<a[^>]*>Prev: [^,]*\), *\(<a[^>]*>Up: .*\)|\1 \3 \4 \2|' \
489 -e '/^Tag Table:$/,/^End Tag Table$/d' \
490 -e '/INFO-DIR/,/^END-INFO-DIR/d' \
491 -e "s|https*://[^>),'\"\`’ ]*|<a href=\"&\">&</a>|g" \
492 -e "s|ftp://[^>),\"\` ]*|<a href=\"&\">&</a>|g" \
493 -e 's|^\* Menu:|<b>Menu:</b>|' \
494 -e "s|^|</pre>|"
495 }
498 # Put some colors into log and DB files.
500 syntax_highlighter() {
501 case $1 in
502 log)
503 # If variables not defined - define them with some rare values
504 : ${_src=#_#_#}
505 : ${_install=#_#_#}
506 : ${_fs=#_#_#}
507 : ${_stuff=#_#_#}
508 # Use one-letter html tags to save some bytes :)
509 # <b>is error (red)</b> <u>is warning (orange)</u> <i>is informative (green)</i>
510 sed \
511 -e 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g' \
512 -e 's#OK$#<i>OK</i>#' \
513 -e 's#\([Dd]one\)$#<i>\1</i>#' \
514 -e 's#Success$#<i>Success</i>#' \
515 -e 's#\([^a-z]\)ok$#\1<i>ok</i>#' \
516 -e 's#\([^a-z]\)yes$#\1<i>yes</i>#' \
517 -e 's#: \(YES.*\)#: <i>\1</i>#' \
518 -e 's#\([^a-z]\)ON$#\1<i>ON</i>#' \
519 -e 's#\(enabled\)$#<i>\1</i>#' \
520 -e 's#\([^a-z]\)no$#\1<u>no</u>#' \
521 -e 's#: \(NO.*\)#: <u>\1</u>#' \
522 -e 's#\([^a-z]\)none$#\1<u>none</u>#' \
523 -e 's#\([^a-z]\)false$#\1<u>false</u>#' \
524 -e 's#\([^a-z]\)OFF$#\1<u>OFF</u>#' \
525 -e 's#\(disabled\)$#<u>\1</u>#' \
526 -e 's#\(^checking .*\.\.\. \)\(.*\)$#\1<i>\2</i>#' \
527 \
528 -e 's#\( \[Y[nm/]\?\] n\)$# <u>\1</u>#' \
529 -e 's#\( \[N[ym/]\?\] y\)$# <i>\1</i>#' \
530 -e 's# y$# <i>y</i>#' \
531 -e 's# n$# <u>n</u>#' \
532 -e 's#(NEW) *$#<b>(NEW)</b>#' \
533 \
534 -e 's#.*(pkg/local).*#<i>\0</i>#' \
535 -e 's#.*(web/cache).*#<u>\0</u>#' \
536 \
537 -e 's#\([^a-zA-Z]\)\([Ee]rror\)$#\1<b>\2</b>#' \
538 -e 's#ERROR:#<b>ERROR:</b>#g' \
539 \
540 -e 's#^.*multiple definition of.*#<b>\0</b>#' \
541 -e 's#^.*[Ff][Aa][Ii][Ll][Ee][Dd].*#<b>\0</b>#' \
542 -e 's#^.*[Ff]atal.*#<b>\0</b>#' \
543 -e '/non-fatal/ s|</*b>||g' \
544 -e 's#^.*[Nn]ot found.*#<b>\0</b>#' \
545 -e 's#^.*[Nn]o such file.*#<b>\0</b>#' \
546 -e 's#^.*No package .* found.*#<b>\0</b>#' \
547 -e 's#^.*Unable to find.*#<b>\0</b>#' \
548 -e 's#[^a-zA-Z-][Ii]nvalid.*#<b>\0</b>#' \
549 -e 's#Segmentation fault#<b>\1</b>#' \
550 -e 's#\([Nn][Oo][Tt] found\.*\)$#<b>\1</b>#' \
551 -e 's#\(found\.*\)$#<i>\1</i>#' \
552 \
553 -e 's#^.*WARNING:.*#<u>\0</u>#' \
554 -e 's#^.*warning:.*#<u>\0</u>#' \
555 -e 's#^.* [Ee]rror:* .*#<b>\0</b>#' \
556 -e 's#^.*terminated.*#<b>\0</b>#' \
557 -e 's#\(missing\)#<b>\1</b>#g' \
558 -e 's#^.*[Cc]annot find.*#<b>\0</b>#' \
559 -e 's#^.*unrecognized option.*#<u>\0</u>#' \
560 -e 's#^.*does not.*#<u>\0</u>#' \
561 -e 's#^.*[Ii]gnoring.*#<u>\0</u>#' \
562 -e 's#^.*note:.*#<u>\0</u>#' \
563 \
564 -e 's#^.* will not .*#<u>\0</u>#' \
565 -e 's!^Hunk .* succeeded at .*!<u>\0</u>!' \
566 -e 's#^.* Warning: .*#<u>\0</u>#' \
567 \
568 -e "s#^Executing:\([^']*\).#<em>\0</em>#" \
569 -e "s#^Making.*#<em>\0</em>#" \
570 -e "s#^Scanning dependencies of target .*#<em>\0</em>#" \
571 -e "s#^====\([^']*\).#<span class='span-line'>\0</span>#g" \
572 -e "s#^[a-zA-Z0-9]\([^']*\) :: #<span class='span-sky'>\0</span>#g" \
573 -e "s#[fh]tt*ps*://[^ '\"]*#<a href='\0'>\0</a>#g" \
574 \
575 -e 's|^<u>\(.*libtool: warning: relinking.*\)</u>|\1|' \
576 -e 's|^<u>\(.*libtool: warning: .* has not been installed in .*\)</u>|\1|' \
577 -e 's|^<u>\(.*checking for a sed.*\)</u>|\1|' \
578 -e 's|^<u><b>\(.*inlining failed.*\)</b></u>|<u>\1</u>|' \
579 \
580 -e "s|$_src|<var>\${src}</var>|g;
581 s|$_install|<var>\${install}</var>|g;
582 s|$_fs|<var>\${fs}</var>|g;
583 s|$_stuff|<var>\${stuff}</var>|g" \
584 \
585 -e "s|\[\([01]\)m\[3\([1-7]\)m|<span class='c\2\1'>|g;
586 s|\[\([01]\);3\([1-7]\)m|<span class='c\2\1'>|g;
587 s|\[3\([1-7]\)m|<span class='c\10'>|g;
588 s|\[\([01]\);0m|<span class='c0\1'>|g;
589 s|\[0m|</span>|g;
590 s|\[m|</span>|g;
591 s|\[0;10m|</span>|g;
592 s|\[K||g;" \
593 \
594 -e "s|\[9\([1-6]\)m|<span class='c\10'>|;
595 s|\[39m|</span>|;
596 #s|\[1m|<span class='c01'>|g;
597 s|\[1m|<span style='font-weight:bold'>|g; s|(B|</span>|g;
598 s|\[m||g;
599 " \
600 -e "s!^|\(+.*\)!|<span class='c20'>\1</span>!;
601 s!^|\(-.*\)!|<span class='c10'>\1</span>!;
602 s!^|\(@@.*@@\)\$!|<span class='c30'>\1</span>!;"
603 \
605 ;;
607 files)
608 # Highlight the Busybox's `ls` output
609 awk '{
610 part1 = substr($0, 0, 16);
611 part2 = substr($0, 17, 9);
612 part3 = substr($0, 26, 9);
613 part4 = substr($0, 35);
614 if (part2 != "root ") part2 = "<span class=\"c11\">" part2 "</span>";
615 if (part3 != "root ") part3 = "<span class=\"c11\">" part3 "</span>";
616 print part1 part2 part3 part4;
617 }' | \
618 sed "s|\[0m/|/\[0m|g;
619 s|\[\([01]\);3\([1-7]\)m|<a class='c\2\1'>|g;
620 s|\[\([01]\);0m|<a class='c0\1'>|g;
621 s|\[0m|</a>|g;
622 s|^\(lrwxrwxrwx\)|<span class='c61'>\1</span>|;
623 s|^\(-rwxr-xr-x\)|<span class='c21'>\1</span>|;
624 s|^\(-rw-r--r--\)|<span class='c31'>\1</span>|;
625 s|^\(drwxr-xr-x\)|<span class='c41'>\1</span>|;
626 s|^\(-rwsr-xr-x\)|<span class='c51'>\1</span>|;
627 s|^\([lrwxs-][lrwxs-]*\)|<span class='c11'>\1</span>|;
628 "
629 ;;
630 esac
631 }
634 show_code() {
635 echo -n "<pre><code class=\"language-$1\">"
636 sed 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g'
637 echo '</code></pre>'
638 }
641 datalist() {
642 cut -d$'\t' -f2 $splitdb | tr ' ' '\n' | sort -u | awk '
643 BEGIN{printf("<datalist id=\"packages\">")}
644 {printf("<option>%s",$1)}
645 END {printf("</datalist>")}
646 '
647 }
650 mklog() {
651 awk '
652 BEGIN { printf("<pre class=\"log dog\">\n") }
653 { print }
654 END { print "</pre>" }'
655 }
658 summary() {
659 log="$1"
660 pkg="$(basename ${log%%.log*})"
662 if [ -f "$log" ]; then
663 if grep -q "cook:$pkg$" $command; then
664 show_note i "The Cooker is currently building $pkg"
665 elif fgrep -q "Summary for:" $log; then
666 sed '/^Summary for:/,$!d' $log | awk '
667 BEGIN { print "<section>" }
668 function row(line) {
669 split(line, s, " : ");
670 printf("\t<tr><td>%s</td><td>%s</td></tr>\n", s[1], s[2]);
671 }
672 function row2(line, rowNum) {
673 split(line, s, " : ");
674 if (rowNum == 1) {
675 print "<thead>";
676 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]);
677 print "</thead><tbody>";
678 }
679 else
680 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]);
681 }
682 {
683 if (NR==1) { printf("<h3>%s</h3>\n<table>\n", $0); next }
684 if ($0 ~ "===") { seen++; if (seen == 1) next; else exit; }
685 if ($0 ~ "---") {
686 seen2++;
687 if (seen2 == 1) print "</table>\n\n<table class=\"pkgslist\">"
688 next
689 }
690 if (seen2) row2($0, seen2); else row($0);
691 }
692 END { print "</tbody></table></section>" }
693 '
694 elif fgrep -q "Debug information" $log; then
695 echo -e '<section>\n<h3>Debug information</h3>'
696 sed -e '/^Debug information/,$!d; /^===/d; /^$/d' $log | sed -n '1!p' | \
697 if [ -n "$2" ]; then
698 syntax_highlighter log | sed 's|\([^0-9 ]\)\([0-9][0-9]*\):|\1<a href="#l\2">\2</a>:|'
699 else
700 sed 's|^[0-9][0-9]*:||' | syntax_highlighter log
701 fi | mklog
702 echo '</section>'
703 fi
704 else
705 [ -n "$pkg" -a -d "$wok/$pkg" ] && show_note e "No log for $pkg"
706 fi
707 }
710 active() {
711 [ "$cmd" == "$1" -o "$cmd" == "${2:-$1}" ] && echo -n ' active'
712 }
715 pkg_info() {
716 local log active bpkg short_desc=''
717 log="$LOGS/$pkg.log"
719 echo -n "<div id=\"hdr\"><a href=\"$base/${requested_pkg:-$pkg}\">"
720 if [ -e $wok/$pkg/.icon.png ]; then
721 echo -n "<img src=\"$base/$pkg/browse/.icon.png\"/>"
722 else
723 echo -n "<img src=\"/tazpkg.png\"/>"
724 fi
725 echo -n "</a>"
726 echo -n "<h2><a href=\"$base/${requested_pkg:-$pkg}\">${requested_pkg:-$pkg}</a>"
727 # Get short description for existing packages
728 [ -f $PKGS/packages.info ] &&
729 short_desc="$(awk -F$'\t' -vp="${requested_pkg:-$pkg}" '{if ($1 == p) { printf("%s", $4); exit; }}' $PKGS/packages.info)"
730 # If package does not exist (not created yet or broken), get short description
731 # (but only for "main" package) from receipt
732 [ -n "$short_desc" ] || short_desc="$(. $wok/$pkg/receipt; echo "$SHORT_DESC")"
733 echo "<br/>$short_desc</h2></div>"
734 echo '<div id="info">'
735 echo "<a class='button icon receipt$(active receipt stuff)' href='$base/$pkg/receipt'>receipt &amp; stuff</a>"
737 # In the receipts $EXTRAVERSION is defined using $kvers, get it here [copy from 'cook' set_paths()]
738 if [ -f "$wok/linux/receipt" ]; then
739 kvers=$(. $wok/linux/receipt; echo $VERSION)
740 kbasevers=$(echo $kvers | cut -d. -f1,2)
741 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
742 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
743 kbasevers=$(echo $kvers | cut -d. -f1,2)
744 fi
746 unset WEB_SITE WANTED
747 . $wok/$pkg/receipt
749 [ -n "$WEB_SITE" ] &&
750 echo "<a class='button icon website' href='$WEB_SITE' target='_blank' rel='noopener noreferrer'>web site</a>"
752 [ -f "$wok/$pkg/taz/$PACKAGE-$VERSION$EXTRAVERSION/receipt" ] &&
753 echo "<a class='button icon files$(active files)' href='$base/$pkg/files'>files</a>"
755 [ -n "$(ls $wok/$pkg/description*.txt)" ] &&
756 echo "<a class='button icon desc$(active description)' href='$base/$pkg/description'>description</a>"
758 [ -n "$TARBALL" -a -s "$SRC/$TARBALL" -o -d "$wok/$pkg/taz" ] &&
759 echo "<a class='button icon download' href='$base/$pkg/download'>download</a>"
761 echo "<a class='button icon browse' href='$base/$pkg/browse/'>browse</a>"
763 [ -x ./man2html.bin -a -d "$wok/$pkg/install/usr/share/man" ] &&
764 echo "<a class='button icon doc$(active man)' href='$base/$pkg/man/'>man</a>"
766 [ -d "$wok/$pkg/install/usr/share/doc" -o -d "$wok/$pkg/install/usr/share/gtk-doc" ] &&
767 echo "<a class='button icon doc$(active doc)' href='$base/$pkg/doc/'>doc</a>"
769 [ -d "$wok/$pkg/install/usr/share/info" ] &&
770 echo "<a class='button icon doc$(active info)' href='$base/$pkg/info/#Top'>info</a>"
772 if [ -n "$LFS" ]; then
773 printf "<a class='button icon doc' href='%s' target='_blank' rel='noopener noreferrer'>" "$LFS"
774 [ "${LFS/blfs/}" != "$LFS" ] && printf "B"
775 printf "LFS</a>\n"
776 fi
778 [ -s "$log" ] &&
779 echo "<a class='button icon log$(active log)' href='$base/$pkg/log/'>logs</a>"
781 echo '</div>'
782 }
785 mktable() {
786 sed 's# : #|#' | awk -vc="$1" '
787 BEGIN { printf("<table class=\"%s\">\n", c); FS="|" }
788 { printf("<tr><td>%s</td>", $1);
789 if (NF == 2) printf("<td>%s</td>", $2);
790 printf("</tr>\n", $2) }
791 END { print "</table>" }'
792 }
795 section() {
796 local i=$(basename "$1")
797 echo -e '\n\n<section>'
798 [ $(wc -l < $1) -gt $2 ] && echo "<a class='button icon more r' href='?$i'>${3#*|}</a>"
799 echo "<h2>${3%|*}</h2>"
800 mktable "$i"
801 echo '</section>'
802 }
805 show_desc() {
806 echo "<section><h3>Description of “$1”</h3>"
807 if [ -n "$md2html" ]; then
808 $md2html $2
809 else
810 show_code markdown < $2
811 fi
812 echo "</section>"
813 }
816 # Return all the names of packages bundled in this receipt
818 all_names() {
819 # Get package names from $SPLIT variable
820 local split=$(echo $SPLIT \
821 | awk '
822 BEGIN { RS = " "; FS = ":"; }
823 { print $1; }' \
824 | tr '\n' ' ')
825 local split_space=" $split "
826 if ! head -n1 $WOK/$pkg/receipt | fgrep -q 'v2'; then
827 # For receipts v1: $SPLIT may present in the $WANTED package,
828 # but split packages have their own receipts
829 echo $PACKAGE
830 elif [ "${split_space/ $PACKAGE /}" != "$split_space" ]; then
831 # $PACKAGE included somewhere in $SPLIT (probably in the end).
832 # We should build packages in the order defined in the $SPLIT.
833 echo $split
834 else
835 # We'll build the $PACKAGE, then all defined in the $SPLIT.
836 echo $PACKAGE $split
837 fi
838 }
841 toolchain_version() {
842 echo "<tr><td><a href='$base/$1'>$1</a></td>"
843 awk -F$'\t' -vpkg="$1" '
844 BEGIN { version = description = "---"; }
845 {
846 if ($1 == pkg) { version = $2; description = $4; }
847 }
848 END { printf("<td>%s</td><td>%s</td></tr>", version, description); }
849 ' $PKGS/packages.info
850 }
853 files_header() {
854 echo '<section><h3>Available downloads:</h3>'
855 echo '<table><thead><tr><th>File</th><th>Size</th><th>Description</th></tr></thead><tbody>'
856 }
859 # Update statistics used in web interface.
860 # There is no need to recalculate the statistics every time the page is displayed.
861 # Note, $webstat file must be owned by www, otherwise this function will not be able to do the job.
863 update_webstat() {
864 # for receipts:
865 rtotal=$(ls $WOK/*/arch.$ARCH | wc -l)
866 rcooked=$(ls -d $WOK/*/taz | wc -l)
867 runbuilt=$(($rtotal - $rcooked))
868 rblocked=$(wc -l < $blocked)
869 rbroken=$(wc -l < $broken)
871 # for packages:
872 ptotal=$(cut -d$'\t' -f2 $CACHE/split.db | tr ' ' '\n' | sort -u | wc -l)
873 pcooked=$(ls $PKGS/*.tazpkg | wc -l)
874 punbuilt=$(($ptotal - $pcooked))
875 pblocked=$(
876 while read i; do
877 sed "/^$i\t/!d" $CACHE/split.db
878 done < $blocked | cut -d$'\t' -f2 | tr ' ' '\n' | wc -l)
879 pbroken=$(
880 while read i; do
881 sed "/^$i\t/!d" $CACHE/split.db
882 done < $broken | cut -d$'\t' -f2 | tr ' ' '\n' | wc -l)
884 cat > $webstat <<EOT
885 rtotal="$rtotal"; rcooked="$rcooked"; runbuilt="$runbuilt"; rblocked="$rblocked"; rbroken="$rbroken"
886 ptotal="$ptotal"; pcooked="$pcooked"; punbuilt="$punbuilt"; pblocked="$pblocked"; pbroken="$pbroken"
887 EOT
888 }
891 # Generate part of the main page
893 part() {
894 echo -n "<div id='$1'>"
896 case $1 in
897 summary)
898 echo '<h2>Summary</h2>'
900 mktable <<EOT
901 Cooker state : $(running_command)
902 Wok revision : <a href='$WOK_URL' target='_blank' rel='noopener noreferrer'>$(cat $wokrev)</a>
903 Commits to cook : $(wc -l < $commits)
904 Current cooklist : $(wc -l < $cooklist)
905 Architecture : $ARCH, <a href="$toolchain">toolchain</a>
906 Server date : <span id='date'>$(date -u '+%F %R %Z')</span>
907 EOT
909 # If command is "cook:*", update gauge and percentage periodically.
910 # If different package is cooking, reload the page (with new settings)
911 cmd="$(cat $command)"
912 case "$cmd" in
913 cook:*)
914 pkg=${cmd#*:}
915 echo "<script>updatePkg = '${pkg//+/%2B}';</script>"
916 ;;
917 esac
918 ;;
919 webstat)
920 # Do we need to update the statistics?
921 if [ -n "$nojs" -a "$activity" -nt "$webstat" ]; then update_webstat; fi
922 . $webstat
924 pct=0; [ "$rtotal" -gt 0 ] && pct=$(( ($rcooked * 100) / $rtotal ))
926 cat <<EOT
927 <div class="meter"><progress max="100" value="$pct">${pct}%</progress><span>${pct}%</span></div>
929 <table class="webstat"><thead>
930 <tr><th> </th><th>Total </th><th>Cooked </th><th>Unbuilt </th><th>Blocked </th><th>Broken </th></tr>
931 </thead><tbody>
932 <tr><td>Receipts</td><td>$rtotal</td><td>$rcooked</td><td>$runbuilt</td><td>$rblocked</td><td>$rbroken</td></tr>
933 <tr><td>Packages</td><td>$ptotal</td><td>$pcooked</td><td>$punbuilt</td><td>$pblocked</td><td>$pbroken</td></tr>
934 </tbody></table>
935 EOT
936 if [ -z "$nojs" ]; then echo "<script>getPart('$1')</script>"; fi
937 ;;
938 activity)
939 tac $activity | head -n12 | sed 's|cooker.cgi?pkg=||;
940 s|\[ Done|<span class="r c20">Done|;
941 s|\[ Failed|<span class="r c10">Failed|;
942 s|\[ -Failed|<span class="r c10"><del>Failed</del>|;
943 s| \]|</span>|;
944 s|%2B|\+|g' | \
945 section $activity 12 "Activity|More activity"
946 ;;
947 cooknotes)
948 [ -s "$cooknotes" ] && tac $cooknotes | head -n12 | \
949 section $cooknotes 12 "Cooknotes|More notes"
950 ;;
951 commits)
952 [ -s "$commits" ] && head -n20 $commits | \
953 section $commits 20 "Commits|More commits"
954 ;;
955 cooklist)
956 [ -s "$cooklist" ] && head -n 20 $cooklist | \
957 section $cooklist 20 "Cooklist|Full cooklist"
958 ;;
959 broken)
960 [ -s "$broken" ] && head -n20 $broken | sed "s|^[^']*|<a href='\0'>\0</a>|g" | \
961 section $broken 20 "Broken|All broken packages"
962 ;;
963 blocked)
964 [ -s "$blocked" ] && sed "s|^[^']*|<a href='\0'>\0</a>|g" $blocked | \
965 section $blocked 12 "Blocked|All blocked packages"
966 ;;
967 pkgs)
968 cd $PKGS
969 # About BusyBox's `ls`
970 # On the Tank server: BusyBox v1.18.4 (2012-03-14 03:32:25 CET) multi-call binary.
971 # It supported the option `-e`, output with `-let` options like this:
972 # -rw-r--r-- 1 user group 100000 Fri Nov 3 10:00:00 2017 filename
973 # 1 2 3 4 5 6 7 8 9 10 11
974 # Newer BusyBox v1.27.2 doesn't support option `-e` and has no configs to
975 # configure it or return the option back. It supported the long option
976 # `--full-time` instead, but output is different:
977 # -rw-r--r-- 1 user group 100000 2017-11-03 10:00:00 +0200 filename
978 # 1 2 3 4 5 6 7 8 9
979 if ls -let >/dev/null 2>&1; then
980 ls -let *.tazpkg \
981 | awk '
982 (NR<=20){
983 sub(/:[0-9][0-9]$/, "", $9);
984 mon = index(" JanFebMarAprMayJunJulAugSepOctNovDec", $7) / 3;
985 printf("%d-%02d-%02d %s : <a href=\"get/%s\">%s</a>\n", $10, mon, $8, $9, $11, $11);
986 }' \
987 | section $activity 1000 "Latest cook"
988 else
989 ls -lt --full-time *.tazpkg \
990 | awk '
991 (NR<=20){
992 sub(/:[0-9][0-9]$/, "", $7);
993 printf("%s %s : <a href=\"get/%s\">%s</a>\n", $6, $7, $9, $9);
994 }' \
995 | section $activity 1000 "Latest cook"
996 fi
997 ;;
998 esac
999 echo "</div>"
1003 # Query '?part=<part>': get part of the main page
1005 if [ -n "$(GET part)" ]; then
1006 part="$(GET part)"
1007 case $part in
1008 summary|webstat|activity|cooknotes|commits|cooklist|broken|blocked|pkgs)
1009 nojs='yes'
1010 part $part
1011 ;;
1012 esac
1013 exit 0
1014 fi
1020 # Load requested page
1023 if [ -z "$pkg" ]; then
1025 page_header
1026 if [ -n "$QUERY_STRING" ]; then
1028 [ "$QUERY_STRING" != 'commits.log' ] &&
1029 for list in activity cooknotes cooklist commits; do
1030 [ -n "$(GET $list)" ] || continue
1031 case $list in
1032 cooklist) nb="- Packages: $(wc -l < $cooklist)";;
1033 commits) nb="- Packages: $(wc -l < $commits)";;
1034 esac
1035 echo '<section id="content2">'
1036 echo "<h2>DB: $list $nb</h2>"
1037 tac $CACHE/$list | sed 's|cooker.cgi?pkg=||; s|%2B|+|g;
1038 s|\[ Done|<span class="r c20">Done|;
1039 s|\[ Failed|<span class="r c10">Failed|;
1040 s|\[ -Failed|<span class="r c10"><del>Failed</del>|;
1041 s| \]|</span>|' | mktable $list
1042 echo '</section>'
1043 done
1045 if [ -n "$(GET broken)" ]; then
1046 echo '<section id="content2">'
1047 echo "<h2>DB: broken - Packages: $(wc -l < $broken)</h2>"
1048 sort $CACHE/broken | sed "s|^[^']*|<a href='$base/\0'>\0</a>|g" | mktable
1049 echo '</section>'
1050 fi
1052 case "$QUERY_STRING" in
1053 *.log)
1054 log=$LOGS/$QUERY_STRING
1055 name=$(basename $log)
1056 if [ -f "$log" ]; then
1057 echo "<h2>Log for: ${name%.log}</h2>"
1058 if fgrep -q "Summary" $log; then
1059 echo '<pre class="log">'
1060 grep -A 20 'Summary' $log | syntax_highlighter log
1061 echo '</pre>'
1062 fi
1063 echo '<pre class="log">'
1064 syntax_highlighter log < $log
1065 echo '</pre>'
1066 if [ "$QUERY_STRING" == 'pkgdb.log' ]; then
1067 # Display button only for SliTaz web browser
1068 case "$HTTP_USER_AGENT" in
1069 *SliTaz*)
1070 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
1071 if grep -qs '^pkgdb$' $CACHE/recook-packages; then
1072 show_note i "The package database has been requested for re-creation"
1073 else
1074 echo "<a class='button' href='$base/?recook=pkgdb'>Re-create the DB</a>"
1075 fi
1076 fi
1077 ;;
1078 esac
1079 fi
1080 else
1081 show_note e "No log file: $log"
1082 fi
1083 ;;
1084 toolchain)
1085 cat <<EOT
1086 <div id="content2">
1087 <section>
1088 <h2>SliTaz GNU/Linux toolchain</h2>
1090 <table>
1091 <tr><td>Build date</td> <td colspan="2">$(sed -n '/^Cook date/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td></tr>
1092 <tr><td>Build duration</td> <td colspan="2">$(sed -n '/^Cook time/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td></tr>
1093 <tr><td>Architecture</td> <td colspan="2">$ARCH</td></tr>
1094 <tr><td>Host system</td> <td colspan="2">$BUILD_SYSTEM</td></tr>
1095 <tr><td>Target system</td> <td colspan="2">$HOST_SYSTEM</td></tr>
1096 <tr><th>Package</th><th>Version</th><th>Description</th></tr>
1097 $(toolchain_version slitaz-toolchain)
1098 $(toolchain_version binutils)
1099 $(toolchain_version linux-api-headers)
1100 $(toolchain_version gcc)
1101 $(toolchain_version glibc)
1102 </table>
1104 <p>Toolchain documentation: <a target="_blank" rel="noopener noreferrer"
1105 href="http://doc.slitaz.org/en:cookbook:toolchain">http://doc.slitaz.org/en:cookbook:toolchain</a>
1106 </p>
1108 </section>
1109 </div>
1110 EOT
1111 ;;
1112 esac
1113 page_footer
1114 exit 0
1115 fi
1118 # We may have a toolchain.cgi script for cross cooker's
1119 if [ -f "toolchain.cgi" ]; then
1120 toolchain="toolchain.cgi"
1121 else
1122 toolchain="?toolchain"
1123 fi
1125 # Main page with summary. Count only packages included in ARCH,
1126 # use 'cooker arch-db' to manually create arch.$ARCH files.
1128 cat <<EOT
1129 <div id="content2">
1131 <section>
1132 <form method="get" action="" class="search r">
1133 <input type="hidden" name="search" value="pkg"/>
1134 <button type="submit" title="Search">Search</button>
1135 <input type="search" name="q" placeholder="Package" list="packages" autocorrect="off" autocapitalize="off"/>
1136 </form>
1137 EOT
1139 unset nojs
1140 part summary
1141 part webstat
1143 if [ -e "$CACHE/cooker-request" -a ! -s $command ]; then
1144 if [ "$activity" -nt "$CACHE/cooker-request" ]; then
1145 echo '<a class="button icon bell r" href="?poke">Wake up</a>'
1146 else
1147 show_note i 'Cooker will be launched in the next 5 minutes.'
1148 fi
1149 fi
1151 cat <<EOT
1152 <p>
1153 Service logs:
1154 <a href="?cookorder.log">cookorder</a> ·
1155 <a href="?commits.log">commits</a> ·
1156 <a href="?pkgdb.log">pkgdb</a>
1157 </p>
1158 </section>
1159 EOT
1161 part activity
1162 part cooknotes
1163 part commits
1164 part cooklist
1165 part broken
1166 part blocked
1167 part pkgs
1169 echo '</div>'
1170 datalist
1171 page_footer
1172 exit 0
1173 fi
1176 # show tag
1178 if [ "$pkg" == '~' -a -n "$cmd" ]; then
1179 tag="$cmd"
1180 page_header
1181 cat <<EOT
1182 <div id="content2">
1183 <section>
1184 <h2>Tag “$tag”</h2>
1186 <table>
1187 <thead>
1188 <tr><th>Name</th><th>Description</th><th>Category</th></tr>
1189 </thead>
1190 <tbody>
1191 EOT
1192 sort $PKGS/packages.info \
1193 | awk -F$'\t' -vtag=" $tag " -vbase="$base" '{
1194 if (index(" " $6 " ", tag)) {
1195 url = base "/" $1 "/";
1196 gsub("+", "%2B", url);
1197 printf("<tr><td><img src=\"%s/s/%s\"> ", base, $1);
1198 printf("<a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", url, $1, $4, $3);
1200 }'
1201 echo '</tbody></table></section></div>'
1202 page_footer
1203 exit 0
1204 fi
1207 case "$cmd" in
1208 '')
1209 page_header
1211 requested_pkg="$pkg"
1212 # Package info.
1213 if [ ! -f "$wok/$pkg/receipt" ]; then
1214 # Let's look at the cases when the package was not found
1216 # Maybe query is the exact name of split package? -> proceed to main package
1217 mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
1218 if (index(" " $2 " ", pkg)) {print $1; exit}
1219 }' $splitdb)
1221 # No, so let's find any matches among packages names (both main and split)
1222 if [ -z "$mainpkg" ]; then
1223 pkgs=$(cut -d$'\t' -f2 $splitdb | tr ' ' '\n' | fgrep "$pkg")
1224 # Nothing matched
1225 if [ -z "$pkgs" ]; then
1226 echo "<h2>Not Found</h2>"
1227 show_note e "The requested package <b>$pkg</b> was not found on this server."
1228 page_footer; exit 0
1229 fi
1230 # Search results page
1231 echo "<section><h2>Package names matching “$pkg”</h2>"
1232 echo "<table><thead><tr><th>Name</th><th>Description</th><th>Category</th></tr></thead><tbody>"
1233 query="$pkg"
1234 for pkg in $pkgs; do
1235 # Find main package
1236 mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
1237 if (index(" " $2 " ", pkg)) {print $1; exit}
1238 }' $splitdb)
1239 unset SHORT_DESC CATEGORY; . $wok/$mainpkg/receipt
1241 unset SHORT_DESC CATEGORY
1242 [ -e "$wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt" ] &&
1243 . $wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt
1245 echo -n "<tr><td><a href="$base/$pkg">${pkg//$query/<mark>$query</mark>}</a>"
1246 [ "$pkg" == "$mainpkg" ] || echo -n " (${mainpkg//$query/<mark>$query</mark>})"
1247 echo -n "</td><td>$SHORT_DESC</td><td>$CATEGORY</td></tr>"
1248 done
1249 echo '</tbody></table></section>'
1250 page_footer; exit 0
1251 fi
1252 pkg="$mainpkg"
1253 fi
1255 log=$LOGS/$pkg.log
1256 pkg_info
1258 # Check for a log file and display summary if it exists.
1259 summary "$log"
1262 # Show tag list
1263 taglist=$(
1264 for i in $pkg $(awk -F$'\t' -vp="$pkg" '{if ($1 == p) print $2}' $splitdb); do
1265 [ -s "$PKGS/packages.info" ] &&
1266 awk -F$'\t' -vpkg="$i" '{
1267 if ($1 == pkg) { print $6; exit; }
1268 }' "$PKGS/packages.info"
1269 done \
1270 | tr ' ' '\n' \
1271 | sort -u
1273 if [ -n "$taglist" ]; then
1274 echo -n '<section><h3>Tags</h3><p>'
1275 lasttag=$(echo "$taglist" | tail -n1)
1276 for tag in $taglist; do
1277 echo -n "<a href=\"$base/~/${tag//+/%2B}\">$tag</a>"
1278 [ "$tag" != "$lasttag" ] && echo -n " · "
1279 done
1280 echo '</p></section>'
1281 fi
1284 # Informational table with dependencies
1285 pkg="$requested_pkg"
1286 inf="$(mktemp -d)"
1288 # 1/3: Build dependencies (from receipt and pkgdb)
1289 for i in $WANTED $BUILD_DEPENDS $(awk -F$'\t' -vp=" $pkg " '{if (index(" " $2 " ", p) && (" " $1 " " != p)) print $1}' $splitdb); do
1290 echo "$i" >> $inf/a
1291 done
1293 # 2/3: Runtime dependencies (from pkgdb)
1295 [ -s "$PKGS/packages.info" ] &&
1296 awk -F$'\t' -vp="$pkg" '{
1297 if ($1 == p) print $8
1298 }' "$PKGS/packages.info"
1299 } | tr ' ' '\n' | sort -u > $inf/b
1301 # 3/3: Required by (from pkgdb)
1303 for i in $pkg $(awk -F$'\t' -vp="$pkg" '{if ($1 == p) print $2}' $splitdb); do
1304 [ -s "$PKGS/packages.info" ] &&
1305 awk -F$'\t' -vp=" $i " '{
1306 if (index(" " $8 " ", p)) print $1
1307 }' "$PKGS/packages.info"
1309 [ -s "$PKGS/bdeps.txt" ] &&
1310 awk -F$'\t' -vp=" $i " '{
1311 if (index(" " $2 " ", p)) print $1
1312 }' $PKGS/bdeps.txt
1313 done
1314 } | sort -u > $inf/c
1316 cat <<EOT
1317 <section>
1318 <h3>Related packages</h3>
1319 <table class="third">
1320 <thead>
1321 <tr>
1322 <th>Build dependencies</th>
1323 <th>Runtime dependencies</th>
1324 <th>Required by</th>
1325 </tr>
1326 </thead>
1327 <tbody>
1328 EOT
1330 awk -vinf="$inf" -vbase="$base" '
1331 function linki(i) {
1332 if (i) return sprintf("<img src=\"%s/s/%s\"> <a href=\"%s/%s\">%s</a>", base, i, base, i, i);
1334 BEGIN{
1335 do {
1336 a = b = c = "";
1337 getline a < inf "/a";
1338 getline b < inf "/b";
1339 getline c < inf "/c";
1340 printf("<tr><td>%s </td><td>%s </td><td>%s </td></tr>", linki(a), linki(b), linki(c));
1341 } while ( a b c )
1342 }'
1343 cat <<EOT
1344 </tbody>
1345 </table>
1346 </section>
1347 EOT
1348 # Clean
1349 rm -r $inf
1354 # Display <Recook> button only for SliTaz web browser
1355 case "$HTTP_USER_AGENT" in
1356 *SliTaz*)
1357 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
1358 if grep -qs "^$pkg$" $CACHE/recook-packages; then
1359 show_note i "The package “$pkg” has been requested for recook"
1360 else
1361 echo "<a class='button' href='$base/?recook=${pkg//+/%2B}'>Recook $pkg</a>"
1362 fi
1363 fi
1364 ;;
1365 esac
1366 ;;
1368 receipt)
1369 page_header
1370 pkg_info
1371 echo "<a class='button receipt' href='$base/$pkg/receipt'>receipt</a>"
1372 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1373 awk -vb="$base/$pkg" '{printf("<a class=\"button\" href=\"%s/%s\">%s</a>\n", b, $0, $0)}'
1375 show_code bash < $wok/$pkg/receipt
1376 ;;
1378 stuff)
1379 page_header
1380 pkg_info
1381 file="$pkg/stuff/$arg"
1382 echo "<a class='button' href='$base/$pkg/receipt'>receipt</a>"
1383 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1384 awk -vb="$base/$pkg" -va="stuff/$arg" '{
1385 printf("<a class=\"button%s\" href=\"%s/%s\">%s</a>\n", a==$0 ? " receipt" : "", b, $0, $0)
1386 }'
1388 if [ -f "$wok/$file" ]; then
1389 case $file in
1390 *.desktop|*.theme) class="ini" ;;
1391 *.patch|*.diff|*.u) class="diff" ;;
1392 *.sh) class="bash" ;;
1393 *.conf*|*.ini)
1394 class="bash"
1395 [ -n "$(cut -c1 < $wok/$file | fgrep '[')" ] && class="ini"
1396 ;;
1397 *.pl) class="perl" ;;
1398 *.c|*.h|*.awk) class="clike" ;;
1399 *.svg) class="svg" ;;
1400 *Makefile*) class="makefile" ;;
1401 *.po|*.pot) class="bash" ;;
1402 *.css) class="css" ;;
1403 *.htm|*.html) class="html" ;;
1404 *.js) class="js" ;;
1405 *.txt) class="asciidoc" ;;
1406 *)
1407 case $(head -n1 $wok/$file) in
1408 *!/bin/sh*|*!/bin/bash*) class="bash" ;;
1409 esac
1410 if [ -z "$class" -a "$(head -n1 $wok/$file | cut -b1)" == '#' ]; then
1411 class="bash"
1412 fi
1413 if [ -z "$class" ]; then
1414 # Follow Busybox restrictions. Search for non-printable chars
1415 if [ $(tr -d '[:alnum:][:punct:][:blank:][:cntrl:]' < "$wok/$file" | wc -c) -gt 0 ]; then
1416 raw="true"
1417 fi
1418 fi
1419 ;;
1420 esac
1422 # Display image
1423 case $file in
1424 *.png|*.svg|*.jpg|*.jpeg|*.ico)
1425 echo "<img src='$base/$pkg/browse/stuff/$arg' style='display: block; max-width: 100%; margin: auto'/>"
1426 ;;
1427 esac
1429 # Display colored listing for all text-based documents (also for *.svg)
1430 case $file in
1431 *.png|*.jpg|*.jpeg|*.ico) ;;
1432 *)
1433 if [ -z "$raw" ]; then
1434 cat $wok/$file | show_code $class
1435 fi
1436 ;;
1437 esac
1439 # Display hex dump for binary files
1440 if [ -n "$raw" ]; then
1441 hexdump -C $wok/$file | show_code #| sed 's|^\([0-9a-f][0-9a-f]*\)|<span class="c2">\1</span>|'
1442 fi
1443 else
1444 show_note e "File “$file” absent!"
1445 fi
1446 ;;
1448 files)
1449 page_header
1450 pkg_info
1452 # find main package
1453 wanted=$(. $wok/$pkg/receipt; echo $WANTED)
1454 main=${wanted:-$pkg}
1455 devpkg=''; [ -d "$wok/$main-dev" ] && devpkg="$main-dev"
1457 splitsets=$(echo $SPLIT" " \
1458 | awk '
1459 BEGIN { RS = " "; FS = ":"; }
1460 { print $2; }' \
1461 | sort -u \
1462 | tr '\n' ' ' \
1463 | sed 's|^ *||; s| *$||')
1465 splitpkgs=$(echo $SPLIT" " \
1466 | awk '
1467 BEGIN { RS = " "; FS = ":"; }
1468 { print $1; }' \
1469 | tr '\n' ' ' \
1470 | sed 's|^ *||; s| *$||')
1472 # we need the version
1473 if [ -f "$WOK/linux/receipt" ]; then
1474 kvers=$(. $WOK/linux/receipt; echo $VERSION)
1475 kbasevers=$(echo $kvers | cut -d. -f1,2)
1476 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
1477 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
1478 kbasevers=$(echo $kvers | cut -d. -f1,2)
1479 fi
1480 ver=$(. $wok/$main/receipt; echo $VERSION$EXTRAVERSION)
1482 echo "<section><h3>Quick jump:</h3>"
1485 for part in head body; do
1487 for set in '' $splitsets; do
1488 pkgsofset=$(echo $SPLIT" " \
1489 | awk -vset="$set" -vmain="$main" -vdev="$devpkg" '
1490 BEGIN {
1491 RS = " "; FS = ":";
1492 if (!set) print main;
1493 if (!set && dev) print dev;
1496 if ($2 == set) print $1;
1497 }' \
1498 | sort -u)
1500 set_description=''
1501 [ -n "$splitsets" ] &&
1502 case "$set" in
1503 '')
1504 set_description=' (default set)'
1505 set_title='Default set'
1506 ;;
1507 *)
1508 set_description=" (set “$set”)"
1509 set_title="Set “$set”"
1510 ;;
1511 esac
1513 install="$wok/$main/install"
1514 [ -n "$set" ] && install="$install-$set"
1516 case $part in
1517 head)
1518 [ -n "$splitsets" ] &&
1519 case "$set" in
1520 '') echo "<ul><li>Default set:";;
1521 *) echo "<li>Set “$set”:";;
1522 esac
1523 echo -e '\t<ul>'
1524 echo "$pkgsofset" | sed 'p' | xargs printf "\t\t<li><a href='#%s'>%s</a></li>\n"
1525 cat <<EOT
1526 <li id='li-repeats$set' style='display:none'>
1527 <a href='#repeats$set'>repeatedly packaged files</a></li>
1528 <li id='li-empty$set' style='display:none'>
1529 <a href='#empty$set'>unpackaged empty folders</a></li>
1530 <li id='li-outoftree$set' style='display:none'>
1531 <a href='#outoftree$set'>out-of-tree files</a></li>
1532 <li id='li-orphans$set' style='display:none'>
1533 <a href='#orphans$set'>unpackaged files</a>
1534 <span id='orphansTypes$set'></span></li>
1535 EOT
1536 echo -e '\t</ul>'
1537 [ -n "$splitsets" ] && echo "</li>"
1538 ;;
1539 body)
1540 all_files=$(mktemp)
1541 cd $install; find ! -type d | sed 's|\.||' > $all_files
1543 # ------------------------------------------------------
1544 # Packages content
1545 # ------------------------------------------------------
1546 packaged=$(mktemp)
1547 for p in $pkgsofset; do
1548 namever="$(awk -F$'\t' -vp="$p" '{
1549 if ($1==p) {printf("%s-%s\n", $1, $2); exit}
1550 }' $PKGS/packages.info)"
1551 if [ -d "$wok/$p/taz/$p-$ver" ]; then
1552 indir=$p
1553 elif [ -d "$wok/$main/taz/$p-$ver" ]; then
1554 indir=$main
1555 fi
1556 dir="$wok/$indir/taz/$p-$ver/fs"
1558 size=$(du -hs $dir | awk '{ sub(/\.0/, ""); print $1 }')
1560 echo
1561 echo "<section id='$p'>"
1562 echo " <h3>Contents of package “$namever” (${size:-empty}):</h3>"
1563 echo ' <pre class="files">'
1564 if [ -s "$wok/$indir/taz/$p-$ver/files.list" ]; then
1565 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
1566 cd $dir
1567 find . -print0 \
1568 | sort -z \
1569 | xargs -0 ls -ldp --color=always \
1570 | syntax_highlighter files \
1571 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$indir/browse/taz/$p-$ver/fs\2'>\2\3|;" \
1572 | awk 'BEGIN { FS="\""; }
1573 { gsub("+", "%2B", $2); print; }'
1574 else
1575 echo 'No files'
1576 fi
1577 echo '</pre>'
1578 echo '</section>'
1580 cat $wok/$indir/taz/$p-$ver/files.list >> $packaged
1581 done
1582 # ------------------------------------------------------
1583 # /Packages content
1584 # ------------------------------------------------------
1586 # ------------------------------------------------------
1587 # Repeatedly packaged files
1588 # ------------------------------------------------------
1589 repeats=$(mktemp)
1590 sort $packaged | uniq -d > $repeats
1591 if [ -s "$repeats" ]; then
1592 echo
1593 echo "<script>document.getElementById('li-repeats$set').style.display = 'list-item'</script>"
1594 echo "<section id='repeats$set'>"
1595 echo " <h3>Repeatedly packaged files$set_description:</h3>"
1596 cd $install
1598 IFS=$'\n'
1599 echo -n ' <pre class="files">'
1600 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
1601 while read i; do
1602 find .$i -exec ls -ldp --color=always '{}' \; \
1603 | syntax_highlighter files \
1604 | sed 's|>\./|>/|'
1605 done < $repeats
1606 echo '</pre>'
1607 echo '</section>'
1608 unset IFS
1609 fi
1610 rm $repeats
1611 # ------------------------------------------------------
1612 # /Repeatedly packaged files
1613 # ------------------------------------------------------
1615 # ------------------------------------------------------
1616 # Unpackaged empty folders
1617 # ------------------------------------------------------
1618 emptydirs=$(mktemp)
1619 cd $install
1620 IFS=$'\n'
1621 find -type d \
1622 | sed 's|\.||' \
1623 | while read d; do
1624 [ -z "$(ls "$install$d")" ] || continue
1625 # empty dir determined by empty `ls`
1626 echo $d
1627 done \
1628 | while read d; do
1629 notfound='yes'
1630 for p in $(cd $wok/$main/taz; ls); do
1631 if [ -d "$wok/$main/taz/$p/fs$d" ]; then
1632 notfound=''
1633 break
1634 fi
1635 done
1636 [ -n "$notfound" ] &&
1637 ls -ldp --color=always .$d \
1638 | syntax_highlighter files \
1639 | sed 's|>\./|>/|'
1640 done > $emptydirs
1641 unset IFS
1642 if [ -s "$emptydirs" ]; then
1643 echo
1644 echo "<script>document.getElementById('li-empty$set').style.display = 'list-item'</script>"
1645 echo "<section id='empty$set'>"
1646 echo " <h3>Unpackaged empty folders$set_description:</h3>"
1647 echo -n ' <pre class="files">'
1648 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
1649 cat $emptydirs
1650 echo '</pre>'
1651 echo '</section>'
1652 fi
1653 rm $emptydirs
1654 # ------------------------------------------------------
1655 # /Unpackaged empty folders
1656 # ------------------------------------------------------
1658 # ------------------------------------------------------
1659 # Out-of-tree files
1660 # ------------------------------------------------------
1661 outoftree=$(mktemp)
1662 awk -F$'\n' -vall="$all_files" '
1664 if (FILENAME == all) files_all[$1] = "1";
1665 else files_pkg[$1] = "1";
1667 END {
1668 for (i in files_pkg) {
1669 if (! files_all[i]) print i;
1672 ' "$all_files" "$packaged" > $outoftree
1674 if [ -d "$install" -a -s "$outoftree" ]; then
1675 echo
1676 echo "<script>document.getElementById('li-outoftree$set').style.display = 'list-item'</script>"
1677 echo "<section id='outoftree$set'>"
1678 echo " <h3>Out-of-tree files$set_description:</h3>"
1679 echo -n ' <pre class="files">'
1680 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
1681 IFS=$'\n'
1682 while read outoftree_line; do
1683 # Find the package out-of-tree file belongs to
1684 for i in $pkgsofset; do
1685 if grep -q "^$outoftree_line$" $wok/$main/taz/$i-$ver/files.list; then
1686 cd $wok/$main/taz/$i-$ver/fs
1687 ls -ldp --color=always ".$outoftree_line" \
1688 | syntax_highlighter files \
1689 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$main/browse/taz/$i-$ver/fs\2'>\2\3|;" \
1690 | awk 'BEGIN { FS="\""; }
1691 { gsub("+", "%2B", $2); print; }'
1692 fi
1693 done
1694 done < $outoftree
1695 unset IFS
1696 echo '</pre>'
1697 echo '</section>'
1698 fi
1699 rm $outoftree
1700 # ------------------------------------------------------
1701 # /Out-of-tree files
1702 # ------------------------------------------------------
1704 # ------------------------------------------------------
1705 # Unpackaged files
1706 # ------------------------------------------------------
1707 orphans=$(mktemp)
1708 awk -F$'\n' -vall="$all_files" '
1710 if (FILENAME == all) files_all[$1] = "1";
1711 else files_pkg[$1] = "1";
1713 END {
1714 for (i in files_all) {
1715 if (! files_pkg[i]) print i;
1718 ' "$all_files" "$packaged" | sort > $orphans
1719 if [ -d "$install" -a -s "$orphans" ]; then
1720 echo
1721 echo "<script>document.getElementById('li-orphans$set').style.display = 'list-item'</script>"
1722 echo "<section id='orphans$set'>"
1723 echo " <h3>Unpackaged files$set_description:</h3>"
1724 table=$(mktemp)
1725 awk '
1726 function tag(text, color) {
1727 printf("<span class=\"c%s1\">%s</span> ", color, text);
1728 printf("%s\n", $0);
1730 /\/perllocal\.pod$/ || /\/\.packlist$/ ||
1731 /\/share\/bash-completion\// || /\/etc\/bash_completion\.d\// ||
1732 /\/lib\/systemd\// || /\.pyc$/ || /\.pyo$/ ||
1733 /\/fonts\.scale$/ || /\/fonts\.dir$/ || /\.la$/ {
1734 tag("---", 0); next }
1735 /\.pod$/ { tag("pod", 5); next }
1736 /\/share\/man\// { tag("man", 5); next }
1737 /\/share\/doc\// || /\/share\/gtk-doc\// || /\/share\/info\// ||
1738 /\/share\/devhelp\// { tag("doc", 5); next }
1739 /\/share\/icons\// { tag("ico", 2); next }
1740 /\/share\/locale\// { tag("loc", 4); next }
1741 /\.h$/ || /\.a$/ || /\.pc$/ || /\/bin\/.*-config$/ ||
1742 /\/Makefile.*$/ { tag("dev", 3); next }
1743 /\/share\/help\// || /\/share\/appdata\// ||
1744 /\/share\/metainfo\// { tag("gnm", 6); next }
1745 { tag("???", 1) }
1746 ' "$orphans" > $table
1748 # Summary table
1749 orphans_types='()'
1750 for i in head body; do
1751 case $i in
1752 head) echo -n '<table class="summary"><tr>';;
1753 body) echo -n '<th> </th></tr><tr>';;
1754 esac
1755 for j in '???1' dev3 loc4 ico2 doc5 man5 pod5 gnm6 '---0'; do
1756 tag=${j:0:3}; class="c${j:3:1}0"; [ "$class" == 'c00' ] && class='c01'
1757 case $i in
1758 head) echo -n "<th class='$class'>$tag</th>";;
1759 body)
1760 tagscount="$(grep ">$tag<" $table | wc -l)"
1761 printf '<td>%s</td>' "$tagscount"
1762 [ "$tagscount" -gt 0 ] && orphans_types="${orphans_types/)/ $tag)}"
1763 ;;
1764 esac
1765 done
1766 done
1767 echo '<td> </td></tr></table>'
1768 orphans_types="${orphans_types/( /(}"
1769 [ "$orphans_types" != '()' ] &&
1770 echo "<script>document.getElementById('orphansTypes$set').innerText = '${orphans_types// /, }';</script>"
1772 suffix=''; [ -n "$set" ] && suffix="-$set"
1773 echo -n ' <pre class="files">'
1774 echo -en '<span class="underline">tag·permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
1775 IFS=$'\n'
1776 while read orphan_line; do
1777 echo -n "${orphan_line/span> */span>} "
1778 cd $install
1779 ls -ldp --color=always ".${orphan_line#*</span> }" \
1780 | syntax_highlighter files \
1781 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$main/browse/install$suffix\2'>\2\3|;" \
1782 | awk 'BEGIN { FS="\""; }
1783 { gsub("+", "%2B", $2); print; }'
1784 done < $table
1785 unset IFS
1786 echo '</pre>'
1787 echo '</section>'
1788 rm $table
1789 fi
1790 rm $orphans
1791 # ------------------------------------------------------
1792 # /Unpackaged files
1793 # ------------------------------------------------------
1795 rm $all_files $packaged
1796 ;;
1797 esac
1798 done # /set
1800 case "$part" in
1801 head)
1802 [ -n "$splitsets" ] && echo "</ul>"
1803 echo "</section>"
1804 ;;
1805 esac
1806 done # /part
1808 ;;
1810 description)
1811 page_header
1812 pkg_info
1813 descs="$(ls $WOK/$pkg/description*.txt)"
1814 if [ -n "$descs" ]; then
1815 echo '<div id="content2">'
1816 [ -f "$WOK/$pkg/description.txt" ] && show_desc "$pkg" "$WOK/$pkg/description.txt"
1817 for i in $descs; do
1818 case $i in
1819 */description.txt) continue ;;
1820 *) package=$(echo $i | cut -d. -f2) ;;
1821 esac
1822 show_desc "$package" "$i"
1823 done
1824 echo '</div>'
1825 else
1826 show_note w "No description of $pkg"
1827 fi
1828 ;;
1830 log)
1831 page_header
1832 pkg_info
1833 [ -z "$arg" ] && arg=$(stat -c %Y $LOGS/$pkg.log)
1835 echo '<div class="btnList">'
1836 acc='l' # access key for the latest log is 'L'
1837 while read log; do
1838 # for all $pkg.log, $pkg.log.0 .. $pkg.log.9, $pkg-pack.log (if any)
1839 timestamp=$(stat -c %Y $log)
1840 class=''
1841 if [ "$arg" == "$timestamp" ]; then
1842 class=' log'
1843 logfile="$log"
1844 fi
1845 case $log in *-pack.log) acc='p';; esac # access key for the packing log is 'P'
1846 echo -n "<a class='button$class' data-acc='$acc' accesskey='$acc' href='$base/$pkg/log/$timestamp'>"
1847 echo "$(stat -c %y $log | cut -d: -f1,2)</a>"
1848 case $acc in
1849 l) acc=0;;
1850 *) acc=$((acc+1));;
1851 esac
1852 done <<EOT
1853 $(find $LOGS -name "$pkg.log*" | sort)
1854 $(find $LOGS -name "$pkg-pack.log")
1855 EOT
1856 echo '</div>'
1858 if [ -z "$logfile" ]; then
1859 show_note e "Requested log is absent"
1860 page_footer
1861 exit 0
1862 fi
1864 # Define cook variables for syntax highlighter
1865 if [ -s "$WOK/$pkg/receipt" ]; then
1866 . "$WOK/$pkg/receipt"
1867 _wok='/home/slitaz/wok'
1868 _src="$_wok/$pkg/source/$PACKAGE-$VERSION"
1869 _install="$_wok/$pkg/install"
1870 _fs="$_wok/$pkg/taz/$PACKAGE-$VERSION/fs"
1871 _stuff="$_wok/$pkg/stuff"
1872 fi
1874 # if [ ! -f "gzlog/$pkg.$arg" ]; then
1875 # {
1876 # summary "$logfile" links
1878 # syntax_highlighter log < $logfile | awk '
1879 # BEGIN { print "<pre class=\"log\">"; }
1880 # { printf("<a name=\"l%d\" href=\"#l%d\">%5d</a> %s\n", NR, NR, NR, $0); }
1881 # END { print "</pre>"; }
1882 # '
1884 # page_footer
1885 # } | gzip > gzlog/$pkg.$arg
1886 # fi
1888 blog=$(basename $logfile)
1889 summary "$logfile" links
1891 # disable next `sed` for the 'like2016' theme
1892 theme=$(COOKIE theme); theme=${theme:-default}; [ "$theme" != 'like2016' ] && theme=''
1893 cat $logfile | syntax_highlighter log | \
1894 sed -e "/(pkg\/local$theme):/ s|: \([^<]*\)|<img src='$base/i/$blog/\1'> \1|" | \
1895 awk '
1896 BEGIN { print "<pre class=\"log\">"; }
1897 { printf("<span id=\"l%d\">%s</span><a href=\"#l%d\"></a>\n", NR, $0, NR); }
1898 END { print "</pre>"; }
1900 ;;
1903 man|doc|info)
1904 page_header
1905 pkg_info
1906 echo '<div style="max-height: 6.4em; overflow: auto; padding: 0 4px">'
1908 dir="wok/$pkg/install/usr/share/$cmd"
1909 [ "$cmd" == 'doc' ] && dir="$dir wok/$pkg/install/usr/share/gtk-doc"
1910 if [ "$cmd" == 'doc' -a -z "$arg" ]; then
1911 try=$(for i in $dir; do find $i -name 'index.htm*'; done | sed q)
1912 [ -n "$try" ] && arg="$try"
1913 fi
1914 while read i; do
1915 [ -s "$i" ] || continue
1916 case "$i" in
1917 *.jp*g|*.png|*.gif|*.svg|*.css) continue
1918 esac
1919 i=${i#$dir/}
1920 [ -n "$arg" ] || arg="$i"
1921 class=''; [ "$arg" == "$i" ] && class=" doc"
1922 case "$cmd" in
1923 man)
1924 case $i in
1925 man*) lang='';;
1926 *) lang="${i%%/*}: ";;
1927 esac
1928 man=$(basename $i .gz)
1929 echo "<a class='button$class' href='$base/$pkg/man/$i'>$lang${man%.*} (${man##*.})</a>"
1930 ;;
1931 doc)
1932 echo "<a class='button$class' href='$base/$pkg/doc/$i'>$(basename $i .gz)</a>"
1933 ;;
1934 info)
1935 info=$(basename $i)
1936 echo "<a class='button$class' href='$base/$pkg/info/$i#Top'>${info/.info/}</a>"
1937 ;;
1938 esac
1939 done <<EOT
1940 $(for i in $dir; do find $i -type f; done | sort)
1941 EOT
1942 echo '</div>'
1944 [ -f "$arg" ] || arg="$dir/$arg"
1945 if [ -f "$arg" ]; then
1946 tmp="$(mktemp)"
1947 docat "$arg" > $tmp
1948 [ -s "$tmp" ] &&
1949 case "$cmd" in
1950 info)
1951 echo '<div id="content2" class="texinfo"><pre class="first">'
1952 info2html < "$tmp"
1953 echo '</pre></div>'
1954 ;;
1955 doc)
1956 case "$arg" in
1957 *.sgml|*.devhelp2) class='xml';;
1958 *.py) class='python';; # pycurl package
1959 *.css) class='css';;
1960 *.sh) class='bash';;
1961 *)
1962 first=$(head -n1 "$tmp")
1963 if [ "${first:0:1}" == '#' ]; then
1964 class='bash' # first line begins with '#'
1965 else
1966 class='asciidoc'
1967 fi;;
1968 esac
1969 case "$arg" in
1970 *.htm*)
1971 case $arg in
1972 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
1973 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
1974 esac
1975 # make the iframe height so long to contain its contents without scrollbar
1976 echo "<iframe id='idoc' src='$page' width='100%' onload='resizeIframe(this)'></iframe>"
1977 ;;
1978 *.pdf)
1979 case $arg in
1980 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
1981 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
1982 esac
1983 cat <<EOT
1984 <object id="idoc" data="$page" width="100%" height="100%" type="application/pdf" style="min-height: 600px">
1985 $(show_note w "Missing PDF plugin.<br/>Get the file <a href="$page">$(basename "$page")</a>.")
1986 </object>
1987 EOT
1988 ;;
1989 *.md|*.markdown)
1990 echo '<section>'
1991 $md2html "$tmp"
1992 echo '</section>'
1993 ;;
1994 *)
1995 show_code $class < "$tmp"
1996 ;;
1997 esac
1998 ;;
1999 man)
2000 #export TEXTDOMAIN='man2html'
2001 echo "<div id='content2'>"
2003 html=$(./man2html.bin "$tmp" | sed -e '1,/<header>/d' -e '/<footer>/,$d' \
2004 -e 's|<a href="file:///[^>]*>\([^<]*\)</a>|\1|g' \
2005 -e 's|<a href="?[1-9]\+[^>]*>\([^<]*\)</a>|\1|g')
2007 if [ -n "$(echo "$html" | fgrep 'The requested file /tmp/tmp.')" ]; then
2008 # Process the pre-formatted man-cat page
2009 # (for example see sudo package without groff in build dependencies)
2010 sed -i '
2011 s|M-bM-^@M-^S|—|g;
2012 s|M-bM-^@M-^\\|<b>|g;
2013 s|M-bM-^@M-^]|</b>|g
2014 s|M-bM-^@M-^X|<u>|g;
2015 s|M-bM-^@M-^Y|</u>|g;
2016 s|M-BM-||g;
2017 s|++oo|•|g;
2018 s|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g;
2019 ' "$tmp"
2020 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 \
2021 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 \
2022 0 1 2 3 4 5 6 7 8 9 _ - '\\+' '\.' /; do
2023 sed -i "s|$i$i|<b>$i</b>|g; s|_$i|<u>$i</u>|g" "$tmp"
2024 done
2025 echo '<pre class="catman">'
2026 sed 's|</b><b>||g; s|</u><u>||g; s|</u><b>_</b><u>|_|g; s|</b> <b>| |g;' "$tmp"
2027 echo '</pre>'
2028 else
2029 echo "$html"
2030 fi
2031 echo "</div>"
2032 ;;
2033 esac
2034 rm -f $tmp
2035 else
2036 show_note e "File “$arg” does not exist!"
2037 fi
2038 ;;
2040 download)
2041 page_header
2042 pkg_info
2043 show=0
2045 . $wok/$pkg/receipt
2047 if [ -n "$TARBALL" -a -s "$SRC/$TARBALL" ]; then
2048 files_header
2049 echo "<tr><td><a href='$base/src/$TARBALL'>$TARBALL</a></td>"
2050 ls -lh "$SRC/$TARBALL" | awk '{printf("<td>%sB</td>", $5)}'
2051 echo "<td>Sources for building the package “$pkg”</td></tr>"
2052 show=1
2053 fi
2055 if [ -d "$wok/$pkg/taz" ]; then
2056 [ "$show" -eq 1 ] || files_header
2058 common_version=$VERSION
2059 for i in $(all_names); do
2060 [ -e "$wok/$pkg/taz/$i-$common_version$EXTRAVERSION/receipt" ] || continue
2061 . $wok/$pkg/taz/$i-$common_version$EXTRAVERSION/receipt
2063 for filename in "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg"; do
2064 [ -f "$PKGS/$filename" ] &&
2065 cat <<EOT
2066 <tr>
2067 <td><a href="$base/get/$filename">$filename</a></td>
2068 <td>$(ls -lh ./packages/$filename | awk '{printf("%sB", $5)}')</td>
2069 <td>$SHORT_DESC</td>
2070 </tr>
2071 EOT
2072 done
2073 done
2074 show=1
2075 fi
2077 if [ "$show" -eq 1 ]; then
2078 echo '</tbody></table></section>'
2079 else
2080 show_note w "Sorry, there's nothing to download…"
2081 fi
2082 ;;
2084 esac
2087 page_footer
2088 exit 0