cookutils view web/cooker.cgi @ rev 628

cook: Aufs mountage failure cleanup
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Jan 05 17:14:38 2014 +0000 (2014-01-05)
parents 9899fbd15073
children b1b010c31c38
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 %Z")
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</lastBuildDate>
52 <pubDate>$pubdate</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/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g' \
74 -e 's#OK$#<span class="span-ok">OK</span>#g' \
75 -e 's#Done$#<span class="span-ok">Done</span>#g' \
76 -e 's#yes$#<span class="span-ok">yes</span>#g' \
77 -e 's#no$#<span class="span-no">no</span>#g' \
78 -e 's#error$#<span class="span-red">error</span>#g' \
79 -e 's#ERROR:#<span class="span-red">ERROR:</span>#g' \
80 -e 's#WARNING:#<span class="span-red">WARNING:</span>#g' \
81 -e s"#^Executing:\([^']*\).#<span class='sh-val'>\0</span>#"g \
82 -e s"#^====\([^']*\).#<span class='span-line'>\0</span>#"g \
83 -e s"#^[a-zA-Z0-9]\([^']*\) :: #<span class='span-sky'>\0</span>#"g \
84 -e s"#ftp://[^ '\"]*#<a href='\0'>\0</a>#"g \
85 -e s"#http://[^ '\"]*#<a href='\0'>\0</a>#"g ;;
86 receipt)
87 sed -e s'|&|\&amp;|g' -e 's|<|\&lt;|g' -e 's|>|\&gt;|'g \
88 -e s"#^\#\([^']*\)#<span class='sh-comment'>\0</span>#"g \
89 -e s"#\"\([^']*\)\"#<span class='sh-val'>\0</span>#"g ;;
90 diff)
91 sed -e 's|&|\&amp;|g' -e 's|<|\&lt;|g' -e 's|>|\&gt;|g' \
92 -e s"#^-\([^']*\).#<span class='span-red'>\0</span>#"g \
93 -e s"#^+\([^']*\).#<span class='span-ok'>\0</span>#"g \
94 -e s"#@@\([^']*\)@@#<span class='span-sky'>@@\1@@</span>#"g ;;
95 activity)
96 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g ;;
97 esac
98 }
100 # Latest build pkgs.
101 list_packages() {
102 cd $PKGS
103 ls -1t *.tazpkg | head -20 | \
104 while read file
105 do
106 echo -n $(stat -c '%y' $PKGS/$file | cut -d . -f 1 | sed s/:[0-9]*$//)
107 echo " : $file"
108 done
109 }
111 # Optional full list button
112 more_button() {
113 [ $(wc -l < ${3:-$CACHE/$1}) -gt ${4:-12} ] &&
114 echo "<a class=\"button\" href=\"cooker.cgi?file=$1\">$2</a>"
115 }
117 # xHTML header. Pages can be customized with a separated html.header file.
118 if [ -f "header.html" ]; then
119 cat header.html
120 else
121 cat << EOT
122 <!DOCTYPE html>
123 <html xmlns="http://www.w3.org/1999/xhtml">
124 <head>
125 <title>SliTaz Cooker</title>
126 <meta charset="utf-8" />
127 <link rel="shortcut icon" href="favicon.ico" />
128 <link rel="stylesheet" type="text/css" href="style.css" />
129 </head>
130 <body>
132 <div id="header">
133 <div id="logo"></div>
134 <h1><a href="cooker.cgi">SliTaz Cooker</a></h1>
135 </div>
137 <!-- Content -->
138 <div id="content">
139 EOT
140 fi
142 #
143 # Load requested page
144 #
146 case "${QUERY_STRING}" in
147 pkg=*)
148 pkg=${QUERY_STRING#pkg=}
149 log=$LOGS/$pkg.log
150 echo "<h2>Package: $pkg</h2>"
152 # Package info.
153 echo '<div id="info">'
154 if [ -f "$wok/$pkg/receipt" ]; then
155 echo "<a href='cooker.cgi?receipt=$pkg'>receipt</a>"
156 unset WEB_SITE
157 . $wok/$pkg/receipt
158 [ -n "$WEB_SITE" ] && # busybox wget -s $WEB_SITE &&
159 echo "<a href='$WEB_SITE'>home</a>"
160 if [ -f "$wok/$pkg/taz/$PACKAGE-$VERSION/receipt" ]; then
161 echo "<a href='cooker.cgi?files=$pkg'>files</a>"
162 unset EXTRAVERSION
163 . $wok/$pkg/taz/$PACKAGE-$VERSION/receipt
164 if [ -f $wok/$pkg/taz/$PACKAGE-$VERSION/description.txt ]; then
165 echo "<a href='cooker.cgi?description=$pkg'>description</a>"
166 fi
167 if [ -f $PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg ]; then
168 echo "<a href='cooker.cgi?download=$PACKAGE-$VERSION$EXTRAVERSION.tazpkg'>download</a>"
169 fi
170 if [ -f $PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg ]; then
171 echo "<a href='cooker.cgi?download=$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg'>download</a>"
172 fi
173 fi
174 else
175 echo "No package named: $pkg"
176 fi
177 echo '</div>'
179 # Check for a log file and display summary if it exists.
180 if [ -f "$log" ]; then
181 if grep -q "cook:$pkg$" $command; then
182 echo "<pre>The Cooker is currently building: $pkg</pre>"
183 fi
184 if fgrep -q "Summary for:" $LOGS/$pkg.log; then
185 echo "<h3>Cook summary</h3>"
186 echo '<pre>'
187 grep -A 9 "^Summary for:" $LOGS/$pkg.log | sed /^$/d | \
188 syntax_highlighter log
189 echo '</pre>'
190 fi
191 if fgrep -q "Debug information" $LOGS/$pkg.log; then
192 echo "<h3>Cook failed</h3>"
193 echo '<pre>'
194 grep -A 8 "^Debug information" $LOGS/$pkg.log | sed /^$/d | \
195 syntax_highlighter log
196 echo '</pre>'
197 fi
198 echo "<h3>Cook log</h3>"
199 echo '<pre>'
200 cat $log | syntax_highlighter log
201 echo '</pre>'
202 else
203 echo "<pre>No log: $pkg</pre>"
204 fi ;;
205 file=*)
206 # Dont allow all files on the system for security reasons.
207 file=${QUERY_STRING#file=}
208 case "$file" in
209 activity|cooknotes|cooklist)
210 [ "$file" == "cooklist" ] && \
211 nb="- Packages: $(cat $cooklist | wc -l)"
212 echo "<h2>DB: $file $nb</h2>"
213 echo '<pre>'
214 tac $CACHE/$file | syntax_highlighter activity
215 echo '</pre>' ;;
216 broken)
217 nb=$(cat $broken | wc -l)
218 echo "<h2>DB: broken - Packages: $nb</h2>"
219 echo '<pre>'
220 cat $CACHE/$file | sort | \
221 sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g
222 echo '</pre>' ;;
223 *.diff)
224 diff=$CACHE/$file
225 echo "<h2>Diff for: ${file%.diff}</h2>"
226 [ "$file" == "installed.diff" ] && echo \
227 "<p>This is the latest diff between installed packages \
228 and installed build dependencies to cook.</p>"
229 echo '<pre>'
230 cat $diff | syntax_highlighter diff
231 echo '</pre>' ;;
232 *.log)
233 log=$LOGS/$file
234 name=$(basename $log)
235 echo "<h2>Log for: ${name%.log}</h2>"
236 if [ -f "$log" ]; then
237 if fgrep -q "Summary" $log; then
238 echo '<pre>'
239 grep -A 20 "^Summary" $log | sed /^$/d | \
240 syntax_highlighter log
241 echo '</pre>'
242 fi
243 echo '<pre>'
244 cat $log | syntax_highlighter log
245 echo '</pre>'
246 else
247 echo "<pre>No log file: $log</pre>"
248 fi ;;
249 esac ;;
250 stuff=*)
251 file=${QUERY_STRING#stuff=}
252 echo "<h2>$file</h2>"
253 echo '<pre>'
254 cat $wok/$file | sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g'
255 echo '</pre>' ;;
256 receipt=*)
257 pkg=${QUERY_STRING#receipt=}
258 echo "<h2>Receipt for: $pkg</h2>"
259 if [ -f "$wok/$pkg/receipt" ]; then
260 ( cd $wok/$pkg ; find stuff -type f 2> /dev/null ) | \
261 while read file ; do
262 echo "<a href=\"?stuff=$pkg/$file\">$file</a>"
263 done
264 echo '<pre>'
265 cat $wok/$pkg/receipt | \
266 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#*wok}/fs\)\(.*\)|\1 <a href=\"?download=../wok\2\3\">\3</a>|;s|^\([^-].*\)\(<a.*\)\">\(.*\)</a>|\1\3|"
279 echo '</pre>'
280 else
281 echo "<pre>No files list for: $pkg</pre>"
282 fi ;;
283 description=*)
284 pkg=${QUERY_STRING#description=}
285 echo "<h2>Description of $pkg</h2>"
286 dir=$(ls -d $WOK/$pkg/taz/$pkg-*)
287 if [ -s "$dir/description.txt" ]; then
288 echo '<pre>'
289 cat $dir/description.txt | \
290 sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g'
291 echo '</pre>'
292 else
293 echo "<pre>No description for: $pkg</pre>"
294 fi ;;
295 *)
296 # We may have a toolchain.cgi script for cross cooker's
297 if [ -f "toolchain.cgi" ]; then
298 toolchain='toolchain.cgi'
299 else
300 toolchain='cooker.cgi?pkg=slitaz-toolchain'
301 fi
302 # Main page with summary. Count only package include in ARCH,
303 # use 'cooker arch' to manually create arch.$ARCH files.
304 # We may have arm only packages, use arch.i486 ?
305 case "$ARCH" in
306 arm|x86_64) inwok=$(ls $WOK/*/arch.$ARCH | wc -l) ;;
307 *) inwok=$(ls $WOK | wc -l) ;;
308 esac
309 cooked=$(ls $PKGS/*.tazpkg | wc -l)
310 unbuilt=$(($inwok - $cooked))
311 pct=0
312 [ $inwok -gt 0 ] && pct=$(( ($cooked * 100) / $inwok ))
313 cat << EOT
314 <div style="float: right;">
315 <form method="get" action="$SCRIPT_NAME">
316 Package:
317 <input type="text" name="pkg" />
318 </form>
319 </div>
321 <h2>Summary</h2>
323 <pre>
324 Running command : $([ -s "$command" ] && cat $command || echo "Not running")
325 Wok revision : <a href="$WOK_URL">$(cat $wokrev)</a>
326 Commits to cook : $(cat $commits | wc -l)
327 Current cooklist : $(cat $cooklist | wc -l)
328 Broken packages : $(cat $broken | wc -l)
329 Blocked packages : $(cat $blocked | wc -l)
330 </pre>
332 <p class="info">
333 Packages: $inwok in the wok - $cooked cooked - $unbuilt unbuilt -
334 Server date: $(date '+%Y-%m-%d %H:%M %Z')
335 </p>
336 <div class="pctbar">
337 <div class="pct" style="width: ${pct}%;">${pct}%</div>
338 </div>
340 <p>
341 Latest:
342 <a href="cooker.cgi?file=cookorder.log">cookorder.log</a>
343 <a href="cooker.cgi?file=commits.log">commits.log</a>
344 <a href="cooker.cgi?file=installed.diff">installed.diff</a>
345 - Architecture $ARCH:
346 <a href="$toolchain">toolchain</a>
347 </p>
349 <a name="activity"></a>
350 <h2>Activity</h2>
351 <pre>
352 $(tac $CACHE/activity | head -n 12 | syntax_highlighter activity)
353 </pre>
354 $(more_button activity "More activity" $CACHE/activity 12)
356 <a name="cooknotes"></a>
357 <h2>Cooknotes</h2>
358 <pre>
359 $(tac $cooknotes | head -n 12 | syntax_highlighter activity)
360 </pre>
361 $(more_button cooknotes "More notes" $cooknotes 12)
363 <a name="commits"></a>
364 <h2>Commits</h2>
365 <pre>
366 $(cat $commits)
367 </pre>
369 <a name="cooklist"></a>
370 <h2>Cooklist</h2>
371 <pre>
372 $(cat $cooklist | head -n 20)
373 </pre>
374 $(more_button cooklist "Full cooklist" $cooklist 20)
376 <a name="broken"></a>
377 <h2>Broken</h2>
378 <pre>
379 $(cat $broken | head -n 20 | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
380 </pre>
381 $(more_button broken "All broken packages" $broken 20)
383 <a name="blocked"></a>
384 <h2>Blocked</h2>
385 <pre>
386 $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
387 </pre>
389 <a name="lastcook"></a>
390 <h2>Latest cook</h2>
391 <pre>
392 $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
393 </pre>
394 EOT
395 ;;
396 esac
398 # Close xHTML page
399 cat << EOT
400 </div>
402 <div id="footer">
403 <a href="http://www.slitaz.org/">SliTaz Website</a>
404 <a href="cooker.cgi">Cooker</a>
405 <a href="http://hg.slitaz.org/cookutils/raw-file/tip/doc/cookutils.en.html">
406 Documentation</a>
407 </div>
409 </body>
410 </html>
411 EOT
413 exit 0