cookutils view web/cooker.cgi @ rev 517

Merge default.
author Christopher Rogers <slaxemulator@gmail.com>
date Sun Jul 29 03:27:59 2012 +0000 (2012-07-29)
parents 4b1f207c4058 b3b8e39cccf5
children bb0473ed32d5
line source
1 #!/bin/sh
2 #
3 # SliTaz Cooker CGI/web interface.
4 #
6 . /usr/lib/slitaz/libcook.sh
8 # We're not logged and want time zone to display correct server date.
9 export TZ=$(cat /etc/TZ)
11 if [ "${QUERY_STRING%%=*}" == "download" ]; then
12 file=$PKGS/${QUERY_STRING#*=}
13 cat <<EOT
14 Content-Type: application/octet-stream
15 Content-Length: $(stat -c %s $file)
16 Content-Disposition: attachment; filename=$(basename $file)
18 EOT
19 cat $file
20 exit
21 fi
23 echo "Content-Type: text/html"
24 echo ""
26 # RSS feed generator
27 if [ "$QUERY_STRING" == "rss" ]; then
28 pubdate=$(date "+%a, %d %b %Y %X")
29 cat << EOT
30 <?xml version="1.0" encoding="utf-8" ?>
31 <rss version="2.0">
32 <channel>
33 <title>SliTaz Cooker</title>
34 <description>The SliTaz packages cooker feed</description>
35 <link>$COOKER_URL</link>
36 <lastBuildDate>$pubdate GMT</lastBuildDate>
37 <pubDate>$pubdate GMT</pubDate>
38 EOT
39 for rss in $(ls -lt $FEEDS/*.xml | head -n 12)
40 do
41 cat $rss
42 done
43 cat << EOT
44 </channel>
45 </rss>
46 EOT
47 exit 0
48 fi
50 #
51 # Functions
52 #
54 # Put some colors in log and DB files.
55 syntax_highlighter() {
56 case $1 in
57 log)
58 sed -e 's#OK$#<span class="span-ok">OK</span>#g' \
59 -e 's#yes$#<span class="span-ok">yes</span>#g' \
60 -e 's#no$#<span class="span-no">no</span>#g' \
61 -e 's#error$#<span class="span-red">error</span>#g' \
62 -e 's#ERROR:#<span class="span-red">ERROR:</span>#g' \
63 -e 's#WARNING:#<span class="span-red">WARNING:</span>#g' \
64 -e s"#^Executing:\([^']*\).#<span class='sh-val'>\0</span>#"g \
65 -e s"#^====\([^']*\).#<span class='span-line'>\0</span>#"g \
66 -e s"#^[a-zA-Z0-9]\([^']*\) :: #<span class='span-sky'>\0</span>#"g \
67 -e s"#ftp://[^ '\"]*#<a href='\0'>\0</a>#"g \
68 -e s"#http://[^ '\"]*#<a href='\0'>\0</a>#"g ;;
69 receipt)
70 sed -e s'|&|\&amp;|g' -e 's|<|\&lt;|g' -e 's|>|\&gt;|'g \
71 -e s"#^\#\([^']*\)#<span class='sh-comment'>\0</span>#"g \
72 -e s"#\"\([^']*\)\"#<span class='sh-val'>\0</span>#"g ;;
73 diff)
74 sed -e 's|&|\&amp;|g' -e 's|<|\&lt;|g' -e 's|>|\&gt;|g' \
75 -e s"#^-\([^']*\).#<span class='span-red'>\0</span>#"g \
76 -e s"#^+\([^']*\).#<span class='span-ok'>\0</span>#"g \
77 -e s"#@@\([^']*\)@@#<span class='span-sky'>@@\1@@</span>#"g ;;
78 activity)
79 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g ;;
80 esac
81 }
83 # Latest build pkgs.
84 list_packages() {
85 cd $PKGS
86 ls -1t *.tazpkg | head -20 | \
87 while read file
88 do
89 echo -n $(stat -c '%y' $PKGS/$file | cut -d . -f 1 | sed s/:[0-9]*$//)
90 echo " : $file"
91 done
92 }
94 list_incoming() {
95 cd $INCOMING
96 ls -1t *.tazpkg | head -20 | \
97 while read file
98 do
99 echo -n $(stat -c '%y' $INCOMING/$file | cut -d . -f 1 | sed s/:[0-9]*$//)
100 echo " : $file"
101 done
102 }
104 # xHTML header. Pages can be customized with a separated html.header file.
105 if [ -f "header.html" ]; then
106 cat header.html
107 else
108 cat << EOT
109 <!DOCTYPE html>
110 <html xmlns="http://www.w3.org/1999/xhtml">
111 <head>
112 <title>SliTaz Cooker</title>
113 <meta charset="utf-8" />
114 <link rel="shortcut icon" href="favicon.ico" />
115 <link rel="stylesheet" type="text/css" href="style.css" />
116 </head>
117 <body>
119 <div id="header">
120 <div id="logo"></div>
121 <div id="network">
122 <a href="http://pkgs.slitaz.org/cooking/">Database</a>
123 <a href="http://tank.slitaz.org/graphs.php#cpu">Cpu</a>
124 <a href="http://hg.slitaz.org/wok/">Hg</a>
125 <a href="packages/">Packages</a>
126 <a href="incoming/">Incoming</a>
127 </div>
128 <h1><a href="cooker.cgi">SliTaz Cooker</a></h1>
129 </div>
131 <!-- Content -->
132 <div id="content">
133 EOT
134 fi
136 #
137 # Load requested page
138 #
140 case "${QUERY_STRING}" in
141 pkg=*)
142 pkg=${QUERY_STRING#pkg=}
143 log=$LOGS/$pkg.log
144 echo "<h2>Package: $pkg</h2>"
146 # Package info.
147 echo '<div id="info">'
148 if [ -f "$WOK/$pkg/receipt" ]; then
149 echo "<a href='cooker.cgi?receipt=$pkg'>receipt</a>"
150 unset WEB_SITE
151 . $WOK/$pkg/receipt
152 [ -n "$WEB_SITE" ] && busybox wget -s $WEB_SITE &&
153 echo "<a href='$WEB_SITE'>home</a>"
154 if [ -f "$WOK/$pkg/taz/$PACKAGE-$VERSION/receipt" ]; then
155 echo "<a href='cooker.cgi?files=$pkg'>files</a>"
156 unset EXTRAVERSION
157 . $WOK/$pkg/taz/$PACKAGE-$VERSION/receipt
158 if [ -f $PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg ]; then
159 echo "<a href='cooker.cgi?download=$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg'>download</a>"
160 elif [ -f $PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg ]; then
161 echo "<a href='cooker.cgi?download=$PACKAGE-$VERSION$EXTRAVERSION.tazpkg'>download</a>"
162 fi
164 if [ -f $SRC/$TARBALL ]; then
165 echo "<a href='cooker.cgi?download=$TARBALL'>src tarball</a>"
166 elif [ -f $SRC/$SOURCE-${KBASEVER:-$VERSION}.tar.lzma ]; then
167 echo "<a href='cooker.cgi?download=$SOURCE-${KBASEVER:-$VERSION}.tar.lzma'>src tarball</a>"
168 elif [ -f $SRC/$PACKAGE-${KBASEVER:-$VERSION}.tar.lzma ]; then
169 echo "<a href='cooker.cgi?download=$PACKAGE-${KBASEVER:-$VERSION}.tar.lzma'>src tarball</a>"
170 fi
171 fi
172 else
173 echo "No package named: $pkg"
174 fi
175 if [ -f $WOK/$pkg/taz/*/library.list ]; then
176 echo "<a href='cooker.cgi?library=$pkg'>library</a>"
177 else
178 echo "No library: $pkg"
179 fi
180 echo '</div>'
182 # Check for a log file and display summary if it exists.
183 if [ -f "$log" ]; then
184 if grep -q "cook:$pkg$" $command; then
185 echo "<pre>The Cooker is currently building: $pkg</pre>"
186 fi
187 if fgrep -q "Summary for:" $LOGS/$pkg.log; then
188 echo "<h3>Cook summary</h3>"
189 echo '<pre>'
190 grep -A 10 "^Summary for:" $LOGS/$pkg.log | sed /^$/d | \
191 syntax_highlighter log
192 echo '</pre>'
193 fi
194 if fgrep -q "Debug information" $LOGS/$pkg.log; then
195 echo "<h3>Cook failed</h3>"
196 echo '<pre>'
197 grep -A 8 "^Debug information" $LOGS/$pkg.log | sed /^$/d | \
198 syntax_highlighter log
199 echo '</pre>'
200 fi
201 echo "<h3>Cook log</h3>"
202 echo '<pre>'
203 cat $log | syntax_highlighter log
204 echo '</pre>'
205 else
206 echo "<pre>No log: $pkg</pre>"
207 fi ;;
208 file=*)
209 # Dont allow all files on the system for security reasons.
210 file=${QUERY_STRING#file=}
211 case "$file" in
212 activity|cooknotes|cooklist)
213 [ "$file" == "cooklist" ] && \
214 nb="- Packages: $(cat $cooklist | wc -l)"
215 echo "<h2>DB: $file $nb</h2>"
216 echo '<pre>'
217 tac $CACHE/$file | syntax_highlighter activity
218 echo '</pre>' ;;
219 broken)
220 nb=$(cat $broken | wc -l)
221 echo "<h2>DB: broken - Packages: $nb</h2>"
222 echo '<pre>'
223 cat $CACHE/$file | sort | \
224 sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g
225 echo '</pre>' ;;
226 unbuild)
227 # Main page with summary.
228 nb=$(cat $unbuild | wc -l)
229 echo "<h2>DB: unbuild - Packages: $nb</h2>"
230 echo '<pre>'
231 cat $CACHE/$file | sort | \
232 sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g
233 echo '</pre>' ;;
234 *.diff)
235 diff=$CACHE/$file
236 echo "<h2>Diff for: ${file%.diff}</h2>"
237 [ "$file" == "installed.diff" ] && echo \
238 "<p>This is the latest diff between installed packages \
239 and installed build dependencies to cook.</p>"
240 echo '<pre>'
241 cat $diff | syntax_highlighter diff
242 echo '</pre>' ;;
243 *.log)
244 log=$LOGS/$file
245 name=$(basename $log)
246 echo "<h2>Log for: ${name%.log}</h2>"
247 if [ -f "$log" ]; then
248 if fgrep -q "Summary" $log; then
249 echo '<pre>'
250 grep -A 20 "^Summary" $log | sed /^$/d | \
251 syntax_highlighter log
252 echo '</pre>'
253 fi
254 echo '<pre>'
255 cat $log | syntax_highlighter log
256 echo '</pre>'
257 else
258 echo "<pre>No log file: $log</pre>"
259 fi ;;
260 esac ;;
261 stuff=*)
262 file=${QUERY_STRING#stuff=}
263 echo "<h2>$file</h2>"
264 echo '<pre>'
265 cat $wok/$file
266 echo '</pre>' ;;
267 receipt=*)
268 pkg=${QUERY_STRING#receipt=}
269 echo "<h2>Receipt for: $pkg</h2>"
270 if [ -f "$WOK/$pkg/receipt" ]; then
271 ( cd $wok/$pkg ; find stuff -type f 2> /dev/null ) | \
272 while read file ; do
273 echo "<a href=\"?stuff=$pkg/$file\">$file</a>"
274 done
275 echo '<pre>'
276 cat $WOK/$pkg/receipt | syntax_highlighter receipt
277 echo '</pre>'
278 else
279 echo "<pre>No receipt for: $pkg</pre>"
280 fi ;;
281 files=*)
282 pkg=${QUERY_STRING#files=}
283 echo "<h2>Installed files by: $pkg</h2>"
284 dir=$(ls -d $WOK/$pkg/taz/$pkg-*)
285 if [ -d "$dir/fs" ]; then
286 echo '<pre>'
287 find $dir/fs -not -type d | xargs ls -ld | \
288 sed "s|$dir/fs||" | syntax_highlighter log
289 echo '</pre>'
290 else
291 echo "<pre>No files list for: $pkg</pre>"
292 fi ;;
293 library=*)
294 pkg=${QUERY_STRING#library=}
295 echo "<h2>Library for: $pkg</h2>"
296 if [ -f $WOK/$pkg/taz/*/library.list ]; then
297 echo '<pre>'
298 cat $WOK/$pkg/taz/*/library.list | sed "s|$pkg ||g" | sed 's| |\n|g' | sed '/^$/d'
299 echo '</pre>'
300 fi ;;
301 description=*)
302 pkg=${QUERY_STRING#description=}
303 echo "<h2>Description of $pkg</h2>"
304 dir=$(ls -d $WOK/$pkg/taz/$pkg-*)
305 if [ -s "$dir/description.txt" ]; then
306 echo '<pre>'
307 cat $dir/description.txt
308 echo '</pre>'
309 else
310 echo "<pre>No description for: $pkg</pre>"
311 fi ;;
312 *)
313 # We may have a toolchain.cgi script for cross cooker's
314 if [ -f "toolchain.cgi" ]; then
315 toolchain='toolchain.cgi'
316 else
317 toolchain='cooker.cgi?pkg=slitaz-toolchain'
318 fi
319 # Main page with summary. Count only package include in ARCH,
320 # use 'cooker arch' to manually create arch.$ARCH files.
321 # We may have arm only packages, use arch.i486 ?
322 case "$ARCH" in
323 arm|x86_64) inwok=$(ls $WOK/*/arch.$ARCH | wc -l) ;;
324 *) inwok=$(ls $WOK | wc -l) ;;
325 esac
326 pkg_cooked=$(ls $PKGS/*.tazpkg | wc -l)
327 incoming_cooked=$(ls $INCOMING/*.tazpkg | wc -l)
328 pkg_unbuilt=$(($inwok - $pkg_cooked))
329 incoming_unbuilt=$(($inwok -$incoming_cooked))
330 pkg_pct=0
331 [ $inwok -gt 0 ] && pkg_pct=$(( ($pkg_cooked * 100) / $inwok ))
332 incoming_pct=0
333 [ $inwok -gt 0 ] && incoming_pct=$(( ($incoming_cooked * 100) / $inwok ))
334 cat << EOT
335 <div style="float: right;">
336 <form method="get" action="$SCRIPT_NAME">
337 Package:
338 <input type="text" name="pkg" />
339 </form>
340 </div>
342 <h2>Summary</h2>
344 <pre>
345 Running command : $([ -s "$command" ] && cat $command || echo "Not running")
346 Wok revision : <a href="$WOK_URL">$(cat $wokrev)</a>
347 Commits to cook : $(cat $commits | wc -l)
348 Current cooklist : $(cat $cooklist | wc -l)
349 Broken packages : $(cat $broken | wc -l)
350 Blocked packages : $(cat $blocked | wc -l)
351 Unbuild packages : $(cat $unbuild | wc -l)
352 </pre>
354 <p>
355 Packages: $inwok in the wok - Server date: $(date '+%Y-%m-%d %H:%M')
356 </p>
358 $pkg_cooked packages cooked - $pkg_unbuilt unbuilt
359 <div class="pctbar">
360 <div class="pct" style="width: ${pkg_pct}%;">${pkg_pct}%</div>
361 </div>
363 $incoming_cooked incoming packages cooked - $incoming_unbuilt unbuilt
364 <div class="pctbar">
365 <div class="pct" style="width: ${incoming_pct}%;">${incoming_pct}%</div>
366 </div>
368 <p>
369 Latest:
370 <a href="cooker.cgi?file=cookorder.log">cookorder.log</a>
371 <a href="cooker.cgi?file=commits.log">commits.log</a>
372 <a href="cooker.cgi?file=installed.diff">installed.diff</a>
373 - Architecture $ARCH:
374 <a href="$toolchain">toolchain</a>
375 </p>
377 <a name="activity"></a>
378 <h2>Activity</h2>
379 <pre>
380 $(tac $activity | head -n 12 | syntax_highlighter activity)
381 </pre>
382 <a class="button" href="cooker.cgi?file=activity">More activity</a>
384 <a name="cooknotes"></a>
385 <h2>Cooknotes</h2>
386 <pre>
387 $(tac $cooknotes | head -n 12 | syntax_highlighter activity)
388 </pre>
389 <a class="button" href="cooker.cgi?file=cooknotes">More notes</a>
391 <a name="commits"></a>
392 <h2>Commits</h2>
393 <pre>
394 $(cat $commits)
395 </pre>
397 <a name="cooklist"></a>
398 <h2>Cooklist</h2>
399 <pre>
400 $(cat $cooklist | head -n 20)
401 </pre>
402 <a class="button" href="cooker.cgi?file=cooklist">Full cooklist</a>
404 <a name="broken"></a>
405 <h2>Broken</h2>
406 <pre>
407 $(cat $broken | head -n 20 | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
408 </pre>
409 <a class="button" href="cooker.cgi?file=broken">All broken packages</a>
411 <a name="blocked"></a>
412 <h2>Blocked</h2>
413 <pre>
414 $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
415 </pre>
417 <a name="unbuild"></a>
418 <h2>Unbuild</h2>
419 <pre>
420 $(cat $unbuild | head -n 20)
421 </pre>
422 <a class="button" href="cooker.cgi?file=unbuild">Unbuild</a>
424 <a name="lastcook"></a>
425 <h2>Latest cook</h2>
426 <pre>
427 $(list_incoming | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
428 </pre>
430 <h2>Latest packages for mirror</h2>
431 <pre>
432 $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
433 </pre>
434 EOT
435 ;;
436 esac
438 if [ -f "footer.html" ]; then
439 cat footer.html
440 else
441 # Close xHTML page
442 cat << EOT
443 </div>
445 <div id="footer">
446 <a href="http://www.slitaz.org/">SliTaz Website</a>
447 <a href="cooker.cgi">Cooker</a>
448 <a href="http://hg.slitaz.org/cookutils/raw-file/tip/doc/cookutils.en.html">
449 Documentation</a>
450 </div>
452 </body>
453 </html>
454 EOT
455 fi
457 exit 0