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