cookutils view web/cooker.cgi @ rev 355

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