cookutils view web/cooker.cgi @ rev 509

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