cookutils view web/cooker.cgi @ rev 892
web/cooker.cgi: tiny edits
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Fri Mar 17 02:42:26 2017 +0200 (2017-03-17) |
parents | 080dd0a18d2e |
children | eff71eaaee4f |
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 # Path to sundown (markdown to html convertor)
27 if [ -n "$(which sundown 2>/dev/null)" ]; then
28 SUNDOWN=$(which sundown)
29 elif [ -x "./sundown" ]; then
30 SUNDOWN="./sundown"
31 fi
33 # We're not logged and want time zone to display correct server date.
34 export TZ=$(cat /etc/TZ)
36 case "$QUERY_STRING" in
37 recook=*)
38 case "$HTTP_USER_AGENT" in
39 *SliTaz*)
40 grep -qs "^${QUERY_STRING#recook=}$" $CACHE/recook-packages ||
41 echo ${QUERY_STRING#recook=} >> $CACHE/recook-packages
42 esac
43 cat <<EOT
44 Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}
46 EOT
47 exit
48 ;;
50 poke)
51 touch $CACHE/cooker-request
52 cat <<EOT
53 Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}
55 EOT
56 exit
57 ;;
59 src*)
60 file=$(busybox httpd -d "$SRC/${QUERY_STRING#*=}")
61 cat <<EOT
62 Content-Type: application/octet-stream
63 Content-Length: $(stat -c %s "$file")
64 Content-Disposition: attachment; filename="$(basename "$file")"
66 EOT
67 cat "$file"
68 exit
69 ;;
71 download*)
72 file=$(busybox httpd -d "$PKGS/${QUERY_STRING#*=}")
73 content_type='application/octet-stream'
74 case $file in
75 *.txt|*.conf|*/README|*/receipt)
76 content_type='text/plain; charset=UTF-8' ;;
77 *.css) content_type='text/css; charset=UTF-8' ;;
78 *.htm|*.html) content_type='text/html; charset=UTF-8' ;;
79 *.js) content_type='application/javascript; charset=UTF-8' ;;
80 *.desktop) content_type='application/x-desktop; charset=UTF-8' ;;
81 *.png) content_type='image/png' ;;
82 *.svg) content_type='image/svg+xml' ;;
83 *.jpg|*.jpeg) content_type='image/jpeg' ;;
84 *.sh|*.cgi) content_type='application/x-shellscript' ;;
85 *.gz) content_type='application/gzip' ;;
86 *.ico) content_type='image/vnd.microsoft.icon' ;;
87 esac
88 echo "Content-Type: $content_type"
89 echo "Content-Length: $(stat -c %s "$file")"
90 [ "$content_type" == 'application/octet-stream' ] &&
91 echo "Content-Disposition: attachment; filename=\"$(basename "$file")\""
93 echo
95 cat "$file"
96 exit
97 ;;
99 rss)
100 echo -e 'Content-Type: application/rss+xml\n'
101 ;;
103 *)
104 echo -e 'Content-Type: text/html; charset=UTF-8\n'
105 ;;
107 esac
110 # RSS feed generator
111 if [ "$QUERY_STRING" == 'rss' ]; then
112 pubdate=$(date -R)
113 cat <<EOT
114 <?xml version="1.0" encoding="utf-8" ?>
115 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
116 <channel>
117 <title>SliTaz Cooker</title>
118 <description>The SliTaz packages cooker feed</description>
119 <link>$COOKER_URL</link>
120 <lastBuildDate>$pubdate</lastBuildDate>
121 <pubDate>$pubdate</pubDate>
122 <atom:link href="http://cook.slitaz.org/?rss" rel="self" type="application/rss+xml" />
123 EOT
124 for rss in $(ls -lt $FEEDS/*.xml | head -n 12); do
125 cat $rss | sed 's|<guid|& isPermaLink="false"|g;s|</pubDate| GMT&|g'
126 done
127 cat <<EOT
128 </channel>
129 </rss>
130 EOT
131 exit 0
132 fi
135 #
136 # Functions
137 #
140 # Unpack to stdout
142 docat() {
143 case "$1" in
144 *gz) zcat ;;
145 *bz2) bzcat ;;
146 *xz) xzcat ;;
147 *) cat
148 esac < $1
149 }
152 # Tiny texinfo browser
154 info2html() {
155 sed \
156 -e 's|&|\&|g' -e 's|<|\<|g' \
157 -e 's|^\* \(.*\)::|* <a href="#\1">\1</a> |' \
158 -e 's|\*note \(.*\)::|<a href="#\1">\1</a>|' \
159 -e '/^File: /s|(dir)|Top|g' \
160 -e '/^File: /s|Node: \([^,]*\)|Node: <a name="\1"></a><u>\1</u>|' \
161 -e '/^File: /s|Next: \([^,]*\)|Next: <a href="#\1">\1</a>|' \
162 -e '/^File: /s|Prev: \([^,]*\)|Prev: <a href="#\1">\1</a>|' \
163 -e '/^File: /s|Up: \([^,]*\)|Up: <a href="#\1">\1</a>|' \
164 -e '/^File: /s|^.*$|<i>&</i>|' \
165 -e '/^Tag Table:$/,/^End Tag Table$/d' \
166 -e '/INFO-DIR/,/^END-INFO-DIR/d' \
167 -e "s|https*://[^>),'\"\` ]*|<a href=\"&\">&</a>|g" \
168 -e "s|ftp://[^>),\"\` ]*|<a href=\"&\">&</a>|g" \
169 -e "s|^|</pre><pre class='info'>|"
170 }
173 htmlize() {
174 sed -e 's|&|\&|g; s|<|\<|g; s|>|\>|g'
175 }
177 # Put some colors in log and DB files.
179 syntax_highlighter() {
180 case $1 in
181 log)
182 # If variables not defined - define them with some rare values
183 : ${_src=#_#_#}
184 : ${_install=#_#_#}
185 : ${_fs=#_#_#}
186 : ${_stuff=#_#_#}
187 sed -e 's/&/\&/g; s/</\</g; s/>/\>/g' \
188 -e 's#OK$#<span class="span-ok">OK</span>#g' \
189 -e 's#Done$#<span class="span-ok">Done</span>#g' \
190 -e 's#done$#<span class="span-ok">done</span>#g' \
191 -e 's#\([^a-z]\)ok$#\1<span class="span-ok">ok</span>#g' \
192 -e 's#\([^a-z]\)yes$#\1<span class="span-ok">yes</span>#g' \
193 -e 's#\([^a-z]\)no$#\1<span class="span-no">no</span>#g' \
194 \
195 -e 's#\( \[Y[nm/]\?\] n\)$# <span class="span-no">\1</span>#g' \
196 -e 's#\( \[N[ym/]\?\] y\)$# <span class="span-ok">\1</span>#g' \
197 -e 's#(NEW) $#<span class="span-red">(NEW) </span>#g' \
198 \
199 -e 's#.*(pkg/local).*#<span class="span-ok">\0</span>#g' \
200 -e 's#.*(web/cache).*#<span class="span-no">\0</span>#g' \
201 \
202 -e 's#error$#<span class="span-red">error</span>#g' \
203 -e 's#ERROR:#<span class="span-red">ERROR:</span>#g' \
204 -e 's#Error#<span class="span-red">Error</span>#g' \
205 \
206 -e 's#^.*[Ff]ailed.*#<span class="span-red">\0</span>#g' \
207 -e 's#^.*[Ff]atal.*#<span class="span-red">\0</span>#g' \
208 -e 's#^.*[Nn]ot found.*#<span class="span-red">\0</span>#g' \
209 -e 's#^.*[Nn]o such file.*#<span class="span-red">\0</span>#g' \
210 \
211 -e 's#WARNING:#<span class="span-red">WARNING:</span>#g' \
212 -e 's#warning:#<span class="span-no">warning:</span>#g' \
213 -e 's#error:#<span class="span-no">error:</span>#g' \
214 -e 's#missing#<span class="span-no">missing</span>#g' \
215 \
216 -e 's#^.* will not .*#<span class="span-no">\0</span>#' \
217 -e 's!^Hunk .* succeeded at .*!<span class="span-no">\0</span>!' \
218 -e 's#^.* Warning: .*#<span class="span-no">\0</span>#' \
219 \
220 -e "s#^Executing:\([^']*\).#<span class='sh-val'>\0</span>#" \
221 -e "s#^Making.*#<span class='sh-val'>\0</span>#" \
222 -e "s#^====\([^']*\).#<span class='span-line'>\0</span>#g" \
223 -e "s#^[a-zA-Z0-9]\([^']*\) :: #<span class='span-sky'>\0</span>#g" \
224 -e "s#ftp://[^ '\"]*#<a href='\0'>\0</a>#g" \
225 -e "s#http://[^ '\"]*#<a href='\0'>\0</a>#g" \
226 -e "s|$_src|<span class='var'>\${src}</span>|g;
227 s|$_install|<span class='var'>\${install}</span>|g;
228 s|$_fs|<span class='var'>\${fs}</span>|g;
229 s|$_stuff|<span class='var'>\${stuff}</span>|g" \
230 -e "s|\[91m|<span style='color: #F00'>|;
231 s|\[92m|<span style='color: #080'>|;
232 s|\[93m|<span style='color: #FF0'>|;
233 s|\[94m|<span style='color: #00F'>|;
234 s|\[95m|<span style='color: #808'>|;
235 s|\[96m|<span style='color: #088'>|;
236 s|\[39m|</span>|;"
237 ;;
239 files)
240 sed \
241 -e "s|\[[01];31m|<span style='color: #F00'>|g;
242 s|\[[01];32m|<span style='color: #080'>|g;
243 s|\[[01];33m|<span style='color: #FF0'>|g;
244 s|\[[01];34m|<span style='color: #00F'>|g;
245 s|\[[01];35m|<span style='color: #808'>|g;
246 s|\[[01];36m|<span style='color: #088'>|g;
247 s|\[[01];0m|<span style='color: #333'>|g;
248 s|\[0m|</span>|g;"
249 ;;
251 receipt)
252 sed -e s'|&|\&|g' -e 's|<|\<|g' -e 's|>|\>|'g \
253 -e s"#^\#\([^']*\)#<span class='sh-comment'>\0</span>#"g \
254 -e s"#\"\([^']*\)\"#<span class='sh-val'>\0</span>#"g
255 ;;
257 diff)
258 sed -e 's|&|\&|g' -e 's|<|\<|g' -e 's|>|\>|g' \
259 -e s"#^-\([^']*\).#<span class='span-red'>\0</span>#"g \
260 -e s"#^+\([^']*\).#<span class='span-ok'>\0</span>#"g \
261 -e s"#@@\([^']*\)@@#<span class='span-sky'>@@\1@@</span>#"g
262 ;;
264 activity)
265 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g
266 ;;
267 esac
268 }
271 # Latest build pkgs.
273 list_packages() {
274 cd $PKGS
275 ls -1t *.tazpkg | head -n 20 | \
276 while read file; do
277 echo -n $(TZ=UTC stat -c '%y' $PKGS/$file | cut -d. -f1 | sed s/:[0-9]*$//)
278 echo " : $file"
279 done
280 }
283 # Optional full list button
285 more_button() {
286 [ $(wc -l < ${3:-$CACHE/$1}) -gt ${4:-12} ] &&
287 echo "<a class='button r' href='?file=$1'>$2</a>"
288 }
291 # Show the running command and its progression
293 running_command() {
294 local state="Not running"
295 if [ -s "$command" ]; then
296 state="$(cat $command)"
297 set -- $(grep "^$state" $cooktime)
298 if [ -n "$1" ]; then
299 state="$state $((($(date +%s)-$3)*100/$2))%"
300 [ $2 -gt 300 ] && state="$state (should end $(date -u -d @$(($2+$3))))"
301 fi
302 fi
303 echo $state
304 }
307 datalist() {
308 (
309 cd $wok
311 ls | awk '
312 BEGIN{printf("<datalist id=\"packages\">")}
313 {printf("<option>%s</option>",$1)}
314 END {printf("</datalist>")}
315 '
316 )
317 }
320 summary() {
321 log="$1"
322 pkg="$(basename ${log%%.log*})"
323 if [ -f "$log" ]; then
324 if grep -q "cook:$pkg$" $command; then
325 echo "<pre>The Cooker is currently building: $pkg</pre>"
326 fi
327 if fgrep -q "Summary for:" $log; then
328 echo "<pre>"
329 sed '/^Summary for:/,$!d' $log | sed /^$/d | syntax_highlighter log
330 echo "</pre>"
331 fi
333 if fgrep -q "Debug information" $log; then
334 echo '<pre>'
335 sed '/^Debug information/,$!d' $log | sed /^$/d | \
336 if [ -n "$2" ]; then
337 syntax_highlighter log | \
338 sed 's|\([0-9][0-9]*\):|<a href="#l\1">\1</a>:|'
339 else
340 sed 's|^[0-9][0-9]*:||' | syntax_highlighter log
341 fi
342 echo '</pre>'
343 fi
344 else
345 [ -n "$pkg" -a -d "$wok/$pkg" ] && echo "<pre>No log for $pkg</pre>"
346 fi
347 }
350 pkg_info() {
351 local log cmd active bpkg
352 log=$LOGS/$pkg.log
353 cmd=${QUERY_STRING%%=*}
354 echo '<div id="info">'
355 active=''; [ "$cmd" == 'receipt' -o "$cmd" == 'stuff' ] && active=' active'
356 echo "<a class='button green$active' href='?receipt=$pkg'>receipt & stuff</a>"
358 unset WEB_SITE WANTED
359 bpkg=$pkg
360 . $wok/$pkg/receipt
362 [ -n "$WANTED" ] && bpkg="${WANTED%% *}" # see locale-* with multiple WANTED
364 [ -n "$WEB_SITE" ] &&
365 echo "<a class='button sky' href='$WEB_SITE'>web site</a>"
367 if [ -f "$wok/$pkg/taz/$PACKAGE-$VERSION/receipt" ]; then
368 active=''; [ "$cmd" == 'files' ] && active=' active'
369 echo "<a class='button khaki$active' href='?files=$pkg'>files</a>"
371 unset EXTRAVERSION
372 . $wok/$pkg/taz/$PACKAGE-$VERSION/receipt
374 if [ -f $wok/$pkg/taz/$PACKAGE-$VERSION/description.txt ]; then
375 active=''; [ "$cmd" == 'description' ] && active=' active'
376 echo "<a class='button brown$active' href='?description=$pkg'>description</a>"
377 fi
379 if [ -f $PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg ]; then
380 echo "<a class='button gold' href='?download=$PACKAGE-$VERSION$EXTRAVERSION.tazpkg'>download</a>"
381 fi
383 if [ -f $PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg ]; then
384 echo "<a class='button gold' href='?download=$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg'>download</a>"
385 fi
386 fi
388 [ -n "$TARBALL" ] && [ -s "$SRC/$TARBALL" ] &&
389 echo "<a class='button yellow' href='?src=$TARBALL'>source</a>"
391 [ -x ./man2html ] &&
392 if [ -d $wok/$bpkg/install/usr/man ] ||
393 [ -d $wok/$bpkg/install/usr/share/man ] ||
394 [ -d $wok/$bpkg/taz/*/fs/usr/man ] ||
395 [ -d $wok/$bpkg/taz/*/fs/usr/share/man ]; then
396 active=''; [ "$cmd" == 'man' ] && active=' active'
397 echo "<a class='button plum$active' href='?man=$bpkg'>man</a>"
398 fi
400 if [ -d $wok/$bpkg/install/usr/doc ] ||
401 [ -d $wok/$bpkg/install/usr/share/doc ] ||
402 [ -d $wok/$bpkg/taz/*/fs/usr/doc ] ||
403 [ -d $wok/$bpkg/taz/*/fs/usr/share/doc ]; then
404 active=''; [ "$cmd" == 'doc' ] && active=' active'
405 echo "<a class='button plum$active' href='?doc=$bpkg'>doc</a>"
406 fi
408 if [ -d $wok/$bpkg/install/usr/info ] ||
409 [ -d $wok/$bpkg/install/usr/share/info ] ||
410 [ -d $wok/$bpkg/taz/*/fs/usr/info ] ||
411 [ -d $wok/$bpkg/taz/*/fs/usr/share/info ]; then
412 active=''; [ "$cmd" == 'info' ] && active=' active'
413 echo "<a class='button plum$active' href='?info=$bpkg'>info</a>"
414 fi
416 [ -n "$(echo $REQUEST_URI | sed 's|/[^/]*?pkg.*||')" ] ||
417 echo "<a class='button' href='ftp://${HTTP_HOST%:*}/$pkg/'>browse</a>"
419 if [ -s "$log" ]; then
420 active=''; [ "$cmd" == 'log' ] && active=' active'
421 echo "<a class='button gray$active' href='?log=$pkg.log'>logs</a>"
422 fi
424 echo '</div>'
425 }
429 # xHTML header. Pages can be customized with a separated html.header file.
431 if [ -f "header.html" ]; then
432 cat header.html
433 else
434 cat <<EOT
435 <!DOCTYPE html>
436 <html lang="en">
437 <head>
438 <meta charset="UTF-8">
439 <meta name="viewport" content="width=device-width, initial-scale=1.0">
440 <title>SliTaz Cooker</title>
441 <link rel="shortcut icon" href="favicon.ico">
442 <link rel="stylesheet" href="style.css">
443 <script src="prism.js"></script>
444 <link rel="stylesheet" href="prism.css">
445 <link rel="alternate" type="application/rss+xml" title="Cooker Feed" href="?rss">
446 <meta name="robots" content="nofollow">
447 </head>
448 <body>
450 <div id="header">
451 <div id="logo"></div>
452 <h1><a href="cooker.cgi">SliTaz Cooker</a></h1>
453 </div>
454 EOT
455 fi
458 #
459 # Load requested page
460 #
462 case "${QUERY_STRING}" in
463 pkg=*)
464 pkg=${QUERY_STRING#pkg=}
465 log=$LOGS/$pkg.log
466 echo "<div id='content'>"
467 echo "<h2>Package: $pkg</h2>"
469 # Define cook variables for syntax highlighter
470 if [ -s "$WOK/$pkg/receipt" ]; then
471 . "$WOK/$pkg/receipt"
472 _wok='/home/slitaz/wok'
473 _src="$_wok/$pkg/source/$PACKAGE-$VERSION"
474 _install="$_wok/$pkg/install"
475 _fs="$_wok/$pkg/taz/$PACKAGE-$VERSION/fs"
476 _stuff="$_wok/$pkg/stuff"
477 fi
479 # Package info.
480 if [ -f "$wok/$pkg/receipt" ]; then
481 pkg_info
482 else
483 if [ $(ls $wok/*$pkg*/receipt 2>/dev/null | wc -l) -eq 0 ]; then
484 echo "No package named: $pkg"
485 else
486 ls $wok/$pkg/receipt >/dev/null 2>&1 || pkg="*$pkg*"
487 echo '<table class="zebra" style="width:100%">'
488 for i in $(cd $wok ; ls $pkg/receipt); do
489 pkg=$(dirname $i)
490 unset SHORT_DESC CATEGORY
491 . $wok/$pkg/receipt
492 cat <<EOT
493 <tr>
494 <td><a href="?pkg=$pkg">$pkg</a></td>
495 <td>$SHORT_DESC</td>
496 <td>$CATEGORY</td>
497 </tr>
498 EOT
499 done
500 echo '</table>'
501 unset pkg
502 fi
503 fi
505 # Check for a log file and display summary if it exists.
506 summary "$log"
507 if [ -f "$log" ]; then
508 case "$HTTP_USER_AGENT" in
509 *SliTaz*)
510 [ -f $CACHE/cooker-request ] && [ -n "$HTTP_REFERER" ] &&
511 echo "<a class=\"button\" href=\"?recook=$pkg\">Recook $pkg</a>"
512 ;;
513 esac
514 fi
515 ;;
517 log=*)
518 log=${QUERY_STRING#log=}
519 logfile=$LOGS/$log
520 pkg=${log%.log*}
521 if [ -s "$logfile" ]; then
522 echo "<div id='content'>"
524 echo "<h2>Cook log $(stat -c %y $logfile | sed 's/:..\..*//')</h2>"
525 pkg_info
527 case $log in
528 *.log) baselog=$logfile ;;
529 *) baselog=${logfile%.*} ;;
530 esac
531 for i in $(ls -t $baselog $baselog.* 2>/dev/null); do
532 class=''; [ $i == $logfile ] && class=' gray'
533 echo -n "<a class='button$class' href=\"?log=$(basename $i)\">"
534 echo "$(stat -c %y $i | cut -d: -f1,2)</a>"
535 done
537 summary "$logfile" links
539 cat $logfile | syntax_highlighter log | awk '
540 BEGIN { print "<pre class=\"log\">"; }
541 { printf("<a name=\"l%d\" href=\"#l%d\">%5d</a> %s\n", NR, NR, NR, $0); }
542 END { print "</pre>"; }
543 '
544 fi
545 ;;
547 file=*)
548 echo "<div id='content'>"
549 # Don't allow all files on the system for security reasons.
550 file=${QUERY_STRING#file=}
551 case "$file" in
552 activity|cooknotes|cooklist)
553 [ "$file" == "cooklist" ] && \
554 nb="- Packages: $(cat $cooklist | wc -l)"
555 echo '<div id="content2">'
556 echo "<h2>DB: $file $nb</h2>"
557 echo '<ul class="activity">'
558 tac $CACHE/$file | syntax_highlighter activity | \
559 sed 's|^|<li>|; s|$|</li>|'
560 echo '</ul></div>'
561 ;;
563 broken)
564 nb=$(wc -l < $broken)
565 echo '<div id="content2">'
566 echo "<h2>DB: broken - Packages: $nb</h2>"
567 echo '<ul class="activity">'
568 cat $CACHE/$file | sort | \
569 sed "s#^[^']*#<a href='?pkg=\0'>\0</a>#g" | \
570 sed 's|^|<li>|; s|$|</li>|'
571 echo '</ul></div>'
572 ;;
574 *.diff)
575 diff=$CACHE/$file
576 echo "<h2>Diff for: ${file%.diff}</h2>"
577 [ "$file" == "installed.diff" ] && echo \
578 "<p>This is the latest diff between installed packages \
579 and installed build dependencies to cook.</p>"
580 echo '<pre>'
581 cat $diff | syntax_highlighter diff
582 echo '</pre>'
583 ;;
585 *.log)
586 log=$LOGS/$file
587 name=$(basename $log)
588 echo "<h2>Log for: ${name%.log}</h2>"
589 if [ -f "$log" ]; then
590 if fgrep -q "Summary" $log; then
591 echo '<pre>'
592 grep -A 20 "^Summary" $log | sed /^$/d | \
593 syntax_highlighter log
594 echo '</pre>'
595 fi
596 echo '<pre>'
597 cat $log | syntax_highlighter log
598 echo '</pre>'
599 else
600 echo "<pre>No log file: $log</pre>"
601 fi
602 ;;
603 esac
604 ;;
606 stuff=*)
607 echo "<div id='content'>"
608 file=${QUERY_STRING#stuff=}
609 pkg=${file%%/*}
610 if [ -f "$wok/$file" ]; then
611 echo "<h2>$file</h2>"
612 pkg_info
613 echo "<a class='button' href='?receipt=$pkg'>receipt</a>"
615 ( cd $wok/$pkg ; find stuff -type f 2> /dev/null ) | sort | \
616 while read i ; do
617 class=''; [ "$pkg/$i" == "$file" ] && class=" green"
618 echo "<a class='button$class' href='?stuff=$pkg/$i'>$i</a>"
619 done
621 case $file in
622 *.desktop|*.theme) class="ini" ;;
623 *.patch|*.diff|*.u) class="diff" ;;
624 *.sh) class="bash" ;;
625 *.conf*)
626 class="bash"
627 [ -n "$(cut -c1 < $wok/$file | fgrep '[')" ] && class="ini"
628 ;;
629 *.pl) class="perl" ;;
630 *.c|*.h|*.awk) class="clike" ;;
631 *.svg) class="svg" ;;
632 *Makefile*) class="makefile" ;;
633 *.po|*.pot) class="bash" ;;
634 *.css) class="css" ;;
635 *.htm|*.html) class="html" ;;
636 *.js) class="js" ;;
637 *.txt) class="asciidoc" ;;
638 *)
639 case $(head -n1 $wok/$file) in
640 *!/bin/sh*|*!/bin/bash*) class="bash" ;;
641 esac
642 if [ -z "$class" -a "$(head -n1 $wok/$file | cut -b1)" == '#' ]; then
643 class="bash"
644 fi
645 if [ -z "$class" ]; then
646 # Follow Busybox restrictions. Search for non-printable chars
647 if [ $(tr -d '[:alnum:][:punct:][:blank:][:cntrl:]' < "$wok/$file" | wc -c) -gt 0 ]; then
648 raw="true"
649 fi
650 fi
651 ;;
652 esac
654 # Display image
655 case $file in
656 *.png|*.svg|*.jpg|*.jpeg|*.ico)
657 echo "<img src='?download=../wok/$file' style='display: block; max-width: 100%; margin: auto'/>"
658 ;;
659 esac
661 # Display colored listing (also for *.svg)
662 case $file in
663 *.png|*.jpg|*.jpeg|*.ico) ;;
664 *)
665 if [ -z "$raw" ]; then
666 echo -n "<pre><code class='language-$class'>"
667 cat $wok/$file | sed 's|&|\&|g; s|<|\<|g; s|>|\>|g'
668 echo '</code></pre>'
669 fi
670 ;;
671 esac
673 # Display hex dump for binary files
674 if [ -n "$raw" ]; then
675 echo -n "<pre><code class='language-$class'>"
676 hexdump -C $wok/$file | sed 's|&|\&|g; s|<|\<|g; s|>|\>|g'
677 echo '</code></pre>'
678 fi
679 else
680 echo "<pre>File '$file' absent!</pre>"
681 fi
682 ;;
684 receipt=*)
685 echo "<div id='content'>"
686 pkg=${QUERY_STRING#receipt=}
687 if [ -f "$wok/$pkg/receipt" ]; then
688 echo "<h2>Receipt for: $pkg</h2>"
689 pkg_info
690 echo "<a class='button green' href='?receipt=$pkg'>receipt</a>"
691 . $wok/$pkg/receipt
693 ( cd $wok/$pkg; find stuff -type f 2> /dev/null ) | sort | \
694 while read file; do
695 echo "<a class='button' href='?stuff=$pkg/$file'>$file</a>"
696 done | sort
697 echo -n '<pre><code class="language-bash">'
698 cat $wok/$pkg/receipt | htmlize
699 echo '</code></pre>'
700 else
701 echo "<pre>No receipt for: $pkg</pre>"
702 fi
703 ;;
705 files=*)
706 echo "<div id='content'>"
707 pkg=${QUERY_STRING#files=}
708 dir=$(ls -d $WOK/$pkg/taz/$pkg-* 2>/dev/null)
709 if [ -d "$dir/fs" ]; then
710 size=$(du -hs $dir/fs | awk '{ print $1 }')
711 echo "<h2>Files installed by the package \"$pkg\" ($size)</h2>"
712 pkg_info
713 #echo "<a class='button gray' href='?pkg=$pkg'>‹ back</a>"
715 echo '<pre class="files">'
717 find $dir/fs -not -type d -print0 | \
718 xargs -0 ls -ld --color=always | \
719 syntax_highlighter files | \
720 sed "s|\([^/]*\)/.*\(${dir#*wok}/fs\)\([^<]*\)\(<.*\)$|\1<a href=\"?download=../wok\2\3\">\3</a>\4|"
722 echo '</pre>'
723 else
724 echo "<h2>No files list for \"$pkg\"</h2>"
725 echo "<a class='button gray' href='?pkg=$pkg'>‹ back</a>"
726 fi
727 ;;
729 description=*)
730 echo "<div id='content'>"
731 pkg=${QUERY_STRING#description=}
732 dir=$(ls -d $WOK/$pkg/taz/$pkg-* 2>/dev/null)
733 if [ -s "$dir/description.txt" ]; then
734 echo "<h2>Description of $pkg</h2>"
735 pkg_info
736 if [ -x "$SUNDOWN" ]; then
737 echo '<div id="content2">'
738 $SUNDOWN $dir/description.txt
739 echo '</div>'
740 else
741 echo '<pre><code class="language-markdown">'
742 cat $dir/description.txt | \
743 sed 's/&/\&/g;s/</\</g;s/>/\>/g'
744 echo '</code></pre>'
745 fi
746 else
747 echo "<pre>No description for: $pkg</pre>"
748 fi
749 ;;
751 man=*|doc=*|info=*)
752 echo '<div id="content">'
753 type=${QUERY_STRING%%=*}
754 pkg=$(GET $type)
755 if [ -d "$wok/$pkg" ]; then
756 dir=$WOK/$pkg/install/usr/share/$type
757 [ -d $dir ] || dir=$WOK/$pkg/install/usr/$type
758 [ -d $dir ] || dir=$(echo $WOK/$pkg/taz/*/fs/usr/share/$type)
759 [ -d $dir ] || dir=$(echo $WOK/$pkg/taz/*/fs/usr/$type)
760 page=$(GET file)
761 if [ -z "$page" ]; then
762 page=$(find $dir -type f | sed q)
763 page=${page#$dir/}
764 fi
766 echo "<h2>$(basename $page)</h2>"
768 pkg_info
769 echo '<div style="max-height: 5em; overflow: auto">'
770 find $dir -type f | sort | while read i ; do
771 [ -s $i ] || continue
772 case "$i" in
773 *.jp*g|*.png|*.gif|*.svg|*.css) continue
774 esac
775 i=${i#$dir/}
776 class=''; [ "$page" == "$i" ] && class=" plum"
777 echo "<a class='button$class' href='?$type=$pkg&file=$i'>$(basename $i .gz)</a>"
778 done | sort -t \> -k 2
779 echo '</div>'
781 if [ -f "$dir/$page" ]; then
782 tmp="$(mktemp)"
783 docat "$dir/$page" > $tmp
784 [ -s "$tmp" ] &&
785 case "$type" in
786 info)
787 echo '<div id="content2">'
788 echo '<pre class="info">'
789 info2html < "$tmp"
790 echo '</pre></div>'
791 ;;
792 doc)
793 case "$page" in
794 *.sgml) class='xml';;
795 *) class='asciidoc';;
796 esac
797 case "$page" in
798 *.htm*)
799 echo '<div id="content2">'
800 cat
801 echo '</div>'
802 ;;
803 *)
804 echo "<pre><code class=\"language-$class\">"
805 sed 's/&/\&/g;s/</\</g;s/>/\>/g'
806 echo '</code></pre>'
807 ;;
808 esac < "$tmp"
809 ;;
810 man)
811 export TEXTDOMAIN='man2html'
812 echo "<div id='content2'>"
814 html=$(./man2html "$tmp" | sed -e '1,/<header>/d' \
815 -e 's|<a href="file:///[^>]*>\([^<]*\)</a>|\1|g' \
816 -e 's|<a href="?[1-9]\+[^>]*>\([^<]*\)</a>|\1|g')
818 if [ -n "$(echo "$html" | fgrep 'The requested file /tmp/tmp.')" ]; then
819 # Process the pre-formatted man-cat page
820 echo '<pre>'
821 sed '
822 s|M-bM-^@M-^S|—|g;
823 s|M-bM-^@M-^\\|<b>|g;
824 s|M-bM-^@M-^]|</b>|g
825 s|M-bM-^@M-^X|<u>|g;
826 s|M-bM-^@M-^Y|</u>|g;
827 s|M-BM-||g;
828 ' "$tmp"
829 echo '</pre>'
830 else
831 echo "$html"
832 fi
833 echo "</div>"
834 ;;
835 esac
836 rm -f $tmp
837 else
838 echo "<pre>File '$page' not exists!</pre>"
839 fi
840 else
841 echo "<pre>Package '$pkg' not exists!</pre>"
842 fi
843 ;;
845 *)
846 # We may have a toolchain.cgi script for cross cooker's
847 if [ -f "toolchain.cgi" ]; then
848 toolchain='toolchain.cgi'
849 else
850 toolchain='?pkg=slitaz-toolchain'
851 fi
852 # Main page with summary. Count only package include in ARCH,
853 # use 'cooker arch-db' to manually create arch.$ARCH files.
854 inwok=$(ls $WOK/*/arch.$ARCH | wc -l)
855 cooked=$(ls $PKGS/*.tazpkg | wc -l)
856 unbuilt=$(($inwok - $cooked))
857 pct=0
858 [ $inwok -gt 0 ] && pct=$(( ($cooked * 100) / $inwok ))
859 cat <<EOT
860 <div id="content2">
862 <form method="get" action="" class="r">
863 <input type="search" name="pkg" placeholder="Package" list="packages" autocorrect="off" autocapitalize="off"/>
864 </form>
866 <h2>Summary</h2>
868 <table>
869 <tr><td>Running command</td><td>: $(running_command)</td></tr>
870 <tr><td>Wok revision</td><td>: <a href="$WOK_URL">$(cat $wokrev)</a></td></tr>
871 <tr><td>Commits to cook</td><td>: $(wc -l < $commits)</td></tr>
872 <tr><td>Current cooklist</td><td>: $(wc -l < $cooklist)</td></tr>
873 <tr><td>Broken packages</td><td>: $(wc -l < $broken)</td></tr>
874 <tr><td>Blocked packages</td><td>: $(wc -l < $blocked)</td></tr>
875 <tr><td>Architecture</td><td>: $ARCH, <a href="$toolchain">toolchain</a></td></tr>
876 <tr><td>Server date</td><td>: $(date -u '+%F %R %Z')</td></tr>
878 </table>
879 EOT
881 [ -e $CACHE/cooker-request ] &&
882 [ $CACHE/activity -nt $CACHE/cooker-request ] &&
883 echo '<a class="button r" href="?poke">Poke cooker</a>'
885 cat <<EOT
886 <p class="info">Packages: $inwok in the wok · $cooked cooked · $unbuilt unbuilt</p>
888 <div class="pctbar">
889 <div class="pct" style="width: ${pct}%;">${pct}%</div>
890 </div>
892 <p>
893 Service logs:
894 <a href="?file=cookorder.log">cookorder</a> ·
895 <a href="?file=commits.log">commits</a> ·
896 <a href="?file=pkgdb.log">pkgdb</a><!-- ·
897 <a href="?file=installed.diff">installed.diff</a> -->
898 </p>
900 $(more_button activity "More activity" $CACHE/activity 12)
901 <h2 id="activity">Activity</h2>
903 <ul class="activity">
904 EOT
906 tac $CACHE/activity | head -n 12 | syntax_highlighter activity | \
907 sed 's|cooker.cgi||; s|^|<li>|; s|$|</li>|'
909 echo '</ul>'
911 [ -s $cooknotes ] && cat <<EOT
912 $(more_button cooknotes "More notes" $cooknotes 12)
913 <h2 id="cooknotes">Cooknotes</h2>
914 <pre>
915 $(tac $cooknotes | head -n 12 | syntax_highlighter activity)
916 </pre>
917 EOT
919 [ -s $commits ] && cat <<EOT
920 <h2 id="commits">Commits</h2>
921 <ul class="activity">
922 $(sed 's|^|<li>|; s|$|</li>|' $commits)
923 </ul>
924 EOT
926 [ -s $cooklist ] && cat <<EOT
927 $(more_button cooklist "Full cooklist" $cooklist 20)
928 <h2 id="cooklist">Cooklist</h2>
929 <ul class="activity">
930 $(head -n 20 $cooklist | sed 's|^|<li>|; s|$|</li>|')
931 </ul>
932 EOT
934 [ -s $broken ] && cat <<EOT
935 $(more_button broken "All broken packages" $broken 20)
936 <h2 id="broken">Broken</h2>
937 <ul class="activity">
938 $(head -n 20 $broken | sed "s#^[^']*#<a href='?pkg=\0'>\0</a>#g" | sed 's|^|<li>|; s|$|</li>|')
939 </ul>
940 EOT
942 [ -s $blocked ] && cat <<EOT
943 <h2 id="blocked">Blocked</h2>
944 <ul class="activity">
945 $(sed "s#^[^']*#<a href='?pkg=\0'>\0</a>#g" $blocked | sed 's|^|<li>|; s|$|</li>|')
946 </ul>
947 EOT
949 cat <<EOT
950 <h2 id="lastcook">Latest cook</h2>
951 <ul class="activity">
952 $(list_packages | sed "s|^.* :|<span class='log-date'>\0</span> <span style='white-space:nowrap'>|g; s|^|<li>|; s|$|</span></li>|")
953 </ul>
955 EOT
956 datalist
957 ;;
958 esac
961 # Close xHTML page
963 cat <<EOT
964 </div>
966 <div id="footer">
967 <a href="http://www.slitaz.org/">SliTaz Website</a>
968 <a href="cooker.cgi">Cooker</a>
969 <a href="doc/cookutils/cookutils.html">Documentation</a>
970 </div>
972 </body>
973 </html>
974 EOT
976 exit 0