cookutils view web/cooker.cgi @ rev 1152

web/cooker.cgi: add browse/view toggle
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Jan 20 10:51:40 2023 +0000 (15 months ago)
parents 00665abb42f1
children
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/../src/${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 sed 's|<guid|& isPermaLink="false"|g;s|</pubDate| GMT&|g' $rss
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/local/man ] ||
343 [ -d $wok/$bpkg/install/usr/share/man ] ||
344 [ -d $wok/$bpkg/taz/*/fs/usr/man ] ||
345 [ -d $wok/$bpkg/taz/*/fs/usr/share/man ]; then
346 echo "<a href='?man=$bpkg'>man</a>"
347 fi
348 if [ -d $wok/$bpkg/install/usr/doc ] ||
349 [ -d $wok/$bpkg/install/usr/share/doc ] ||
350 [ -d $wok/$bpkg/taz/*/fs/usr/doc ] ||
351 [ -d $wok/$bpkg/taz/*/fs/usr/share/doc ]; then
352 echo "<a href='?doc=$bpkg'>doc</a>"
353 fi
354 if [ -d $wok/$bpkg/install/usr/info ] ||
355 [ -d $wok/$bpkg/install/usr/share/info ] ||
356 [ -d $wok/$bpkg/taz/*/fs/usr/info ] ||
357 [ -d $wok/$bpkg/taz/*/fs/usr/share/info ]; then
358 echo "<a href='?info=$bpkg'>info</a>"
359 fi
360 [ -n "$(echo $REQUEST_URI | sed 's|/[^/]*?pkg.*||')" ] ||
361 echo "<a href='?browse=$pkg/'>browse</a>"
362 else
363 if [ $(ls $wok/*$pkg*/receipt 2>/dev/null | wc -l) -eq 0 ]; then
364 echo "No package named: $pkg"
365 else
366 ls $wok/$pkg/receipt >/dev/null 2>&1 || pkg="*$pkg*"
367 echo '<table style="width:100%">'
368 for i in $(cd $wok ; ls $pkg/receipt); do
369 pkg=$(dirname $i)
370 unset SHORT_DESC CATEGORY
371 . $wok/$pkg/receipt
372 cat <<EOT
373 <tr>
374 <td><a href="?pkg=$pkg">$pkg</a></td>
375 <td>$SHORT_DESC</td>
376 <td>$CATEGORY</td>
377 </tr>
378 EOT
379 done
380 echo '</table>'
381 unset pkg
382 fi
383 fi
384 echo '</div>'
386 # Check for a log file and display summary if it exists.
387 if [ -f "$log" ]; then
388 if grep -q "cook:$pkg$" $command; then
389 echo "<pre>The Cooker is currently building: $pkg</pre>"
390 fi
391 if fgrep -q "Summary for:" $LOGS/$pkg.log; then
392 echo '<h3>Cook summary</h3>'
393 echo '<pre>'
394 grep -A 12 "^Summary for:" $LOGS/$pkg.log | sed /^$/d | \
395 syntax_highlighter log
396 echo '</pre>'
397 fi
398 if fgrep -q "Debug information" $LOGS/$pkg.log; then
399 echo '<h3>Cook failed</h3>'
400 echo '<pre>'
401 grep -A 8 "^Debug information" $LOGS/$pkg.log | sed /^$/d | \
402 syntax_highlighter log
403 echo '</pre>'
404 fi
405 echo "<h3>Cook log $(stat -c %y $log | sed 's/:..\..*//')</h3>"
406 for i in $(ls -t $log.*); do
407 echo -n "<a href=\"?log=$(basename $i)\">"
408 echo "$(stat -c %y $i | sed 's/ .*//')</a>"
409 done
410 echo '<pre>'
411 syntax_highlighter log < $log
412 echo '</pre>'
413 case "$HTTP_USER_AGENT" in
414 *SliTaz*)
415 [ -f $CACHE/cooker-request ] && [ -n "$HTTP_REFERER" ] &&
416 echo "<a class=\"button\" href=\"?recook=$pkg\">Recook $pkg</a>"
417 esac
418 else
419 [ "$pkg" ] && echo "<pre>No log: $pkg</pre>"
420 fi ;;
422 view=*)
423 file="${QUERY_STRING#view=}"
424 echo "<a href=\"?browse=$file\"><h2>View: $file</h2></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 "<a href=\"?view=$file\"><h2>Browse: $file</h2></a>"
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 syntax_highlighter log < $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: $(wc -l < $cooklist)"
474 echo "<h2>DB: $file $nb</h2>"
475 echo '<pre>'
476 tac $CACHE/$file | syntax_highlighter activity
477 echo '</pre>' ;;
479 broken)
480 nb=$(wc -l < $broken)
481 echo "<h2>DB: broken - Packages: $nb</h2>"
482 echo '<pre>'
483 sort < $CACHE/$file | \
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 syntax_highlighter diff < $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 syntax_highlighter log < $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 sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g' "$wok/$file"
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 syntax_highlighter receipt < $wok/$pkg/receipt
539 echo '</pre>'
540 else
541 echo "<pre>No receipt for: $pkg</pre>"
542 fi ;;
544 files=*)
545 pkg=${QUERY_STRING#files=}
546 dir=$(ls -d $WOK/$pkg/taz/$pkg-*)
547 if [ -d "$dir/fs" ]; then
548 echo "<h2>Installed files by: $pkg ($(du -hs $dir/fs | awk '{ print $1 }'))</h2>"
549 echo '<pre>'
550 find $dir/fs -not -type d -print0 | xargs -0 ls -ld | \
551 sed "s|^\(-.*\) /.*\(${dir#*wok}/fs\)\(.*\)|\1 <a href=\"?download=../wok\2\3\">\3</a>|;s| /[^>]*${dir#*wok}/fs| \1|"
552 echo '</pre>'
553 else
554 echo "<pre>No files list for: $pkg</pre>"
555 fi ;;
557 description=*)
558 pkg=${QUERY_STRING#description=}
559 echo "<h2>Description of $pkg</h2>"
560 dir=$(ls -d $WOK/$pkg/taz/$pkg-*)
561 if [ -s "$dir/description.txt" ]; then
562 echo '<pre>'
563 sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g' < $dir/description.txt
564 echo '</pre>'
565 else
566 echo "<pre>No description for: $pkg</pre>"
567 fi ;;
569 man=*|doc=*|info=*)
570 type=${QUERY_STRING%%=*}
571 pkg=$(GET $type)
572 dir=$WOK/$pkg/install/usr/share/$type
573 [ -d $dir ] || dir=$WOK/$pkg/install/usr/$type
574 [ -d $dir ] || dir=$(echo $WOK/$pkg/taz/*/fs/usr/share/$type)
575 [ -d $dir ] || dir=$(echo $WOK/$pkg/taz/*/fs/usr/$type)
576 page=$(GET file)
577 if [ -z "$page" ]; then
578 page=$(find $dir -type f | sed q)
579 page=${page#$dir/}
580 fi
581 find $dir -type f | while read file ; do
582 [ -s $file ] || continue
583 case "$file" in
584 *.jp*g|*.png|*.gif|*.svg) continue
585 esac
586 file=${file#$dir/}
587 echo "<a href='?$type=$pkg&amp;file=$file'>$(basename $file)</a>"
588 done | sort -t \> -k 2
589 echo "<h2>$(basename $page)</h2>"
590 tmp="$(mktemp)"
591 docat "$dir/$page" > $tmp
592 [ -s "$tmp" ] && case "$type" in
593 info)
594 echo '<pre>'
595 info2html < "$tmp"
596 echo '</pre>' ;;
597 doc)
598 echo '<pre>'
599 case "$page" in
600 *.htm*) cat ;;
601 *) sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g'
602 esac < "$tmp"
603 echo '</pre>' ;;
604 man)
605 export TEXTDOMAIN='man2html'
606 ./man2html "$tmp" | sed -e '1,/<header>/d' \
607 -e 's|<a href="file:///[^>]*>\([^<]*\)</a>|\1|g' \
608 -e 's|<a href="?[1-9]\+[^>]*>\([^<]*\)</a>|\1|g' ;;
609 esac
610 rm -f $tmp
611 ;;
612 *)
613 # We may have a toolchain.cgi script for cross cooker's
614 if [ -f "toolchain.cgi" ]; then
615 toolchain='toolchain.cgi'
616 else
617 toolchain='?pkg=slitaz-toolchain'
618 fi
619 # Main page with summary. Count only package include in ARCH,
620 # use 'cooker arch-db' to manually create arch.$ARCH files.
621 inwok=$(ls $WOK/*/arch.$ARCH | wc -l)
622 cooked=$(ls $PKGS/*.tazpkg | wc -l)
623 unbuilt=$(($inwok - $cooked))
624 pct=0
625 [ $inwok -gt 0 ] && pct=$(( ($cooked * 100) / $inwok ))
626 cat <<EOT
627 <div style="float: right;">
628 <form method="get" action="$SCRIPT_NAME">
629 Package:
630 <input type="text" name="pkg" />
631 </form>
632 </div>
634 <h2>Summary</h2>
636 <pre>
637 Running command : $(running_command)
638 Wok revision : <a href="$WOK_URL">$(cat $wokrev)</a>
639 Commits to cook : $(wc -l < $commits)
640 Current cooklist : $(wc -l < $cooklist)
641 Broken packages : $(wc -l < $broken)
642 Blocked packages : $(wc -l < $blocked)
643 </pre>
644 EOT
645 [ -e $CACHE/cooker-request ] &&
646 [ $CACHE/activity -nt $CACHE/cooker-request ] && cat <<EOT
647 <div style="float: right;">
648 <a class="button" href="?poke">Poke cooker</a>
649 </div>
650 EOT
651 cat <<EOT
652 <p class="info">
653 Packages: $inwok in the wok | $cooked cooked | $unbuilt unbuilt |
654 Server date: $(date -u '+%F %R %Z')
655 </p>
656 <div class="pctbar">
657 <div class="pct" style="width: ${pct}%;">${pct}%</div>
658 </div>
660 <p>
661 Latest:
662 <a href="?file=cookorder.log">cookorder.log</a>
663 <a href="?file=commits.log">commits.log</a>
664 <a href="?file=pkgdb.log">pkgdb.log</a>
665 <a href="?file=installed.diff">installed.diff</a>
666 - Architecture $ARCH:
667 <a href="$toolchain">toolchain</a>
668 </p>
670 $(more_button activity "More activity" $CACHE/activity 12)
671 <h2 id="activity">Activity</h2>
672 <pre>
673 $(tac $CACHE/activity | head -n 12 | syntax_highlighter activity)
674 </pre>
675 EOT
677 [ -s $cooknotes ] && cat <<EOT
678 $(more_button cooknotes "More notes" $cooknotes 12)
679 <h2 id="cooknotes">Cooknotes</h2>
680 <pre>
681 $(tac $cooknotes | head -n 12 | syntax_highlighter activity)
682 </pre>
683 EOT
685 [ -s $commits ] && cat <<EOT
686 <h2 id="commits">Commits</h2>
687 <pre>
688 $(cat $commits)
689 </pre>
690 EOT
692 [ -s $cooklist ] && cat <<EOT
693 $(more_button cooklist "Full cooklist" $cooklist 20)
694 <h2 id="cooklist">Cooklist</h2>
695 <pre>
696 $(head -n 20 $cooklist)
697 </pre>
698 EOT
700 [ -s $broken ] && cat <<EOT
701 $(more_button broken "All broken packages" $broken 20)
702 <h2 id="broken">Broken</h2>
703 <pre>
704 $(tac $broken | sed "1,20!d;s#^[^']*#<a href='?pkg=\0'>\0</a>#g")
705 </pre>
706 EOT
708 [ -s $blocked ] && cat <<EOT
709 <h2 id="blocked">Blocked</h2>
710 <pre>
711 $(sed s"#^[^']*#<a href='?pkg=\0'>\0</a>#"g < $blocked)
712 </pre>
713 EOT
715 cat <<EOT
716 <h2 id="lastcook">Latest cook</h2>
717 <pre>
718 $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
719 </pre>
720 EOT
721 ;;
722 esac
725 # Close xHTML page
727 cat <<EOT
728 </div>
730 <div id="footer">
731 <a href="http://www.slitaz.org/">SliTaz Website</a>
732 <a href="cooker.cgi">Cooker</a>
733 <a href="doc/cookutils/cookutils.en.html">Documentation</a>
734 </div>
736 </body>
737 </html>
738 EOT
740 exit 0