cookutils view web/cooker.cgi @ rev 781

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