cookutils view lighttpd/index.cgi @ rev 915

cook, lighttpd/index.cgi: forgot about EXTRAVERSION.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Wed Jun 07 22:36:09 2017 +0300 (2017-06-07)
parents a608dbb232df
children 5f884df71b44
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"
34 # Path to markdown to html convertor
35 cmark_opts='--smart -e table -e strikethrough -e autolink -e tagfilter'
36 if [ -n "$(which cmark 2>/dev/null)" ]; then
37 md2html="$(which cmark) $cmark_opts"
38 elif [ -x "./cmark" ]; then
39 md2html="./cmark $cmark_opts"
40 elif [ -n "$(which sundown 2>/dev/null)" ]; then
41 md2html=$(which sundown)
42 elif [ -x "./sundown" ]; then
43 md2html="./sundown"
44 fi
49 # Search form redirection
50 if [ -n "$(GET search)" ]; then
51 echo -e "HTTP/1.1 301 Moved Permanently\nLocation: $base/$(GET q)\n\n"
52 exit 0
53 fi
56 # Show the running command and it's progression
58 running_command() {
59 state="$(cat $command)"
60 local pct
61 if [ -n "$state" ];then
62 echo -n "$state</td></tr><tr><td>Completion</td>"
63 set -- $(grep "^$state" $cooktime)
64 [ -n "$1" -a $2 -ne 0 ] && pct=$((($(date +%s)-$3)*100/$2))
65 [ -n "$pct" ] && max="max='100'"
66 echo -n "<td><progress id='gauge' $max value='$pct' title='Click to stop updating' onclick='stopUpdating()'>"
67 echo -n "</progress> <span id='pct'>${pct:-?}%</span>"
68 [ "$2" -gt 60 ] &&
69 echo -n "</td></tr><tr><td>Estimated end time</td><td>$(date +%H:%M -ud @$(($2+$3)))"
70 else
71 echo 'not running'
72 fi
73 }
76 # HTML page header
78 page_header() {
79 local theme t='' css
80 theme=$(COOKIE theme)
81 [ "$theme" == 'default' ] && theme=''
82 [ -n "$theme" ] && theme="-$theme"
83 css="cooker$theme.css"
85 echo -e 'Content-Type: text/html; charset=UTF-8\n'
87 cat <<EOT
88 <!DOCTYPE html>
89 <html lang="en">
90 <head>
91 <title>$([ -n "$pkg" ] && echo "$pkg - ")$title</title>
92 <link rel="stylesheet" href="/$css">
93 <link rel="icon" type="image/png" href="/slitaz-cooker.png">
94 <link rel="search" href="$base/os.xml" title="$title" type="application/opensearchdescription+xml">
95 <!-- mobile -->
96 <meta name="viewport" content="width=device-width, initial-scale=1.0">
97 <meta name="theme-color" content="#222">
98 <!-- rss -->
99 <link rel="alternate" type="application/rss+xml" title="$title Feed" href="?rss">
100 </head>
101 <body>
102 <div id="container">
103 <header>
104 <h1><a href="$base/">$title</a></h1>
105 <div class="network">
106 <a href="http://www.slitaz.org/">Home</a>
107 <a href="http://bugs.slitaz.org/">Bugs</a>
108 <a href="http://hg.slitaz.org/wok-next/">Hg</a>
109 <a href="http://roadmap.slitaz.org/">Roadmap</a>
110 <a href="http://pizza.slitaz.me/">Pizza</a>
111 <a href="http://tank.slitaz.org/">Tank</a>
112 |
113 <a href="$base/cross/">Cross</a>
114 <a href="$base/i486.cgi">i486</a>
115 <a href="$base/cookiso.cgi">ISO</a>
116 <select onChange="window.location.href=this.value" style="display: none">
117 <option value=".">Go to…</option>
118 <option value="http://www.slitaz.org/">Home</option>
119 <option value="http://bugs.slitaz.org/">Bug tracker</option>
120 <option value="http://hg.slitaz.org/wok/">Hg wok</option>
121 <option value="http://roadmap.slitaz.org/">Roadmap</option>
122 <option value="http://pizza.slitaz.me/">Pizza</option>
123 <option value="http://tank.slitaz.org/">Tank</option>
124 <option disabled>---------</option>
125 <option value="cross/">Cross</option>
126 <option value="i486.cgi">i486</option>
127 <option value="cookiso.cgi">ISO</option>
128 </select>
129 </div>
130 </header>
132 <main>
133 EOT
135 [ -n "$(GET debug)" ] && echo "<pre><code class='language-ini'>$(env | sort)</code></pre>"
136 }
139 # HTML page footer
141 page_footer() {
142 date_now=$(date +%s)
143 sec_now=$(date +%S); sec_now=${sec_now#0} # remove one leading zero
144 wait_sec=$(( 60 - $sec_now ))
145 cat <<EOT
146 </main>
148 <footer>
149 <a href="http://www.slitaz.org/">SliTaz Website</a>
150 <a href="$base/">Cooker</a>
151 <a href="$base/doc/cookutils/cookutils.html">Documentation</a>
152 <a href="$base/?theme">Theme</a>
153 </footer>
154 </div>
155 <script src="/cooker.js"></script>
156 <script>refreshDate(${wait_sec}000, ${date_now}000)</script>
157 </body>
158 </html>
159 EOT
160 }
163 show_note() {
164 echo "<div class='bigicon-$1'>$2</div>"
165 }
168 not_found() {
169 local file="${1#$PKGS/}"; file="${file#$LOGS/}"; file="${file#$WOK/}"
170 echo "HTTP/1.1 404 Not Found"
171 page_header
172 echo "<h2>Not Found</h2>"
173 case $2 in
174 pkg)
175 show_note e "The requested package “$(basename "$(dirname "$file")")” was not found." ;;
176 *)
177 show_note e "The requested file “$file” was not found." ;;
178 esac
179 page_footer
180 }
183 manage_modified() {
184 local file="$1" option="$2" nul day mon year time hh mm ss date_s
185 if [ ! -f "$file" ]; then
186 if [ "$option" == 'silently-absent' ]; then
187 echo "HTTP/1.1 404 Not Found"
188 return
189 else
190 not_found "$file" "$2"
191 exit
192 fi
193 fi
194 [ "$option" == 'no-last-modified' ] && return
195 if [ -n "$HTTP_IF_MODIFIED_SINCE" ]; then
196 echo "$HTTP_IF_MODIFIED_SINCE" | \
197 while read nul day mon year time nul; do
198 case $mon in
199 Jan) mon='01';; Feb) mon='02';; Mar) mon='03';; Apr) mon='04';;
200 May) mon='05';; Jun) mon='06';; Jul) mon='07';; Aug) mon='08';;
201 Sep) mon='09';; Oct) mon='10';; Nov) mon='11';; Dec) mon='12';;
202 esac
203 hh=$(echo $time | cut -d: -f1)
204 mm=$(echo $time | cut -d: -f2)
205 ss=$(echo $time | cut -d: -f3)
206 date_s=$(date -ud "$year$mon$day$hh$mm.$ss" +%s)
207 # if [ "$date_s" -ge "$(date -ur "$file" +%s)" ]; then
208 # echo -e 'HTTP/1.1 304 Not Modified\n'
209 # exit
210 # fi
211 # TODO: improve caching control
212 done
213 fi
214 echo "Last-Modified: $(date -Rur "$file" | sed 's|UTC|GMT|')"
215 echo "Cache-Control: public, max-age=3600"
216 }
219 # Query '?pct=<package>': update percentage
221 if [ -n "$(GET pct)" ]; then
222 pkg="$(GET pct)"
223 state="$(cat $command)"
224 if [ "$state" == "cook:$pkg" ]; then
225 set -- $(grep "^$state" $cooktime)
226 [ -n "$1" ] && pct=$(( ($(date +%s) - $3) * 100 / $2 ))
227 echo "${pct:-?}"
228 else
229 echo 'reload'
230 fi
231 exit 0
232 fi
235 # Query '?poke': poke cooker
237 if [ -n "$(GET poke)" ]; then
238 touch $CACHE/cooker-request
239 echo -e "Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}\n"
240 exit
241 fi
244 # Query '?recook=<package>': query to recook package
246 if [ -n "$(GET recook)" ]; then
247 pkg="$(GET recook)"
248 case "$HTTP_USER_AGENT" in
249 *SliTaz*)
250 grep -qs "^$pkg$" $CACHE/recook-packages ||
251 echo "$pkg" >> $CACHE/recook-packages
252 esac
253 echo -e "Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}\n"
254 exit
255 fi
258 # Query '/i/<log>/<pkg>': show indicator icon
259 # Can't use ?query - not able to change '+' to '%2B' in the sed rules (see log handler)
261 if [ "$pkg" == 'i' ]; then
262 echo -en "Content-Type: image/svg+xml\n\n<svg xmlns='http://www.w3.org/2000/svg' height='12' width='8'><path d='"
263 if [ $LOGS/$cmd -nt $PKGS/$arg.tazpkg ]; then
264 echo "m1 2-1 1v8l1 1h6l1-1v-8l-1-1z' fill='#090'/></svg>"
265 else
266 echo "m0 3v8l1 1h6l1-1v-8l-1-1h-6zm3 0h2v5h-2zm0 6h2v2h-2z' fill='#d00'/></svg>"
267 fi
268 exit
269 fi
272 # Query '?theme[=<theme>]': change UI theme
274 if [ -n "$(GET theme)" ]; then
275 theme="$(GET theme)"
276 case $theme in
277 theme)
278 current=$(COOKIE theme)
279 page_header
280 cat <<EOT
281 <section>
282 <h2>Change theme</h2>
283 <p>Current theme: “${current:-default}”. Select other:</p>
284 <ul>
285 $(
286 for i in default emerald sky goldenrod midnight like2016 terminal; do
287 [ "$i" == "${current:-default}" ] || echo "<li><a href="$base/?theme=$i">$i</a></li>"
288 done
289 )
290 </ul>
291 </section>
292 EOT
293 page_footer
294 exit 0
295 ;;
296 default|emerald|sky|goldenrod|midnight|like2016|terminal)
297 # Expires in a year
298 expires=$(date -uRd @$(($(date +%s)+31536000)) | sed 's|UTC|GMT|')
299 echo -e "HTTP/1.1 302 Found\nLocation: $base/\nCache-Control: no-cache\nSet-Cookie: theme=$theme; expires=$expires\n\n"
300 exit 0
301 ;;
302 esac
303 fi
306 #case "$QUERY_STRING" in
307 # stuff*)
308 # file="$wok/$(GET stuff)"
309 # manage_modified "$file"
310 # ;;
311 #
312 # pkg=*|receipt=*|description=*|files=*|log=*|man=*|doc=*|info=*)
313 # type=${QUERY_STRING%%=*}
314 # pkg=$(GET $type)
315 # case "$type" in
316 # description)
317 # manage_modified "$wok/$pkg/receipt" 'no-last-modified'
318 # manage_modified "$wok/$pkg/description.txt" 'silently-absent'
319 # ;;
320 # log)
321 # manage_modified "$wok/${pkg%%.log*}/receipt" 'no-last-modified'
322 # manage_modified "$LOGS/$pkg"
323 # ;;
324 # *)
325 # manage_modified "$wok/$pkg/receipt" pkg
326 # ;;
327 # esac
328 # ;;
329 #esac
332 # RSS feed generator
333 # URI: ?rss[&limit={1..100}]
335 if [ -n "$(GET rss)" ]; then
336 limit=$(GET limit); limit="${limit:-12}"; [ "$limit" -gt 100 ] && limit='100'
337 pubdate=$(date -Rur$(ls -t $FEEDS/*.xml | head -n1) | sed 's|UTC|GMT|')
338 cooker_url="http://$HTTP_HOST$base/"
339 cat <<EOT
340 Content-Type: application/rss+xml
342 <?xml version="1.0" encoding="utf-8" ?>
343 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
344 <channel>
345 <title>$title</title>
346 <description>The SliTaz packages cooker feed</description>
347 <link>$cooker_url</link>
348 <lastBuildDate>$pubdate</lastBuildDate>
349 <pubDate>$pubdate</pubDate>
350 <atom:link href="$cooker_url?rss" rel="self" type="application/rss+xml" />
351 EOT
352 for rss in $(ls -t $FEEDS/*.xml | head -n$limit); do
353 sed "s|http[^=]*=|$cooker_url|; s|<guid|& isPermaLink=\"false\"|g; s|</pubDate| GMT&|g" $rss
354 done
355 cat <<EOT
356 </channel>
357 </rss>
358 EOT
359 exit 0
360 fi
363 ### OpenSearch ###
365 # Query '/os.xml': get OpenSearch Description
367 if [ "$pkg" == 'os.xml' ]; then
368 cat <<EOT
369 Content-Type: application/xml; charset=UTF-8
371 <?xml version="1.0" encoding="UTF-8"?>
372 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
373 <ShortName>$title</ShortName>
374 <Description>SliTaz packages search</Description>
375 <Image width="16" height="16" type="image/png">http://$HTTP_HOST/images/logo.png</Image>
376 <Url type="text/html" method="GET" template="http://$HTTP_HOST$base/{searchTerms}"/>
377 <Url type="application/x-suggestions+json" method="GET" template="http://$HTTP_HOST$base/">
378 <Param name="oss" value="{searchTerms}"/>
379 </Url>
380 <SearchForm>http://$HTTP_HOST$base/</SearchForm>
381 <InputEncoding>UTF-8</InputEncoding>
382 </OpenSearchDescription>
383 EOT
384 exit 0
385 fi
387 # Query '?oss[=<term>]': OpenSearch suggestions
389 if [ -n "$(GET oss)" ]; then
390 term="$(GET oss | tr -cd '[:alnum:]+-')"
391 echo -e 'Content-Type: application/x-suggestions+json; charset=UTF-8\n'
392 cd $wok
393 ls | fgrep "$term" | head -n10 | awk -vterm="$term" '
394 BEGIN{printf("[\"%s\",[", term)}
395 {printf("%s\"%s\"", NR != 1 ? "," : "", $0)}
396 END {printf("]]")}
397 '
398 exit 0
399 fi
404 #
405 # Functions
406 #
409 # Unpack to stdout
411 docat() {
412 case "$1" in
413 *gz) zcat ;;
414 *bz2) bzcat ;;
415 *xz) xzcat ;;
416 *) cat
417 esac < $1
418 }
421 # Tiny texinfo converter
423 info2html() {
424 sed \
425 -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g' \
426 -e 's|^\* \(.*\)::|* <a href="#\1">\1</a> |' \
427 -e 's|\*note \(.*\)::|<a href="#\1">\1</a>|' \
428 -e '/^File: / s|(dir)|Top|g' \
429 -e '/^File: / s|Next: \([^,]*\)|<a class="button" href="#\1">Next: \1</a>|' \
430 -e '/^File: / s|Prev: \([^,]*\)|<a class="button" href="#\1">Prev: \1</a>|' \
431 -e '/^File: / s|Up: \([^,]*\)|<a class="button" href="#\1">Up: \1</a>|' \
432 -e '/^File: / s|^.* Node: \([^,]*\), *\(.*\)$|<pre id="\1">\2|' \
433 -e '/^<pre id=/ s|^\([^>]*>\)\(<a[^>]*>Next: [^,]*\), *\(<a[^>]*>Prev: [^,]*\), *\(<a[^>]*>Up: .*\)|\1 \3 \4 \2|' \
434 -e '/^Tag Table:$/,/^End Tag Table$/d' \
435 -e '/INFO-DIR/,/^END-INFO-DIR/d' \
436 -e "s|https*://[^>),'\"\`’ ]*|<a href=\"&\">&</a>|g" \
437 -e "s|ftp://[^>),\"\` ]*|<a href=\"&\">&</a>|g" \
438 -e 's|^\* Menu:|<b>Menu:</b>|' \
439 -e "s|^|</pre>|"
440 }
443 # Put some colors into log and DB files.
445 syntax_highlighter() {
446 case $1 in
447 log)
448 # If variables not defined - define them with some rare values
449 : ${_src=#_#_#}
450 : ${_install=#_#_#}
451 : ${_fs=#_#_#}
452 : ${_stuff=#_#_#}
453 # Use one-letter html tags to save some bytes :)
454 # <b>is error (red)</b> <u>is warning (orange)</u> <i>is informal (green)</i>
455 sed -e 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g' \
456 -e 's#OK$#<i>OK</i>#' \
457 -e 's#\([Dd]one\)$#<i>\1</i>#' \
458 -e 's#Success$#<i>Success</i>#' \
459 -e 's#\([^a-z]\)ok$#\1<i>ok</i>#' \
460 -e 's#\([^a-z]\)yes$#\1<i>yes</i>#' \
461 -e 's#\([^a-z]\)ON$#\1<i>ON</i>#' \
462 -e 's#\([^a-z]\)no$#\1<u>no</u>#' \
463 -e 's#\([^a-z]\)none$#\1<u>none</u>#' \
464 -e 's#\([^a-z]\)false$#\1<u>false</u>#' \
465 -e 's#\([^a-z]\)OFF$#\1<u>OFF</u>#' \
466 -e 's#\(^checking .*\.\.\. \)\(.*\)$#\1<i>\2</i>#' \
467 \
468 -e 's#\( \[Y[nm/]\?\] n\)$# <u>\1</u>#' \
469 -e 's#\( \[N[ym/]\?\] y\)$# <i>\1</i>#' \
470 -e 's# y$# <i>y</i>#' \
471 -e 's# n$# <u>n</u>#' \
472 -e 's#(NEW) *$#<b>(NEW)</b>#' \
473 \
474 -e 's#.*(pkg/local).*#<i>\0</i>#' \
475 -e 's#.*(web/cache).*#<u>\0</u>#' \
476 \
477 -e 's#\([^a-zA-Z]\)\([Ee]rror\)$#\1<b>\2</b>#' \
478 -e 's#ERROR:#<b>ERROR:</b>#g' \
479 \
480 -e 's#^.*[Ff][Aa][Ii][Ll][Ee][Dd].*#<b>\0</b>#' \
481 -e 's#^.*[Ff]atal.*#<b>\0</b>#' \
482 -e 's#^.*[Nn]ot found.*#<b>\0</b>#' \
483 -e 's#^.*[Nn]o such file.*#<b>\0</b>#' \
484 -e 's#^.*No package .* found.*#<b>\0</b>#' \
485 -e 's#^.*Unable to find.*#<b>\0</b>#' \
486 -e 's#^.*[Ii]nvalid.*#<b>\0</b>#' \
487 -e 's#\([Nn][Oo][Tt] found\.*\)$#<b>\1</b>#' \
488 -e 's#\(found\.*\)$#<i>\1</i>#' \
489 \
490 -e 's#^.*WARNING:.*#<u>\0</u>#' \
491 -e 's#^.*warning:.*#<u>\0</u>#' \
492 -e 's#^.* [Ee]rror:* .*#<b>\0</b>#' \
493 -e 's#^.*terminated.*#<b>\0</b>#' \
494 -e 's#\(missing\)#<b>\1</b>#g' \
495 -e 's#^.*[Cc]annot find.*#<b>\0</b>#' \
496 -e 's#^.*unrecognized options.*#<u>\0</u>#' \
497 -e 's#^.*does not.*#<u>\0</u>#' \
498 -e 's#^.*[Ii]gnoring.*#<u>\0</u>#' \
499 -e 's#^.*note:.*#<u>\0</u>#' \
500 \
501 -e 's#^.* will not .*#<u>\0</u>#' \
502 -e 's!^Hunk .* succeeded at .*!<u>\0</u>!' \
503 -e 's#^.* Warning: .*#<u>\0</u>#' \
504 \
505 -e "s#^Executing:\([^']*\).#<em>\0</em>#" \
506 -e "s#^Making.*#<em>\0</em>#" \
507 -e "s#^Scanning dependencies of target .*#<em>\0</em>#" \
508 -e "s#^====\([^']*\).#<span class='span-line'>\0</span>#g" \
509 -e "s#^[a-zA-Z0-9]\([^']*\) :: #<span class='span-sky'>\0</span>#g" \
510 -e "s#[fh]tt*ps*://[^ '\"]*#<a href='\0'>\0</a>#g" \
511 \
512 -e "s|$_src|<span class='var'>\${src}</span>|g;
513 s|$_install|<span class='var'>\${install}</span>|g;
514 s|$_fs|<span class='var'>\${fs}</span>|g;
515 s|$_stuff|<span class='var'>\${stuff}</span>|g" \
516 -e "s|\[9\([1-6]\)m|<span class='c\10'>|;
517 s|\[39m|</span>|;"
518 ;;
520 files)
521 # Highlight the Busybox's `ls` output
522 awk '{
523 part1 = substr($0, 0, 16);
524 part2 = substr($0, 17, 9);
525 part3 = substr($0, 26, 9);
526 part4 = substr($0, 35);
527 if (part2 != "root ") part2 = "<span class=\"c11\">" part2 "</span>";
528 if (part3 != "root ") part3 = "<span class=\"c11\">" part3 "</span>";
529 print part1 part2 part3 part4;
530 }' | \
531 sed "s|\[\([01]\);3\([1-7]\)m|<a class='c\2\1'>|g;
532 s|\[\([01]\);0m|<a class='c0\1'>|g;
533 s|\[0m|</a>|g;
534 s|^\(lrwxrwxrwx\)|<span class='c61'>\1</span>|;
535 s|^\(-rwxr-xr-x\)|<span class='c21'>\1</span>|;
536 s|^\(-rw-r--r--\)|<span class='c31'>\1</span>|;
537 s|^\([lrwxs-]*\)|<span class='c11'>\1</span>|;
538 "
539 ;;
540 esac
541 }
544 show_code() {
545 echo -n "<pre><code class=\"language-$1\">"
546 sed 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g'
547 echo '</code></pre>'
548 }
551 datalist() {
552 (
553 cd $wok
555 ls | awk '
556 BEGIN{printf("<datalist id=\"packages\">")}
557 {printf("<option>%s</option>",$1)}
558 END {printf("</datalist>")}
559 '
560 )
561 }
564 mklog() {
565 awk '
566 BEGIN { printf("<pre class=\"log dog\">\n") }
567 { print }
568 END { print "</pre>" }'
569 }
572 summary() {
573 log="$1"
574 pkg="$(basename ${log%%.log*})"
576 if [ -f "$log" ]; then
577 if grep -q "cook:$pkg$" $command; then
578 show_note i "The Cooker is currently building $pkg"
579 elif fgrep -q "Summary for:" $log; then
580 sed '/^Summary for:/,$!d' $log | awk '
581 BEGIN { print "<section>" }
582 function row(line) {
583 split(line, s, " : ");
584 printf("\t<tr><td>%s</td><td>%s</td></tr>\n", s[1], s[2]);
585 }
586 function row2(line, rowNum) {
587 split(line, s, " : ");
588 if (rowNum == 1)
589 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]);
590 else
591 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]);
592 }
593 {
594 if (NR==1) { printf("<h3>%s</h3>\n<table>\n", $0); next }
595 if ($0 ~ "===") { seen++; if (seen == 1) next; else exit; }
596 if ($0 ~ "---") {
597 seen2++;
598 if (seen2 == 1) printf("</table>\n<table class=\"pkgslist\">\n")
599 next
600 }
601 if (seen2) row2($0, seen2); else row($0);
602 }
603 END { print "</table></section>" }
604 '
605 elif fgrep -q "Debug information" $log; then
606 echo -e '<section>\n<h3>Debug information</h3>'
607 sed -e '/^Debug information/,$!d; /^===/d; /^$/d' $log | sed -n '1!p' | \
608 if [ -n "$2" ]; then
609 syntax_highlighter log | sed 's|\([0-9][0-9]*\):|<a href="#l\1">\1</a>:|'
610 else
611 sed 's|^[0-9][0-9]*:||' | syntax_highlighter log
612 fi | mklog
613 echo '</section>'
614 fi
615 else
616 [ -n "$pkg" -a -d "$wok/$pkg" ] && show_note e "No log for $pkg"
617 fi
618 }
621 active() {
622 [ "$cmd" == "$1" -o "$cmd" == "${2:-$1}" ] && echo -n ' active'
623 }
626 pkg_info() {
627 local log active bpkg
628 log="$LOGS/$pkg.log"
630 echo "<h2>Package “$pkg”</h2>"
631 echo '<div id="info">'
632 echo "<a class='button icon receipt$(active receipt stuff)' href='$base/$pkg/receipt'>receipt &amp; stuff</a>"
634 unset WEB_SITE WANTED
635 . $wok/$pkg/receipt
637 [ -n "$WEB_SITE" ] &&
638 echo "<a class='button icon website' href='$WEB_SITE' target='_blank' rel='noopener noreferrer'>web site</a>"
640 if [ -f "$wok/$pkg/taz/$PACKAGE-$VERSION/receipt" ]; then
641 echo "<a class='button icon files$(active files)' href='$base/$pkg/files'>files</a>"
643 [ -n "$(ls $wok/$pkg/description*.txt)" ] &&
644 echo "<a class='button icon desc$(active description)' href='$base/$pkg/description'>description</a>"
646 unset EXTRAVERSION
647 . $wok/$pkg/taz/$PACKAGE-$VERSION/receipt
648 for filename in "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg"; do
649 [ -f "$PKGS/$filename" ] &&
650 echo "<a class='button icon download' href='$base/get/$filename'>download</a>"
651 done
653 fi
655 [ -n "$TARBALL" -a -s "$SRC/$TARBALL" ] &&
656 echo "<a class='button icon source' href='$base/src/$TARBALL'>source</a>"
658 echo "<a class='button icon browse' href='$base/$pkg/browse/'>browse</a>"
660 [ -x ./man2html -a -d "$wok/$pkg/install/usr/share/man" ] &&
661 echo "<a class='button icon doc$(active man)' href='$base/$pkg/man/'>man</a>"
663 [ -d "$wok/$pkg/install/usr/share/doc" -o -d "$wok/$pkg/install/usr/share/gtk-doc" ] &&
664 echo "<a class='button icon doc$(active doc)' href='$base/$pkg/doc/'>doc</a>"
666 [ -d "$wok/$pkg/install/usr/share/info" ] &&
667 echo "<a class='button icon doc$(active info)' href='$base/$pkg/info/#Top'>info</a>"
669 [ -s "$log" ] &&
670 echo "<a class='button icon log$(active log)' href='$base/$pkg/log/'>logs</a>"
672 echo '</div>'
673 }
676 mktable() {
677 sed 's# : #|#' | awk -vc="$1" '
678 BEGIN { printf("<table class=\"%s\">\n", c); FS="|" }
679 { printf("<tr><td>%s</td>", $1);
680 if (NF == 2) printf("<td>%s</td>", $2);
681 printf("</tr>\n", $2) }
682 END { print "</table>" }'
683 }
686 section() {
687 local i=$(basename "$1")
688 echo -e '\n\n<section>'
689 [ $(wc -l < $1) -gt $2 ] && echo "<a class='button icon more r' href='?$i'>${3#*|}</a>"
690 echo "<h2>${3%|*}</h2>"
691 mktable "$i"
692 echo '</section>'
693 }
696 show_desc() {
697 echo "<section><h3>Description of “$1”</h3>"
698 if [ -n "$md2html" ]; then
699 $md2html $2
700 else
701 show_code markdown < $2
702 fi
703 echo "</section>"
704 }
709 #
710 # Load requested page
711 #
713 if [ -z "$pkg" ]; then
715 page_header
716 if [ -n "$QUERY_STRING" -a "$QUERY_STRING" != 'debug' ]; then
718 for list in activity cooknotes cooklist; do
719 [ -n "$(GET $list)" ] || continue
720 [ "$list" == 'cooklist' ] && nb="- Packages: $(wc -l < $cooklist)"
721 echo '<section id="content2">'
722 echo "<h2>DB: $list $nb</h2>"
723 tac $CACHE/$list | sed 's|cooker.cgi?pkg=||; s|%2B|+|g;
724 s|\[ Done|<span class="r c20">Done|;
725 s|\[ Failed|<span class="r c10">Failed|;
726 s| \]|</span>|' | mktable $list
727 echo '</section>'
728 done
730 if [ -n "$(GET broken)" ]; then
731 echo '<div id="content2">'
732 echo "<h2>DB: broken - Packages: $(wc -l < $broken)</h2>"
733 sort $CACHE/broken | sed "s|^[^']*|<a href='$base/\0'>\0</a>|g" | mktable
734 echo '</div>'
735 fi
737 case "$QUERY_STRING" in
738 *.log)
739 log=$LOGS/$QUERY_STRING
740 name=$(basename $log)
741 if [ -f "$log" ]; then
742 echo "<h2>Log for: ${name%.log}</h2>"
743 if fgrep -q "Summary" $log; then
744 echo '<pre class="log">'
745 grep -A 20 '^Summary' $log | syntax_highlighter log
746 echo '</pre>'
747 fi
748 echo '<pre class="log">'
749 syntax_highlighter log < $log
750 echo '</pre>'
751 else
752 show_note e "No log file: $log"
753 fi
754 ;;
755 esac
756 page_footer
757 exit 0
758 fi
761 # We may have a toolchain.cgi script for cross cooker's
762 if [ -f "toolchain.cgi" ]; then
763 toolchain="toolchain.cgi"
764 else
765 toolchain="slitaz-toolchain/"
766 fi
767 # Main page with summary. Count only packages included in ARCH,
768 # use 'cooker arch-db' to manually create arch.$ARCH files.
769 inwok=$(ls $WOK/*/arch.$ARCH | wc -l)
770 cooked=$(ls $PKGS/*.tazpkg | wc -l)
771 unbuilt=$(($inwok - $cooked))
772 pct=0; [ $inwok -gt 0 ] && pct=$(( ($cooked * 100) / $inwok ))
773 cat <<EOT
774 <div id="content2">
776 <section>
777 <form method="get" action="" class="search r">
778 <input type="hidden" name="search" value="pkg"/>
779 <button type="submit" title="Search">Search</button>
780 <input type="search" name="q" placeholder="Package" list="packages" autocorrect="off" autocapitalize="off"/>
781 </form>
783 <h2>Summary</h2>
784 EOT
786 mktable <<EOT
787 Cooker state : $(running_command)
788 Wok revision : <a href='$WOK_URL' target='_blank' rel='noopener noreferrer'>$(cat $wokrev)</a>
789 Commits to cook : $(wc -l < $commits)
790 Current cooklist : $(wc -l < $cooklist)
791 Broken packages : $(wc -l < $broken)
792 Blocked packages : $(wc -l < $blocked)
793 Architecture : $ARCH, <a href="$toolchain">toolchain</a>
794 Server date : <span id='date'>$(date -u '+%F %R %Z')</span>
795 EOT
797 # If command is "cook:*", update gauge and percentage periodically.
798 # If different package is cooking, reload the page (with new settings)
799 cmd="$(cat $command)"
800 case "$cmd" in
801 cook:*)
802 pkg=${cmd#*:}
803 echo "<script>updatePkg = '${pkg//+/%2B}';</script>"
804 ;;
805 esac
807 if [ -e "$CACHE/cooker-request" -a ! -s $command ]; then
808 if [ "$activity" -nt "$CACHE/cooker-request" ]; then
809 echo '<a class="button icon bell r" href="?poke">Wake up</a>'
810 else
811 show_note i 'Cooker will be launched in the next 5 minutes.'
812 fi
813 fi
815 cat <<EOT
816 <p>Packages: $inwok in the wok · $cooked cooked · $unbuilt unbuilt</p>
818 <div class="meter"><progress max="100" value="$pct">${pct}%</progress><span>${pct}%</span></div>
820 <p>
821 Service logs:
822 <a href="?cookorder.log">cookorder</a> ·
823 <a href="?commits.log">commits</a> ·
824 <a href="?pkgdb.log">pkgdb</a>
825 </p>
826 </section>
827 EOT
829 tac $activity | head -n12 | sed 's|cooker.cgi?pkg=||;
830 s|\[ Done|<span class="r c20">Done|;
831 s|\[ Failed|<span class="r c10">Failed|;
832 s| \]|</span>|;
833 s|%2B|\+|g' | \
834 section $activity 12 "Activity|More activity"
836 [ -s "$cooknotes" ] && tac $cooknotes | head -n12 | \
837 section $cooknotes 12 "Cooknotes|More notes"
839 [ -s "$commits" ] &&
840 section $commits 20 "Commits|More commits" < $commits
842 [ -s "$cooklist" ] && head -n 20 $cooklist | \
843 section $cooklist 20 "Cooklist|Full cooklist"
845 [ -s "$broken" ] && head -n20 $broken | sed "s|^[^']*|<a href='\0'>\0</a>|g" | \
846 section $broken 20 "Broken|All broken packages"
848 [ -s "$blocked" ] && sed "s|^[^']*|<a href='\0'>\0</a>|g" $blocked | \
849 section $blocked 12 "Blocked|All blocked packages"
851 cd $PKGS
852 ls -let *.tazpkg | awk '
853 (NR<=20){
854 sub(/:[0-9][0-9]$/, "", $9);
855 mon = index(" JanFebMarAprMayJunJulAugSepOctNovDec", $7) / 3;
856 printf("%d-%02d-%02d %s : <a href=\"get/%s\">%s</a>\n", $10, mon, $8, $9, $11, $11);
857 }' | \
858 section $activity 1000 "Latest cook"
860 echo '</div>'
861 datalist
862 page_footer
863 exit 0
864 fi
867 case "$cmd" in
868 '')
869 page_header
870 log=$LOGS/$pkg.log
872 # Package info.
873 if [ -f "$wok/$pkg/receipt" ]; then
874 pkg_info
875 else
876 if [ $(ls $wok/*$pkg*/receipt 2>/dev/null | wc -l) -eq 0 ]; then
877 echo "<h2>Not Found</h2>"
878 show_note e "The requested package <b>$pkg</b> was not found on this server."
879 else
880 # Search page
881 echo "<section><h2>Package names matching “$pkg”</h2>"
882 echo "<table><thead><tr><th>Name</th><th>Description</th><th>Category</th></tr></thead><tbody>"
883 for i in $(cd $wok; ls *$pkg*/receipt); do
884 pkg=$(dirname $i)
885 unset SHORT_DESC CATEGORY
886 . $wok/$pkg/receipt
887 echo -n "<tr><td><a href="$base/$pkg">$pkg</a></td>"
888 echo -n "<td>$SHORT_DESC</td><td>$CATEGORY</td></tr>"
889 done
890 echo '</tbody></table></section>'
891 unset pkg
892 fi
893 page_footer
894 exit 0
895 fi
897 # Check for a log file and display summary if it exists.
898 summary "$log"
900 # Display <Recook> button only for SliTaz web browser
901 if [ -f "$log" ]; then
902 case "$HTTP_USER_AGENT" in
903 *SliTaz*)
904 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
905 if grep -qs "^$pkg$" $CACHE/recook-packages; then
906 show_note i "The package “$pkg” has been requested for recook"
907 else
908 echo "<a class='button' href='$base/?recook=${pkg//+/%2B}'>Recook $pkg</a>"
909 fi
910 fi
911 ;;
912 esac
913 fi
914 ;;
916 receipt)
917 page_header
918 pkg_info
919 echo "<a class='button receipt' href='$base/$pkg/receipt'>receipt</a>"
920 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
921 awk -vb="$base/$pkg" '{printf("<a class=\"button\" href=\"%s/%s\">%s</a>\n", b, $0, $0)}'
923 show_code bash < $wok/$pkg/receipt
924 ;;
926 stuff)
927 page_header
928 pkg_info
929 file="$pkg/stuff/$arg"
930 echo "<a class='button' href='$base/$pkg/receipt'>receipt</a>"
931 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
932 awk -vb="$base/$pkg" -va="stuff/$arg" '{
933 printf("<a class=\"button%s\" href=\"%s/%s\">%s</a>\n", a==$0 ? " receipt" : "", b, $0, $0)
934 }'
936 if [ -f "$wok/$file" ]; then
937 case $file in
938 *.desktop|*.theme) class="ini" ;;
939 *.patch|*.diff|*.u) class="diff" ;;
940 *.sh) class="bash" ;;
941 *.conf*|*.ini)
942 class="bash"
943 [ -n "$(cut -c1 < $wok/$file | fgrep '[')" ] && class="ini"
944 ;;
945 *.pl) class="perl" ;;
946 *.c|*.h|*.awk) class="clike" ;;
947 *.svg) class="svg" ;;
948 *Makefile*) class="makefile" ;;
949 *.po|*.pot) class="bash" ;;
950 *.css) class="css" ;;
951 *.htm|*.html) class="html" ;;
952 *.js) class="js" ;;
953 *.txt) class="asciidoc" ;;
954 *)
955 case $(head -n1 $wok/$file) in
956 *!/bin/sh*|*!/bin/bash*) class="bash" ;;
957 esac
958 if [ -z "$class" -a "$(head -n1 $wok/$file | cut -b1)" == '#' ]; then
959 class="bash"
960 fi
961 if [ -z "$class" ]; then
962 # Follow Busybox restrictions. Search for non-printable chars
963 if [ $(tr -d '[:alnum:][:punct:][:blank:][:cntrl:]' < "$wok/$file" | wc -c) -gt 0 ]; then
964 raw="true"
965 fi
966 fi
967 ;;
968 esac
970 # Display image
971 case $file in
972 *.png|*.svg|*.jpg|*.jpeg|*.ico)
973 echo "<img src='$base/$pkg/browse/stuff/$arg' style='display: block; max-width: 100%; margin: auto'/>"
974 ;;
975 esac
977 # Display colored listing for all text-based documents (also for *.svg)
978 case $file in
979 *.png|*.jpg|*.jpeg|*.ico) ;;
980 *)
981 if [ -z "$raw" ]; then
982 cat $wok/$file | show_code $class
983 fi
984 ;;
985 esac
987 # Display hex dump for binary files
988 if [ -n "$raw" ]; then
989 hexdump -C $wok/$file | show_code #| sed 's|^\([0-9a-f][0-9a-f]*\)|<span class="c2">\1</span>|'
990 fi
991 else
992 show_note e "File “$file” absent!"
993 fi
994 ;;
996 files)
997 page_header
998 pkg_info
1000 packaged=$(mktemp)
1002 # find main package
1003 wanted=$(. $wok/$pkg/receipt; echo $WANTED)
1004 main=${wanted:-$pkg}
1006 # identify split packages
1007 split="$main $(. $wok/$main/receipt; echo $SPLIT)"
1008 [ -d "$wok/$main-dev" ] && split="$split $main-dev"
1009 split="$(echo $split | tr ' ' '\n' | sort -u)"
1011 # finally we need the version
1012 if [ -f "$WOK/linux/receipt" ]; then
1013 kvers=$(. $WOK/linux/receipt; echo $VERSION)
1014 kbasevers=$(echo $kvers | cut -d. -f1,2)
1015 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
1016 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
1017 kbasevers=$(echo $kvers | cut -d. -f1,2)
1018 fi
1019 ver=$(. $wok/$main/receipt; echo $VERSION$EXTRAVERSION)
1021 for p in $split; do
1022 namever="$p-$ver"
1023 if [ -d "$wok/$p/taz/$p-$ver" ]; then
1024 indir=$p
1025 elif [ -d "$wok/$main/taz/$p-$ver" ]; then
1026 indir=$main
1027 fi
1028 dir="$wok/$indir/taz/$p-$ver/fs"
1030 size=$(du -hs $dir | awk '{ sub(/\.0/, ""); print $1 }')
1032 echo "<section><h3>Files of package “$namever” (${size:-empty}):</h3>"
1033 echo '<pre class="files">'
1034 if [ -s "$wok/$indir/taz/$p-$ver/files.list" ]; then
1035 echo -n '<span class="underline">permissions·lnk·user ·'
1036 echo -en 'group · size·date &amp; time ·file name\n</span>'
1037 cd $dir
1038 find . -not -type d -print0 | sort -z | xargs -0 ls -ld --color=always | \
1039 syntax_highlighter files | \
1040 sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$indir/browse/taz/$p-$ver/fs\2'>\2\3|" | \
1041 awk 'BEGIN { FS="\""; }
1042 { gsub("+", "%2B", $2); print; }'
1043 else
1044 echo 'No files'
1045 fi
1046 echo '</pre></section>'
1047 cat $wok/$indir/taz/$p-$ver/files.list >> $packaged
1048 done
1050 # find repeatedly packaged files
1051 repeats="$(sort $packaged | uniq -d)"
1052 if [ -n "$repeats" ]; then
1053 echo -n '<section><h3>Repeatedly packaged files:</h3><pre class="files">'
1054 echo "$repeats" | sed 's|^|<span class="c11">!!!</span> |'
1055 echo "</pre></section>"
1056 fi
1058 # find unpackaged files
1059 all_files=$(mktemp)
1060 cd $wok/$main/install; find ! -type d | sed 's|\.||' > $all_files
1061 orphans="$(sort $all_files $packaged | uniq -u)"
1062 if [ -d "$wok/$main/install" -a -n "$orphans" ]; then
1063 echo '<section><h3>Unpackaged files:</h3>'
1064 table=$(mktemp)
1065 echo "$orphans" | awk '
1066 function tag(text, color) { printf("<span class=\"c%s1\">%s</span> %s\n", color, text, $0); }
1067 /\/perllocal.pod$/ || /\/\.packlist$/ || /\/share\/bash-completion\// ||
1068 /\/lib\/systemd\// || /\.pyc$/ || /\.pyo$/ { tag("---", 0); next }
1069 /\.pod$/ { tag("pod", 5); next }
1070 /\/share\/man\// { tag("man", 5); next }
1071 /\/share\/doc\// || /\/share\/gtk-doc\// || /\/share\/info\// ||
1072 /\/share\/devhelp\// { tag("doc", 5); next }
1073 /\/share\/icons\// { tag("ico", 2); next }
1074 /\/share\/locale\// { tag("loc", 4); next }
1075 /\.h$/ || /\.a$/ || /\.la$/ || /\.pc$/ || /\/bin\/.*-config$/ { tag("dev", 3); next }
1076 { tag("???", 1) }
1077 ' > $table
1079 # Summary table
1080 for i in head body; do
1081 case $i in
1082 head) echo -n '<table class="summary"><tr>';;
1083 body) echo -n '<th> </th></tr><tr>';;
1084 esac
1085 for j in '???1' dev3 loc4 ico2 doc5 man5 pod5 '---0'; do
1086 tag=${j:0:3}; class="c${j:3:1}0"; [ "$class" == 'c00' ] && class='c01'
1087 case $i in
1088 head) echo -n "<th class='$class'>$tag</th>";;
1089 body) printf '<td>%s</td>' "$(grep ">$tag<" $table | wc -l)";;
1090 esac
1091 done
1092 done
1093 echo '<td> </td></tr></table>'
1095 echo -n '<pre class="files">'
1096 cat $table
1097 echo '</pre></section>'
1098 rm $table
1099 fi
1100 rm $packaged $all_files
1101 ;;
1103 description)
1104 page_header
1105 pkg_info
1106 descs="$(ls $WOK/$pkg/description*.txt)"
1107 if [ -n "$descs" ]; then
1108 echo '<div id="content2">'
1109 [ -f "$WOK/$pkg/description.txt" ] && show_desc "$pkg" "$WOK/$pkg/description.txt"
1110 for i in $descs; do
1111 case $i in
1112 */description.txt) continue ;;
1113 *) package=$(echo $i | cut -d. -f2) ;;
1114 esac
1115 show_desc "$package" "$i"
1116 done
1117 echo '</div>'
1118 else
1119 show_note w "No description of $pkg"
1120 fi
1121 ;;
1123 log)
1124 page_header
1125 pkg_info
1126 [ -z "$arg" ] && arg=$(stat -c %Y $LOGS/$pkg.log)
1128 echo '<div class="btnList">'
1129 acc='l'
1130 while read log; do
1131 timestamp=$(stat -c %Y $log)
1132 class=''
1133 if [ "$arg" == "$timestamp" ]; then
1134 class=' log'
1135 logfile="$log"
1136 fi
1137 echo -n "<a class='button$class' data-acc='$acc' accesskey='$acc' href='$base/$pkg/log/$timestamp'>"
1138 echo "$(stat -c %y $log | cut -d: -f1,2)</a>"
1139 case $acc in
1140 l) acc=0;;
1141 *) acc=$((acc+1));;
1142 esac
1143 done <<EOT
1144 $(find $LOGS -name "$pkg.log*" | sort)
1145 EOT
1146 echo '</div>'
1148 if [ -z "$logfile" ]; then
1149 show_note e "Requested log is absent"
1150 page_footer
1151 exit 0
1152 fi
1154 # Define cook variables for syntax highlighter
1155 if [ -s "$WOK/$pkg/receipt" ]; then
1156 . "$WOK/$pkg/receipt"
1157 _wok='/home/slitaz/wok'
1158 _src="$_wok/$pkg/source/$PACKAGE-$VERSION"
1159 _install="$_wok/$pkg/install"
1160 _fs="$_wok/$pkg/taz/$PACKAGE-$VERSION/fs"
1161 _stuff="$_wok/$pkg/stuff"
1162 fi
1164 # if [ ! -f "gzlog/$pkg.$arg" ]; then
1165 # {
1166 # summary "$logfile" links
1168 # syntax_highlighter log < $logfile | awk '
1169 # BEGIN { print "<pre class=\"log\">"; }
1170 # { printf("<a name=\"l%d\" href=\"#l%d\">%5d</a> %s\n", NR, NR, NR, $0); }
1171 # END { print "</pre>"; }
1172 # '
1174 # page_footer
1175 # } | gzip > gzlog/$pkg.$arg
1176 # fi
1178 blog=$(basename $logfile)
1179 summary "$logfile" links
1181 # disable next `sed` for the 'like2016' theme
1182 theme=$(COOKIE theme); theme=${theme:-default}; [ "$theme" != 'like2016' ] && theme=''
1183 cat $logfile | syntax_highlighter log | \
1184 sed -e "/(pkg\/local$theme):/ s|: \([^<]*\)|<img src='$base/i/$blog/\1'> \1|" | \
1185 awk '
1186 BEGIN { print "<pre class=\"log\">"; }
1187 { printf("<a name=\"l%d\" href=\"#l%d\">%5d</a> %s\n", NR, NR, NR, $0); }
1188 END { print "</pre>"; }
1190 ;;
1193 man|doc|info)
1194 page_header
1195 pkg_info
1196 echo '<div style="max-height: 6.4em; overflow: auto; padding: 0 4px">'
1198 dir="wok/$pkg/install/usr/share/$cmd"
1199 [ "$cmd" == 'doc' ] && dir="$dir wok/$pkg/install/usr/share/gtk-doc"
1200 if [ "$cmd" == 'doc' -a -z "$arg" ]; then
1201 try=$(for i in $dir; do find $i -name 'index.htm*'; done | sed q)
1202 [ -n "$try" ] && arg="$try"
1203 fi
1204 while read i; do
1205 [ -s "$i" ] || continue
1206 case "$i" in
1207 *.jp*g|*.png|*.gif|*.svg|*.css) continue
1208 esac
1209 i=${i#$dir/}
1210 [ -n "$arg" ] || arg="$i"
1211 class=''; [ "$arg" == "$i" ] && class=" doc"
1212 case "$cmd" in
1213 man)
1214 case $i in
1215 man*) lang='';;
1216 *) lang="${i%%/*}: ";;
1217 esac
1218 man=$(basename $i .gz)
1219 echo "<a class='button$class' href='$base/$pkg/man/$i'>$lang${man%.*} (${man##*.})</a>"
1220 ;;
1221 doc)
1222 echo "<a class='button$class' href='$base/$pkg/doc/$i'>$(basename $i .gz)</a>"
1223 ;;
1224 info)
1225 info=$(basename $i)
1226 echo "<a class='button$class' href='$base/$pkg/info/$i#Top'>${info/.info/}</a>"
1227 ;;
1228 esac
1229 done <<EOT
1230 $(for i in $dir; do find $i -type f; done | sort)
1231 EOT
1232 echo '</div>'
1234 [ -f "$arg" ] || arg="$dir/$arg"
1235 if [ -f "$arg" ]; then
1236 tmp="$(mktemp)"
1237 docat "$arg" > $tmp
1238 [ -s "$tmp" ] &&
1239 case "$cmd" in
1240 info)
1241 echo '<div id="content2" class="texinfo"><pre class="first">'
1242 info2html < "$tmp"
1243 echo '</pre></div>'
1244 ;;
1245 doc)
1246 case "$arg" in
1247 *.sgml|*.devhelp2) class='xml';;
1248 *.py) class='python';; # pycurl package
1249 *.css) class='css';;
1250 *) class='asciidoc';;
1251 esac
1252 case "$arg" in
1253 *.htm*)
1254 case $arg in
1255 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
1256 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
1257 esac
1258 # make the iframe height so long to contain its content without scrollbar
1259 echo "<iframe id='idoc' src='$page' width='100%' onload='resizeIframe(this)'></iframe>"
1260 ;;
1261 *.pdf)
1262 case $arg in
1263 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
1264 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
1265 esac
1266 cat <<EOT
1267 <object id="idoc" data="$page" width="100%" height="100%" type="application/pdf" style="min-height: 600px">
1268 $(show_note w "Missing PDF plugin.<br/>Get the file <a href="$page">$(basename "$page")</a>.")
1269 </object>
1270 EOT
1271 ;;
1272 *)
1273 show_code $class < "$tmp"
1274 ;;
1275 esac
1276 ;;
1277 man)
1278 #export TEXTDOMAIN='man2html'
1279 echo "<div id='content2'>"
1281 html=$(./man2html "$tmp" | sed -e '1,/<header>/d' -e '/<footer>/,$d' \
1282 -e 's|<a href="file:///[^>]*>\([^<]*\)</a>|\1|g' \
1283 -e 's|<a href="?[1-9]\+[^>]*>\([^<]*\)</a>|\1|g')
1285 if [ -n "$(echo "$html" | fgrep 'The requested file /tmp/tmp.')" ]; then
1286 # Process the pre-formatted man-cat page
1287 # (for example see sudo package without groff in build dependencies)
1288 sed -i '
1289 s|M-bM-^@M-^S|—|g;
1290 s|M-bM-^@M-^\\|<b>|g;
1291 s|M-bM-^@M-^]|</b>|g
1292 s|M-bM-^@M-^X|<u>|g;
1293 s|M-bM-^@M-^Y|</u>|g;
1294 s|M-BM-||g;
1295 s|++oo|•|g;
1296 s|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g;
1297 ' "$tmp"
1298 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 \
1299 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 \
1300 0 1 2 3 4 5 6 7 8 9 _ - '\\+' '\.' /; do
1301 sed -i "s|$i$i|<b>$i</b>|g; s|_$i|<u>$i</u>|g" "$tmp"
1302 done
1303 echo '<pre class="catman">'
1304 sed 's|</b><b>||g; s|</u><u>||g; s|</u><b>_</b><u>|_|g; s|</b> <b>| |g;' "$tmp"
1305 echo '</pre>'
1306 else
1307 echo "$html"
1308 fi
1309 echo "</div>"
1310 ;;
1311 esac
1312 rm -f $tmp
1313 else
1314 show_note e "File “$arg” not exists!"
1315 fi
1316 ;;
1318 esac
1321 page_footer
1322 exit 0