cookutils view web/cooker.cgi @ rev 590

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