cookutils view lighttpd/index.cgi @ rev 1057

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