cookutils view web/cooker.cgi @ rev 439

cooker.cgi: add download link for ARCH
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed May 23 13:33:29 2012 +0200 (2012-05-23)
parents f96794734ee6
children 4721d19207ed a13f21acf937
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 $PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg ]; then
157 echo "<a href='cooker.cgi?download=$PACKAGE-$VERSION$EXTRAVERSION.tazpkg'>download</a>"
158 fi
159 if [ -f $PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg ]; then
160 echo "<a href='cooker.cgi?download=$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg'>download</a>"
161 fi
162 fi
163 else
164 echo "No package named: $pkg"
165 fi
166 echo '</div>'
168 # Check for a log file and display summary if it exists.
169 if [ -f "$log" ]; then
170 if grep -q "cook:$pkg$" $command; then
171 echo "<pre>The Cooker is currently building: $pkg</pre>"
172 fi
173 if fgrep -q "Summary for:" $LOGS/$pkg.log; then
174 echo "<h3>Cook summary</h3>"
175 echo '<pre>'
176 grep -A 9 "^Summary for:" $LOGS/$pkg.log | sed /^$/d | \
177 syntax_highlighter log
178 echo '</pre>'
179 fi
180 if fgrep -q "Debug information" $LOGS/$pkg.log; then
181 echo "<h3>Cook failed</h3>"
182 echo '<pre>'
183 grep -A 8 "^Debug information" $LOGS/$pkg.log | sed /^$/d | \
184 syntax_highlighter log
185 echo '</pre>'
186 fi
187 echo "<h3>Cook log</h3>"
188 echo '<pre>'
189 cat $log | syntax_highlighter log
190 echo '</pre>'
191 else
192 echo "<pre>No log: $pkg</pre>"
193 fi ;;
194 file=*)
195 # Dont allow all files on the system for security reasons.
196 file=${QUERY_STRING#file=}
197 case "$file" in
198 activity|cooknotes|cooklist)
199 [ "$file" == "cooklist" ] && \
200 nb="- Packages: $(cat $cooklist | wc -l)"
201 echo "<h2>DB: $file $nb</h2>"
202 echo '<pre>'
203 tac $CACHE/$file | syntax_highlighter activity
204 echo '</pre>' ;;
205 broken)
206 nb=$(cat $broken | wc -l)
207 echo "<h2>DB: broken - Packages: $nb</h2>"
208 echo '<pre>'
209 cat $CACHE/$file | sort | \
210 sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g
211 echo '</pre>' ;;
212 *.diff)
213 diff=$CACHE/$file
214 echo "<h2>Diff for: ${file%.diff}</h2>"
215 [ "$file" == "installed.diff" ] && echo \
216 "<p>This is the latest diff between installed packages \
217 and installed build dependencies to cook.</p>"
218 echo '<pre>'
219 cat $diff | syntax_highlighter diff
220 echo '</pre>' ;;
221 *.log)
222 log=$LOGS/$file
223 name=$(basename $log)
224 echo "<h2>Log for: ${name%.log}</h2>"
225 if [ -f "$log" ]; then
226 if fgrep -q "Summary" $log; then
227 echo '<pre>'
228 grep -A 20 "^Summary" $log | sed /^$/d | \
229 syntax_highlighter log
230 echo '</pre>'
231 fi
232 echo '<pre>'
233 cat $log | syntax_highlighter log
234 echo '</pre>'
235 else
236 echo "<pre>No log file: $log</pre>"
237 fi ;;
238 esac ;;
239 receipt=*)
240 pkg=${QUERY_STRING#receipt=}
241 echo "<h2>Receipt for: $pkg</h2>"
242 if [ -f "$wok/$pkg/receipt" ]; then
243 echo '<pre>'
244 cat $wok/$pkg/receipt | syntax_highlighter receipt
245 echo '</pre>'
246 else
247 echo "<pre>No receipt for: $pkg</pre>"
248 fi ;;
249 files=*)
250 pkg=${QUERY_STRING#files=}
251 echo "<h2>Installed files by: $pkg</h2>"
252 dir=$(ls -d $WOK/$pkg/taz/$pkg-*)
253 if [ -d "$dir/fs" ]; then
254 echo '<pre>'
255 find $dir/fs -not -type d | xargs ls -ld | \
256 sed "s|$dir/fs||" | syntax_highlighter log
257 echo '</pre>'
258 else
259 echo "<pre>No files list for: $pkg</pre>"
260 fi ;;
261 *)
262 # We may have a toolchain.cgi script for cross cooker's
263 if [ -f "toolchain.cgi" ]; then
264 toolchain='toolchain.cgi'
265 else
266 toolchain='cooker.cgi?pkg=slitaz-toolchain'
267 fi
268 # Main page with summary. Count only package include in ARCH,
269 # use 'cooker arch' to manually create arch.$ARCH files.
270 # We may have arm only packages, use arch.i486 ?
271 case "$ARCH" in
272 arm|x86_64) inwok=$(ls $WOK/*/arch.$ARCH | wc -l) ;;
273 *) inwok=$(ls $WOK | wc -l) ;;
274 esac
275 cooked=$(ls $PKGS/*.tazpkg | wc -l)
276 unbuilt=$(($inwok - $cooked))
277 pct=0
278 [ $inwok -gt 0 ] && pct=$(( ($cooked * 100) / $inwok ))
279 cat << EOT
280 <div style="float: right;">
281 <form method="get" action="$SCRIPT_NAME">
282 Package:
283 <input type="text" name="pkg" />
284 </form>
285 </div>
287 <h2>Summary</h2>
289 <pre>
290 Running command : $([ -s "$command" ] && cat $command || echo "Not running")
291 Wok revision : <a href="$WOK_URL">$(cat $wokrev)</a>
292 Commits to cook : $(cat $commits | wc -l)
293 Current cooklist : $(cat $cooklist | wc -l)
294 Broken packages : $(cat $broken | wc -l)
295 Blocked packages : $(cat $blocked | wc -l)
296 </pre>
298 <p class="info">
299 Packages: $inwok in the wok - $cooked cooked - $unbuilt unbuilt -
300 Server date: $(date '+%Y-%m-%d %H:%M')
301 </p>
302 <div class="pctbar">
303 <div class="pct" style="width: ${pct}%;">${pct}%</div>
304 </div>
306 <p>
307 Latest:
308 <a href="cooker.cgi?file=cookorder.log">cookorder.log</a>
309 <a href="cooker.cgi?file=commits.log">commits.log</a>
310 <a href="cooker.cgi?file=installed.diff">installed.diff</a>
311 - Architecture $ARCH:
312 <a href="$toolchain">toolchain</a>
313 </p>
315 <a name="activity"></a>
316 <h2>Activity</h2>
317 <pre>
318 $(tac $CACHE/activity | head -n 12 | syntax_highlighter activity)
319 </pre>
320 <a class="button" href="cooker.cgi?file=activity">More activity</a>
322 <a name="cooknotes"></a>
323 <h2>Cooknotes</h2>
324 <pre>
325 $(tac $cooknotes | head -n 12 | syntax_highlighter activity)
326 </pre>
327 <a class="button" href="cooker.cgi?file=cooknotes">More notes</a>
329 <a name="commits"></a>
330 <h2>Commits</h2>
331 <pre>
332 $(cat $commits)
333 </pre>
335 <a name="cooklist"></a>
336 <h2>Cooklist</h2>
337 <pre>
338 $(cat $cooklist | head -n 20)
339 </pre>
340 <a class="button" href="cooker.cgi?file=cooklist">Full cooklist</a>
342 <a name="broken"></a>
343 <h2>Broken</h2>
344 <pre>
345 $(cat $broken | head -n 20 | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
346 </pre>
347 <a class="button" href="cooker.cgi?file=broken">All broken packages</a>
349 <a name="blocked"></a>
350 <h2>Blocked</h2>
351 <pre>
352 $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
353 </pre>
355 <a name="lastcook"></a>
356 <h2>Latest cook</h2>
357 <pre>
358 $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
359 </pre>
360 EOT
361 ;;
362 esac
364 # Close xHTML page
365 cat << EOT
366 </div>
368 <div id="footer">
369 <a href="http://www.slitaz.org/">SliTaz Website</a>
370 <a href="cooker.cgi">Cooker</a>
371 <a href="http://hg.slitaz.org/cookutils/raw-file/tip/doc/cookutils.en.html">
372 Documentation</a>
373 </div>
375 </body>
376 </html>
377 EOT
379 exit 0