cookutils view web/cooker.cgi @ rev 790

cook: fix new package build
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Dec 26 20:18:36 2015 +0100 (2015-12-26)
parents b40b5b271d4d
children bddeccba5e51
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 [ -f $CACHE/cooker-request ] && [ -n "$HTTP_REFERER" ] &&
282 echo "<a class=\"button\" href=\"cooker.cgi?recook=$pkg\">Recook $pkg</a>"
283 else
284 [ "$pkg" ] && echo "<pre>No log: $pkg</pre>"
285 fi ;;
287 file=*)
288 # Don't allow all files on the system for security reasons.
289 file=${QUERY_STRING#file=}
290 case "$file" in
291 activity|cooknotes|cooklist)
292 [ "$file" == "cooklist" ] && \
293 nb="- Packages: $(cat $cooklist | wc -l)"
294 echo "<h2>DB: $file $nb</h2>"
295 echo '<pre>'
296 tac $CACHE/$file | syntax_highlighter activity
297 echo '</pre>' ;;
299 broken)
300 nb=$(cat $broken | wc -l)
301 echo "<h2>DB: broken - Packages: $nb</h2>"
302 echo '<pre>'
303 cat $CACHE/$file | sort | \
304 sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g
305 echo '</pre>' ;;
307 *.diff)
308 diff=$CACHE/$file
309 echo "<h2>Diff for: ${file%.diff}</h2>"
310 [ "$file" == "installed.diff" ] && echo \
311 "<p>This is the latest diff between installed packages \
312 and installed build dependencies to cook.</p>"
313 echo '<pre>'
314 cat $diff | syntax_highlighter diff
315 echo '</pre>' ;;
317 *.log)
318 log=$LOGS/$file
319 name=$(basename $log)
320 echo "<h2>Log for: ${name%.log}</h2>"
321 if [ -f "$log" ]; then
322 if fgrep -q "Summary" $log; then
323 echo '<pre>'
324 grep -A 20 "^Summary" $log | sed /^$/d | \
325 syntax_highlighter log
326 echo '</pre>'
327 fi
328 echo '<pre>'
329 cat $log | syntax_highlighter log
330 echo '</pre>'
331 else
332 echo "<pre>No log file: $log</pre>"
333 fi ;;
334 esac ;;
336 stuff=*)
337 file=${QUERY_STRING#stuff=}
338 echo "<h2>$file</h2>"
339 echo '<pre>'
340 cat $wok/$file | sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g'
341 echo '</pre>' ;;
343 receipt=*)
344 pkg=${QUERY_STRING#receipt=}
345 echo "<h2>Receipt for: $pkg</h2>"
346 if [ -f "$wok/$pkg/receipt" ]; then
347 ( cd $wok/$pkg ; find stuff -type f 2> /dev/null ) | \
348 while read file ; do
349 echo "<a href=\"?stuff=$pkg/$file\">$file</a>"
350 done
351 echo '<pre>'
352 cat $wok/$pkg/receipt | \
353 syntax_highlighter receipt
354 echo '</pre>'
355 else
356 echo "<pre>No receipt for: $pkg</pre>"
357 fi ;;
359 files=*)
360 pkg=${QUERY_STRING#files=}
361 dir=$(ls -d $WOK/$pkg/taz/$pkg-*)
362 if [ -d "$dir/fs" ]; then
363 echo "<h2>Installed files by: $pkg ($(du -hs $dir/fs | awk '{ print $1 }'))</h2>"
364 echo '<pre>'
365 find $dir/fs -not -type d -print0 | xargs -0 ls -ld | \
366 sed "s|\(.*\) /.*\(${dir#*wok}/fs\)\(.*\)|\1 <a href=\"?download=../wok\2\3\">\3</a>|;s|^\([^-].*\)\(<a.*\)\">\(.*\)</a>|\1\3|"
367 echo '</pre>'
368 else
369 echo "<pre>No files list for: $pkg</pre>"
370 fi ;;
372 description=*)
373 pkg=${QUERY_STRING#description=}
374 echo "<h2>Description of $pkg</h2>"
375 dir=$(ls -d $WOK/$pkg/taz/$pkg-*)
376 if [ -s "$dir/description.txt" ]; then
377 echo '<pre>'
378 cat $dir/description.txt | \
379 sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g'
380 echo '</pre>'
381 else
382 echo "<pre>No description for: $pkg</pre>"
383 fi ;;
385 *)
386 # We may have a toolchain.cgi script for cross cooker's
387 if [ -f "toolchain.cgi" ]; then
388 toolchain='toolchain.cgi'
389 else
390 toolchain='cooker.cgi?pkg=slitaz-toolchain'
391 fi
392 # Main page with summary. Count only package include in ARCH,
393 # use 'cooker arch-db' to manually create arch.$ARCH files.
394 inwok=$(ls $WOK/*/arch.$ARCH | wc -l)
395 cooked=$(ls $PKGS/*.tazpkg | wc -l)
396 unbuilt=$(($inwok - $cooked))
397 pct=0
398 [ $inwok -gt 0 ] && pct=$(( ($cooked * 100) / $inwok ))
399 cat <<EOT
400 <div style="float: right;">
401 <form method="get" action="$SCRIPT_NAME">
402 Package:
403 <input type="text" name="pkg" />
404 </form>
405 </div>
407 <h2>Summary</h2>
409 <pre>
410 Running command : $(running_command)
411 Wok revision : <a href="$WOK_URL">$(cat $wokrev)</a>
412 Commits to cook : $(cat $commits | wc -l)
413 Current cooklist : $(cat $cooklist | wc -l)
414 Broken packages : $(cat $broken | wc -l)
415 Blocked packages : $(cat $blocked | wc -l)
416 </pre>
418 <p class="info">
419 Packages: $inwok in the wok | $cooked cooked | $unbuilt unbuilt |
420 Server date: $(date -u '+%F %R %Z')
421 </p>
422 <div class="pctbar">
423 <div class="pct" style="width: ${pct}%;">${pct}%</div>
424 </div>
426 <p>
427 Latest:
428 <a href="cooker.cgi?file=cookorder.log">cookorder.log</a>
429 <a href="cooker.cgi?file=commits.log">commits.log</a>
430 <a href="cooker.cgi?file=pkgdb.log">pkgdb.log</a>
431 <a href="cooker.cgi?file=installed.diff">installed.diff</a>
432 - Architecture $ARCH:
433 <a href="$toolchain">toolchain</a>
434 </p>
435 EOT
436 [ -e $CACHE/cooker-request ] &&
437 [ $CACHE/activity -nt $CACHE/cooker-request ] && cat <<EOT
439 <a class="button" href="cooker.cgi?poke">Poke cooker</a>
440 EOT
441 cat <<EOT
443 <h2 id="activity">Activity</h2>
444 <pre>
445 $(tac $CACHE/activity | head -n 12 | syntax_highlighter activity)
446 </pre>
447 $(more_button activity "More activity" $CACHE/activity 12)
450 <h2 id="cooknotes">Cooknotes</h2>
451 <pre>
452 $(tac $cooknotes | head -n 12 | syntax_highlighter activity)
453 </pre>
454 $(more_button cooknotes "More notes" $cooknotes 12)
457 <h2 id="commits">Commits</h2>
458 <pre>
459 $(cat $commits)
460 </pre>
463 <h2 id="cooklist">Cooklist</h2>
464 <pre>
465 $(cat $cooklist | head -n 20)
466 </pre>
467 $(more_button cooklist "Full cooklist" $cooklist 20)
470 <h2 id="broken">Broken</h2>
471 <pre>
472 $(cat $broken | head -n 20 | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
473 </pre>
474 $(more_button broken "All broken packages" $broken 20)
477 <h2 id="blocked">Blocked</h2>
478 <pre>
479 $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
480 </pre>
483 <h2 id="lastcook">Latest cook</h2>
484 <pre>
485 $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
486 </pre>
487 EOT
488 ;;
489 esac
492 # Close xHTML page
494 cat <<EOT
495 </div>
497 <div id="footer">
498 <a href="http://www.slitaz.org/">SliTaz Website</a>
499 <a href="cooker.cgi">Cooker</a>
500 <a href="http://hg.slitaz.org/cookutils/raw-file/tip/doc/cookutils.en.html">
501 Documentation</a>
502 </div>
504 </body>
505 </html>
506 EOT
508 exit 0