cookutils view web/cooker.cgi @ rev 758

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