cookutils view lighttpd/index.cgi @ rev 1015

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