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