cookutils view web/cooker.cgi @ rev 502

Merge default.
author Christopher Rogers <slaxemulator@gmail.com>
date Wed Jun 20 23:17:27 2012 +0000 (2012-06-20)
parents 4721d19207ed 37e50cc5ecfb
children 8a9e17bb0140
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 receipt=*)
262 pkg=${QUERY_STRING#receipt=}
263 echo "<h2>Receipt for: $pkg</h2>"
264 if [ -f "$WOK/$pkg/receipt" ]; then
265 echo '<pre>'
266 cat $WOK/$pkg/receipt | syntax_highlighter receipt
267 echo '</pre>'
268 else
269 echo "<pre>No receipt for: $pkg</pre>"
270 fi ;;
271 files=*)
272 pkg=${QUERY_STRING#files=}
273 echo "<h2>Installed files by: $pkg</h2>"
274 dir=$(ls -d $WOK/$pkg/taz/$pkg-*)
275 if [ -d "$dir/fs" ]; then
276 echo '<pre>'
277 find $dir/fs -not -type d | xargs ls -ld | \
278 sed "s|$dir/fs||" | syntax_highlighter log
279 echo '</pre>'
280 else
281 echo "<pre>No files list for: $pkg</pre>"
282 fi ;;
283 library=*)
284 pkg=${QUERY_STRING#library=}
285 echo "<h2>Library for: $pkg</h2>"
286 if [ -f $WOK/$pkg/taz/*/library.list ]; then
287 echo '<pre>'
288 cat $WOK/$pkg/taz/*/library.list | sed "s|$pkg ||g" | sed 's| |\n|g' | sed '/^$/d'
289 echo '</pre>'
290 fi ;;
291 description=*)
292 pkg=${QUERY_STRING#description=}
293 echo "<h2>Description of $pkg</h2>"
294 dir=$(ls -d $WOK/$pkg/taz/$pkg-*)
295 if [ -s "$dir/description.txt" ]; then
296 echo '<pre>'
297 cat $dir/description.txt
298 echo '</pre>'
299 else
300 echo "<pre>No description for: $pkg</pre>"
301 fi ;;
302 *)
303 # We may have a toolchain.cgi script for cross cooker's
304 if [ -f "toolchain.cgi" ]; then
305 toolchain='toolchain.cgi'
306 else
307 toolchain='cooker.cgi?pkg=slitaz-toolchain'
308 fi
309 # Main page with summary. Count only package include in ARCH,
310 # use 'cooker arch' to manually create arch.$ARCH files.
311 # We may have arm only packages, use arch.i486 ?
312 case "$ARCH" in
313 arm|x86_64) inwok=$(ls $WOK/*/arch.$ARCH | wc -l) ;;
314 *) inwok=$(ls $WOK | wc -l) ;;
315 esac
316 pkg_cooked=$(ls $PKGS/*.tazpkg | wc -l)
317 incoming_cooked=$(ls $INCOMING/*.tazpkg | wc -l)
318 pkg_unbuilt=$(($inwok - $pkg_cooked))
319 incoming_unbuilt=$(($inwok -$incoming_cooked))
320 pkg_pct=0
321 [ $inwok -gt 0 ] && pkg_pct=$(( ($pkg_cooked * 100) / $inwok ))
322 incoming_pct=0
323 [ $inwok -gt 0 ] && incoming_pct=$(( ($incoming_cooked * 100) / $inwok ))
324 cat << EOT
325 <div style="float: right;">
326 <form method="get" action="$SCRIPT_NAME">
327 Package:
328 <input type="text" name="pkg" />
329 </form>
330 </div>
332 <h2>Summary</h2>
334 <pre>
335 Running command : $([ -s "$command" ] && cat $command || echo "Not running")
336 Wok revision : <a href="$WOK_URL">$(cat $wokrev)</a>
337 Commits to cook : $(cat $commits | wc -l)
338 Current cooklist : $(cat $cooklist | wc -l)
339 Broken packages : $(cat $broken | wc -l)
340 Blocked packages : $(cat $blocked | wc -l)
341 Unbuild packages : $(cat $unbuild | wc -l)
342 </pre>
344 <p>
345 Packages: $inwok in the wok - Server date: $(date '+%Y-%m-%d %H:%M')
346 </p>
348 $pkg_cooked packages cooked - $pkg_unbuilt unbuilt
349 <div class="pctbar">
350 <div class="pct" style="width: ${pkg_pct}%;">${pkg_pct}%</div>
351 </div>
353 $incoming_cooked incoming packages cooked - $incoming_unbuilt unbuilt
354 <div class="pctbar">
355 <div class="pct" style="width: ${incoming_pct}%;">${incoming_pct}%</div>
356 </div>
358 <p>
359 Latest:
360 <a href="cooker.cgi?file=cookorder.log">cookorder.log</a>
361 <a href="cooker.cgi?file=commits.log">commits.log</a>
362 <a href="cooker.cgi?file=installed.diff">installed.diff</a>
363 - Architecture $ARCH:
364 <a href="$toolchain">toolchain</a>
365 </p>
367 <a name="activity"></a>
368 <h2>Activity</h2>
369 <pre>
370 $(tac $activity | head -n 12 | syntax_highlighter activity)
371 </pre>
372 <a class="button" href="cooker.cgi?file=activity">More activity</a>
374 <a name="cooknotes"></a>
375 <h2>Cooknotes</h2>
376 <pre>
377 $(tac $cooknotes | head -n 12 | syntax_highlighter activity)
378 </pre>
379 <a class="button" href="cooker.cgi?file=cooknotes">More notes</a>
381 <a name="commits"></a>
382 <h2>Commits</h2>
383 <pre>
384 $(cat $commits)
385 </pre>
387 <a name="cooklist"></a>
388 <h2>Cooklist</h2>
389 <pre>
390 $(cat $cooklist | head -n 20)
391 </pre>
392 <a class="button" href="cooker.cgi?file=cooklist">Full cooklist</a>
394 <a name="broken"></a>
395 <h2>Broken</h2>
396 <pre>
397 $(cat $broken | head -n 20 | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
398 </pre>
399 <a class="button" href="cooker.cgi?file=broken">All broken packages</a>
401 <a name="blocked"></a>
402 <h2>Blocked</h2>
403 <pre>
404 $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
405 </pre>
407 <a name="unbuild"></a>
408 <h2>Unbuild</h2>
409 <pre>
410 $(cat $unbuild | head -n 20)
411 </pre>
412 <a class="button" href="cooker.cgi?file=unbuild">Unbuild</a>
414 <a name="lastcook"></a>
415 <h2>Latest cook</h2>
416 <pre>
417 $(list_incoming | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
418 </pre>
420 <h2>Latest packages for mirror</h2>
421 <pre>
422 $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
423 </pre>
424 EOT
425 ;;
426 esac
428 if [ -f "footer.html" ]; then
429 cat footer.html
430 else
431 # Close xHTML page
432 cat << EOT
433 </div>
435 <div id="footer">
436 <a href="http://www.slitaz.org/">SliTaz Website</a>
437 <a href="cooker.cgi">Cooker</a>
438 <a href="http://hg.slitaz.org/cookutils/raw-file/tip/doc/cookutils.en.html">
439 Documentation</a>
440 </div>
442 </body>
443 </html>
444 EOT
445 fi
447 exit 0