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