cookutils view web/cooker.cgi @ rev 694

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