cookutils view lighttpd/index.cgi @ rev 1072

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