cookutils view web/cooker.cgi @ rev 728

Move to using short i18n functions with "printf", so rewrite sources and po files. Fix: stripping before list files (python packages listed missed .pyc files). Also remove few hacks from code, make pot and msgmerge.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Thu May 07 15:11:47 2015 +0300 (2015-05-07)
parents 851a2b8075dc
children d15a44a622f6
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=$(busybox httpd -d "$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 -n "Content-Type: "
39 if [ "$QUERY_STRING" == 'rss' ]; then
40 echo 'application/rss+xml'
41 else
42 echo 'text/html; charset=utf-8'
43 fi
44 echo ''
46 # RSS feed generator
47 if [ "$QUERY_STRING" == 'rss' ]; then
48 pubdate=$(date -R)
49 cat <<EOT
50 <?xml version="1.0" encoding="utf-8" ?>
51 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
52 <channel>
53 <title>SliTaz Cooker</title>
54 <description>The SliTaz packages cooker feed</description>
55 <link>$COOKER_URL</link>
56 <lastBuildDate>$pubdate</lastBuildDate>
57 <pubDate>$pubdate</pubDate>
58 <atom:link href="http://cook.slitaz.org/cooker.cgi?rss" rel="self" type="application/rss+xml" />
59 EOT
60 for rss in $(ls -lt $FEEDS/*.xml | head -n 12); do
61 cat $rss | sed 's|<guid|& isPermaLink="false"|g;s|</pubDate| GMT&|g'
62 done
63 cat <<EOT
64 </channel>
65 </rss>
66 EOT
67 exit 0
68 fi
71 #
72 # Functions
73 #
76 # Put some colors in log and DB files.
78 syntax_highlighter() {
79 case $1 in
80 log)
81 sed -e 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g' \
82 -e 's#OK$#<span class="span-ok">OK</span>#g' \
83 -e 's#Done$#<span class="span-ok">Done</span>#g' \
84 -e 's#yes$#<span class="span-ok">yes</span>#g' \
85 -e 's#no$#<span class="span-no">no</span>#g' \
86 -e 's#error$#<span class="span-red">error</span>#g' \
87 -e 's#ERROR:#<span class="span-red">ERROR:</span>#g' \
88 -e 's#WARNING:#<span class="span-red">WARNING:</span>#g' \
89 -e s"#^Executing:\([^']*\).#<span class='sh-val'>\0</span>#"g \
90 -e s"#^====\([^']*\).#<span class='span-line'>\0</span>#"g \
91 -e s"#^[a-zA-Z0-9]\([^']*\) :: #<span class='span-sky'>\0</span>#"g \
92 -e s"#ftp://[^ '\"]*#<a href='\0'>\0</a>#"g \
93 -e s"#http://[^ '\"]*#<a href='\0'>\0</a>#"g ;;
95 receipt)
96 sed -e s'|&|\&amp;|g' -e 's|<|\&lt;|g' -e 's|>|\&gt;|'g \
97 -e s"#^\#\([^']*\)#<span class='sh-comment'>\0</span>#"g \
98 -e s"#\"\([^']*\)\"#<span class='sh-val'>\0</span>#"g ;;
100 diff)
101 sed -e 's|&|\&amp;|g' -e 's|<|\&lt;|g' -e 's|>|\&gt;|g' \
102 -e s"#^-\([^']*\).#<span class='span-red'>\0</span>#"g \
103 -e s"#^+\([^']*\).#<span class='span-ok'>\0</span>#"g \
104 -e s"#@@\([^']*\)@@#<span class='span-sky'>@@\1@@</span>#"g ;;
106 activity)
107 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g ;;
108 esac
109 }
112 # Latest build pkgs.
114 list_packages() {
115 cd $PKGS
116 ls -1t *.tazpkg | head -20 | \
117 while read file; do
118 echo -n $(stat -c '%y' $PKGS/$file | cut -d . -f 1 | sed s/:[0-9]*$//)
119 echo " : $file"
120 done
121 }
124 # Optional full list button
126 more_button() {
127 [ $(wc -l < ${3:-$CACHE/$1}) -gt ${4:-12} ] &&
128 echo "<a class=\"button\" href=\"cooker.cgi?file=$1\">$2</a>"
129 }
132 # xHTML header. Pages can be customized with a separated html.header file.
134 if [ -f "header.html" ]; then
135 cat header.html
136 else
137 cat <<EOT
138 <!DOCTYPE html>
139 <html lang="en">
140 <head>
141 <meta charset="utf-8"/>
142 <title>SliTaz Cooker</title>
143 <link rel="shortcut icon" href="favicon.ico"/>
144 <link rel="stylesheet" type="text/css" href="style.css"/>
145 </head>
146 <body>
148 <div id="header">
149 <div id="logo"></div>
150 <h1><a href="cooker.cgi">SliTaz Cooker</a></h1>
151 </div>
153 <!-- Content -->
154 <div id="content">
155 EOT
156 fi
159 #
160 # Load requested page
161 #
163 case "${QUERY_STRING}" in
164 pkg=*)
165 pkg=${QUERY_STRING#pkg=}
166 log=$LOGS/$pkg.log
167 echo "<h2>Package: $pkg</h2>"
169 # Package info.
170 echo '<div id="info">'
171 if [ -f "$wok/$pkg/receipt" ]; then
172 echo "<a href='cooker.cgi?receipt=$pkg'>receipt</a>"
173 unset WEB_SITE
174 . $wok/$pkg/receipt
176 [ -n "$WEB_SITE" ] && # busybox wget -s $WEB_SITE &&
177 echo "<a href='$WEB_SITE'>home</a>"
179 if [ -f "$wok/$pkg/taz/$PACKAGE-$VERSION/receipt" ]; then
180 echo "<a href='cooker.cgi?files=$pkg'>files</a>"
181 unset EXTRAVERSION
182 . $wok/$pkg/taz/$PACKAGE-$VERSION/receipt
183 if [ -f $wok/$pkg/taz/$PACKAGE-$VERSION/description.txt ]; then
184 echo "<a href='cooker.cgi?description=$pkg'>description</a>"
185 fi
186 if [ -f $PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg ]; then
187 echo "<a href='cooker.cgi?download=$PACKAGE-$VERSION$EXTRAVERSION.tazpkg'>download</a>"
188 fi
189 if [ -f $PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg ]; then
190 echo "<a href='cooker.cgi?download=$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg'>download</a>"
191 fi
192 echo "<a href='ftp://${HTTP_HOST%:*}/$pkg/'>browse</a>"
193 fi
194 else
195 if [ $(ls $wok/*$pkg*/receipt 2> /dev/null | wc -l) -eq 0 ]; then
196 echo "No package named: $pkg"
197 else
198 ls $wok/$pkg/receipt >/dev/null 2>&1 || pkg="*$pkg*"
199 echo '<table style="width:100%">'
200 for i in $(cd $wok ; ls $pkg/receipt); do
201 pkg=$(dirname $i)
202 unset SHORT_DESC CATEGORY
203 . $wok/$pkg/receipt
204 cat <<EOT
205 <tr>
206 <td><a href="cooker.cgi?pkg=$pkg">$pkg</a></td>
207 <td>$SHORT_DESC</td>
208 <td>$CATEGORY</td>
209 </tr>
210 EOT
211 done
212 echo '</table>'
213 unset pkg
214 fi
215 fi
216 echo '</div>'
218 # Check for a log file and display summary if it exists.
219 if [ -f "$log" ]; then
220 if grep -q "cook:$pkg$" $command; then
221 echo "<pre>The Cooker is currently building: $pkg</pre>"
222 fi
223 if fgrep -q "Summary for:" $LOGS/$pkg.log; then
224 echo '<h3>Cook summary</h3>'
225 echo '<pre>'
226 grep -A 12 "^Summary for:" $LOGS/$pkg.log | sed /^$/d | \
227 syntax_highlighter log
228 echo '</pre>'
229 fi
230 if fgrep -q "Debug information" $LOGS/$pkg.log; then
231 echo '<h3>Cook failed</h3>'
232 echo '<pre>'
233 grep -A 8 "^Debug information" $LOGS/$pkg.log | sed /^$/d | \
234 syntax_highlighter log
235 echo '</pre>'
236 fi
237 echo '<h3>Cook log</h3>'
238 echo '<pre>'
239 cat $log | syntax_highlighter log
240 echo '</pre>'
241 else
242 [ "$pkg" ] && echo "<pre>No log: $pkg</pre>"
243 fi ;;
245 file=*)
246 # Don't allow all files on the system for security reasons.
247 file=${QUERY_STRING#file=}
248 case "$file" in
249 activity|cooknotes|cooklist)
250 [ "$file" == "cooklist" ] && \
251 nb="- Packages: $(cat $cooklist | wc -l)"
252 echo "<h2>DB: $file $nb</h2>"
253 echo '<pre>'
254 tac $CACHE/$file | syntax_highlighter activity
255 echo '</pre>' ;;
257 broken)
258 nb=$(cat $broken | wc -l)
259 echo "<h2>DB: broken - Packages: $nb</h2>"
260 echo '<pre>'
261 cat $CACHE/$file | sort | \
262 sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g
263 echo '</pre>' ;;
265 *.diff)
266 diff=$CACHE/$file
267 echo "<h2>Diff for: ${file%.diff}</h2>"
268 [ "$file" == "installed.diff" ] && echo \
269 "<p>This is the latest diff between installed packages \
270 and installed build dependencies to cook.</p>"
271 echo '<pre>'
272 cat $diff | syntax_highlighter diff
273 echo '</pre>' ;;
275 *.log)
276 log=$LOGS/$file
277 name=$(basename $log)
278 echo "<h2>Log for: ${name%.log}</h2>"
279 if [ -f "$log" ]; then
280 if fgrep -q "Summary" $log; then
281 echo '<pre>'
282 grep -A 20 "^Summary" $log | sed /^$/d | \
283 syntax_highlighter log
284 echo '</pre>'
285 fi
286 echo '<pre>'
287 cat $log | syntax_highlighter log
288 echo '</pre>'
289 else
290 echo "<pre>No log file: $log</pre>"
291 fi ;;
292 esac ;;
294 stuff=*)
295 file=${QUERY_STRING#stuff=}
296 echo "<h2>$file</h2>"
297 echo '<pre>'
298 cat $wok/$file | sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g'
299 echo '</pre>' ;;
301 receipt=*)
302 pkg=${QUERY_STRING#receipt=}
303 echo "<h2>Receipt for: $pkg</h2>"
304 if [ -f "$wok/$pkg/receipt" ]; then
305 ( cd $wok/$pkg ; find stuff -type f 2> /dev/null ) | \
306 while read file ; do
307 echo "<a href=\"?stuff=$pkg/$file\">$file</a>"
308 done
309 echo '<pre>'
310 cat $wok/$pkg/receipt | \
311 syntax_highlighter receipt
312 echo '</pre>'
313 else
314 echo "<pre>No receipt for: $pkg</pre>"
315 fi ;;
317 files=*)
318 pkg=${QUERY_STRING#files=}
319 dir=$(ls -d $WOK/$pkg/taz/$pkg-*)
320 if [ -d "$dir/fs" ]; then
321 echo "<h2>Installed files by: $pkg ($(du -hs $dir/fs | awk '{ print $1 }'))</h2>"
322 echo '<pre>'
323 find $dir/fs -not -type d -print0 | xargs -0 ls -ld | \
324 sed "s|\(.*\) /.*\(${dir#*wok}/fs\)\(.*\)|\1 <a href=\"?download=../wok\2\3\">\3</a>|;s|^\([^-].*\)\(<a.*\)\">\(.*\)</a>|\1\3|"
325 echo '</pre>'
326 else
327 echo "<pre>No files list for: $pkg</pre>"
328 fi ;;
330 description=*)
331 pkg=${QUERY_STRING#description=}
332 echo "<h2>Description of $pkg</h2>"
333 dir=$(ls -d $WOK/$pkg/taz/$pkg-*)
334 if [ -s "$dir/description.txt" ]; then
335 echo '<pre>'
336 cat $dir/description.txt | \
337 sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g'
338 echo '</pre>'
339 else
340 echo "<pre>No description for: $pkg</pre>"
341 fi ;;
343 *)
344 # We may have a toolchain.cgi script for cross cooker's
345 if [ -f "toolchain.cgi" ]; then
346 toolchain='toolchain.cgi'
347 else
348 toolchain='cooker.cgi?pkg=slitaz-toolchain'
349 fi
350 # Main page with summary. Count only package include in ARCH,
351 # use 'cooker arch-db' to manually create arch.$ARCH files.
352 inwok=$(ls $WOK/*/arch.$ARCH | wc -l)
353 cooked=$(ls $PKGS/*.tazpkg | wc -l)
354 unbuilt=$(($inwok - $cooked))
355 pct=0
356 [ $inwok -gt 0 ] && pct=$(( ($cooked * 100) / $inwok ))
357 cat <<EOT
358 <div style="float: right;">
359 <form method="get" action="$SCRIPT_NAME">
360 Package:
361 <input type="text" name="pkg" />
362 </form>
363 </div>
365 <h2>Summary</h2>
367 <pre>
368 Running command : $([ -s "$command" ] && cat $command || echo "Not running")
369 Wok revision : <a href="$WOK_URL">$(cat $wokrev)</a>
370 Commits to cook : $(cat $commits | wc -l)
371 Current cooklist : $(cat $cooklist | wc -l)
372 Broken packages : $(cat $broken | wc -l)
373 Blocked packages : $(cat $blocked | wc -l)
374 </pre>
376 <p class="info">
377 Packages: $inwok in the wok | $cooked cooked | $unbuilt unbuilt |
378 Server date: $(date -u '+%F %R %Z')
379 </p>
380 <div class="pctbar">
381 <div class="pct" style="width: ${pct}%;">${pct}%</div>
382 </div>
384 <p>
385 Latest:
386 <a href="cooker.cgi?file=cookorder.log">cookorder.log</a>
387 <a href="cooker.cgi?file=commits.log">commits.log</a>
388 <a href="cooker.cgi?file=installed.diff">installed.diff</a>
389 - Architecture $ARCH:
390 <a href="$toolchain">toolchain</a>
391 </p>
394 <h2 id="activity">Activity</h2>
395 <pre>
396 $(tac $CACHE/activity | head -n 12 | syntax_highlighter activity)
397 </pre>
398 $(more_button activity "More activity" $CACHE/activity 12)
401 <h2 id="cooknotes">Cooknotes</h2>
402 <pre>
403 $(tac $cooknotes | head -n 12 | syntax_highlighter activity)
404 </pre>
405 $(more_button cooknotes "More notes" $cooknotes 12)
408 <h2 id="commits">Commits</h2>
409 <pre>
410 $(cat $commits)
411 </pre>
414 <h2 id="cooklist">Cooklist</h2>
415 <pre>
416 $(cat $cooklist | head -n 20)
417 </pre>
418 $(more_button cooklist "Full cooklist" $cooklist 20)
421 <h2 id="broken">Broken</h2>
422 <pre>
423 $(cat $broken | head -n 20 | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
424 </pre>
425 $(more_button broken "All broken packages" $broken 20)
428 <h2 id="blocked">Blocked</h2>
429 <pre>
430 $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
431 </pre>
434 <h2 id="lastcook">Latest cook</h2>
435 <pre>
436 $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
437 </pre>
438 EOT
439 ;;
440 esac
443 # Close xHTML page
445 cat <<EOT
446 </div>
448 <div id="footer">
449 <a href="http://www.slitaz.org/">SliTaz Website</a>
450 <a href="cooker.cgi">Cooker</a>
451 <a href="http://hg.slitaz.org/cookutils/raw-file/tip/doc/cookutils.en.html">
452 Documentation</a>
453 </div>
455 </body>
456 </html>
457 EOT
459 exit 0