cookutils view lighttpd/index.cgi @ rev 1067

modules/compressor: compress_gif(): compress files with spaces in the file names (see amsn package)
author Aleksej Bobylev <al.bobylev@gmail.com>
date Wed Jun 06 01:42:12 2018 +0300 (2018-06-06)
parents 2233dc83fc9e
children c1db2b6009d0
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 if [ -z "$nojs" ]; then
880 case $1 in
881 webstat)
882 echo -n "<div id='$1'>"
883 show_note i 'Please wait while statistics are being collected.'
884 echo "</div><script>getPart('$1')</script>"
885 ;;
886 *)
887 echo "<div id='$1'></div><script>getPart('$1')</script>"
888 ;;
889 esac
890 return
891 fi
893 case $1 in
894 summary)
895 echo '<h2>Summary</h2>'
897 mktable <<EOT
898 Cooker state : $(running_command)
899 Wok revision : <a href='$WOK_URL' target='_blank' rel='noopener noreferrer'>$(cat $wokrev)</a>
900 Commits to cook : $(wc -l < $commits)
901 Current cooklist : $(wc -l < $cooklist)
902 Architecture : $ARCH, <a href="$toolchain">toolchain</a>
903 Server date : <span id='date'>$(date -u '+%F %R %Z')</span>
904 EOT
906 # If command is "cook:*", update gauge and percentage periodically.
907 # If different package is cooking, reload the page (with new settings)
908 cmd="$(cat $command)"
909 case "$cmd" in
910 cook:*)
911 pkg=${cmd#*:}
912 echo "<script>updatePkg = '${pkg//+/%2B}';</script>"
913 ;;
914 esac
915 ;;
916 webstat)
917 # Do we need to update the statistics?
918 [ "$webstat" -nt "$activity" ] || update_webstat
919 . $webstat
921 pct=0; [ "$rtotal" -gt 0 ] && pct=$(( ($rcooked * 100) / $rtotal ))
923 cat <<EOT
924 <div class="meter"><progress max="100" value="$pct">${pct}%</progress><span>${pct}%</span></div>
926 <table class="webstat"><thead>
927 <tr><th> </th><th>Total </th><th>Cooked </th><th>Unbuilt </th><th>Blocked </th><th>Broken </th></tr>
928 </thead><tbody>
929 <tr><td>Receipts</td><td>$rtotal</td><td>$rcooked</td><td>$runbuilt</td><td>$rblocked</td><td>$rbroken</td></tr>
930 <tr><td>Packages</td><td>$ptotal</td><td>$pcooked</td><td>$punbuilt</td><td>$pblocked</td><td>$pbroken</td></tr>
931 </tbody></table>
932 EOT
933 ;;
934 activity)
935 tac $activity | head -n12 | sed 's|cooker.cgi?pkg=||;
936 s|\[ Done|<span class="r c20">Done|;
937 s|\[ Failed|<span class="r c10">Failed|;
938 s|\[ -Failed|<span class="r c10"><del>Failed</del>|;
939 s| \]|</span>|;
940 s|%2B|\+|g' | \
941 section $activity 12 "Activity|More activity"
942 ;;
943 cooknotes)
944 [ -s "$cooknotes" ] && tac $cooknotes | head -n12 | \
945 section $cooknotes 12 "Cooknotes|More notes"
946 ;;
947 commits)
948 [ -s "$commits" ] && head -n20 $commits | \
949 section $commits 20 "Commits|More commits"
950 ;;
951 cooklist)
952 [ -s "$cooklist" ] && head -n 20 $cooklist | \
953 section $cooklist 20 "Cooklist|Full cooklist"
954 ;;
955 broken)
956 [ -s "$broken" ] && head -n20 $broken | sed "s|^[^']*|<a href='\0'>\0</a>|g" | \
957 section $broken 20 "Broken|All broken packages"
958 ;;
959 blocked)
960 [ -s "$blocked" ] && sed "s|^[^']*|<a href='\0'>\0</a>|g" $blocked | \
961 section $blocked 12 "Blocked|All blocked packages"
962 ;;
963 pkgs)
964 cd $PKGS
965 # About BusyBox's `ls`
966 # On the Tank server: BusyBox v1.18.4 (2012-03-14 03:32:25 CET) multi-call binary.
967 # It supported the option `-e`, output with `-let` options like this:
968 # -rw-r--r-- 1 user group 100000 Fri Nov 3 10:00:00 2017 filename
969 # 1 2 3 4 5 6 7 8 9 10 11
970 # Newer BusyBox v1.27.2 doesn't support option `-e` and has no configs to
971 # configure it or return the option back. It supported the long option
972 # `--full-time` instead, but output is different:
973 # -rw-r--r-- 1 user group 100000 2017-11-03 10:00:00 +0200 filename
974 # 1 2 3 4 5 6 7 8 9
975 if ls -let >/dev/null 2>&1; then
976 ls -let *.tazpkg \
977 | awk '
978 (NR<=20){
979 sub(/:[0-9][0-9]$/, "", $9);
980 mon = index(" JanFebMarAprMayJunJulAugSepOctNovDec", $7) / 3;
981 printf("%d-%02d-%02d %s : <a href=\"get/%s\">%s</a>\n", $10, mon, $8, $9, $11, $11);
982 }' \
983 | section $activity 1000 "Latest cook"
984 else
985 ls -lt --full-time *.tazpkg \
986 | awk '
987 (NR<=20){
988 sub(/:[0-9][0-9]$/, "", $7);
989 printf("%s %s : <a href=\"get/%s\">%s</a>\n", $6, $7, $9, $9);
990 }' \
991 | section $activity 1000 "Latest cook"
992 fi
993 ;;
994 esac
995 }
998 # Query '?part=<part>': get part of the main page
1000 if [ -n "$(GET part)" ]; then
1001 part="$(GET part)"
1002 case $part in
1003 summary|webstat|activity|cooknotes|commits|cooklist|broken|blocked|pkgs)
1004 nojs='yes'
1005 part $part
1006 ;;
1007 esac
1008 exit 0
1009 fi
1015 # Load requested page
1018 if [ -z "$pkg" ]; then
1020 page_header
1021 if [ -n "$QUERY_STRING" -a "$QUERY_STRING" != 'debug' ]; then
1023 for list in activity cooknotes cooklist; do
1024 [ -n "$(GET $list)" ] || continue
1025 [ "$list" == 'cooklist' ] && nb="- Packages: $(wc -l < $cooklist)"
1026 echo '<section id="content2">'
1027 echo "<h2>DB: $list $nb</h2>"
1028 tac $CACHE/$list | sed 's|cooker.cgi?pkg=||; s|%2B|+|g;
1029 s|\[ Done|<span class="r c20">Done|;
1030 s|\[ Failed|<span class="r c10">Failed|;
1031 s|\[ -Failed|<span class="r c10"><del>Failed</del>|;
1032 s| \]|</span>|' | mktable $list
1033 echo '</section>'
1034 done
1036 if [ -n "$(GET broken)" ]; then
1037 echo '<section id="content2">'
1038 echo "<h2>DB: broken - Packages: $(wc -l < $broken)</h2>"
1039 sort $CACHE/broken | sed "s|^[^']*|<a href='$base/\0'>\0</a>|g" | mktable
1040 echo '</section>'
1041 fi
1043 case "$QUERY_STRING" in
1044 *.log)
1045 log=$LOGS/$QUERY_STRING
1046 name=$(basename $log)
1047 if [ -f "$log" ]; then
1048 echo "<h2>Log for: ${name%.log}</h2>"
1049 if fgrep -q "Summary" $log; then
1050 echo '<pre class="log">'
1051 grep -A 20 'Summary' $log | syntax_highlighter log
1052 echo '</pre>'
1053 fi
1054 echo '<pre class="log">'
1055 syntax_highlighter log < $log
1056 echo '</pre>'
1057 if [ "$QUERY_STRING" == 'pkgdb.log' ]; then
1058 # Display button only for SliTaz web browser
1059 case "$HTTP_USER_AGENT" in
1060 *SliTaz*)
1061 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
1062 if grep -qs '^pkgdb$' $CACHE/recook-packages; then
1063 show_note i "The package database has been requested for re-creation"
1064 else
1065 echo "<a class='button' href='$base/?recook=pkgdb'>Re-create the DB</a>"
1066 fi
1067 fi
1068 ;;
1069 esac
1070 fi
1071 else
1072 show_note e "No log file: $log"
1073 fi
1074 ;;
1075 toolchain)
1076 cat <<EOT
1077 <div id="content2">
1078 <section>
1079 <h2>SliTaz GNU/Linux toolchain</h2>
1081 <table>
1082 <tr><td>Build date</td> <td colspan="2">$(sed -n '/^Cook date/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td></tr>
1083 <tr><td>Build duration</td> <td colspan="2">$(sed -n '/^Cook time/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td></tr>
1084 <tr><td>Architecture</td> <td colspan="2">$ARCH</td></tr>
1085 <tr><td>Host system</td> <td colspan="2">$BUILD_SYSTEM</td></tr>
1086 <tr><td>Target system</td> <td colspan="2">$HOST_SYSTEM</td></tr>
1087 <tr><th>Package</th><th>Version</th><th>Description</th></tr>
1088 $(toolchain_version slitaz-toolchain)
1089 $(toolchain_version binutils)
1090 $(toolchain_version linux-api-headers)
1091 $(toolchain_version gcc)
1092 $(toolchain_version glibc)
1093 </table>
1095 <p>Toolchain documentation: <a target="_blank" rel="noopener noreferrer"
1096 href="http://doc.slitaz.org/en:cookbook:toolchain">http://doc.slitaz.org/en:cookbook:toolchain</a>
1097 </p>
1099 </section>
1100 </div>
1101 EOT
1102 ;;
1103 esac
1104 page_footer
1105 exit 0
1106 fi
1109 # We may have a toolchain.cgi script for cross cooker's
1110 if [ -f "toolchain.cgi" ]; then
1111 toolchain="toolchain.cgi"
1112 else
1113 toolchain="?toolchain"
1114 fi
1116 # Main page with summary. Count only packages included in ARCH,
1117 # use 'cooker arch-db' to manually create arch.$ARCH files.
1119 cat <<EOT
1120 <div id="content2">
1122 <section>
1123 <form method="get" action="" class="search r">
1124 <input type="hidden" name="search" value="pkg"/>
1125 <button type="submit" title="Search">Search</button>
1126 <input type="search" name="q" placeholder="Package" list="packages" autocorrect="off" autocapitalize="off"/>
1127 </form>
1128 EOT
1130 part summary
1131 part webstat
1133 if [ -e "$CACHE/cooker-request" -a ! -s $command ]; then
1134 if [ "$activity" -nt "$CACHE/cooker-request" ]; then
1135 echo '<a class="button icon bell r" href="?poke">Wake up</a>'
1136 else
1137 show_note i 'Cooker will be launched in the next 5 minutes.'
1138 fi
1139 fi
1141 cat <<EOT
1142 <p>
1143 Service logs:
1144 <a href="?cookorder.log">cookorder</a> ·
1145 <a href="?commits.log">commits</a> ·
1146 <a href="?pkgdb.log">pkgdb</a>
1147 </p>
1148 </section>
1149 EOT
1151 part activity
1152 part cooknotes
1153 part commits
1154 part cooklist
1155 part broken
1156 part blocked
1157 part pkgs
1159 echo '</div>'
1160 datalist
1161 page_footer
1162 exit 0
1163 fi
1166 # show tag
1168 if [ "$pkg" == '~' -a -n "$cmd" ]; then
1169 tag="$cmd"
1170 page_header
1171 cat <<EOT
1172 <div id="content2">
1173 <section>
1174 <h2>Tag “$tag”</h2>
1176 <table>
1177 <thead>
1178 <tr><th>Name</th><th>Description</th><th>Category</th></tr>
1179 </thead>
1180 <tbody>
1181 EOT
1182 sort $PKGS/packages.info \
1183 | awk -F$'\t' -vtag=" $tag " -vbase="$base" '{
1184 if (index(" " $6 " ", tag)) {
1185 url = base "/" $1 "/";
1186 gsub("+", "%2B", url);
1187 printf("<tr><td><img src=\"%s/s/%s\"> ", base, $1);
1188 printf("<a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", url, $1, $4, $3);
1190 }'
1191 echo '</tbody></table></section></div>'
1192 page_footer
1193 exit 0
1194 fi
1197 case "$cmd" in
1198 '')
1199 page_header
1201 requested_pkg="$pkg"
1202 # Package info.
1203 if [ ! -f "$wok/$pkg/receipt" ]; then
1204 # Let's look at the cases when the package was not found
1206 # Maybe query is the exact name of split package? -> proceed to main package
1207 mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
1208 if (index(" " $2 " ", pkg)) {print $1; exit}
1209 }' $splitdb)
1211 # No, so let's find any matches among packages names (both main and split)
1212 if [ -z "$mainpkg" ]; then
1213 pkgs=$(cut -d$'\t' -f2 $splitdb | tr ' ' '\n' | fgrep "$pkg")
1214 # Nothing matched
1215 if [ -z "$pkgs" ]; then
1216 echo "<h2>Not Found</h2>"
1217 show_note e "The requested package <b>$pkg</b> was not found on this server."
1218 page_footer; exit 0
1219 fi
1220 # Search results page
1221 echo "<section><h2>Package names matching “$pkg”</h2>"
1222 echo "<table><thead><tr><th>Name</th><th>Description</th><th>Category</th></tr></thead><tbody>"
1223 query="$pkg"
1224 for pkg in $pkgs; do
1225 # Find main package
1226 mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
1227 if (index(" " $2 " ", pkg)) {print $1; exit}
1228 }' $splitdb)
1229 unset SHORT_DESC CATEGORY; . $wok/$mainpkg/receipt
1231 unset SHORT_DESC CATEGORY
1232 [ -e "$wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt" ] &&
1233 . $wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt
1235 echo -n "<tr><td><a href="$base/$pkg">${pkg//$query/<mark>$query</mark>}</a>"
1236 [ "$pkg" == "$mainpkg" ] || echo -n " (${mainpkg//$query/<mark>$query</mark>})"
1237 echo -n "</td><td>$SHORT_DESC</td><td>$CATEGORY</td></tr>"
1238 done
1239 echo '</tbody></table></section>'
1240 page_footer; exit 0
1241 fi
1242 pkg="$mainpkg"
1243 fi
1245 log=$LOGS/$pkg.log
1246 pkg_info
1248 # Check for a log file and display summary if it exists.
1249 summary "$log"
1252 # Show tag list
1253 taglist=$(
1254 for i in $pkg $(awk -F$'\t' -vp="$pkg" '{if ($1 == p) print $2}' $splitdb); do
1255 [ -s "$PKGS/packages.info" ] &&
1256 awk -F$'\t' -vpkg="$i" '{
1257 if ($1 == pkg) { print $6; exit; }
1258 }' "$PKGS/packages.info"
1259 done \
1260 | tr ' ' '\n' \
1261 | sort -u
1263 if [ -n "$taglist" ]; then
1264 echo -n '<section><h3>Tags</h3><p>'
1265 lasttag=$(echo "$taglist" | tail -n1)
1266 for tag in $taglist; do
1267 echo -n "<a href=\"$base/~/${tag//+/%2B}\">$tag</a>"
1268 [ "$tag" != "$lasttag" ] && echo -n " · "
1269 done
1270 echo '</p></section>'
1271 fi
1274 # Informational table with dependencies
1275 pkg="$requested_pkg"
1276 inf="$(mktemp -d)"
1278 # 1/3: Build dependencies (from receipt and pkgdb)
1279 for i in $WANTED $BUILD_DEPENDS $(awk -F$'\t' -vp=" $pkg " '{if (index(" " $2 " ", p) && (" " $1 " " != p)) print $1}' $splitdb); do
1280 echo "$i" >> $inf/a
1281 done
1283 # 2/3: Runtime dependencies (from pkgdb)
1285 [ -s "$PKGS/packages.info" ] &&
1286 awk -F$'\t' -vp="$pkg" '{
1287 if ($1 == p) print $8
1288 }' "$PKGS/packages.info"
1289 } | tr ' ' '\n' | sort -u > $inf/b
1291 # 3/3: Required by (from pkgdb)
1293 for i in $pkg $(awk -F$'\t' -vp="$pkg" '{if ($1 == p) print $2}' $splitdb); do
1294 [ -s "$PKGS/packages.info" ] &&
1295 awk -F$'\t' -vp=" $i " '{
1296 if (index(" " $8 " ", p)) print $1
1297 }' "$PKGS/packages.info"
1299 [ -s "$PKGS/bdeps.txt" ] &&
1300 awk -F$'\t' -vp=" $i " '{
1301 if (index(" " $2 " ", p)) print $1
1302 }' $PKGS/bdeps.txt
1303 done
1304 } | sort -u > $inf/c
1306 cat <<EOT
1307 <section>
1308 <h3>Related packages</h3>
1309 <table class="third">
1310 <thead>
1311 <tr>
1312 <th>Build dependencies</th>
1313 <th>Runtime dependencies</th>
1314 <th>Required by</th>
1315 </tr>
1316 </thead>
1317 <tbody>
1318 EOT
1320 awk -vinf="$inf" -vbase="$base" '
1321 function linki(i) {
1322 if (i) return sprintf("<img src=\"%s/s/%s\"> <a href=\"%s/%s\">%s</a>", base, i, base, i, i);
1324 BEGIN{
1325 do {
1326 a = b = c = "";
1327 getline a < inf "/a";
1328 getline b < inf "/b";
1329 getline c < inf "/c";
1330 printf("<tr><td>%s </td><td>%s </td><td>%s </td></tr>", linki(a), linki(b), linki(c));
1331 } while ( a b c )
1332 }'
1333 cat <<EOT
1334 </tbody>
1335 </table>
1336 </section>
1337 EOT
1338 # Clean
1339 rm -r $inf
1344 # Display <Recook> button only for SliTaz web browser
1345 case "$HTTP_USER_AGENT" in
1346 *SliTaz*)
1347 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
1348 if grep -qs "^$pkg$" $CACHE/recook-packages; then
1349 show_note i "The package “$pkg” has been requested for recook"
1350 else
1351 echo "<a class='button' href='$base/?recook=${pkg//+/%2B}'>Recook $pkg</a>"
1352 fi
1353 fi
1354 ;;
1355 esac
1356 ;;
1358 receipt)
1359 page_header
1360 pkg_info
1361 echo "<a class='button receipt' href='$base/$pkg/receipt'>receipt</a>"
1362 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1363 awk -vb="$base/$pkg" '{printf("<a class=\"button\" href=\"%s/%s\">%s</a>\n", b, $0, $0)}'
1365 show_code bash < $wok/$pkg/receipt
1366 ;;
1368 stuff)
1369 page_header
1370 pkg_info
1371 file="$pkg/stuff/$arg"
1372 echo "<a class='button' href='$base/$pkg/receipt'>receipt</a>"
1373 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1374 awk -vb="$base/$pkg" -va="stuff/$arg" '{
1375 printf("<a class=\"button%s\" href=\"%s/%s\">%s</a>\n", a==$0 ? " receipt" : "", b, $0, $0)
1376 }'
1378 if [ -f "$wok/$file" ]; then
1379 case $file in
1380 *.desktop|*.theme) class="ini" ;;
1381 *.patch|*.diff|*.u) class="diff" ;;
1382 *.sh) class="bash" ;;
1383 *.conf*|*.ini)
1384 class="bash"
1385 [ -n "$(cut -c1 < $wok/$file | fgrep '[')" ] && class="ini"
1386 ;;
1387 *.pl) class="perl" ;;
1388 *.c|*.h|*.awk) class="clike" ;;
1389 *.svg) class="svg" ;;
1390 *Makefile*) class="makefile" ;;
1391 *.po|*.pot) class="bash" ;;
1392 *.css) class="css" ;;
1393 *.htm|*.html) class="html" ;;
1394 *.js) class="js" ;;
1395 *.txt) class="asciidoc" ;;
1396 *)
1397 case $(head -n1 $wok/$file) in
1398 *!/bin/sh*|*!/bin/bash*) class="bash" ;;
1399 esac
1400 if [ -z "$class" -a "$(head -n1 $wok/$file | cut -b1)" == '#' ]; then
1401 class="bash"
1402 fi
1403 if [ -z "$class" ]; then
1404 # Follow Busybox restrictions. Search for non-printable chars
1405 if [ $(tr -d '[:alnum:][:punct:][:blank:][:cntrl:]' < "$wok/$file" | wc -c) -gt 0 ]; then
1406 raw="true"
1407 fi
1408 fi
1409 ;;
1410 esac
1412 # Display image
1413 case $file in
1414 *.png|*.svg|*.jpg|*.jpeg|*.ico)
1415 echo "<img src='$base/$pkg/browse/stuff/$arg' style='display: block; max-width: 100%; margin: auto'/>"
1416 ;;
1417 esac
1419 # Display colored listing for all text-based documents (also for *.svg)
1420 case $file in
1421 *.png|*.jpg|*.jpeg|*.ico) ;;
1422 *)
1423 if [ -z "$raw" ]; then
1424 cat $wok/$file | show_code $class
1425 fi
1426 ;;
1427 esac
1429 # Display hex dump for binary files
1430 if [ -n "$raw" ]; then
1431 hexdump -C $wok/$file | show_code #| sed 's|^\([0-9a-f][0-9a-f]*\)|<span class="c2">\1</span>|'
1432 fi
1433 else
1434 show_note e "File “$file” absent!"
1435 fi
1436 ;;
1438 files)
1439 page_header
1440 pkg_info
1442 # find main package
1443 wanted=$(. $wok/$pkg/receipt; echo $WANTED)
1444 main=${wanted:-$pkg}
1445 devpkg=''; [ -d "$wok/$main-dev" ] && devpkg="$main-dev"
1447 splitsets=$(echo $SPLIT" " \
1448 | awk '
1449 BEGIN { RS = " "; FS = ":"; }
1450 { print $2; }' \
1451 | sort -u \
1452 | tr '\n' ' ' \
1453 | sed 's|^ *||; s| *$||')
1455 splitpkgs=$(echo $SPLIT" " \
1456 | awk '
1457 BEGIN { RS = " "; FS = ":"; }
1458 { print $1; }' \
1459 | tr '\n' ' ' \
1460 | sed 's|^ *||; s| *$||')
1462 # we need the version
1463 if [ -f "$WOK/linux/receipt" ]; then
1464 kvers=$(. $WOK/linux/receipt; echo $VERSION)
1465 kbasevers=$(echo $kvers | cut -d. -f1,2)
1466 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
1467 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
1468 kbasevers=$(echo $kvers | cut -d. -f1,2)
1469 fi
1470 ver=$(. $wok/$main/receipt; echo $VERSION$EXTRAVERSION)
1472 echo "<section><h3>Quick jump:</h3>"
1475 for part in head body; do
1477 for set in '' $splitsets; do
1478 pkgsofset=$(echo $SPLIT" " \
1479 | awk -vset="$set" -vmain="$main" -vdev="$devpkg" '
1480 BEGIN {
1481 RS = " "; FS = ":";
1482 if (!set) print main;
1483 if (!set && dev) print dev;
1486 if ($2 == set) print $1;
1487 }' \
1488 | sort -u)
1490 set_description=''
1491 [ -n "$splitsets" ] &&
1492 case "$set" in
1493 '')
1494 set_description=' (default set)'
1495 set_title='Default set'
1496 ;;
1497 *)
1498 set_description=" (set “$set”)"
1499 set_title="Set “$set”"
1500 ;;
1501 esac
1503 install="$wok/$main/install"
1504 [ -n "$set" ] && install="$install-$set"
1506 case $part in
1507 head)
1508 [ -n "$splitsets" ] &&
1509 case "$set" in
1510 '') echo "<ul><li>Default set:";;
1511 *) echo "<li>Set “$set”:";;
1512 esac
1513 echo -e '\t<ul>'
1514 echo "$pkgsofset" | sed 'p' | xargs printf "\t\t<li><a href='#%s'>%s</a></li>\n"
1515 cat <<EOT
1516 <li id='li-repeats$set' style='display:none'>
1517 <a href='#repeats$set'>repeatedly packaged files</a></li>
1518 <li id='li-empty$set' style='display:none'>
1519 <a href='#empty$set'>unpackaged empty folders</a></li>
1520 <li id='li-outoftree$set' style='display:none'>
1521 <a href='#outoftree$set'>out-of-tree files</a></li>
1522 <li id='li-orphans$set' style='display:none'>
1523 <a href='#orphans$set'>unpackaged files</a>
1524 <span id='orphansTypes$set'></span></li>
1525 EOT
1526 echo -e '\t</ul>'
1527 [ -n "$splitsets" ] && echo "</li>"
1528 ;;
1529 body)
1530 all_files=$(mktemp)
1531 cd $install; find ! -type d | sed 's|\.||' > $all_files
1533 # ------------------------------------------------------
1534 # Packages content
1535 # ------------------------------------------------------
1536 packaged=$(mktemp)
1537 for p in $pkgsofset; do
1538 namever="$(awk -F$'\t' -vp="$p" '{
1539 if ($1==p) {printf("%s-%s\n", $1, $2); exit}
1540 }' $PKGS/packages.info)"
1541 if [ -d "$wok/$p/taz/$p-$ver" ]; then
1542 indir=$p
1543 elif [ -d "$wok/$main/taz/$p-$ver" ]; then
1544 indir=$main
1545 fi
1546 dir="$wok/$indir/taz/$p-$ver/fs"
1548 size=$(du -hs $dir | awk '{ sub(/\.0/, ""); print $1 }')
1550 echo
1551 echo "<section id='$p'>"
1552 echo " <h3>Contents of package “$namever” (${size:-empty}):</h3>"
1553 echo ' <pre class="files">'
1554 if [ -s "$wok/$indir/taz/$p-$ver/files.list" ]; then
1555 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
1556 cd $dir
1557 find . -print0 \
1558 | sort -z \
1559 | xargs -0 ls -ldp --color=always \
1560 | syntax_highlighter files \
1561 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$indir/browse/taz/$p-$ver/fs\2'>\2\3|;" \
1562 | awk 'BEGIN { FS="\""; }
1563 { gsub("+", "%2B", $2); print; }'
1564 else
1565 echo 'No files'
1566 fi
1567 echo '</pre>'
1568 echo '</section>'
1570 cat $wok/$indir/taz/$p-$ver/files.list >> $packaged
1571 done
1572 # ------------------------------------------------------
1573 # /Packages content
1574 # ------------------------------------------------------
1576 # ------------------------------------------------------
1577 # Repeatedly packaged files
1578 # ------------------------------------------------------
1579 repeats=$(mktemp)
1580 sort $packaged | uniq -d > $repeats
1581 if [ -s "$repeats" ]; then
1582 echo
1583 echo "<script>document.getElementById('li-repeats$set').style.display = 'list-item'</script>"
1584 echo "<section id='repeats$set'>"
1585 echo " <h3>Repeatedly packaged files$set_description:</h3>"
1586 cd $install
1588 IFS=$'\n'
1589 echo -n ' <pre class="files">'
1590 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
1591 while read i; do
1592 find .$i -exec ls -ldp --color=always '{}' \; \
1593 | syntax_highlighter files \
1594 | sed 's|>\./|>/|'
1595 done < $repeats
1596 echo '</pre>'
1597 echo '</section>'
1598 unset IFS
1599 fi
1600 rm $repeats
1601 # ------------------------------------------------------
1602 # /Repeatedly packaged files
1603 # ------------------------------------------------------
1605 # ------------------------------------------------------
1606 # Unpackaged empty folders
1607 # ------------------------------------------------------
1608 emptydirs=$(mktemp)
1609 cd $install
1610 IFS=$'\n'
1611 find -type d \
1612 | sed 's|\.||' \
1613 | while read d; do
1614 [ -z "$(ls "$install$d")" ] || continue
1615 # empty dir determined by empty `ls`
1616 echo $d
1617 done \
1618 | while read d; do
1619 notfound='yes'
1620 for p in $(cd $wok/$main/taz; ls); do
1621 if [ -d "$wok/$main/taz/$p/fs$d" ]; then
1622 notfound=''
1623 break
1624 fi
1625 done
1626 [ -n "$notfound" ] &&
1627 ls -ldp --color=always .$d \
1628 | syntax_highlighter files \
1629 | sed 's|>\./|>/|'
1630 done > $emptydirs
1631 unset IFS
1632 if [ -s "$emptydirs" ]; then
1633 echo
1634 echo "<script>document.getElementById('li-empty$set').style.display = 'list-item'</script>"
1635 echo "<section id='empty$set'>"
1636 echo " <h3>Unpackaged empty folders$set_description:</h3>"
1637 echo -n ' <pre class="files">'
1638 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
1639 cat $emptydirs
1640 echo '</pre>'
1641 echo '</section>'
1642 fi
1643 rm $emptydirs
1644 # ------------------------------------------------------
1645 # /Unpackaged empty folders
1646 # ------------------------------------------------------
1648 # ------------------------------------------------------
1649 # Out-of-tree files
1650 # ------------------------------------------------------
1651 outoftree=$(mktemp)
1652 awk -F$'\n' -vall="$all_files" '
1654 if (FILENAME == all) files_all[$1] = "1";
1655 else files_pkg[$1] = "1";
1657 END {
1658 for (i in files_pkg) {
1659 if (! files_all[i]) print i;
1662 ' "$all_files" "$packaged" > $outoftree
1664 if [ -d "$install" -a -s "$outoftree" ]; then
1665 echo
1666 echo "<script>document.getElementById('li-outoftree$set').style.display = 'list-item'</script>"
1667 echo "<section id='outoftree$set'>"
1668 echo " <h3>Out-of-tree files$set_description:</h3>"
1669 echo -n ' <pre class="files">'
1670 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
1671 IFS=$'\n'
1672 while read outoftree_line; do
1673 # Find the package out-of-tree file belongs to
1674 for i in $pkgsofset; do
1675 if grep -q "^$outoftree_line$" $wok/$main/taz/$i-$ver/files.list; then
1676 cd $wok/$main/taz/$i-$ver/fs
1677 ls -ldp --color=always ".$outoftree_line" \
1678 | syntax_highlighter files \
1679 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$main/browse/taz/$i-$ver/fs\2'>\2\3|;" \
1680 | awk 'BEGIN { FS="\""; }
1681 { gsub("+", "%2B", $2); print; }'
1682 fi
1683 done
1684 done < $outoftree
1685 unset IFS
1686 echo '</pre>'
1687 echo '</section>'
1688 fi
1689 rm $outoftree
1690 # ------------------------------------------------------
1691 # /Out-of-tree files
1692 # ------------------------------------------------------
1694 # ------------------------------------------------------
1695 # Unpackaged files
1696 # ------------------------------------------------------
1697 orphans=$(mktemp)
1698 awk -F$'\n' -vall="$all_files" '
1700 if (FILENAME == all) files_all[$1] = "1";
1701 else files_pkg[$1] = "1";
1703 END {
1704 for (i in files_all) {
1705 if (! files_pkg[i]) print i;
1708 ' "$all_files" "$packaged" | sort > $orphans
1709 if [ -d "$install" -a -s "$orphans" ]; then
1710 echo
1711 echo "<script>document.getElementById('li-orphans$set').style.display = 'list-item'</script>"
1712 echo "<section id='orphans$set'>"
1713 echo " <h3>Unpackaged files$set_description:</h3>"
1714 table=$(mktemp)
1715 awk '
1716 function tag(text, color) {
1717 printf("<span class=\"c%s1\">%s</span> ", color, text);
1718 printf("%s\n", $0);
1720 /\/perllocal\.pod$/ || /\/\.packlist$/ ||
1721 /\/share\/bash-completion\// || /\/etc\/bash_completion\.d\// ||
1722 /\/lib\/systemd\// || /\.pyc$/ || /\.pyo$/ ||
1723 /\/fonts\.scale$/ || /\/fonts\.dir$/ || /\.la$/ {
1724 tag("---", 0); next }
1725 /\.pod$/ { tag("pod", 5); next }
1726 /\/share\/man\// { tag("man", 5); next }
1727 /\/share\/doc\// || /\/share\/gtk-doc\// || /\/share\/info\// ||
1728 /\/share\/devhelp\// { tag("doc", 5); next }
1729 /\/share\/icons\// { tag("ico", 2); next }
1730 /\/share\/locale\// { tag("loc", 4); next }
1731 /\.h$/ || /\.a$/ || /\.pc$/ || /\/bin\/.*-config$/ ||
1732 /\/Makefile.*$/ { tag("dev", 3); next }
1733 /\/share\/help\// || /\/share\/appdata\// { tag("gnm", 6); next }
1734 { tag("???", 1) }
1735 ' "$orphans" > $table
1737 # Summary table
1738 orphans_types='()'
1739 for i in head body; do
1740 case $i in
1741 head) echo -n '<table class="summary"><tr>';;
1742 body) echo -n '<th> </th></tr><tr>';;
1743 esac
1744 for j in '???1' dev3 loc4 ico2 doc5 man5 pod5 gnm6 '---0'; do
1745 tag=${j:0:3}; class="c${j:3:1}0"; [ "$class" == 'c00' ] && class='c01'
1746 case $i in
1747 head) echo -n "<th class='$class'>$tag</th>";;
1748 body)
1749 tagscount="$(grep ">$tag<" $table | wc -l)"
1750 printf '<td>%s</td>' "$tagscount"
1751 [ "$tagscount" -gt 0 ] && orphans_types="${orphans_types/)/ $tag)}"
1752 ;;
1753 esac
1754 done
1755 done
1756 echo '<td> </td></tr></table>'
1757 orphans_types="${orphans_types/( /(}"
1758 [ "$orphans_types" != '()' ] &&
1759 echo "<script>document.getElementById('orphansTypes$set').innerText = '${orphans_types// /, }';</script>"
1761 suffix=''; [ -n "$set" ] && suffix="-$set"
1762 echo -n ' <pre class="files">'
1763 echo -en '<span class="underline">tag·permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
1764 IFS=$'\n'
1765 while read orphan_line; do
1766 echo -n "${orphan_line/span> */span>} "
1767 cd $install
1768 ls -ldp --color=always ".${orphan_line#*</span> }" \
1769 | syntax_highlighter files \
1770 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$main/browse/install$suffix\2'>\2\3|;" \
1771 | awk 'BEGIN { FS="\""; }
1772 { gsub("+", "%2B", $2); print; }'
1773 done < $table
1774 unset IFS
1775 echo '</pre>'
1776 echo '</section>'
1777 rm $table
1778 fi
1779 rm $orphans
1780 # ------------------------------------------------------
1781 # /Unpackaged files
1782 # ------------------------------------------------------
1784 rm $all_files $packaged
1785 ;;
1786 esac
1787 done # /set
1789 case "$part" in
1790 head)
1791 [ -n "$splitsets" ] && echo "</ul>"
1792 echo "</section>"
1793 ;;
1794 esac
1795 done # /part
1797 ;;
1799 description)
1800 page_header
1801 pkg_info
1802 descs="$(ls $WOK/$pkg/description*.txt)"
1803 if [ -n "$descs" ]; then
1804 echo '<div id="content2">'
1805 [ -f "$WOK/$pkg/description.txt" ] && show_desc "$pkg" "$WOK/$pkg/description.txt"
1806 for i in $descs; do
1807 case $i in
1808 */description.txt) continue ;;
1809 *) package=$(echo $i | cut -d. -f2) ;;
1810 esac
1811 show_desc "$package" "$i"
1812 done
1813 echo '</div>'
1814 else
1815 show_note w "No description of $pkg"
1816 fi
1817 ;;
1819 log)
1820 page_header
1821 pkg_info
1822 [ -z "$arg" ] && arg=$(stat -c %Y $LOGS/$pkg.log)
1824 echo '<div class="btnList">'
1825 acc='l' # access key for the latest log is 'L'
1826 while read log; do
1827 # for all $pkg.log, $pkg.log.0 .. $pkg.log.9, $pkg-pack.log (if any)
1828 timestamp=$(stat -c %Y $log)
1829 class=''
1830 if [ "$arg" == "$timestamp" ]; then
1831 class=' log'
1832 logfile="$log"
1833 fi
1834 case $log in *-pack.log) acc='p';; esac # access key for the packing log is 'P'
1835 echo -n "<a class='button$class' data-acc='$acc' accesskey='$acc' href='$base/$pkg/log/$timestamp'>"
1836 echo "$(stat -c %y $log | cut -d: -f1,2)</a>"
1837 case $acc in
1838 l) acc=0;;
1839 *) acc=$((acc+1));;
1840 esac
1841 done <<EOT
1842 $(find $LOGS -name "$pkg.log*" | sort)
1843 $(find $LOGS -name "$pkg-pack.log")
1844 EOT
1845 echo '</div>'
1847 if [ -z "$logfile" ]; then
1848 show_note e "Requested log is absent"
1849 page_footer
1850 exit 0
1851 fi
1853 # Define cook variables for syntax highlighter
1854 if [ -s "$WOK/$pkg/receipt" ]; then
1855 . "$WOK/$pkg/receipt"
1856 _wok='/home/slitaz/wok'
1857 _src="$_wok/$pkg/source/$PACKAGE-$VERSION"
1858 _install="$_wok/$pkg/install"
1859 _fs="$_wok/$pkg/taz/$PACKAGE-$VERSION/fs"
1860 _stuff="$_wok/$pkg/stuff"
1861 fi
1863 # if [ ! -f "gzlog/$pkg.$arg" ]; then
1864 # {
1865 # summary "$logfile" links
1867 # syntax_highlighter log < $logfile | awk '
1868 # BEGIN { print "<pre class=\"log\">"; }
1869 # { printf("<a name=\"l%d\" href=\"#l%d\">%5d</a> %s\n", NR, NR, NR, $0); }
1870 # END { print "</pre>"; }
1871 # '
1873 # page_footer
1874 # } | gzip > gzlog/$pkg.$arg
1875 # fi
1877 blog=$(basename $logfile)
1878 summary "$logfile" links
1880 # disable next `sed` for the 'like2016' theme
1881 theme=$(COOKIE theme); theme=${theme:-default}; [ "$theme" != 'like2016' ] && theme=''
1882 cat $logfile | syntax_highlighter log | \
1883 sed -e "/(pkg\/local$theme):/ s|: \([^<]*\)|<img src='$base/i/$blog/\1'> \1|" | \
1884 awk '
1885 BEGIN { print "<pre class=\"log\">"; }
1886 { printf("<span id=\"l%d\">%s</span><a href=\"#l%d\"></a>\n", NR, $0, NR); }
1887 END { print "</pre>"; }
1889 ;;
1892 man|doc|info)
1893 page_header
1894 pkg_info
1895 echo '<div style="max-height: 6.4em; overflow: auto; padding: 0 4px">'
1897 dir="wok/$pkg/install/usr/share/$cmd"
1898 [ "$cmd" == 'doc' ] && dir="$dir wok/$pkg/install/usr/share/gtk-doc"
1899 if [ "$cmd" == 'doc' -a -z "$arg" ]; then
1900 try=$(for i in $dir; do find $i -name 'index.htm*'; done | sed q)
1901 [ -n "$try" ] && arg="$try"
1902 fi
1903 while read i; do
1904 [ -s "$i" ] || continue
1905 case "$i" in
1906 *.jp*g|*.png|*.gif|*.svg|*.css) continue
1907 esac
1908 i=${i#$dir/}
1909 [ -n "$arg" ] || arg="$i"
1910 class=''; [ "$arg" == "$i" ] && class=" doc"
1911 case "$cmd" in
1912 man)
1913 case $i in
1914 man*) lang='';;
1915 *) lang="${i%%/*}: ";;
1916 esac
1917 man=$(basename $i .gz)
1918 echo "<a class='button$class' href='$base/$pkg/man/$i'>$lang${man%.*} (${man##*.})</a>"
1919 ;;
1920 doc)
1921 echo "<a class='button$class' href='$base/$pkg/doc/$i'>$(basename $i .gz)</a>"
1922 ;;
1923 info)
1924 info=$(basename $i)
1925 echo "<a class='button$class' href='$base/$pkg/info/$i#Top'>${info/.info/}</a>"
1926 ;;
1927 esac
1928 done <<EOT
1929 $(for i in $dir; do find $i -type f; done | sort)
1930 EOT
1931 echo '</div>'
1933 [ -f "$arg" ] || arg="$dir/$arg"
1934 if [ -f "$arg" ]; then
1935 tmp="$(mktemp)"
1936 docat "$arg" > $tmp
1937 [ -s "$tmp" ] &&
1938 case "$cmd" in
1939 info)
1940 echo '<div id="content2" class="texinfo"><pre class="first">'
1941 info2html < "$tmp"
1942 echo '</pre></div>'
1943 ;;
1944 doc)
1945 case "$arg" in
1946 *.sgml|*.devhelp2) class='xml';;
1947 *.py) class='python';; # pycurl package
1948 *.css) class='css';;
1949 *.sh) class='bash';;
1950 *)
1951 first=$(head -n1 "$tmp")
1952 if [ "${first:0:1}" == '#' ]; then
1953 class='bash' # first line begins with '#'
1954 else
1955 class='asciidoc'
1956 fi;;
1957 esac
1958 case "$arg" in
1959 *.htm*)
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 # make the iframe height so long to contain its contents without scrollbar
1965 echo "<iframe id='idoc' src='$page' width='100%' onload='resizeIframe(this)'></iframe>"
1966 ;;
1967 *.pdf)
1968 case $arg in
1969 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
1970 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
1971 esac
1972 cat <<EOT
1973 <object id="idoc" data="$page" width="100%" height="100%" type="application/pdf" style="min-height: 600px">
1974 $(show_note w "Missing PDF plugin.<br/>Get the file <a href="$page">$(basename "$page")</a>.")
1975 </object>
1976 EOT
1977 ;;
1978 *.md|*.markdown)
1979 echo '<section>'
1980 $md2html "$tmp"
1981 echo '</section>'
1982 ;;
1983 *)
1984 show_code $class < "$tmp"
1985 ;;
1986 esac
1987 ;;
1988 man)
1989 #export TEXTDOMAIN='man2html'
1990 echo "<div id='content2'>"
1992 html=$(./man2html.bin "$tmp" | sed -e '1,/<header>/d' -e '/<footer>/,$d' \
1993 -e 's|<a href="file:///[^>]*>\([^<]*\)</a>|\1|g' \
1994 -e 's|<a href="?[1-9]\+[^>]*>\([^<]*\)</a>|\1|g')
1996 if [ -n "$(echo "$html" | fgrep 'The requested file /tmp/tmp.')" ]; then
1997 # Process the pre-formatted man-cat page
1998 # (for example see sudo package without groff in build dependencies)
1999 sed -i '
2000 s|M-bM-^@M-^S|—|g;
2001 s|M-bM-^@M-^\\|<b>|g;
2002 s|M-bM-^@M-^]|</b>|g
2003 s|M-bM-^@M-^X|<u>|g;
2004 s|M-bM-^@M-^Y|</u>|g;
2005 s|M-BM-||g;
2006 s|++oo|•|g;
2007 s|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g;
2008 ' "$tmp"
2009 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 \
2010 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 \
2011 0 1 2 3 4 5 6 7 8 9 _ - '\\+' '\.' /; do
2012 sed -i "s|$i$i|<b>$i</b>|g; s|_$i|<u>$i</u>|g" "$tmp"
2013 done
2014 echo '<pre class="catman">'
2015 sed 's|</b><b>||g; s|</u><u>||g; s|</u><b>_</b><u>|_|g; s|</b> <b>| |g;' "$tmp"
2016 echo '</pre>'
2017 else
2018 echo "$html"
2019 fi
2020 echo "</div>"
2021 ;;
2022 esac
2023 rm -f $tmp
2024 else
2025 show_note e "File “$arg” does not exist!"
2026 fi
2027 ;;
2029 download)
2030 page_header
2031 pkg_info
2032 show=0
2034 . $wok/$pkg/receipt
2036 if [ -n "$TARBALL" -a -s "$SRC/$TARBALL" ]; then
2037 files_header
2038 echo "<tr><td><a href='$base/src/$TARBALL'>$TARBALL</a></td>"
2039 ls -lh "$SRC/$TARBALL" | awk '{printf("<td>%sB</td>", $5)}'
2040 echo "<td>Sources for building the package “$pkg”</td></tr>"
2041 show=1
2042 fi
2044 if [ -d "$wok/$pkg/taz" ]; then
2045 [ "$show" -eq 1 ] || files_header
2047 common_version=$VERSION
2048 for i in $(all_names); do
2049 [ -e "$wok/$pkg/taz/$i-$common_version$EXTRAVERSION/receipt" ] || continue
2050 . $wok/$pkg/taz/$i-$common_version$EXTRAVERSION/receipt
2052 for filename in "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg"; do
2053 [ -f "$PKGS/$filename" ] &&
2054 cat <<EOT
2055 <tr>
2056 <td><a href="$base/get/$filename">$filename</a></td>
2057 <td>$(ls -lh ./packages/$filename | awk '{printf("%sB", $5)}')</td>
2058 <td>$SHORT_DESC</td>
2059 </tr>
2060 EOT
2061 done
2062 done
2063 show=1
2064 fi
2066 if [ "$show" -eq 1 ]; then
2067 echo '</tbody></table></section>'
2068 else
2069 show_note w "Sorry, there's nothing to download…"
2070 fi
2071 ;;
2073 esac
2076 page_footer
2077 exit 0