cookutils view web/cooker.cgi @ rev 787

cooker.cgi: estimate end date for long build
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Dec 16 18:39:00 2015 +0100 (2015-12-16)
parents 256af05e0925
children b40b5b271d4d
line source
1 #!/bin/sh
2 #
3 # SliTaz Cooker CGI/web interface.
4 #
6 [ -f "/etc/slitaz/cook.conf" ] && . /etc/slitaz/cook.conf
7 [ -f "cook.conf" ] && . ./cook.conf
9 # The same wok as cook.
10 wok="$WOK"
12 # Cooker DB files.
13 activity="$CACHE/activity"
14 commits="$CACHE/commits"
15 cooklist="$CACHE/cooklist"
16 cookorder="$CACHE/cookorder"
17 command="$CACHE/command"
18 blocked="$CACHE/blocked"
19 broken="$CACHE/broken"
20 cooknotes="$CACHE/cooknotes"
21 cooktime="$CACHE/cooktime"
22 wokrev="$CACHE/wokrev"
24 # We're not logged and want time zone to display correct server date.
25 export TZ=$(cat /etc/TZ)
27 case "$QUERY_STRING" in
28 recook=*)
29 grep -qs "^${QUERY_STRING#recook=}$" $CACHE/recook-packages ||
30 echo ${QUERY_STRING#recook=} >> $CACHE/recook-packages
31 cat <<EOT
32 Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}
34 EOT
35 exit ;;
36 poke)
37 touch $CACHE/cooker-request
38 cat <<EOT
39 Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}
41 EOT
42 exit ;;
43 download*)
44 file=$(busybox httpd -d "$PKGS/${QUERY_STRING#*=}")
45 cat <<EOT
46 Content-Type: application/octet-stream
47 Content-Length: $(stat -c %s "$file")
48 Content-Disposition: attachment; filename="$(basename "$file")"
50 EOT
51 cat "$file"
52 exit ;;
53 rss)
54 cat <<EOT
55 Content-Type: application/rss+xml
57 EOT
58 ;;
59 *)
60 cat <<EOT
61 Content-Type: text/html; charset=utf-8
63 EOT
64 ;;
65 esac
68 # RSS feed generator
69 if [ "$QUERY_STRING" == 'rss' ]; then
70 pubdate=$(date -R)
71 cat <<EOT
72 <?xml version="1.0" encoding="utf-8" ?>
73 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
74 <channel>
75 <title>SliTaz Cooker</title>
76 <description>The SliTaz packages cooker feed</description>
77 <link>$COOKER_URL</link>
78 <lastBuildDate>$pubdate</lastBuildDate>
79 <pubDate>$pubdate</pubDate>
80 <atom:link href="http://cook.slitaz.org/cooker.cgi?rss" rel="self" type="application/rss+xml" />
81 EOT
82 for rss in $(ls -lt $FEEDS/*.xml | head -n 12); do
83 cat $rss | sed 's|<guid|& isPermaLink="false"|g;s|</pubDate| GMT&|g'
84 done
85 cat <<EOT
86 </channel>
87 </rss>
88 EOT
89 exit 0
90 fi
93 #
94 # Functions
95 #
98 # Put some colors in log and DB files.
100 syntax_highlighter() {
101 case $1 in
102 log)
103 sed -e 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g' \
104 -e 's#OK$#<span class="span-ok">OK</span>#g' \
105 -e 's#Done$#<span class="span-ok">Done</span>#g' \
106 -e 's#yes$#<span class="span-ok">yes</span>#g' \
107 -e 's#no$#<span class="span-no">no</span>#g' \
108 -e 's#error$#<span class="span-red">error</span>#g' \
109 -e 's#ERROR:#<span class="span-red">ERROR:</span>#g' \
110 -e 's#WARNING:#<span class="span-red">WARNING:</span>#g' \
111 -e s"#^Executing:\([^']*\).#<span class='sh-val'>\0</span>#"g \
112 -e s"#^====\([^']*\).#<span class='span-line'>\0</span>#"g \
113 -e s"#^[a-zA-Z0-9]\([^']*\) :: #<span class='span-sky'>\0</span>#"g \
114 -e s"#ftp://[^ '\"]*#<a href='\0'>\0</a>#"g \
115 -e s"#http://[^ '\"]*#<a href='\0'>\0</a>#"g ;;
117 receipt)
118 sed -e s'|&|\&amp;|g' -e 's|<|\&lt;|g' -e 's|>|\&gt;|'g \
119 -e s"#^\#\([^']*\)#<span class='sh-comment'>\0</span>#"g \
120 -e s"#\"\([^']*\)\"#<span class='sh-val'>\0</span>#"g ;;
122 diff)
123 sed -e 's|&|\&amp;|g' -e 's|<|\&lt;|g' -e 's|>|\&gt;|g' \
124 -e s"#^-\([^']*\).#<span class='span-red'>\0</span>#"g \
125 -e s"#^+\([^']*\).#<span class='span-ok'>\0</span>#"g \
126 -e s"#@@\([^']*\)@@#<span class='span-sky'>@@\1@@</span>#"g ;;
128 activity)
129 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g ;;
130 esac
131 }
134 # Latest build pkgs.
136 list_packages() {
137 cd $PKGS
138 ls -1t *.tazpkg | head -20 | \
139 while read file; do
140 echo -n $(stat -c '%y' $PKGS/$file | cut -d . -f 1 | sed s/:[0-9]*$//)
141 echo " : $file"
142 done
143 }
146 # Optional full list button
148 more_button() {
149 [ $(wc -l < ${3:-$CACHE/$1}) -gt ${4:-12} ] &&
150 echo "<a class=\"button\" href=\"cooker.cgi?file=$1\">$2</a>"
151 }
154 # Show the running command and its progression
156 running_command()
157 {
158 local state="Not running"
159 if [ -s "$command" ]; then
160 state="$(cat $command)"
161 if grep -q "^$state" $cooktime ; then
162 set -- $(cat $cooktime)
163 state="$state $((($(date +%s)-$3)*100/$2))%"
164 [ $2 -gt 300 ] && state="$state (should end $(date -u -d @$(($2+$3))))"
165 fi
166 fi
167 echo $state
168 }
171 # xHTML header. Pages can be customized with a separated html.header file.
173 if [ -f "header.html" ]; then
174 cat header.html
175 else
176 cat <<EOT
177 <!DOCTYPE html>
178 <html lang="en">
179 <head>
180 <meta charset="utf-8"/>
181 <title>SliTaz Cooker</title>
182 <link rel="shortcut icon" href="favicon.ico"/>
183 <link rel="stylesheet" type="text/css" href="style.css"/>
184 <meta name="robots" content="nofollow">
185 </head>
186 <body>
188 <div id="header">
189 <div id="logo"></div>
190 <h1><a href="cooker.cgi">SliTaz Cooker</a></h1>
191 </div>
193 <!-- Content -->
194 <div id="content">
195 EOT
196 fi
199 #
200 # Load requested page
201 #
203 case "${QUERY_STRING}" in
204 pkg=*)
205 pkg=${QUERY_STRING#pkg=}
206 log=$LOGS/$pkg.log
207 echo "<h2>Package: $pkg</h2>"
209 # Package info.
210 echo '<div id="info">'
211 if [ -f "$wok/$pkg/receipt" ]; then
212 echo "<a href='cooker.cgi?receipt=$pkg'>receipt</a>"
213 unset WEB_SITE
214 . $wok/$pkg/receipt
216 [ -n "$WEB_SITE" ] && # busybox wget -s $WEB_SITE &&
217 echo "<a href='$WEB_SITE'>home</a>"
219 if [ -f "$wok/$pkg/taz/$PACKAGE-$VERSION/receipt" ]; then
220 echo "<a href='cooker.cgi?files=$pkg'>files</a>"
221 unset EXTRAVERSION
222 . $wok/$pkg/taz/$PACKAGE-$VERSION/receipt
223 if [ -f $wok/$pkg/taz/$PACKAGE-$VERSION/description.txt ]; then
224 echo "<a href='cooker.cgi?description=$pkg'>description</a>"
225 fi
226 if [ -f $PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg ]; then
227 echo "<a href='cooker.cgi?download=$PACKAGE-$VERSION$EXTRAVERSION.tazpkg'>download</a>"
228 fi
229 if [ -f $PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg ]; then
230 echo "<a href='cooker.cgi?download=$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg'>download</a>"
231 fi
232 fi
233 echo "<a href='ftp://${HTTP_HOST%:*}/$pkg/'>browse</a>"
234 else
235 if [ $(ls $wok/*$pkg*/receipt 2> /dev/null | wc -l) -eq 0 ]; then
236 echo "No package named: $pkg"
237 else
238 ls $wok/$pkg/receipt >/dev/null 2>&1 || pkg="*$pkg*"
239 echo '<table style="width:100%">'
240 for i in $(cd $wok ; ls $pkg/receipt); do
241 pkg=$(dirname $i)
242 unset SHORT_DESC CATEGORY
243 . $wok/$pkg/receipt
244 cat <<EOT
245 <tr>
246 <td><a href="cooker.cgi?pkg=$pkg">$pkg</a></td>
247 <td>$SHORT_DESC</td>
248 <td>$CATEGORY</td>
249 </tr>
250 EOT
251 done
252 echo '</table>'
253 unset pkg
254 fi
255 fi
256 echo '</div>'
258 # Check for a log file and display summary if it exists.
259 if [ -f "$log" ]; then
260 if grep -q "cook:$pkg$" $command; then
261 echo "<pre>The Cooker is currently building: $pkg</pre>"
262 fi
263 if fgrep -q "Summary for:" $LOGS/$pkg.log; then
264 echo '<h3>Cook summary</h3>'
265 echo '<pre>'
266 grep -A 12 "^Summary for:" $LOGS/$pkg.log | sed /^$/d | \
267 syntax_highlighter log
268 echo '</pre>'
269 fi
270 if fgrep -q "Debug information" $LOGS/$pkg.log; then
271 echo '<h3>Cook failed</h3>'
272 echo '<pre>'
273 grep -A 8 "^Debug information" $LOGS/$pkg.log | sed /^$/d | \
274 syntax_highlighter log
275 echo '</pre>'
276 fi
277 echo '<h3>Cook log</h3>'
278 echo '<pre>'
279 cat $log | syntax_highlighter log
280 echo '</pre>'
281 echo "<a class=\"button\" href=\"cooker.cgi?recook=$pkg\">Recook $pkg</a>"
282 else
283 [ "$pkg" ] && echo "<pre>No log: $pkg</pre>"
284 fi ;;
286 file=*)
287 # Don't allow all files on the system for security reasons.
288 file=${QUERY_STRING#file=}
289 case "$file" in
290 activity|cooknotes|cooklist)
291 [ "$file" == "cooklist" ] && \
292 nb="- Packages: $(cat $cooklist | wc -l)"
293 echo "<h2>DB: $file $nb</h2>"
294 echo '<pre>'
295 tac $CACHE/$file | syntax_highlighter activity
296 echo '</pre>' ;;
298 broken)
299 nb=$(cat $broken | wc -l)
300 echo "<h2>DB: broken - Packages: $nb</h2>"
301 echo '<pre>'
302 cat $CACHE/$file | sort | \
303 sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g
304 echo '</pre>' ;;
306 *.diff)
307 diff=$CACHE/$file
308 echo "<h2>Diff for: ${file%.diff}</h2>"
309 [ "$file" == "installed.diff" ] && echo \
310 "<p>This is the latest diff between installed packages \
311 and installed build dependencies to cook.</p>"
312 echo '<pre>'
313 cat $diff | syntax_highlighter diff
314 echo '</pre>' ;;
316 *.log)
317 log=$LOGS/$file
318 name=$(basename $log)
319 echo "<h2>Log for: ${name%.log}</h2>"
320 if [ -f "$log" ]; then
321 if fgrep -q "Summary" $log; then
322 echo '<pre>'
323 grep -A 20 "^Summary" $log | sed /^$/d | \
324 syntax_highlighter log
325 echo '</pre>'
326 fi
327 echo '<pre>'
328 cat $log | syntax_highlighter log
329 echo '</pre>'
330 else
331 echo "<pre>No log file: $log</pre>"
332 fi ;;
333 esac ;;
335 stuff=*)
336 file=${QUERY_STRING#stuff=}
337 echo "<h2>$file</h2>"
338 echo '<pre>'
339 cat $wok/$file | sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g'
340 echo '</pre>' ;;
342 receipt=*)
343 pkg=${QUERY_STRING#receipt=}
344 echo "<h2>Receipt for: $pkg</h2>"
345 if [ -f "$wok/$pkg/receipt" ]; then
346 ( cd $wok/$pkg ; find stuff -type f 2> /dev/null ) | \
347 while read file ; do
348 echo "<a href=\"?stuff=$pkg/$file\">$file</a>"
349 done
350 echo '<pre>'
351 cat $wok/$pkg/receipt | \
352 syntax_highlighter receipt
353 echo '</pre>'
354 else
355 echo "<pre>No receipt for: $pkg</pre>"
356 fi ;;
358 files=*)
359 pkg=${QUERY_STRING#files=}
360 dir=$(ls -d $WOK/$pkg/taz/$pkg-*)
361 if [ -d "$dir/fs" ]; then
362 echo "<h2>Installed files by: $pkg ($(du -hs $dir/fs | awk '{ print $1 }'))</h2>"
363 echo '<pre>'
364 find $dir/fs -not -type d -print0 | xargs -0 ls -ld | \
365 sed "s|\(.*\) /.*\(${dir#*wok}/fs\)\(.*\)|\1 <a href=\"?download=../wok\2\3\">\3</a>|;s|^\([^-].*\)\(<a.*\)\">\(.*\)</a>|\1\3|"
366 echo '</pre>'
367 else
368 echo "<pre>No files list for: $pkg</pre>"
369 fi ;;
371 description=*)
372 pkg=${QUERY_STRING#description=}
373 echo "<h2>Description of $pkg</h2>"
374 dir=$(ls -d $WOK/$pkg/taz/$pkg-*)
375 if [ -s "$dir/description.txt" ]; then
376 echo '<pre>'
377 cat $dir/description.txt | \
378 sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g'
379 echo '</pre>'
380 else
381 echo "<pre>No description for: $pkg</pre>"
382 fi ;;
384 *)
385 # We may have a toolchain.cgi script for cross cooker's
386 if [ -f "toolchain.cgi" ]; then
387 toolchain='toolchain.cgi'
388 else
389 toolchain='cooker.cgi?pkg=slitaz-toolchain'
390 fi
391 # Main page with summary. Count only package include in ARCH,
392 # use 'cooker arch-db' to manually create arch.$ARCH files.
393 inwok=$(ls $WOK/*/arch.$ARCH | wc -l)
394 cooked=$(ls $PKGS/*.tazpkg | wc -l)
395 unbuilt=$(($inwok - $cooked))
396 pct=0
397 [ $inwok -gt 0 ] && pct=$(( ($cooked * 100) / $inwok ))
398 cat <<EOT
399 <div style="float: right;">
400 <form method="get" action="$SCRIPT_NAME">
401 Package:
402 <input type="text" name="pkg" />
403 </form>
404 </div>
406 <h2>Summary</h2>
408 <pre>
409 Running command : $(running_command)
410 Wok revision : <a href="$WOK_URL">$(cat $wokrev)</a>
411 Commits to cook : $(cat $commits | wc -l)
412 Current cooklist : $(cat $cooklist | wc -l)
413 Broken packages : $(cat $broken | wc -l)
414 Blocked packages : $(cat $blocked | wc -l)
415 </pre>
417 <p class="info">
418 Packages: $inwok in the wok | $cooked cooked | $unbuilt unbuilt |
419 Server date: $(date -u '+%F %R %Z')
420 </p>
421 <div class="pctbar">
422 <div class="pct" style="width: ${pct}%;">${pct}%</div>
423 </div>
425 <p>
426 Latest:
427 <a href="cooker.cgi?file=cookorder.log">cookorder.log</a>
428 <a href="cooker.cgi?file=commits.log">commits.log</a>
429 <a href="cooker.cgi?file=pkgdb.log">pkgdb.log</a>
430 <a href="cooker.cgi?file=installed.diff">installed.diff</a>
431 - Architecture $ARCH:
432 <a href="$toolchain">toolchain</a>
433 </p>
434 EOT
435 [ -e $CACHE/cooker-request ] &&
436 [ $CACHE/activity -nt $CACHE/cooker-request ] && cat <<EOT
438 <a class="button" href="cooker.cgi?poke">Poke cooker</a>
439 EOT
440 cat <<EOT
442 <h2 id="activity">Activity</h2>
443 <pre>
444 $(tac $CACHE/activity | head -n 12 | syntax_highlighter activity)
445 </pre>
446 $(more_button activity "More activity" $CACHE/activity 12)
449 <h2 id="cooknotes">Cooknotes</h2>
450 <pre>
451 $(tac $cooknotes | head -n 12 | syntax_highlighter activity)
452 </pre>
453 $(more_button cooknotes "More notes" $cooknotes 12)
456 <h2 id="commits">Commits</h2>
457 <pre>
458 $(cat $commits)
459 </pre>
462 <h2 id="cooklist">Cooklist</h2>
463 <pre>
464 $(cat $cooklist | head -n 20)
465 </pre>
466 $(more_button cooklist "Full cooklist" $cooklist 20)
469 <h2 id="broken">Broken</h2>
470 <pre>
471 $(cat $broken | head -n 20 | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
472 </pre>
473 $(more_button broken "All broken packages" $broken 20)
476 <h2 id="blocked">Blocked</h2>
477 <pre>
478 $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
479 </pre>
482 <h2 id="lastcook">Latest cook</h2>
483 <pre>
484 $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
485 </pre>
486 EOT
487 ;;
488 esac
491 # Close xHTML page
493 cat <<EOT
494 </div>
496 <div id="footer">
497 <a href="http://www.slitaz.org/">SliTaz Website</a>
498 <a href="cooker.cgi">Cooker</a>
499 <a href="http://hg.slitaz.org/cookutils/raw-file/tip/doc/cookutils.en.html">
500 Documentation</a>
501 </div>
503 </body>
504 </html>
505 EOT
507 exit 0