cookutils view web/cooker.cgi @ rev 560

cooker.cgi: packages content downloadable
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Dec 31 16:50:06 2012 +0100 (2012-12-31)
parents 5f7de45f7440
children 1bd258f7838a
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 | syntax_highlighter log
194 echo '</pre>'
195 else
196 echo "<pre>No log: $pkg</pre>"
197 fi ;;
198 file=*)
199 # Dont allow all files on the system for security reasons.
200 file=${QUERY_STRING#file=}
201 case "$file" in
202 activity|cooknotes|cooklist)
203 [ "$file" == "cooklist" ] && \
204 nb="- Packages: $(cat $cooklist | wc -l)"
205 echo "<h2>DB: $file $nb</h2>"
206 echo '<pre>'
207 tac $CACHE/$file | syntax_highlighter activity
208 echo '</pre>' ;;
209 broken)
210 nb=$(cat $broken | wc -l)
211 echo "<h2>DB: broken - Packages: $nb</h2>"
212 echo '<pre>'
213 cat $CACHE/$file | sort | \
214 sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g
215 echo '</pre>' ;;
216 *.diff)
217 diff=$CACHE/$file
218 echo "<h2>Diff for: ${file%.diff}</h2>"
219 [ "$file" == "installed.diff" ] && echo \
220 "<p>This is the latest diff between installed packages \
221 and installed build dependencies to cook.</p>"
222 echo '<pre>'
223 cat $diff | syntax_highlighter diff
224 echo '</pre>' ;;
225 *.log)
226 log=$LOGS/$file
227 name=$(basename $log)
228 echo "<h2>Log for: ${name%.log}</h2>"
229 if [ -f "$log" ]; then
230 if fgrep -q "Summary" $log; then
231 echo '<pre>'
232 grep -A 20 "^Summary" $log | sed /^$/d | \
233 syntax_highlighter log
234 echo '</pre>'
235 fi
236 echo '<pre>'
237 cat $log | syntax_highlighter log
238 echo '</pre>'
239 else
240 echo "<pre>No log file: $log</pre>"
241 fi ;;
242 esac ;;
243 stuff=*)
244 file=${QUERY_STRING#stuff=}
245 echo "<h2>$file</h2>"
246 echo '<pre>'
247 cat $wok/$file
248 echo '</pre>' ;;
249 receipt=*)
250 pkg=${QUERY_STRING#receipt=}
251 echo "<h2>Receipt for: $pkg</h2>"
252 if [ -f "$wok/$pkg/receipt" ]; then
253 ( cd $wok/$pkg ; find stuff -type f 2> /dev/null ) | \
254 while read file ; do
255 echo "<a href=\"?stuff=$pkg/$file\">$file</a>"
256 done
257 echo '<pre>'
258 cat $wok/$pkg/receipt | syntax_highlighter receipt
259 echo '</pre>'
260 else
261 echo "<pre>No receipt for: $pkg</pre>"
262 fi ;;
263 files=*)
264 pkg=${QUERY_STRING#files=}
265 echo "<h2>Installed files by: $pkg</h2>"
266 dir=$(ls -d $WOK/$pkg/taz/$pkg-*)
267 if [ -d "$dir/fs" ]; then
268 echo '<pre>'
269 find $dir/fs -not -type d | xargs ls -ld | \
270 sed "s|\(.*\) /.*\(${dir#*wok}/fs\)\(.*\)|\1 <a href=\"?download=../wok\2\3\">\3</a>|" | \
271 syntax_highlighter log
272 echo '</pre>'
273 else
274 echo "<pre>No files list for: $pkg</pre>"
275 fi ;;
276 description=*)
277 pkg=${QUERY_STRING#description=}
278 echo "<h2>Description of $pkg</h2>"
279 dir=$(ls -d $WOK/$pkg/taz/$pkg-*)
280 if [ -s "$dir/description.txt" ]; then
281 echo '<pre>'
282 cat $dir/description.txt
283 echo '</pre>'
284 else
285 echo "<pre>No description for: $pkg</pre>"
286 fi ;;
287 *)
288 # We may have a toolchain.cgi script for cross cooker's
289 if [ -f "toolchain.cgi" ]; then
290 toolchain='toolchain.cgi'
291 else
292 toolchain='cooker.cgi?pkg=slitaz-toolchain'
293 fi
294 # Main page with summary. Count only package include in ARCH,
295 # use 'cooker arch' to manually create arch.$ARCH files.
296 # We may have arm only packages, use arch.i486 ?
297 case "$ARCH" in
298 arm|x86_64) inwok=$(ls $WOK/*/arch.$ARCH | wc -l) ;;
299 *) inwok=$(ls $WOK | wc -l) ;;
300 esac
301 cooked=$(ls $PKGS/*.tazpkg | wc -l)
302 unbuilt=$(($inwok - $cooked))
303 pct=0
304 [ $inwok -gt 0 ] && pct=$(( ($cooked * 100) / $inwok ))
305 cat << EOT
306 <div style="float: right;">
307 <form method="get" action="$SCRIPT_NAME">
308 Package:
309 <input type="text" name="pkg" />
310 </form>
311 </div>
313 <h2>Summary</h2>
315 <pre>
316 Running command : $([ -s "$command" ] && cat $command || echo "Not running")
317 Wok revision : <a href="$WOK_URL">$(cat $wokrev)</a>
318 Commits to cook : $(cat $commits | wc -l)
319 Current cooklist : $(cat $cooklist | wc -l)
320 Broken packages : $(cat $broken | wc -l)
321 Blocked packages : $(cat $blocked | wc -l)
322 </pre>
324 <p class="info">
325 Packages: $inwok in the wok - $cooked cooked - $unbuilt unbuilt -
326 Server date: $(date '+%Y-%m-%d %H:%M')
327 </p>
328 <div class="pctbar">
329 <div class="pct" style="width: ${pct}%;">${pct}%</div>
330 </div>
332 <p>
333 Latest:
334 <a href="cooker.cgi?file=cookorder.log">cookorder.log</a>
335 <a href="cooker.cgi?file=commits.log">commits.log</a>
336 <a href="cooker.cgi?file=installed.diff">installed.diff</a>
337 - Architecture $ARCH:
338 <a href="$toolchain">toolchain</a>
339 </p>
341 <a name="activity"></a>
342 <h2>Activity</h2>
343 <pre>
344 $(tac $CACHE/activity | head -n 12 | syntax_highlighter activity)
345 </pre>
346 <a class="button" href="cooker.cgi?file=activity">More activity</a>
348 <a name="cooknotes"></a>
349 <h2>Cooknotes</h2>
350 <pre>
351 $(tac $cooknotes | head -n 12 | syntax_highlighter activity)
352 </pre>
353 <a class="button" href="cooker.cgi?file=cooknotes">More notes</a>
355 <a name="commits"></a>
356 <h2>Commits</h2>
357 <pre>
358 $(cat $commits)
359 </pre>
361 <a name="cooklist"></a>
362 <h2>Cooklist</h2>
363 <pre>
364 $(cat $cooklist | head -n 20)
365 </pre>
366 <a class="button" href="cooker.cgi?file=cooklist">Full cooklist</a>
368 <a name="broken"></a>
369 <h2>Broken</h2>
370 <pre>
371 $(cat $broken | head -n 20 | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
372 </pre>
373 <a class="button" href="cooker.cgi?file=broken">All broken packages</a>
375 <a name="blocked"></a>
376 <h2>Blocked</h2>
377 <pre>
378 $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
379 </pre>
381 <a name="lastcook"></a>
382 <h2>Latest cook</h2>
383 <pre>
384 $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
385 </pre>
386 EOT
387 ;;
388 esac
390 # Close xHTML page
391 cat << EOT
392 </div>
394 <div id="footer">
395 <a href="http://www.slitaz.org/">SliTaz Website</a>
396 <a href="cooker.cgi">Cooker</a>
397 <a href="http://hg.slitaz.org/cookutils/raw-file/tip/doc/cookutils.en.html">
398 Documentation</a>
399 </div>
401 </body>
402 </html>
403 EOT
405 exit 0