cookutils view web/cooker.cgi @ rev 563

cookiso: check if we have a hg repo before calling pull -u
author Christopher Rogers <slaxemulator@gmail.com>
date Mon Dec 31 17:13:41 2012 +0000 (2012-12-31)
parents 8a9e17bb0140
children 096f73373805
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#*wok}/fs\)\(.*\)|\1 <a href=\"?download=../wok\2\3\">\3</a>|;s|\(<a.* -> .*\)\">\(.*\)</a>|\2|" | \
289 syntax_highlighter log
290 echo '</pre>'
291 else
292 echo "<pre>No files list for: $pkg</pre>"
293 fi ;;
294 library=*)
295 pkg=${QUERY_STRING#library=}
296 echo "<h2>Library for: $pkg</h2>"
297 if [ -f $WOK/$pkg/taz/*/library.list ]; then
298 echo '<pre>'
299 cat $WOK/$pkg/taz/*/library.list | sed "s|$pkg ||g" | sed 's| |\n|g' | sed '/^$/d'
300 echo '</pre>'
301 fi ;;
302 description=*)
303 pkg=${QUERY_STRING#description=}
304 echo "<h2>Description of $pkg</h2>"
305 dir=$(ls -d $WOK/$pkg/taz/$pkg-*)
306 if [ -s "$dir/description.txt" ]; then
307 echo '<pre>'
308 cat $dir/description.txt
309 echo '</pre>'
310 else
311 echo "<pre>No description for: $pkg</pre>"
312 fi ;;
313 *)
314 # We may have a toolchain.cgi script for cross cooker's
315 if [ -f "toolchain.cgi" ]; then
316 toolchain='toolchain.cgi'
317 else
318 toolchain='cooker.cgi?pkg=slitaz-toolchain'
319 fi
320 # Main page with summary. Count only package include in ARCH,
321 # use 'cooker arch' to manually create arch.$ARCH files.
322 # We may have arm only packages, use arch.i486 ?
323 case "$ARCH" in
324 arm|x86_64) inwok=$(ls $WOK/*/arch.$ARCH | wc -l) ;;
325 *) inwok=$(ls $WOK | wc -l) ;;
326 esac
327 pkg_cooked=$(ls $PKGS/*.tazpkg | wc -l)
328 incoming_cooked=$(ls $INCOMING/*.tazpkg | wc -l)
329 pkg_unbuilt=$(($inwok - $pkg_cooked))
330 incoming_unbuilt=$(($inwok -$incoming_cooked))
331 pkg_pct=0
332 [ $inwok -gt 0 ] && pkg_pct=$(( ($pkg_cooked * 100) / $inwok ))
333 incoming_pct=0
334 [ $inwok -gt 0 ] && incoming_pct=$(( ($incoming_cooked * 100) / $inwok ))
335 cat << EOT
336 <div style="float: right;">
337 <form method="get" action="$SCRIPT_NAME">
338 Package:
339 <input type="text" name="pkg" />
340 </form>
341 </div>
343 <h2>Summary</h2>
345 <pre>
346 Running command : $([ -s "$command" ] && cat $command || echo "Not running")
347 Wok revision : <a href="$WOK_URL">$(cat $wokrev)</a>
348 Commits to cook : $(cat $commits | wc -l)
349 Current cooklist : $(cat $cooklist | wc -l)
350 Broken packages : $(cat $broken | wc -l)
351 Blocked packages : $(cat $blocked | wc -l)
352 Unbuild packages : $(cat $unbuild | wc -l)
353 </pre>
355 <p>
356 Packages: $inwok in the wok - Server date: $(date '+%Y-%m-%d %H:%M')
357 </p>
359 $pkg_cooked packages cooked - $pkg_unbuilt unbuilt
360 <div class="pctbar">
361 <div class="pct" style="width: ${pkg_pct}%;">${pkg_pct}%</div>
362 </div>
364 $incoming_cooked incoming packages cooked - $incoming_unbuilt unbuilt
365 <div class="pctbar">
366 <div class="pct" style="width: ${incoming_pct}%;">${incoming_pct}%</div>
367 </div>
369 <p>
370 Latest:
371 <a href="cooker.cgi?file=cookorder.log">cookorder.log</a>
372 <a href="cooker.cgi?file=commits.log">commits.log</a>
373 <a href="cooker.cgi?file=installed.diff">installed.diff</a>
374 - Architecture $ARCH:
375 <a href="$toolchain">toolchain</a>
376 </p>
378 <a name="activity"></a>
379 <h2>Activity</h2>
380 <pre>
381 $(tac $activity | head -n 12 | syntax_highlighter activity)
382 </pre>
383 <a class="button" href="cooker.cgi?file=activity">More activity</a>
385 <a name="cooknotes"></a>
386 <h2>Cooknotes</h2>
387 <pre>
388 $(tac $cooknotes | head -n 12 | syntax_highlighter activity)
389 </pre>
390 <a class="button" href="cooker.cgi?file=cooknotes">More notes</a>
392 <a name="commits"></a>
393 <h2>Commits</h2>
394 <pre>
395 $(cat $commits)
396 </pre>
398 <a name="cooklist"></a>
399 <h2>Cooklist</h2>
400 <pre>
401 $(cat $cooklist | head -n 20)
402 </pre>
403 <a class="button" href="cooker.cgi?file=cooklist">Full cooklist</a>
405 <a name="broken"></a>
406 <h2>Broken</h2>
407 <pre>
408 $(cat $broken | head -n 20 | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
409 </pre>
410 <a class="button" href="cooker.cgi?file=broken">All broken packages</a>
412 <a name="blocked"></a>
413 <h2>Blocked</h2>
414 <pre>
415 $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
416 </pre>
418 <a name="unbuild"></a>
419 <h2>Unbuild</h2>
420 <pre>
421 $(cat $unbuild | head -n 20)
422 </pre>
423 <a class="button" href="cooker.cgi?file=unbuild">Unbuild</a>
425 <a name="lastcook"></a>
426 <h2>Latest cook</h2>
427 <pre>
428 $(list_incoming | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
429 </pre>
431 <h2>Latest packages for mirror</h2>
432 <pre>
433 $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
434 </pre>
435 EOT
436 ;;
437 esac
439 if [ -f "footer.html" ]; then
440 cat footer.html
441 else
442 # Close xHTML page
443 cat << EOT
444 </div>
446 <div id="footer">
447 <a href="http://www.slitaz.org/">SliTaz Website</a>
448 <a href="cooker.cgi">Cooker</a>
449 <a href="http://hg.slitaz.org/cookutils/raw-file/tip/doc/cookutils.en.html">
450 Documentation</a>
451 </div>
453 </body>
454 </html>
455 EOT
456 fi
458 exit 0