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