cookutils view lighttpd/index.cgi @ rev 1029

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