cookutils view lighttpd/index.cgi @ rev 1076

lighttpd/index.cgi: show icon for all sub-packages (like *-dev, etc.); better handle "debug" query; fix display commits.log
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue Jun 12 01:38:59 2018 +0300 (2018-06-12)
parents 12ab43dfc0a9
children aa5729cf385c
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="$base/">Cooker</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|^\([lrwxs-][lrwxs-]*\)|<span class='c11'>\1</span>|;
627 "
628 ;;
629 esac
630 }
633 show_code() {
634 echo -n "<pre><code class=\"language-$1\">"
635 sed 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g'
636 echo '</code></pre>'
637 }
640 datalist() {
641 cut -d$'\t' -f2 $splitdb | tr ' ' '\n' | sort -u | awk '
642 BEGIN{printf("<datalist id=\"packages\">")}
643 {printf("<option>%s",$1)}
644 END {printf("</datalist>")}
645 '
646 }
649 mklog() {
650 awk '
651 BEGIN { printf("<pre class=\"log dog\">\n") }
652 { print }
653 END { print "</pre>" }'
654 }
657 summary() {
658 log="$1"
659 pkg="$(basename ${log%%.log*})"
661 if [ -f "$log" ]; then
662 if grep -q "cook:$pkg$" $command; then
663 show_note i "The Cooker is currently building $pkg"
664 elif fgrep -q "Summary for:" $log; then
665 sed '/^Summary for:/,$!d' $log | awk '
666 BEGIN { print "<section>" }
667 function row(line) {
668 split(line, s, " : ");
669 printf("\t<tr><td>%s</td><td>%s</td></tr>\n", s[1], s[2]);
670 }
671 function row2(line, rowNum) {
672 split(line, s, " : ");
673 if (rowNum == 1) {
674 print "<thead>";
675 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]);
676 print "</thead><tbody>";
677 }
678 else
679 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]);
680 }
681 {
682 if (NR==1) { printf("<h3>%s</h3>\n<table>\n", $0); next }
683 if ($0 ~ "===") { seen++; if (seen == 1) next; else exit; }
684 if ($0 ~ "---") {
685 seen2++;
686 if (seen2 == 1) print "</table>\n\n<table class=\"pkgslist\">"
687 next
688 }
689 if (seen2) row2($0, seen2); else row($0);
690 }
691 END { print "</tbody></table></section>" }
692 '
693 elif fgrep -q "Debug information" $log; then
694 echo -e '<section>\n<h3>Debug information</h3>'
695 sed -e '/^Debug information/,$!d; /^===/d; /^$/d' $log | sed -n '1!p' | \
696 if [ -n "$2" ]; then
697 syntax_highlighter log | sed 's|\([^0-9 ]\)\([0-9][0-9]*\):|\1<a href="#l\2">\2</a>:|'
698 else
699 sed 's|^[0-9][0-9]*:||' | syntax_highlighter log
700 fi | mklog
701 echo '</section>'
702 fi
703 else
704 [ -n "$pkg" -a -d "$wok/$pkg" ] && show_note e "No log for $pkg"
705 fi
706 }
709 active() {
710 [ "$cmd" == "$1" -o "$cmd" == "${2:-$1}" ] && echo -n ' active'
711 }
714 pkg_info() {
715 local log active bpkg short_desc=''
716 log="$LOGS/$pkg.log"
718 echo -n "<div id=\"hdr\"><a href=\"$base/${requested_pkg:-$pkg}\">"
719 if [ -e $wok/$pkg/.icon.png ]; then
720 echo -n "<img src=\"$base/$pkg/browse/.icon.png\"/>"
721 else
722 echo -n "<img src=\"/tazpkg.png\"/>"
723 fi
724 echo -n "</a>"
725 echo -n "<h2><a href=\"$base/${requested_pkg:-$pkg}\">${requested_pkg:-$pkg}</a>"
726 # Get short description for existing packages
727 [ -f $PKGS/packages.info ] &&
728 short_desc="$(awk -F$'\t' -vp="${requested_pkg:-$pkg}" '{if ($1 == p) { printf("%s", $4); exit; }}' $PKGS/packages.info)"
729 # If package does not exist (not created yet or broken), get short description
730 # (but only for "main" package) from receipt
731 [ -n "$short_desc" ] || short_desc="$(. $wok/$pkg/receipt; echo "$SHORT_DESC")"
732 echo "<br/>$short_desc</h2></div>"
733 echo '<div id="info">'
734 echo "<a class='button icon receipt$(active receipt stuff)' href='$base/$pkg/receipt'>receipt &amp; stuff</a>"
736 # In the receipts $EXTRAVERSION is defined using $kvers, get it here [copy from 'cook' set_paths()]
737 if [ -f "$wok/linux/receipt" ]; then
738 kvers=$(. $wok/linux/receipt; echo $VERSION)
739 kbasevers=$(echo $kvers | cut -d. -f1,2)
740 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
741 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
742 kbasevers=$(echo $kvers | cut -d. -f1,2)
743 fi
745 unset WEB_SITE WANTED
746 . $wok/$pkg/receipt
748 [ -n "$WEB_SITE" ] &&
749 echo "<a class='button icon website' href='$WEB_SITE' target='_blank' rel='noopener noreferrer'>web site</a>"
751 [ -f "$wok/$pkg/taz/$PACKAGE-$VERSION$EXTRAVERSION/receipt" ] &&
752 echo "<a class='button icon files$(active files)' href='$base/$pkg/files'>files</a>"
754 [ -n "$(ls $wok/$pkg/description*.txt)" ] &&
755 echo "<a class='button icon desc$(active description)' href='$base/$pkg/description'>description</a>"
757 [ -n "$TARBALL" -a -s "$SRC/$TARBALL" -o -d "$wok/$pkg/taz" ] &&
758 echo "<a class='button icon download' href='$base/$pkg/download'>download</a>"
760 echo "<a class='button icon browse' href='$base/$pkg/browse/'>browse</a>"
762 [ -x ./man2html.bin -a -d "$wok/$pkg/install/usr/share/man" ] &&
763 echo "<a class='button icon doc$(active man)' href='$base/$pkg/man/'>man</a>"
765 [ -d "$wok/$pkg/install/usr/share/doc" -o -d "$wok/$pkg/install/usr/share/gtk-doc" ] &&
766 echo "<a class='button icon doc$(active doc)' href='$base/$pkg/doc/'>doc</a>"
768 [ -d "$wok/$pkg/install/usr/share/info" ] &&
769 echo "<a class='button icon doc$(active info)' href='$base/$pkg/info/#Top'>info</a>"
771 if [ -n "$LFS" ]; then
772 printf "<a class='button icon doc' href='%s' target='_blank' rel='noopener noreferrer'>" "$LFS"
773 [ "${LFS/blfs/}" != "$LFS" ] && printf "B"
774 printf "LFS</a>\n"
775 fi
777 [ -s "$log" ] &&
778 echo "<a class='button icon log$(active log)' href='$base/$pkg/log/'>logs</a>"
780 echo '</div>'
781 }
784 mktable() {
785 sed 's# : #|#' | awk -vc="$1" '
786 BEGIN { printf("<table class=\"%s\">\n", c); FS="|" }
787 { printf("<tr><td>%s</td>", $1);
788 if (NF == 2) printf("<td>%s</td>", $2);
789 printf("</tr>\n", $2) }
790 END { print "</table>" }'
791 }
794 section() {
795 local i=$(basename "$1")
796 echo -e '\n\n<section>'
797 [ $(wc -l < $1) -gt $2 ] && echo "<a class='button icon more r' href='?$i'>${3#*|}</a>"
798 echo "<h2>${3%|*}</h2>"
799 mktable "$i"
800 echo '</section>'
801 }
804 show_desc() {
805 echo "<section><h3>Description of “$1”</h3>"
806 if [ -n "$md2html" ]; then
807 $md2html $2
808 else
809 show_code markdown < $2
810 fi
811 echo "</section>"
812 }
815 # Return all the names of packages bundled in this receipt
817 all_names() {
818 # Get package names from $SPLIT variable
819 local split=$(echo $SPLIT \
820 | awk '
821 BEGIN { RS = " "; FS = ":"; }
822 { print $1; }' \
823 | tr '\n' ' ')
824 local split_space=" $split "
825 if ! head -n1 $WOK/$pkg/receipt | fgrep -q 'v2'; then
826 # For receipts v1: $SPLIT may present in the $WANTED package,
827 # but split packages have their own receipts
828 echo $PACKAGE
829 elif [ "${split_space/ $PACKAGE /}" != "$split_space" ]; then
830 # $PACKAGE included somewhere in $SPLIT (probably in the end).
831 # We should build packages in the order defined in the $SPLIT.
832 echo $split
833 else
834 # We'll build the $PACKAGE, then all defined in the $SPLIT.
835 echo $PACKAGE $split
836 fi
837 }
840 toolchain_version() {
841 echo "<tr><td><a href='$base/$1'>$1</a></td>"
842 awk -F$'\t' -vpkg="$1" '
843 BEGIN { version = description = "---"; }
844 {
845 if ($1 == pkg) { version = $2; description = $4; }
846 }
847 END { printf("<td>%s</td><td>%s</td></tr>", version, description); }
848 ' $PKGS/packages.info
849 }
852 files_header() {
853 echo '<section><h3>Available downloads:</h3>'
854 echo '<table><thead><tr><th>File</th><th>Size</th><th>Description</th></tr></thead><tbody>'
855 }
858 # Update statistics used in web interface.
859 # There is no need to recalculate the statistics every time the page is displayed.
860 # Note, $webstat file must be owned by www, otherwise this function will not be able to do the job.
862 update_webstat() {
863 # for receipts:
864 rtotal=$(ls $WOK/*/arch.$ARCH | wc -l)
865 rcooked=$(ls -d $WOK/*/taz | wc -l)
866 runbuilt=$(($rtotal - $rcooked))
867 rblocked=$(wc -l < $blocked)
868 rbroken=$(wc -l < $broken)
870 # for packages:
871 ptotal=$(cut -d$'\t' -f2 $CACHE/split.db | tr ' ' '\n' | sort -u | wc -l)
872 pcooked=$(ls $PKGS/*.tazpkg | wc -l)
873 punbuilt=$(($ptotal - $pcooked))
874 pblocked=$(
875 while read i; do
876 sed "/^$i\t/!d" $CACHE/split.db
877 done < $blocked | cut -d$'\t' -f2 | tr ' ' '\n' | wc -l)
878 pbroken=$(
879 while read i; do
880 sed "/^$i\t/!d" $CACHE/split.db
881 done < $broken | cut -d$'\t' -f2 | tr ' ' '\n' | wc -l)
883 cat > $webstat <<EOT
884 rtotal="$rtotal"; rcooked="$rcooked"; runbuilt="$runbuilt"; rblocked="$rblocked"; rbroken="$rbroken"
885 ptotal="$ptotal"; pcooked="$pcooked"; punbuilt="$punbuilt"; pblocked="$pblocked"; pbroken="$pbroken"
886 EOT
887 }
890 # Generate part of the main page
892 part() {
893 echo -n "<div id='$1'>"
895 case $1 in
896 summary)
897 echo '<h2>Summary</h2>'
899 mktable <<EOT
900 Cooker state : $(running_command)
901 Wok revision : <a href='$WOK_URL' target='_blank' rel='noopener noreferrer'>$(cat $wokrev)</a>
902 Commits to cook : $(wc -l < $commits)
903 Current cooklist : $(wc -l < $cooklist)
904 Architecture : $ARCH, <a href="$toolchain">toolchain</a>
905 Server date : <span id='date'>$(date -u '+%F %R %Z')</span>
906 EOT
908 # If command is "cook:*", update gauge and percentage periodically.
909 # If different package is cooking, reload the page (with new settings)
910 cmd="$(cat $command)"
911 case "$cmd" in
912 cook:*)
913 pkg=${cmd#*:}
914 echo "<script>updatePkg = '${pkg//+/%2B}';</script>"
915 ;;
916 esac
917 ;;
918 webstat)
919 # Do we need to update the statistics?
920 if [ -n "$nojs" -a "$activity" -nt "$webstat" ]; then update_webstat; fi
921 . $webstat
923 pct=0; [ "$rtotal" -gt 0 ] && pct=$(( ($rcooked * 100) / $rtotal ))
925 cat <<EOT
926 <div class="meter"><progress max="100" value="$pct">${pct}%</progress><span>${pct}%</span></div>
928 <table class="webstat"><thead>
929 <tr><th> </th><th>Total </th><th>Cooked </th><th>Unbuilt </th><th>Blocked </th><th>Broken </th></tr>
930 </thead><tbody>
931 <tr><td>Receipts</td><td>$rtotal</td><td>$rcooked</td><td>$runbuilt</td><td>$rblocked</td><td>$rbroken</td></tr>
932 <tr><td>Packages</td><td>$ptotal</td><td>$pcooked</td><td>$punbuilt</td><td>$pblocked</td><td>$pbroken</td></tr>
933 </tbody></table>
934 EOT
935 if [ -z "$nojs" ]; then echo "<script>getPart('$1')</script>"; fi
936 ;;
937 activity)
938 tac $activity | head -n12 | sed 's|cooker.cgi?pkg=||;
939 s|\[ Done|<span class="r c20">Done|;
940 s|\[ Failed|<span class="r c10">Failed|;
941 s|\[ -Failed|<span class="r c10"><del>Failed</del>|;
942 s| \]|</span>|;
943 s|%2B|\+|g' | \
944 section $activity 12 "Activity|More activity"
945 ;;
946 cooknotes)
947 [ -s "$cooknotes" ] && tac $cooknotes | head -n12 | \
948 section $cooknotes 12 "Cooknotes|More notes"
949 ;;
950 commits)
951 [ -s "$commits" ] && head -n20 $commits | \
952 section $commits 20 "Commits|More commits"
953 ;;
954 cooklist)
955 [ -s "$cooklist" ] && head -n 20 $cooklist | \
956 section $cooklist 20 "Cooklist|Full cooklist"
957 ;;
958 broken)
959 [ -s "$broken" ] && head -n20 $broken | sed "s|^[^']*|<a href='\0'>\0</a>|g" | \
960 section $broken 20 "Broken|All broken packages"
961 ;;
962 blocked)
963 [ -s "$blocked" ] && sed "s|^[^']*|<a href='\0'>\0</a>|g" $blocked | \
964 section $blocked 12 "Blocked|All blocked packages"
965 ;;
966 pkgs)
967 cd $PKGS
968 # About BusyBox's `ls`
969 # On the Tank server: BusyBox v1.18.4 (2012-03-14 03:32:25 CET) multi-call binary.
970 # It supported the option `-e`, output with `-let` options like this:
971 # -rw-r--r-- 1 user group 100000 Fri Nov 3 10:00:00 2017 filename
972 # 1 2 3 4 5 6 7 8 9 10 11
973 # Newer BusyBox v1.27.2 doesn't support option `-e` and has no configs to
974 # configure it or return the option back. It supported the long option
975 # `--full-time` instead, but output is different:
976 # -rw-r--r-- 1 user group 100000 2017-11-03 10:00:00 +0200 filename
977 # 1 2 3 4 5 6 7 8 9
978 if ls -let >/dev/null 2>&1; then
979 ls -let *.tazpkg \
980 | awk '
981 (NR<=20){
982 sub(/:[0-9][0-9]$/, "", $9);
983 mon = index(" JanFebMarAprMayJunJulAugSepOctNovDec", $7) / 3;
984 printf("%d-%02d-%02d %s : <a href=\"get/%s\">%s</a>\n", $10, mon, $8, $9, $11, $11);
985 }' \
986 | section $activity 1000 "Latest cook"
987 else
988 ls -lt --full-time *.tazpkg \
989 | awk '
990 (NR<=20){
991 sub(/:[0-9][0-9]$/, "", $7);
992 printf("%s %s : <a href=\"get/%s\">%s</a>\n", $6, $7, $9, $9);
993 }' \
994 | section $activity 1000 "Latest cook"
995 fi
996 ;;
997 esac
998 echo "</div>"
999 }
1002 # Query '?part=<part>': get part of the main page
1004 if [ -n "$(GET part)" ]; then
1005 part="$(GET part)"
1006 case $part in
1007 summary|webstat|activity|cooknotes|commits|cooklist|broken|blocked|pkgs)
1008 nojs='yes'
1009 part $part
1010 ;;
1011 esac
1012 exit 0
1013 fi
1019 # Load requested page
1022 if [ -z "$pkg" ]; then
1024 page_header
1025 if [ -n "$QUERY_STRING" ]; then
1027 [ "$QUERY_STRING" != 'commits.log' ] &&
1028 for list in activity cooknotes cooklist commits; do
1029 [ -n "$(GET $list)" ] || continue
1030 case $list in
1031 cooklist) nb="- Packages: $(wc -l < $cooklist)";;
1032 commits) nb="- Packages: $(wc -l < $commits)";;
1033 esac
1034 echo '<section id="content2">'
1035 echo "<h2>DB: $list $nb</h2>"
1036 tac $CACHE/$list | sed 's|cooker.cgi?pkg=||; s|%2B|+|g;
1037 s|\[ Done|<span class="r c20">Done|;
1038 s|\[ Failed|<span class="r c10">Failed|;
1039 s|\[ -Failed|<span class="r c10"><del>Failed</del>|;
1040 s| \]|</span>|' | mktable $list
1041 echo '</section>'
1042 done
1044 if [ -n "$(GET broken)" ]; then
1045 echo '<section id="content2">'
1046 echo "<h2>DB: broken - Packages: $(wc -l < $broken)</h2>"
1047 sort $CACHE/broken | sed "s|^[^']*|<a href='$base/\0'>\0</a>|g" | mktable
1048 echo '</section>'
1049 fi
1051 case "$QUERY_STRING" in
1052 *.log)
1053 log=$LOGS/$QUERY_STRING
1054 name=$(basename $log)
1055 if [ -f "$log" ]; then
1056 echo "<h2>Log for: ${name%.log}</h2>"
1057 if fgrep -q "Summary" $log; then
1058 echo '<pre class="log">'
1059 grep -A 20 'Summary' $log | syntax_highlighter log
1060 echo '</pre>'
1061 fi
1062 echo '<pre class="log">'
1063 syntax_highlighter log < $log
1064 echo '</pre>'
1065 if [ "$QUERY_STRING" == 'pkgdb.log' ]; then
1066 # Display button only for SliTaz web browser
1067 case "$HTTP_USER_AGENT" in
1068 *SliTaz*)
1069 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
1070 if grep -qs '^pkgdb$' $CACHE/recook-packages; then
1071 show_note i "The package database has been requested for re-creation"
1072 else
1073 echo "<a class='button' href='$base/?recook=pkgdb'>Re-create the DB</a>"
1074 fi
1075 fi
1076 ;;
1077 esac
1078 fi
1079 else
1080 show_note e "No log file: $log"
1081 fi
1082 ;;
1083 toolchain)
1084 cat <<EOT
1085 <div id="content2">
1086 <section>
1087 <h2>SliTaz GNU/Linux toolchain</h2>
1089 <table>
1090 <tr><td>Build date</td> <td colspan="2">$(sed -n '/^Cook date/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td></tr>
1091 <tr><td>Build duration</td> <td colspan="2">$(sed -n '/^Cook time/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td></tr>
1092 <tr><td>Architecture</td> <td colspan="2">$ARCH</td></tr>
1093 <tr><td>Host system</td> <td colspan="2">$BUILD_SYSTEM</td></tr>
1094 <tr><td>Target system</td> <td colspan="2">$HOST_SYSTEM</td></tr>
1095 <tr><th>Package</th><th>Version</th><th>Description</th></tr>
1096 $(toolchain_version slitaz-toolchain)
1097 $(toolchain_version binutils)
1098 $(toolchain_version linux-api-headers)
1099 $(toolchain_version gcc)
1100 $(toolchain_version glibc)
1101 </table>
1103 <p>Toolchain documentation: <a target="_blank" rel="noopener noreferrer"
1104 href="http://doc.slitaz.org/en:cookbook:toolchain">http://doc.slitaz.org/en:cookbook:toolchain</a>
1105 </p>
1107 </section>
1108 </div>
1109 EOT
1110 ;;
1111 esac
1112 page_footer
1113 exit 0
1114 fi
1117 # We may have a toolchain.cgi script for cross cooker's
1118 if [ -f "toolchain.cgi" ]; then
1119 toolchain="toolchain.cgi"
1120 else
1121 toolchain="?toolchain"
1122 fi
1124 # Main page with summary. Count only packages included in ARCH,
1125 # use 'cooker arch-db' to manually create arch.$ARCH files.
1127 cat <<EOT
1128 <div id="content2">
1130 <section>
1131 <form method="get" action="" class="search r">
1132 <input type="hidden" name="search" value="pkg"/>
1133 <button type="submit" title="Search">Search</button>
1134 <input type="search" name="q" placeholder="Package" list="packages" autocorrect="off" autocapitalize="off"/>
1135 </form>
1136 EOT
1138 unset nojs
1139 part summary
1140 part webstat
1142 if [ -e "$CACHE/cooker-request" -a ! -s $command ]; then
1143 if [ "$activity" -nt "$CACHE/cooker-request" ]; then
1144 echo '<a class="button icon bell r" href="?poke">Wake up</a>'
1145 else
1146 show_note i 'Cooker will be launched in the next 5 minutes.'
1147 fi
1148 fi
1150 cat <<EOT
1151 <p>
1152 Service logs:
1153 <a href="?cookorder.log">cookorder</a> ·
1154 <a href="?commits.log">commits</a> ·
1155 <a href="?pkgdb.log">pkgdb</a>
1156 </p>
1157 </section>
1158 EOT
1160 part activity
1161 part cooknotes
1162 part commits
1163 part cooklist
1164 part broken
1165 part blocked
1166 part pkgs
1168 echo '</div>'
1169 datalist
1170 page_footer
1171 exit 0
1172 fi
1175 # show tag
1177 if [ "$pkg" == '~' -a -n "$cmd" ]; then
1178 tag="$cmd"
1179 page_header
1180 cat <<EOT
1181 <div id="content2">
1182 <section>
1183 <h2>Tag “$tag”</h2>
1185 <table>
1186 <thead>
1187 <tr><th>Name</th><th>Description</th><th>Category</th></tr>
1188 </thead>
1189 <tbody>
1190 EOT
1191 sort $PKGS/packages.info \
1192 | awk -F$'\t' -vtag=" $tag " -vbase="$base" '{
1193 if (index(" " $6 " ", tag)) {
1194 url = base "/" $1 "/";
1195 gsub("+", "%2B", url);
1196 printf("<tr><td><img src=\"%s/s/%s\"> ", base, $1);
1197 printf("<a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", url, $1, $4, $3);
1199 }'
1200 echo '</tbody></table></section></div>'
1201 page_footer
1202 exit 0
1203 fi
1206 case "$cmd" in
1207 '')
1208 page_header
1210 requested_pkg="$pkg"
1211 # Package info.
1212 if [ ! -f "$wok/$pkg/receipt" ]; then
1213 # Let's look at the cases when the package was not found
1215 # Maybe query is the exact name of split package? -> proceed to main package
1216 mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
1217 if (index(" " $2 " ", pkg)) {print $1; exit}
1218 }' $splitdb)
1220 # No, so let's find any matches among packages names (both main and split)
1221 if [ -z "$mainpkg" ]; then
1222 pkgs=$(cut -d$'\t' -f2 $splitdb | tr ' ' '\n' | fgrep "$pkg")
1223 # Nothing matched
1224 if [ -z "$pkgs" ]; then
1225 echo "<h2>Not Found</h2>"
1226 show_note e "The requested package <b>$pkg</b> was not found on this server."
1227 page_footer; exit 0
1228 fi
1229 # Search results page
1230 echo "<section><h2>Package names matching “$pkg”</h2>"
1231 echo "<table><thead><tr><th>Name</th><th>Description</th><th>Category</th></tr></thead><tbody>"
1232 query="$pkg"
1233 for pkg in $pkgs; do
1234 # Find main package
1235 mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
1236 if (index(" " $2 " ", pkg)) {print $1; exit}
1237 }' $splitdb)
1238 unset SHORT_DESC CATEGORY; . $wok/$mainpkg/receipt
1240 unset SHORT_DESC CATEGORY
1241 [ -e "$wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt" ] &&
1242 . $wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt
1244 echo -n "<tr><td><a href="$base/$pkg">${pkg//$query/<mark>$query</mark>}</a>"
1245 [ "$pkg" == "$mainpkg" ] || echo -n " (${mainpkg//$query/<mark>$query</mark>})"
1246 echo -n "</td><td>$SHORT_DESC</td><td>$CATEGORY</td></tr>"
1247 done
1248 echo '</tbody></table></section>'
1249 page_footer; exit 0
1250 fi
1251 pkg="$mainpkg"
1252 fi
1254 log=$LOGS/$pkg.log
1255 pkg_info
1257 # Check for a log file and display summary if it exists.
1258 summary "$log"
1261 # Show tag list
1262 taglist=$(
1263 for i in $pkg $(awk -F$'\t' -vp="$pkg" '{if ($1 == p) print $2}' $splitdb); do
1264 [ -s "$PKGS/packages.info" ] &&
1265 awk -F$'\t' -vpkg="$i" '{
1266 if ($1 == pkg) { print $6; exit; }
1267 }' "$PKGS/packages.info"
1268 done \
1269 | tr ' ' '\n' \
1270 | sort -u
1272 if [ -n "$taglist" ]; then
1273 echo -n '<section><h3>Tags</h3><p>'
1274 lasttag=$(echo "$taglist" | tail -n1)
1275 for tag in $taglist; do
1276 echo -n "<a href=\"$base/~/${tag//+/%2B}\">$tag</a>"
1277 [ "$tag" != "$lasttag" ] && echo -n " · "
1278 done
1279 echo '</p></section>'
1280 fi
1283 # Informational table with dependencies
1284 pkg="$requested_pkg"
1285 inf="$(mktemp -d)"
1287 # 1/3: Build dependencies (from receipt and pkgdb)
1288 for i in $WANTED $BUILD_DEPENDS $(awk -F$'\t' -vp=" $pkg " '{if (index(" " $2 " ", p) && (" " $1 " " != p)) print $1}' $splitdb); do
1289 echo "$i" >> $inf/a
1290 done
1292 # 2/3: Runtime dependencies (from pkgdb)
1294 [ -s "$PKGS/packages.info" ] &&
1295 awk -F$'\t' -vp="$pkg" '{
1296 if ($1 == p) print $8
1297 }' "$PKGS/packages.info"
1298 } | tr ' ' '\n' | sort -u > $inf/b
1300 # 3/3: Required by (from pkgdb)
1302 for i in $pkg $(awk -F$'\t' -vp="$pkg" '{if ($1 == p) print $2}' $splitdb); do
1303 [ -s "$PKGS/packages.info" ] &&
1304 awk -F$'\t' -vp=" $i " '{
1305 if (index(" " $8 " ", p)) print $1
1306 }' "$PKGS/packages.info"
1308 [ -s "$PKGS/bdeps.txt" ] &&
1309 awk -F$'\t' -vp=" $i " '{
1310 if (index(" " $2 " ", p)) print $1
1311 }' $PKGS/bdeps.txt
1312 done
1313 } | sort -u > $inf/c
1315 cat <<EOT
1316 <section>
1317 <h3>Related packages</h3>
1318 <table class="third">
1319 <thead>
1320 <tr>
1321 <th>Build dependencies</th>
1322 <th>Runtime dependencies</th>
1323 <th>Required by</th>
1324 </tr>
1325 </thead>
1326 <tbody>
1327 EOT
1329 awk -vinf="$inf" -vbase="$base" '
1330 function linki(i) {
1331 if (i) return sprintf("<img src=\"%s/s/%s\"> <a href=\"%s/%s\">%s</a>", base, i, base, i, i);
1333 BEGIN{
1334 do {
1335 a = b = c = "";
1336 getline a < inf "/a";
1337 getline b < inf "/b";
1338 getline c < inf "/c";
1339 printf("<tr><td>%s </td><td>%s </td><td>%s </td></tr>", linki(a), linki(b), linki(c));
1340 } while ( a b c )
1341 }'
1342 cat <<EOT
1343 </tbody>
1344 </table>
1345 </section>
1346 EOT
1347 # Clean
1348 rm -r $inf
1353 # Display <Recook> button only for SliTaz web browser
1354 case "$HTTP_USER_AGENT" in
1355 *SliTaz*)
1356 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
1357 if grep -qs "^$pkg$" $CACHE/recook-packages; then
1358 show_note i "The package “$pkg” has been requested for recook"
1359 else
1360 echo "<a class='button' href='$base/?recook=${pkg//+/%2B}'>Recook $pkg</a>"
1361 fi
1362 fi
1363 ;;
1364 esac
1365 ;;
1367 receipt)
1368 page_header
1369 pkg_info
1370 echo "<a class='button receipt' href='$base/$pkg/receipt'>receipt</a>"
1371 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1372 awk -vb="$base/$pkg" '{printf("<a class=\"button\" href=\"%s/%s\">%s</a>\n", b, $0, $0)}'
1374 show_code bash < $wok/$pkg/receipt
1375 ;;
1377 stuff)
1378 page_header
1379 pkg_info
1380 file="$pkg/stuff/$arg"
1381 echo "<a class='button' href='$base/$pkg/receipt'>receipt</a>"
1382 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1383 awk -vb="$base/$pkg" -va="stuff/$arg" '{
1384 printf("<a class=\"button%s\" href=\"%s/%s\">%s</a>\n", a==$0 ? " receipt" : "", b, $0, $0)
1385 }'
1387 if [ -f "$wok/$file" ]; then
1388 case $file in
1389 *.desktop|*.theme) class="ini" ;;
1390 *.patch|*.diff|*.u) class="diff" ;;
1391 *.sh) class="bash" ;;
1392 *.conf*|*.ini)
1393 class="bash"
1394 [ -n "$(cut -c1 < $wok/$file | fgrep '[')" ] && class="ini"
1395 ;;
1396 *.pl) class="perl" ;;
1397 *.c|*.h|*.awk) class="clike" ;;
1398 *.svg) class="svg" ;;
1399 *Makefile*) class="makefile" ;;
1400 *.po|*.pot) class="bash" ;;
1401 *.css) class="css" ;;
1402 *.htm|*.html) class="html" ;;
1403 *.js) class="js" ;;
1404 *.txt) class="asciidoc" ;;
1405 *)
1406 case $(head -n1 $wok/$file) in
1407 *!/bin/sh*|*!/bin/bash*) class="bash" ;;
1408 esac
1409 if [ -z "$class" -a "$(head -n1 $wok/$file | cut -b1)" == '#' ]; then
1410 class="bash"
1411 fi
1412 if [ -z "$class" ]; then
1413 # Follow Busybox restrictions. Search for non-printable chars
1414 if [ $(tr -d '[:alnum:][:punct:][:blank:][:cntrl:]' < "$wok/$file" | wc -c) -gt 0 ]; then
1415 raw="true"
1416 fi
1417 fi
1418 ;;
1419 esac
1421 # Display image
1422 case $file in
1423 *.png|*.svg|*.jpg|*.jpeg|*.ico)
1424 echo "<img src='$base/$pkg/browse/stuff/$arg' style='display: block; max-width: 100%; margin: auto'/>"
1425 ;;
1426 esac
1428 # Display colored listing for all text-based documents (also for *.svg)
1429 case $file in
1430 *.png|*.jpg|*.jpeg|*.ico) ;;
1431 *)
1432 if [ -z "$raw" ]; then
1433 cat $wok/$file | show_code $class
1434 fi
1435 ;;
1436 esac
1438 # Display hex dump for binary files
1439 if [ -n "$raw" ]; then
1440 hexdump -C $wok/$file | show_code #| sed 's|^\([0-9a-f][0-9a-f]*\)|<span class="c2">\1</span>|'
1441 fi
1442 else
1443 show_note e "File “$file” absent!"
1444 fi
1445 ;;
1447 files)
1448 page_header
1449 pkg_info
1451 # find main package
1452 wanted=$(. $wok/$pkg/receipt; echo $WANTED)
1453 main=${wanted:-$pkg}
1454 devpkg=''; [ -d "$wok/$main-dev" ] && devpkg="$main-dev"
1456 splitsets=$(echo $SPLIT" " \
1457 | awk '
1458 BEGIN { RS = " "; FS = ":"; }
1459 { print $2; }' \
1460 | sort -u \
1461 | tr '\n' ' ' \
1462 | sed 's|^ *||; s| *$||')
1464 splitpkgs=$(echo $SPLIT" " \
1465 | awk '
1466 BEGIN { RS = " "; FS = ":"; }
1467 { print $1; }' \
1468 | tr '\n' ' ' \
1469 | sed 's|^ *||; s| *$||')
1471 # we need the version
1472 if [ -f "$WOK/linux/receipt" ]; then
1473 kvers=$(. $WOK/linux/receipt; echo $VERSION)
1474 kbasevers=$(echo $kvers | cut -d. -f1,2)
1475 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
1476 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
1477 kbasevers=$(echo $kvers | cut -d. -f1,2)
1478 fi
1479 ver=$(. $wok/$main/receipt; echo $VERSION$EXTRAVERSION)
1481 echo "<section><h3>Quick jump:</h3>"
1484 for part in head body; do
1486 for set in '' $splitsets; do
1487 pkgsofset=$(echo $SPLIT" " \
1488 | awk -vset="$set" -vmain="$main" -vdev="$devpkg" '
1489 BEGIN {
1490 RS = " "; FS = ":";
1491 if (!set) print main;
1492 if (!set && dev) print dev;
1495 if ($2 == set) print $1;
1496 }' \
1497 | sort -u)
1499 set_description=''
1500 [ -n "$splitsets" ] &&
1501 case "$set" in
1502 '')
1503 set_description=' (default set)'
1504 set_title='Default set'
1505 ;;
1506 *)
1507 set_description=" (set “$set”)"
1508 set_title="Set “$set”"
1509 ;;
1510 esac
1512 install="$wok/$main/install"
1513 [ -n "$set" ] && install="$install-$set"
1515 case $part in
1516 head)
1517 [ -n "$splitsets" ] &&
1518 case "$set" in
1519 '') echo "<ul><li>Default set:";;
1520 *) echo "<li>Set “$set”:";;
1521 esac
1522 echo -e '\t<ul>'
1523 echo "$pkgsofset" | sed 'p' | xargs printf "\t\t<li><a href='#%s'>%s</a></li>\n"
1524 cat <<EOT
1525 <li id='li-repeats$set' style='display:none'>
1526 <a href='#repeats$set'>repeatedly packaged files</a></li>
1527 <li id='li-empty$set' style='display:none'>
1528 <a href='#empty$set'>unpackaged empty folders</a></li>
1529 <li id='li-outoftree$set' style='display:none'>
1530 <a href='#outoftree$set'>out-of-tree files</a></li>
1531 <li id='li-orphans$set' style='display:none'>
1532 <a href='#orphans$set'>unpackaged files</a>
1533 <span id='orphansTypes$set'></span></li>
1534 EOT
1535 echo -e '\t</ul>'
1536 [ -n "$splitsets" ] && echo "</li>"
1537 ;;
1538 body)
1539 all_files=$(mktemp)
1540 cd $install; find ! -type d | sed 's|\.||' > $all_files
1542 # ------------------------------------------------------
1543 # Packages content
1544 # ------------------------------------------------------
1545 packaged=$(mktemp)
1546 for p in $pkgsofset; do
1547 namever="$(awk -F$'\t' -vp="$p" '{
1548 if ($1==p) {printf("%s-%s\n", $1, $2); exit}
1549 }' $PKGS/packages.info)"
1550 if [ -d "$wok/$p/taz/$p-$ver" ]; then
1551 indir=$p
1552 elif [ -d "$wok/$main/taz/$p-$ver" ]; then
1553 indir=$main
1554 fi
1555 dir="$wok/$indir/taz/$p-$ver/fs"
1557 size=$(du -hs $dir | awk '{ sub(/\.0/, ""); print $1 }')
1559 echo
1560 echo "<section id='$p'>"
1561 echo " <h3>Contents of package “$namever” (${size:-empty}):</h3>"
1562 echo ' <pre class="files">'
1563 if [ -s "$wok/$indir/taz/$p-$ver/files.list" ]; then
1564 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
1565 cd $dir
1566 find . -print0 \
1567 | sort -z \
1568 | xargs -0 ls -ldp --color=always \
1569 | syntax_highlighter files \
1570 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$indir/browse/taz/$p-$ver/fs\2'>\2\3|;" \
1571 | awk 'BEGIN { FS="\""; }
1572 { gsub("+", "%2B", $2); print; }'
1573 else
1574 echo 'No files'
1575 fi
1576 echo '</pre>'
1577 echo '</section>'
1579 cat $wok/$indir/taz/$p-$ver/files.list >> $packaged
1580 done
1581 # ------------------------------------------------------
1582 # /Packages content
1583 # ------------------------------------------------------
1585 # ------------------------------------------------------
1586 # Repeatedly packaged files
1587 # ------------------------------------------------------
1588 repeats=$(mktemp)
1589 sort $packaged | uniq -d > $repeats
1590 if [ -s "$repeats" ]; then
1591 echo
1592 echo "<script>document.getElementById('li-repeats$set').style.display = 'list-item'</script>"
1593 echo "<section id='repeats$set'>"
1594 echo " <h3>Repeatedly packaged files$set_description:</h3>"
1595 cd $install
1597 IFS=$'\n'
1598 echo -n ' <pre class="files">'
1599 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
1600 while read i; do
1601 find .$i -exec ls -ldp --color=always '{}' \; \
1602 | syntax_highlighter files \
1603 | sed 's|>\./|>/|'
1604 done < $repeats
1605 echo '</pre>'
1606 echo '</section>'
1607 unset IFS
1608 fi
1609 rm $repeats
1610 # ------------------------------------------------------
1611 # /Repeatedly packaged files
1612 # ------------------------------------------------------
1614 # ------------------------------------------------------
1615 # Unpackaged empty folders
1616 # ------------------------------------------------------
1617 emptydirs=$(mktemp)
1618 cd $install
1619 IFS=$'\n'
1620 find -type d \
1621 | sed 's|\.||' \
1622 | while read d; do
1623 [ -z "$(ls "$install$d")" ] || continue
1624 # empty dir determined by empty `ls`
1625 echo $d
1626 done \
1627 | while read d; do
1628 notfound='yes'
1629 for p in $(cd $wok/$main/taz; ls); do
1630 if [ -d "$wok/$main/taz/$p/fs$d" ]; then
1631 notfound=''
1632 break
1633 fi
1634 done
1635 [ -n "$notfound" ] &&
1636 ls -ldp --color=always .$d \
1637 | syntax_highlighter files \
1638 | sed 's|>\./|>/|'
1639 done > $emptydirs
1640 unset IFS
1641 if [ -s "$emptydirs" ]; then
1642 echo
1643 echo "<script>document.getElementById('li-empty$set').style.display = 'list-item'</script>"
1644 echo "<section id='empty$set'>"
1645 echo " <h3>Unpackaged empty folders$set_description:</h3>"
1646 echo -n ' <pre class="files">'
1647 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
1648 cat $emptydirs
1649 echo '</pre>'
1650 echo '</section>'
1651 fi
1652 rm $emptydirs
1653 # ------------------------------------------------------
1654 # /Unpackaged empty folders
1655 # ------------------------------------------------------
1657 # ------------------------------------------------------
1658 # Out-of-tree files
1659 # ------------------------------------------------------
1660 outoftree=$(mktemp)
1661 awk -F$'\n' -vall="$all_files" '
1663 if (FILENAME == all) files_all[$1] = "1";
1664 else files_pkg[$1] = "1";
1666 END {
1667 for (i in files_pkg) {
1668 if (! files_all[i]) print i;
1671 ' "$all_files" "$packaged" > $outoftree
1673 if [ -d "$install" -a -s "$outoftree" ]; then
1674 echo
1675 echo "<script>document.getElementById('li-outoftree$set').style.display = 'list-item'</script>"
1676 echo "<section id='outoftree$set'>"
1677 echo " <h3>Out-of-tree files$set_description:</h3>"
1678 echo -n ' <pre class="files">'
1679 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
1680 IFS=$'\n'
1681 while read outoftree_line; do
1682 # Find the package out-of-tree file belongs to
1683 for i in $pkgsofset; do
1684 if grep -q "^$outoftree_line$" $wok/$main/taz/$i-$ver/files.list; then
1685 cd $wok/$main/taz/$i-$ver/fs
1686 ls -ldp --color=always ".$outoftree_line" \
1687 | syntax_highlighter files \
1688 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$main/browse/taz/$i-$ver/fs\2'>\2\3|;" \
1689 | awk 'BEGIN { FS="\""; }
1690 { gsub("+", "%2B", $2); print; }'
1691 fi
1692 done
1693 done < $outoftree
1694 unset IFS
1695 echo '</pre>'
1696 echo '</section>'
1697 fi
1698 rm $outoftree
1699 # ------------------------------------------------------
1700 # /Out-of-tree files
1701 # ------------------------------------------------------
1703 # ------------------------------------------------------
1704 # Unpackaged files
1705 # ------------------------------------------------------
1706 orphans=$(mktemp)
1707 awk -F$'\n' -vall="$all_files" '
1709 if (FILENAME == all) files_all[$1] = "1";
1710 else files_pkg[$1] = "1";
1712 END {
1713 for (i in files_all) {
1714 if (! files_pkg[i]) print i;
1717 ' "$all_files" "$packaged" | sort > $orphans
1718 if [ -d "$install" -a -s "$orphans" ]; then
1719 echo
1720 echo "<script>document.getElementById('li-orphans$set').style.display = 'list-item'</script>"
1721 echo "<section id='orphans$set'>"
1722 echo " <h3>Unpackaged files$set_description:</h3>"
1723 table=$(mktemp)
1724 awk '
1725 function tag(text, color) {
1726 printf("<span class=\"c%s1\">%s</span> ", color, text);
1727 printf("%s\n", $0);
1729 /\/perllocal\.pod$/ || /\/\.packlist$/ ||
1730 /\/share\/bash-completion\// || /\/etc\/bash_completion\.d\// ||
1731 /\/lib\/systemd\// || /\.pyc$/ || /\.pyo$/ ||
1732 /\/fonts\.scale$/ || /\/fonts\.dir$/ || /\.la$/ {
1733 tag("---", 0); next }
1734 /\.pod$/ { tag("pod", 5); next }
1735 /\/share\/man\// { tag("man", 5); next }
1736 /\/share\/doc\// || /\/share\/gtk-doc\// || /\/share\/info\// ||
1737 /\/share\/devhelp\// { tag("doc", 5); next }
1738 /\/share\/icons\// { tag("ico", 2); next }
1739 /\/share\/locale\// { tag("loc", 4); next }
1740 /\.h$/ || /\.a$/ || /\.pc$/ || /\/bin\/.*-config$/ ||
1741 /\/Makefile.*$/ { tag("dev", 3); next }
1742 /\/share\/help\// || /\/share\/appdata\// ||
1743 /\/share\/metainfo\// { tag("gnm", 6); next }
1744 { tag("???", 1) }
1745 ' "$orphans" > $table
1747 # Summary table
1748 orphans_types='()'
1749 for i in head body; do
1750 case $i in
1751 head) echo -n '<table class="summary"><tr>';;
1752 body) echo -n '<th> </th></tr><tr>';;
1753 esac
1754 for j in '???1' dev3 loc4 ico2 doc5 man5 pod5 gnm6 '---0'; do
1755 tag=${j:0:3}; class="c${j:3:1}0"; [ "$class" == 'c00' ] && class='c01'
1756 case $i in
1757 head) echo -n "<th class='$class'>$tag</th>";;
1758 body)
1759 tagscount="$(grep ">$tag<" $table | wc -l)"
1760 printf '<td>%s</td>' "$tagscount"
1761 [ "$tagscount" -gt 0 ] && orphans_types="${orphans_types/)/ $tag)}"
1762 ;;
1763 esac
1764 done
1765 done
1766 echo '<td> </td></tr></table>'
1767 orphans_types="${orphans_types/( /(}"
1768 [ "$orphans_types" != '()' ] &&
1769 echo "<script>document.getElementById('orphansTypes$set').innerText = '${orphans_types// /, }';</script>"
1771 suffix=''; [ -n "$set" ] && suffix="-$set"
1772 echo -n ' <pre class="files">'
1773 echo -en '<span class="underline">tag·permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
1774 IFS=$'\n'
1775 while read orphan_line; do
1776 echo -n "${orphan_line/span> */span>} "
1777 cd $install
1778 ls -ldp --color=always ".${orphan_line#*</span> }" \
1779 | syntax_highlighter files \
1780 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$main/browse/install$suffix\2'>\2\3|;" \
1781 | awk 'BEGIN { FS="\""; }
1782 { gsub("+", "%2B", $2); print; }'
1783 done < $table
1784 unset IFS
1785 echo '</pre>'
1786 echo '</section>'
1787 rm $table
1788 fi
1789 rm $orphans
1790 # ------------------------------------------------------
1791 # /Unpackaged files
1792 # ------------------------------------------------------
1794 rm $all_files $packaged
1795 ;;
1796 esac
1797 done # /set
1799 case "$part" in
1800 head)
1801 [ -n "$splitsets" ] && echo "</ul>"
1802 echo "</section>"
1803 ;;
1804 esac
1805 done # /part
1807 ;;
1809 description)
1810 page_header
1811 pkg_info
1812 descs="$(ls $WOK/$pkg/description*.txt)"
1813 if [ -n "$descs" ]; then
1814 echo '<div id="content2">'
1815 [ -f "$WOK/$pkg/description.txt" ] && show_desc "$pkg" "$WOK/$pkg/description.txt"
1816 for i in $descs; do
1817 case $i in
1818 */description.txt) continue ;;
1819 *) package=$(echo $i | cut -d. -f2) ;;
1820 esac
1821 show_desc "$package" "$i"
1822 done
1823 echo '</div>'
1824 else
1825 show_note w "No description of $pkg"
1826 fi
1827 ;;
1829 log)
1830 page_header
1831 pkg_info
1832 [ -z "$arg" ] && arg=$(stat -c %Y $LOGS/$pkg.log)
1834 echo '<div class="btnList">'
1835 acc='l' # access key for the latest log is 'L'
1836 while read log; do
1837 # for all $pkg.log, $pkg.log.0 .. $pkg.log.9, $pkg-pack.log (if any)
1838 timestamp=$(stat -c %Y $log)
1839 class=''
1840 if [ "$arg" == "$timestamp" ]; then
1841 class=' log'
1842 logfile="$log"
1843 fi
1844 case $log in *-pack.log) acc='p';; esac # access key for the packing log is 'P'
1845 echo -n "<a class='button$class' data-acc='$acc' accesskey='$acc' href='$base/$pkg/log/$timestamp'>"
1846 echo "$(stat -c %y $log | cut -d: -f1,2)</a>"
1847 case $acc in
1848 l) acc=0;;
1849 *) acc=$((acc+1));;
1850 esac
1851 done <<EOT
1852 $(find $LOGS -name "$pkg.log*" | sort)
1853 $(find $LOGS -name "$pkg-pack.log")
1854 EOT
1855 echo '</div>'
1857 if [ -z "$logfile" ]; then
1858 show_note e "Requested log is absent"
1859 page_footer
1860 exit 0
1861 fi
1863 # Define cook variables for syntax highlighter
1864 if [ -s "$WOK/$pkg/receipt" ]; then
1865 . "$WOK/$pkg/receipt"
1866 _wok='/home/slitaz/wok'
1867 _src="$_wok/$pkg/source/$PACKAGE-$VERSION"
1868 _install="$_wok/$pkg/install"
1869 _fs="$_wok/$pkg/taz/$PACKAGE-$VERSION/fs"
1870 _stuff="$_wok/$pkg/stuff"
1871 fi
1873 # if [ ! -f "gzlog/$pkg.$arg" ]; then
1874 # {
1875 # summary "$logfile" links
1877 # syntax_highlighter log < $logfile | awk '
1878 # BEGIN { print "<pre class=\"log\">"; }
1879 # { printf("<a name=\"l%d\" href=\"#l%d\">%5d</a> %s\n", NR, NR, NR, $0); }
1880 # END { print "</pre>"; }
1881 # '
1883 # page_footer
1884 # } | gzip > gzlog/$pkg.$arg
1885 # fi
1887 blog=$(basename $logfile)
1888 summary "$logfile" links
1890 # disable next `sed` for the 'like2016' theme
1891 theme=$(COOKIE theme); theme=${theme:-default}; [ "$theme" != 'like2016' ] && theme=''
1892 cat $logfile | syntax_highlighter log | \
1893 sed -e "/(pkg\/local$theme):/ s|: \([^<]*\)|<img src='$base/i/$blog/\1'> \1|" | \
1894 awk '
1895 BEGIN { print "<pre class=\"log\">"; }
1896 { printf("<span id=\"l%d\">%s</span><a href=\"#l%d\"></a>\n", NR, $0, NR); }
1897 END { print "</pre>"; }
1899 ;;
1902 man|doc|info)
1903 page_header
1904 pkg_info
1905 echo '<div style="max-height: 6.4em; overflow: auto; padding: 0 4px">'
1907 dir="wok/$pkg/install/usr/share/$cmd"
1908 [ "$cmd" == 'doc' ] && dir="$dir wok/$pkg/install/usr/share/gtk-doc"
1909 if [ "$cmd" == 'doc' -a -z "$arg" ]; then
1910 try=$(for i in $dir; do find $i -name 'index.htm*'; done | sed q)
1911 [ -n "$try" ] && arg="$try"
1912 fi
1913 while read i; do
1914 [ -s "$i" ] || continue
1915 case "$i" in
1916 *.jp*g|*.png|*.gif|*.svg|*.css) continue
1917 esac
1918 i=${i#$dir/}
1919 [ -n "$arg" ] || arg="$i"
1920 class=''; [ "$arg" == "$i" ] && class=" doc"
1921 case "$cmd" in
1922 man)
1923 case $i in
1924 man*) lang='';;
1925 *) lang="${i%%/*}: ";;
1926 esac
1927 man=$(basename $i .gz)
1928 echo "<a class='button$class' href='$base/$pkg/man/$i'>$lang${man%.*} (${man##*.})</a>"
1929 ;;
1930 doc)
1931 echo "<a class='button$class' href='$base/$pkg/doc/$i'>$(basename $i .gz)</a>"
1932 ;;
1933 info)
1934 info=$(basename $i)
1935 echo "<a class='button$class' href='$base/$pkg/info/$i#Top'>${info/.info/}</a>"
1936 ;;
1937 esac
1938 done <<EOT
1939 $(for i in $dir; do find $i -type f; done | sort)
1940 EOT
1941 echo '</div>'
1943 [ -f "$arg" ] || arg="$dir/$arg"
1944 if [ -f "$arg" ]; then
1945 tmp="$(mktemp)"
1946 docat "$arg" > $tmp
1947 [ -s "$tmp" ] &&
1948 case "$cmd" in
1949 info)
1950 echo '<div id="content2" class="texinfo"><pre class="first">'
1951 info2html < "$tmp"
1952 echo '</pre></div>'
1953 ;;
1954 doc)
1955 case "$arg" in
1956 *.sgml|*.devhelp2) class='xml';;
1957 *.py) class='python';; # pycurl package
1958 *.css) class='css';;
1959 *.sh) class='bash';;
1960 *)
1961 first=$(head -n1 "$tmp")
1962 if [ "${first:0:1}" == '#' ]; then
1963 class='bash' # first line begins with '#'
1964 else
1965 class='asciidoc'
1966 fi;;
1967 esac
1968 case "$arg" in
1969 *.htm*)
1970 case $arg in
1971 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
1972 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
1973 esac
1974 # make the iframe height so long to contain its contents without scrollbar
1975 echo "<iframe id='idoc' src='$page' width='100%' onload='resizeIframe(this)'></iframe>"
1976 ;;
1977 *.pdf)
1978 case $arg in
1979 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
1980 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
1981 esac
1982 cat <<EOT
1983 <object id="idoc" data="$page" width="100%" height="100%" type="application/pdf" style="min-height: 600px">
1984 $(show_note w "Missing PDF plugin.<br/>Get the file <a href="$page">$(basename "$page")</a>.")
1985 </object>
1986 EOT
1987 ;;
1988 *.md|*.markdown)
1989 echo '<section>'
1990 $md2html "$tmp"
1991 echo '</section>'
1992 ;;
1993 *)
1994 show_code $class < "$tmp"
1995 ;;
1996 esac
1997 ;;
1998 man)
1999 #export TEXTDOMAIN='man2html'
2000 echo "<div id='content2'>"
2002 html=$(./man2html.bin "$tmp" | sed -e '1,/<header>/d' -e '/<footer>/,$d' \
2003 -e 's|<a href="file:///[^>]*>\([^<]*\)</a>|\1|g' \
2004 -e 's|<a href="?[1-9]\+[^>]*>\([^<]*\)</a>|\1|g')
2006 if [ -n "$(echo "$html" | fgrep 'The requested file /tmp/tmp.')" ]; then
2007 # Process the pre-formatted man-cat page
2008 # (for example see sudo package without groff in build dependencies)
2009 sed -i '
2010 s|M-bM-^@M-^S|—|g;
2011 s|M-bM-^@M-^\\|<b>|g;
2012 s|M-bM-^@M-^]|</b>|g
2013 s|M-bM-^@M-^X|<u>|g;
2014 s|M-bM-^@M-^Y|</u>|g;
2015 s|M-BM-||g;
2016 s|++oo|•|g;
2017 s|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g;
2018 ' "$tmp"
2019 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 \
2020 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 0 1 2 3 4 5 6 7 8 9 _ - '\\+' '\.' /; do
2022 sed -i "s|$i$i|<b>$i</b>|g; s|_$i|<u>$i</u>|g" "$tmp"
2023 done
2024 echo '<pre class="catman">'
2025 sed 's|</b><b>||g; s|</u><u>||g; s|</u><b>_</b><u>|_|g; s|</b> <b>| |g;' "$tmp"
2026 echo '</pre>'
2027 else
2028 echo "$html"
2029 fi
2030 echo "</div>"
2031 ;;
2032 esac
2033 rm -f $tmp
2034 else
2035 show_note e "File “$arg” does not exist!"
2036 fi
2037 ;;
2039 download)
2040 page_header
2041 pkg_info
2042 show=0
2044 . $wok/$pkg/receipt
2046 if [ -n "$TARBALL" -a -s "$SRC/$TARBALL" ]; then
2047 files_header
2048 echo "<tr><td><a href='$base/src/$TARBALL'>$TARBALL</a></td>"
2049 ls -lh "$SRC/$TARBALL" | awk '{printf("<td>%sB</td>", $5)}'
2050 echo "<td>Sources for building the package “$pkg”</td></tr>"
2051 show=1
2052 fi
2054 if [ -d "$wok/$pkg/taz" ]; then
2055 [ "$show" -eq 1 ] || files_header
2057 common_version=$VERSION
2058 for i in $(all_names); do
2059 [ -e "$wok/$pkg/taz/$i-$common_version$EXTRAVERSION/receipt" ] || continue
2060 . $wok/$pkg/taz/$i-$common_version$EXTRAVERSION/receipt
2062 for filename in "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg"; do
2063 [ -f "$PKGS/$filename" ] &&
2064 cat <<EOT
2065 <tr>
2066 <td><a href="$base/get/$filename">$filename</a></td>
2067 <td>$(ls -lh ./packages/$filename | awk '{printf("%sB", $5)}')</td>
2068 <td>$SHORT_DESC</td>
2069 </tr>
2070 EOT
2071 done
2072 done
2073 show=1
2074 fi
2076 if [ "$show" -eq 1 ]; then
2077 echo '</tbody></table></section>'
2078 else
2079 show_note w "Sorry, there's nothing to download…"
2080 fi
2081 ;;
2083 esac
2086 page_footer
2087 exit 0