cookutils view lighttpd/index.cgi @ rev 1069

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