cookutils view web/cooker.cgi @ rev 1140

cooker.cgi: use http download
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Jun 08 16:40:51 2019 +0200 (2019-06-08)
parents 4e8c86306ce2
children e69f1fca1e39
line source
1 #!/bin/sh
2 #
3 # SliTaz Cooker CGI/web interface.
4 #
6 . /usr/lib/slitaz/httphelper.sh
8 [ -f "/etc/slitaz/cook.conf" ] && . /etc/slitaz/cook.conf
9 [ -f "cook.conf" ] && . ./cook.conf
11 # The same wok as cook.
12 wok="$WOK"
14 # Cooker DB files.
15 activity="$CACHE/activity"
16 commits="$CACHE/commits"
17 cooklist="$CACHE/cooklist"
18 cookorder="$CACHE/cookorder"
19 command="$CACHE/command"; touch $command
20 blocked="$CACHE/blocked"
21 broken="$CACHE/broken"
22 cooknotes="$CACHE/cooknotes"
23 cooktime="$CACHE/cooktime"
24 wokrev="$CACHE/wokrev"
26 # We're not logged and want time zone to display correct server date.
27 export TZ=$(cat /etc/TZ)
29 case "$QUERY_STRING" in
30 recook=*)
31 case "$HTTP_USER_AGENT" in
32 *SliTaz*)
33 grep -qs "^${QUERY_STRING#recook=}$" $CACHE/recook-packages ||
34 echo ${QUERY_STRING#recook=} >> $CACHE/recook-packages
35 esac
36 cat <<EOT
37 Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}
39 EOT
40 exit ;;
41 poke)
42 touch $CACHE/cooker-request
43 cat <<EOT
44 Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}
46 EOT
47 exit ;;
48 src*)
49 file="$PKGS/${QUERY_STRING#*=}"
50 cat <<EOT
51 Content-Type: application/octet-stream
52 Content-Length: $(stat -c %s "$file")
53 Content-Disposition: attachment; filename="$(basename "$file")"
55 EOT
56 cat "$file"
57 exit ;;
58 download*)
59 file="$PKGS/${QUERY_STRING#*=}"
60 cat <<EOT
61 Content-Type: application/octet-stream
62 Content-Length: $(stat -c %s "$file")
63 Content-Disposition: attachment; filename="$(basename "$file")"
65 EOT
66 cat "$file"
67 exit ;;
68 rss)
69 cat <<EOT
70 Content-Type: application/rss+xml
72 EOT
73 ;;
74 *)
75 cat <<EOT
76 Content-Type: text/html; charset=utf-8
78 EOT
79 ;;
80 esac
83 # RSS feed generator
84 if [ "$QUERY_STRING" == 'rss' ]; then
85 pubdate=$(date -R)
86 cat <<EOT
87 <?xml version="1.0" encoding="utf-8" ?>
88 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
89 <channel>
90 <title>SliTaz Cooker</title>
91 <description>The SliTaz packages cooker feed</description>
92 <link>$COOKER_URL</link>
93 <lastBuildDate>$pubdate</lastBuildDate>
94 <pubDate>$pubdate</pubDate>
95 <atom:link href="http://cook.slitaz.org/?rss" rel="self" type="application/rss+xml" />
96 EOT
97 for rss in $(ls -lt $FEEDS/*.xml | head -n 12); do
98 cat $rss | sed 's|<guid|& isPermaLink="false"|g;s|</pubDate| GMT&|g'
99 done
100 cat <<EOT
101 </channel>
102 </rss>
103 EOT
104 exit 0
105 fi
108 #
109 # Functions
110 #
113 # Unpack to stdout
115 docat() {
116 case "$1" in
117 *gz) zcat ;;
118 *bz2) bzcat ;;
119 *xz) xzcat ;;
120 *) cat
121 esac < $1
122 }
125 # Tiny texinfo browser
127 info2html() {
128 sed \
129 -e 's|&|\&amp;|g' -e 's|<|\&lt;|g' \
130 -e 's|^\* \(.*\)::|* <a href="#\1">\1</a> |' \
131 -e 's|\*note \(.*\)::|<a href="#\1">\1</a>|' \
132 -e '/^File: /s|(dir)|Top|g' \
133 -e '/^File: /s|Node: \([^,]*\)|Node: <a name="\1"></a><u>\1</u>|' \
134 -e '/^File: /s|Next: \([^,]*\)|Next: <a href="#\1">\1</a>|' \
135 -e '/^File: /s|Prev: \([^,]*\)|Prev: <a href="#\1">\1</a>|' \
136 -e '/^File: /s|Up: \([^,]*\)|Up: <a href="#\1">\1</a>|' \
137 -e '/^File: /s|^.*$|<i>&</i>|' \
138 -e '/^Tag Table:$/,/^End Tag Table$/d' \
139 -e '/INFO-DIR/,/^END-INFO-DIR/d' \
140 -e "s|https*://[^>),'\"\` ]*|<a href=\"&\">&</a>|g" \
141 -e "s|ftp://[^>),\"\` ]*|<a href=\"&\">&</a>|g" \
142 -e "s|^|</pre><pre>|"
143 }
146 # Put some colors in log and DB files.
148 syntax_highlighter() {
149 case $1 in
150 log)
151 # If variables not defined - define them with some rare values
152 : ${_src=#_#_#}
153 : ${_install=#_#_#}
154 : ${_fs=#_#_#}
155 : ${_stuff=#_#_#}
156 sed -e 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g' \
157 -e 's#OK$#<span class="span-ok">OK</span>#g' \
158 -e 's#Done$#<span class="span-ok">Done</span>#g' \
159 -e 's#done$#<span class="span-ok">done</span>#g' \
160 -e 's#\([^a-z]\)ok$#\1<span class="span-ok">ok</span>#g' \
161 -e 's#\([^a-z]\)yes$#\1<span class="span-ok">yes</span>#g' \
162 -e 's#\([^a-z]\)no$#\1<span class="span-no">no</span>#g' \
163 \
164 -e 's#\( \[Y[nm/]\?\] n\)$# <span class="span-no">\1</span>#g' \
165 -e 's#\( \[N[ym/]\?\] y\)$# <span class="span-ok">\1</span>#g' \
166 -e 's#(NEW) $#<span class="span-red">(NEW) </span>#g' \
167 \
168 -e 's#.*(pkg/local).*#<span class="span-ok">\0</span>#g' \
169 -e 's#.*(web/cache).*#<span class="span-no">\0</span>#g' \
170 \
171 -e 's#error$#<span class="span-red">error</span>#g' \
172 -e 's#ERROR:#<span class="span-red">ERROR:</span>#g' \
173 -e 's#Error#<span class="span-red">Error</span>#g' \
174 \
175 -e 's#^.*[Ff]ailed.*#<span class="span-red">\0</span>#g' \
176 -e 's#^.*[Ff]atal.*#<span class="span-red">\0</span>#g' \
177 -e 's#^.*[Nn]ot found.*#<span class="span-red">\0</span>#g' \
178 -e 's#^.*[Nn]o such file.*#<span class="span-red">\0</span>#g' \
179 \
180 -e 's#WARNING:#<span class="span-red">WARNING:</span>#g' \
181 -e 's#warning:#<span class="span-no">warning:</span>#g' \
182 -e 's#error:#<span class="span-no">error:</span>#g' \
183 -e 's#missing#<span class="span-no">missing</span>#g' \
184 \
185 -e 's#^.* will not .*#<span class="span-no">\0</span>#' \
186 -e 's!^Hunk .* succeeded at .*!<span class="span-no">\0</span>!' \
187 -e 's#^.* Warning: .*#<span class="span-no">\0</span>#' \
188 \
189 -e "s#^Executing:\([^']*\).#<span class='sh-val'>\0</span>#" \
190 -e "s#^Making.*#<span class='sh-val'>\0</span>#" \
191 -e "s#^====\([^']*\).#<span class='span-line'>\0</span>#g" \
192 -e "s#^[a-zA-Z0-9]\([^']*\) :: #<span class='span-sky'>\0</span>#g" \
193 -e "s#ftp://[^ '\"]*#<a href='\0'>\0</a>#g" \
194 -e "s#http://[^ '\"]*#<a href='\0'>\0</a>#g" \
195 -e "s|$_src|<span class='var'>\${src}</span>|g;
196 s|$_install|<span class='var'>\${install}</span>|g;
197 s|$_fs|<span class='var'>\${fs}</span>|g;
198 s|$_stuff|<span class='var'>\${stuff}</span>|g" \
199 -e "s|\[91m|<span style='color: #F00'>|;
200 s|\[92m|<span style='color: #080'>|;
201 s|\[93m|<span style='color: #FF0'>|;
202 s|\[94m|<span style='color: #00F'>|;
203 s|\[95m|<span style='color: #808'>|;
204 s|\[96m|<span style='color: #0CC'>|;
205 s|\[39m|</span>|;"
206 ;;
208 receipt)
209 sed -e s'|&|\&amp;|g' -e 's|<|\&lt;|g' -e 's|>|\&gt;|'g \
210 -e s"#^\#\([^']*\)#<span class='sh-comment'>\0</span>#"g \
211 -e s"#\"\([^']*\)\"#<span class='sh-val'>\0</span>#"g ;;
213 diff)
214 sed -e 's|&|\&amp;|g' -e 's|<|\&lt;|g' -e 's|>|\&gt;|g' \
215 -e s"#^-\([^']*\).#<span class='span-red'>\0</span>#"g \
216 -e s"#^+\([^']*\).#<span class='span-ok'>\0</span>#"g \
217 -e s"#@@\([^']*\)@@#<span class='span-sky'>@@\1@@</span>#"g ;;
219 activity)
220 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g ;;
221 esac
222 }
225 # Latest build pkgs.
227 list_packages() {
228 cd $PKGS
229 ls -1t *.tazpkg | head -n20 | \
230 while read file; do
231 echo -n $(TZ=UTC stat -c '%y' $PKGS/$file | cut -d. -f1 | sed s/:[0-9]*$//)
232 echo " : $file"
233 done
234 }
237 # Optional full list button
239 more_button() {
240 [ $(wc -l < ${3:-$CACHE/$1}) -gt ${4:-12} ] && cat <<EOT
241 <div style="float: right;">
242 <a class="button" href="?file=$1">$2</a>
243 </div>
244 EOT
245 }
248 # Show the running command and its progression
250 running_command()
251 {
252 local state="Not running"
253 if [ -s "$command" ]; then
254 state="$(cat $command)"
255 set -- $(grep "^$state" $cooktime)
256 if [ -n "$1" -a $2 -ne 0 ]; then
257 state="$state $((($(date +%s)-$3)*100/$2))%"
258 [ $2 -gt 300 ] && state="$state (should end $(date -u -d @$(($2+$3))))"
259 fi
260 fi
261 echo $state
262 }
265 # xHTML header. Pages can be customized with a separated html.header file.
267 if [ -f "header.html" ]; then
268 cat header.html
269 else
270 cat <<EOT
271 <!DOCTYPE html>
272 <html lang="en">
273 <head>
274 <meta charset="UTF-8">
275 <title>SliTaz Cooker</title>
276 <link rel="shortcut icon" href="favicon.ico">
277 <link rel="stylesheet" href="style.css">
278 <meta name="robots" content="nofollow">
279 </head>
280 <body>
282 <div id="header">
283 <div id="logo"></div>
284 <h1><a href="cooker.cgi">SliTaz Cooker</a></h1>
285 </div>
287 <!-- Content -->
288 <div id="content">
289 EOT
290 fi
293 #
294 # Load requested page
295 #
297 case "${QUERY_STRING}" in
298 pkg=*)
299 pkg=${QUERY_STRING#pkg=}
300 log=$LOGS/$pkg.log
301 echo "<h2>Package: $pkg</h2>"
303 # Define cook variables for syntax highlighter
304 if [ -s "$WOK/$pkg/receipt" ]; then
305 . "$WOK/$pkg/receipt"
306 _wok='/home/slitaz/wok'
307 _src="$_wok/$pkg/source/$PACKAGE-$VERSION"
308 _install="$_wok/$pkg/install"
309 _fs="$_wok/$pkg/taz/$PACKAGE-$VERSION/fs"
310 _stuff="$_wok/$pkg/stuff"
311 fi
313 # Package info.
314 echo '<div id="info">'
315 if [ -f "$wok/$pkg/receipt" ]; then
316 echo "<a href='?receipt=$pkg'>receipt</a>"
317 unset WEB_SITE
318 unset WANTED
319 bpkg=$pkg
320 . $wok/$pkg/receipt
322 [ -n "$WANTED" ] && bpkg="${WANTED%% *}" # see locale-* with multiple WANTED
323 [ -n "$WEB_SITE" ] && # busybox wget -s $WEB_SITE &&
324 echo "<a href='$WEB_SITE'>home</a>"
326 if [ -f "$wok/$pkg/taz/$PACKAGE-$VERSION/receipt" ]; then
327 echo "<a href='?files=$pkg'>files</a>"
328 unset EXTRAVERSION
329 . $wok/$pkg/taz/$PACKAGE-$VERSION/receipt
330 if [ -f $wok/$pkg/taz/$PACKAGE-$VERSION/description.txt ]; then
331 echo "<a href='?description=$pkg'>description</a>"
332 fi
333 if [ -f $PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg ]; then
334 echo "<a href='?download=$PACKAGE-$VERSION$EXTRAVERSION.tazpkg'>download</a>"
335 fi
336 if [ -f $PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg ]; then
337 echo "<a href='?download=$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg'>download</a>"
338 fi
339 fi
340 [ -x ./man2html ] &&
341 if [ -d $wok/$bpkg/install/usr/man ] ||
342 [ -d $wok/$bpkg/install/usr/share/man ] ||
343 [ -d $wok/$bpkg/taz/*/fs/usr/man ] ||
344 [ -d $wok/$bpkg/taz/*/fs/usr/share/man ]; then
345 echo "<a href='?man=$bpkg'>man</a>"
346 fi
347 if [ -d $wok/$bpkg/install/usr/doc ] ||
348 [ -d $wok/$bpkg/install/usr/share/doc ] ||
349 [ -d $wok/$bpkg/taz/*/fs/usr/doc ] ||
350 [ -d $wok/$bpkg/taz/*/fs/usr/share/doc ]; then
351 echo "<a href='?doc=$bpkg'>doc</a>"
352 fi
353 if [ -d $wok/$bpkg/install/usr/info ] ||
354 [ -d $wok/$bpkg/install/usr/share/info ] ||
355 [ -d $wok/$bpkg/taz/*/fs/usr/info ] ||
356 [ -d $wok/$bpkg/taz/*/fs/usr/share/info ]; then
357 echo "<a href='?info=$bpkg'>info</a>"
358 fi
359 [ -n "$(echo $REQUEST_URI | sed 's|/[^/]*?pkg.*||')" ] ||
360 echo "<a href='?browse=$pkg/'>browse</a>"
361 else
362 if [ $(ls $wok/*$pkg*/receipt 2>/dev/null | wc -l) -eq 0 ]; then
363 echo "No package named: $pkg"
364 else
365 ls $wok/$pkg/receipt >/dev/null 2>&1 || pkg="*$pkg*"
366 echo '<table style="width:100%">'
367 for i in $(cd $wok ; ls $pkg/receipt); do
368 pkg=$(dirname $i)
369 unset SHORT_DESC CATEGORY
370 . $wok/$pkg/receipt
371 cat <<EOT
372 <tr>
373 <td><a href="?pkg=$pkg">$pkg</a></td>
374 <td>$SHORT_DESC</td>
375 <td>$CATEGORY</td>
376 </tr>
377 EOT
378 done
379 echo '</table>'
380 unset pkg
381 fi
382 fi
383 echo '</div>'
385 # Check for a log file and display summary if it exists.
386 if [ -f "$log" ]; then
387 if grep -q "cook:$pkg$" $command; then
388 echo "<pre>The Cooker is currently building: $pkg</pre>"
389 fi
390 if fgrep -q "Summary for:" $LOGS/$pkg.log; then
391 echo '<h3>Cook summary</h3>'
392 echo '<pre>'
393 grep -A 12 "^Summary for:" $LOGS/$pkg.log | sed /^$/d | \
394 syntax_highlighter log
395 echo '</pre>'
396 fi
397 if fgrep -q "Debug information" $LOGS/$pkg.log; then
398 echo '<h3>Cook failed</h3>'
399 echo '<pre>'
400 grep -A 8 "^Debug information" $LOGS/$pkg.log | sed /^$/d | \
401 syntax_highlighter log
402 echo '</pre>'
403 fi
404 echo "<h3>Cook log $(stat -c %y $log | sed 's/:..\..*//')</h3>"
405 for i in $(ls -t $log.*); do
406 echo -n "<a href=\"?log=$(basename $i)\">"
407 echo "$(stat -c %y $i | sed 's/ .*//')</a>"
408 done
409 echo '<pre>'
410 cat $log | syntax_highlighter log
411 echo '</pre>'
412 case "$HTTP_USER_AGENT" in
413 *SliTaz*)
414 [ -f $CACHE/cooker-request ] && [ -n "$HTTP_REFERER" ] &&
415 echo "<a class=\"button\" href=\"?recook=$pkg\">Recook $pkg</a>"
416 esac
417 else
418 [ "$pkg" ] && echo "<pre>No log: $pkg</pre>"
419 fi ;;
421 view=*)
422 file="${QUERY_STRING#view=}"
423 echo "<h2>View: $file</h2>"
424 echo "<a href=\"?browse=?$file\">browse</a>"
425 echo "<pre>"
426 ls "$WOK/$file" | while read i; do
427 meta="$(ls -ld "$WOK/$file/$i" | cut -c-57)"
428 name="$i"
429 ref="stuff=../wok/$file$i"
430 [ -d "$WOK/$file/$i" ] && ref="view=$file$i/"
431 [ -L "$WOK/$file/$i" ] && name="$i -> $(readlink "$i")"
432 echo "$meta<a href=\"?$ref\">$name</a>"
433 done
434 echo "</pre>"
435 ;;
437 browse=*)
438 file="${QUERY_STRING#browse=}"
439 echo "<h2>Browse: $file</h2>"
440 echo "<pre>"
441 ls "$WOK/$file" | while read i; do
442 meta="$(ls -ld "$WOK/$file/$i" | cut -c-57)"
443 name="$i"
444 ref="download=../wok/$file$i"
445 [ -d "$WOK/$file/$i" ] && ref="browse=$file$i/"
446 [ -L "$WOK/$file/$i" ] && name="$i -> $(readlink "$i")"
447 echo "$meta<a href=\"?$ref\">$name</a>"
448 done
449 echo "</pre>"
450 ;;
452 log=*)
453 log=$LOGS/${QUERY_STRING#log=}
454 if [ -s $log ]; then
455 echo "<h3>Cook log $(stat -c %y $log | sed 's/:..\..*//')</h3>"
456 if fgrep -q "Summary" $log; then
457 echo '<pre>'
458 grep -A 20 "^Summary" $log | sed /^$/d | \
459 syntax_highlighter log
460 echo '</pre>'
461 fi
462 echo '<pre>'
463 cat $log | syntax_highlighter log
464 echo '</pre>'
465 fi
466 ;;
467 file=*)
468 # Don't allow all files on the system for security reasons.
469 file=${QUERY_STRING#file=}
470 case "$file" in
471 activity|cooknotes|cooklist)
472 [ "$file" == "cooklist" ] && \
473 nb="- Packages: $(cat $cooklist | wc -l)"
474 echo "<h2>DB: $file $nb</h2>"
475 echo '<pre>'
476 tac $CACHE/$file | syntax_highlighter activity
477 echo '</pre>' ;;
479 broken)
480 nb=$(cat $broken | wc -l)
481 echo "<h2>DB: broken - Packages: $nb</h2>"
482 echo '<pre>'
483 cat $CACHE/$file | sort | \
484 sed s"#^[^']*#<a href='?pkg=\0'>\0</a>#"g
485 echo '</pre>' ;;
487 *.diff)
488 diff=$CACHE/$file
489 echo "<h2>Diff for: ${file%.diff}</h2>"
490 [ "$file" == "installed.diff" ] && echo \
491 "<p>This is the latest diff between installed packages \
492 and installed build dependencies to cook.</p>"
493 echo '<pre>'
494 cat $diff | syntax_highlighter diff
495 echo '</pre>' ;;
497 *.log)
498 log=$LOGS/$file
499 name=$(basename $log)
500 echo "<h2>Log for: ${name%.log}</h2>"
501 if [ -f "$log" ]; then
502 if fgrep -q "Summary" $log; then
503 echo '<pre>'
504 grep -A 20 "^Summary" $log | sed /^$/d | \
505 syntax_highlighter log
506 echo '</pre>'
507 fi
508 echo '<pre>'
509 cat $log | syntax_highlighter log
510 echo '</pre>'
511 else
512 echo "<pre>No log file: $log</pre>"
513 fi ;;
514 esac ;;
516 stuff=*)
517 file=${QUERY_STRING#stuff=}
518 file="${file//%20/ }"
519 echo "<h2>$file</h2>"
520 #echo "<a href=\"?download=$file\">download</a>"
521 echo '<pre>'
522 cat "$wok/$file" | sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g'
523 echo '</pre>' ;;
525 receipt=*)
526 pkg=${QUERY_STRING#receipt=}
527 echo "<h2>Receipt for: $pkg</h2>"
528 if [ -f "$wok/$pkg/receipt" ]; then
529 . $wok/$pkg/receipt
530 [ -n "$TARBALL" ] && [ -s "$SRC/$TARBALL" ] &&
531 echo "<a href='?src=$TARBALL'>source</a>"
533 ( cd $wok/$pkg ; find stuff -type f 2> /dev/null ) | \
534 while read file ; do
535 echo "<a href=\"?stuff=$pkg/$file\">$file</a>"
536 done | sort
537 echo '<pre>'
538 cat $wok/$pkg/receipt | \
539 syntax_highlighter receipt
540 echo '</pre>'
541 else
542 echo "<pre>No receipt for: $pkg</pre>"
543 fi ;;
545 files=*)
546 pkg=${QUERY_STRING#files=}
547 dir=$(ls -d $WOK/$pkg/taz/$pkg-*)
548 if [ -d "$dir/fs" ]; then
549 echo "<h2>Installed files by: $pkg ($(du -hs $dir/fs | awk '{ print $1 }'))</h2>"
550 echo '<pre>'
551 find $dir/fs -not -type d -print0 | xargs -0 ls -ld | \
552 sed "s|^\(-.*\) /.*\(${dir#*wok}/fs\)\(.*\)|\1 <a href=\"?download=../wok\2\3\">\3</a>|;s| /[^>]*${dir#*wok}/fs| \1|"
553 echo '</pre>'
554 else
555 echo "<pre>No files list for: $pkg</pre>"
556 fi ;;
558 description=*)
559 pkg=${QUERY_STRING#description=}
560 echo "<h2>Description of $pkg</h2>"
561 dir=$(ls -d $WOK/$pkg/taz/$pkg-*)
562 if [ -s "$dir/description.txt" ]; then
563 echo '<pre>'
564 cat $dir/description.txt | \
565 sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g'
566 echo '</pre>'
567 else
568 echo "<pre>No description for: $pkg</pre>"
569 fi ;;
571 man=*|doc=*|info=*)
572 type=${QUERY_STRING%%=*}
573 pkg=$(GET $type)
574 dir=$WOK/$pkg/install/usr/share/$type
575 [ -d $dir ] || dir=$WOK/$pkg/install/usr/$type
576 [ -d $dir ] || dir=$(echo $WOK/$pkg/taz/*/fs/usr/share/$type)
577 [ -d $dir ] || dir=$(echo $WOK/$pkg/taz/*/fs/usr/$type)
578 page=$(GET file)
579 if [ -z "$page" ]; then
580 page=$(find $dir -type f | sed q)
581 page=${page#$dir/}
582 fi
583 find $dir -type f | while read file ; do
584 [ -s $file ] || continue
585 case "$file" in
586 *.jp*g|*.png|*.gif|*.svg) continue
587 esac
588 file=${file#$dir/}
589 echo "<a href='?$type=$pkg&amp;file=$file'>$(basename $file)</a>"
590 done | sort -t \> -k 2
591 echo "<h2>$(basename $page)</h2>"
592 tmp="$(mktemp)"
593 docat "$dir/$page" > $tmp
594 [ -s "$tmp" ] && case "$type" in
595 info)
596 echo '<pre>'
597 info2html < "$tmp"
598 echo '</pre>' ;;
599 doc)
600 echo '<pre>'
601 case "$page" in
602 *.htm*) cat ;;
603 *) sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g'
604 esac < "$tmp"
605 echo '</pre>' ;;
606 man)
607 export TEXTDOMAIN='man2html'
608 ./man2html "$tmp" | sed -e '1,/<header>/d' \
609 -e 's|<a href="file:///[^>]*>\([^<]*\)</a>|\1|g' \
610 -e 's|<a href="?[1-9]\+[^>]*>\([^<]*\)</a>|\1|g' ;;
611 esac
612 rm -f $tmp
613 ;;
614 *)
615 # We may have a toolchain.cgi script for cross cooker's
616 if [ -f "toolchain.cgi" ]; then
617 toolchain='toolchain.cgi'
618 else
619 toolchain='?pkg=slitaz-toolchain'
620 fi
621 # Main page with summary. Count only package include in ARCH,
622 # use 'cooker arch-db' to manually create arch.$ARCH files.
623 inwok=$(ls $WOK/*/arch.$ARCH | wc -l)
624 cooked=$(ls $PKGS/*.tazpkg | wc -l)
625 unbuilt=$(($inwok - $cooked))
626 pct=0
627 [ $inwok -gt 0 ] && pct=$(( ($cooked * 100) / $inwok ))
628 cat <<EOT
629 <div style="float: right;">
630 <form method="get" action="$SCRIPT_NAME">
631 Package:
632 <input type="text" name="pkg" />
633 </form>
634 </div>
636 <h2>Summary</h2>
638 <pre>
639 Running command : $(running_command)
640 Wok revision : <a href="$WOK_URL">$(cat $wokrev)</a>
641 Commits to cook : $(cat $commits | wc -l)
642 Current cooklist : $(cat $cooklist | wc -l)
643 Broken packages : $(cat $broken | wc -l)
644 Blocked packages : $(cat $blocked | wc -l)
645 </pre>
646 EOT
647 [ -e $CACHE/cooker-request ] &&
648 [ $CACHE/activity -nt $CACHE/cooker-request ] && cat <<EOT
649 <div style="float: right;">
650 <a class="button" href="?poke">Poke cooker</a>
651 </div>
652 EOT
653 cat <<EOT
654 <p class="info">
655 Packages: $inwok in the wok | $cooked cooked | $unbuilt unbuilt |
656 Server date: $(date -u '+%F %R %Z')
657 </p>
658 <div class="pctbar">
659 <div class="pct" style="width: ${pct}%;">${pct}%</div>
660 </div>
662 <p>
663 Latest:
664 <a href="?file=cookorder.log">cookorder.log</a>
665 <a href="?file=commits.log">commits.log</a>
666 <a href="?file=pkgdb.log">pkgdb.log</a>
667 <a href="?file=installed.diff">installed.diff</a>
668 - Architecture $ARCH:
669 <a href="$toolchain">toolchain</a>
670 </p>
672 $(more_button activity "More activity" $CACHE/activity 12)
673 <h2 id="activity">Activity</h2>
674 <pre>
675 $(tac $CACHE/activity | head -n 12 | syntax_highlighter activity)
676 </pre>
677 EOT
679 [ -s $cooknotes ] && cat <<EOT
680 $(more_button cooknotes "More notes" $cooknotes 12)
681 <h2 id="cooknotes">Cooknotes</h2>
682 <pre>
683 $(tac $cooknotes | head -n 12 | syntax_highlighter activity)
684 </pre>
685 EOT
687 [ -s $commits ] && cat <<EOT
688 <h2 id="commits">Commits</h2>
689 <pre>
690 $(cat $commits)
691 </pre>
692 EOT
694 [ -s $cooklist ] && cat <<EOT
695 $(more_button cooklist "Full cooklist" $cooklist 20)
696 <h2 id="cooklist">Cooklist</h2>
697 <pre>
698 $(cat $cooklist | head -n 20)
699 </pre>
700 EOT
702 [ -s $broken ] && cat <<EOT
703 $(more_button broken "All broken packages" $broken 20)
704 <h2 id="broken">Broken</h2>
705 <pre>
706 $(cat $broken | head -n 20 | sed s"#^[^']*#<a href='?pkg=\0'>\0</a>#"g)
707 </pre>
708 EOT
710 [ -s $blocked ] && cat <<EOT
711 <h2 id="blocked">Blocked</h2>
712 <pre>
713 $(cat $blocked | sed s"#^[^']*#<a href='?pkg=\0'>\0</a>#"g)
714 </pre>
715 EOT
717 cat <<EOT
718 <h2 id="lastcook">Latest cook</h2>
719 <pre>
720 $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
721 </pre>
722 EOT
723 ;;
724 esac
727 # Close xHTML page
729 cat <<EOT
730 </div>
732 <div id="footer">
733 <a href="http://www.slitaz.org/">SliTaz Website</a>
734 <a href="cooker.cgi">Cooker</a>
735 <a href="doc/cookutils/cookutils.en.html">Documentation</a>
736 </div>
738 </body>
739 </html>
740 EOT
742 exit 0