cookutils view web/cooker.cgi @ rev 327
cookiso: add rsync.log var to CGI
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Fri Mar 16 03:06:17 2012 +0100 (2012-03-16) |
parents | 47462be366b7 |
children | 512cece24f7c |
line source
1 #!/bin/sh
2 #
3 # SliTaz Cooker CGI/web interface.
4 #
5 echo "Content-Type: text/html"
6 echo ""
8 [ -f "/etc/slitaz/cook.conf" ] && . /etc/slitaz/cook.conf
9 [ -f "cook.conf" ] && . ./cook.conf
11 # The same wok as cook.
12 wok="$WOK"
14 # Cooker DB files.
15 activity="$CACHE/activity"
16 commits="$CACHE/commits"
17 cooklist="$CACHE/cooklist"
18 cookorder="$CACHE/cookorder"
19 command="$CACHE/command"
20 blocked="$CACHE/blocked"
21 broken="$CACHE/broken"
22 cooknotes="$CACHE/cooknotes"
23 wokrev="$CACHE/wokrev"
25 # We're not logged and want time zone to display correct server date.
26 export TZ=$(cat /etc/TZ)
28 #
29 # Functions
30 #
32 # RSS feed generator
33 if [ "$QUERY_STRING" == "rss" ]; then
34 pubdate=$(date "+%a, %d %b %Y %X")
35 cat << EOT
36 <?xml version="1.0" encoding="utf-8" ?>
37 <rss version="2.0">
38 <channel>
39 <title>SliTaz Cooker</title>
40 <description>The SliTaz packages cooker feed</description>
41 <link>$COOKER_URL</link>
42 <lastBuildDate>$pubdate GMT</lastBuildDate>
43 <pubDate>$pubdate GMT</pubDate>
44 EOT
45 for rss in $(ls -lt $FEEDS/*.xml | head -n 12)
46 do
47 cat $rss
48 done
49 cat << EOT
50 </channel>
51 </rss>
52 EOT
53 exit 0
54 fi
56 # Put some colors in log and DB files.
57 syntax_highlighter() {
58 case $1 in
59 log)
60 sed -e 's#OK$#<span class="span-ok">OK</span>#g' \
61 -e 's#yes$#<span class="span-ok">yes</span>#g' \
62 -e 's#no$#<span class="span-no">no</span>#g' \
63 -e 's#error$#<span class="span-red">error</span>#g' \
64 -e 's#ERROR:#<span class="span-red">ERROR:</span>#g' \
65 -e 's#WARNING:#<span class="span-red">WARNING:</span>#g' \
66 -e s"#^Executing:\([^']*\).#<span class='sh-val'>\0</span>#"g \
67 -e s"#^====\([^']*\).#<span class='span-line'>\0</span>#"g \
68 -e s"#^[a-zA-Z0-9]\([^']*\) :: #<span class='span-sky'>\0</span>#"g \
69 -e s"#ftp://\([^']*\).*#<a href='\0'>\0</a>#"g \
70 -e s"#http://\([^']*\).*#<a href='\0'>\0</a>#"g ;;
71 receipt)
72 sed -e s'|&|\&|g' -e 's|<|\<|g' -e 's|>|\>|'g \
73 -e s"#^\#\([^']*\)#<span class='sh-comment'>\0</span>#"g \
74 -e s"#\"\([^']*\)\"#<span class='sh-val'>\0</span>#"g ;;
75 diff)
76 sed -e 's|&|\&|g' -e 's|<|\<|g' -e 's|>|\>|g' \
77 -e s"#^-\([^']*\).#<span class='span-red'>\0</span>#"g \
78 -e s"#^+\([^']*\).#<span class='span-ok'>\0</span>#"g \
79 -e s"#@@\([^']*\)@@#<span class='span-sky'>@@\1@@</span>#"g ;;
80 activity)
81 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g ;;
82 esac
83 }
85 # Latest build pkgs.
86 list_packages() {
87 cd $PKGS
88 ls -1t *.tazpkg | head -20 | \
89 while read file
90 do
91 echo -n $(stat -c '%y' $PKGS/$file | cut -d . -f 1 | sed s/:[0-9]*$//)
92 echo " : $file"
93 done
94 }
96 # xHTML header. Pages can be customized with a separated html.header file.
97 if [ -f "header.html" ]; then
98 cat header.html
99 else
100 cat << EOT
101 <!DOCTYPE html>
102 <html xmlns="http://www.w3.org/1999/xhtml">
103 <head>
104 <title>SliTaz Cooker</title>
105 <meta charset="utf-8" />
106 <link rel="shortcut icon" href="favicon.ico" />
107 <link rel="stylesheet" type="text/css" href="style.css" />
108 </head>
109 <body>
111 <div id="header">
112 <div id="logo"></div>
113 <h1><a href="cooker.cgi">SliTaz Cooker</a></h1>
114 </div>
116 <!-- Content -->
117 <div id="content">
118 EOT
119 fi
121 #
122 # Load requested page
123 #
125 case "${QUERY_STRING}" in
126 pkg=*)
127 pkg=${QUERY_STRING#pkg=}
128 log=$LOGS/$pkg.log
129 echo "<h2>Package: $pkg</h2>"
131 # Package info.
132 echo '<div id="info">'
133 if [ -f "$wok/$pkg/receipt" ]; then
134 echo "<a href='cooker.cgi?receipt=$pkg'>receipt</a>"
135 unset WEB_SITE
136 . $wok/$pkg/receipt
137 [ -n "$WEB_SITE" ] && # busybox wget -s $WEB_SITE &&
138 echo "<a href='$WEB_SITE'>home</a>"
139 echo "<a href='cooker.cgi?files=$pkg'>files</a>"
140 else
141 echo "No package named: $pkg"
142 fi
143 echo '</div>'
145 # Check for a log file and display summary if it exists.
146 if [ -f "$log" ]; then
147 if grep -q "cook:$pkg$" $command; then
148 echo "<pre>The Cooker is currently building: $pkg</pre>"
149 fi
150 if fgrep -q "Summary for:" $LOGS/$pkg.log; then
151 echo "<h3>Cook summary</h3>"
152 echo '<pre>'
153 grep -A 8 "^Summary for:" $LOGS/$pkg.log | sed /^$/d | \
154 syntax_highlighter log
155 echo '</pre>'
156 fi
157 if fgrep -q "Debug information" $LOGS/$pkg.log; then
158 echo "<h3>Cook failed</h3>"
159 echo '<pre>'
160 grep -A 8 "^Debug information" $LOGS/$pkg.log | sed /^$/d | \
161 syntax_highlighter log
162 echo '</pre>'
163 fi
164 echo "<h3>Cook log</h3>"
165 echo '<pre>'
166 cat $log | syntax_highlighter log
167 echo '</pre>'
168 else
169 echo "<pre>No log: $pkg</pre>"
170 fi ;;
171 file=*)
172 # Dont allow all files on the system for security reasons.
173 file=${QUERY_STRING#file=}
174 case "$file" in
175 activity|cooknotes|cooklist)
176 [ "$file" == "cooklist" ] && \
177 nb="- Packages: $(cat $cooklist | wc -l)"
178 echo "<h2>DB: $file $nb</h2>"
179 echo '<pre>'
180 tac $CACHE/$file | syntax_highlighter activity
181 echo '</pre>' ;;
182 broken)
183 nb=$(cat $broken | wc -l)
184 echo "<h2>DB: broken - Packages: $nb</h2>"
185 echo '<pre>'
186 cat $CACHE/$file | sort | \
187 sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g
188 echo '</pre>' ;;
189 *.diff)
190 diff=$CACHE/$file
191 echo "<h2>Diff for: ${file%.diff}</h2>"
192 [ "$file" == "installed.diff" ] && echo \
193 "<p>This is the latest diff between installed packages \
194 and installed build dependencies to cook.</p>"
195 echo '<pre>'
196 cat $diff | syntax_highlighter diff
197 echo '</pre>' ;;
198 *.log)
199 log=$LOGS/$file
200 name=$(basename $log)
201 echo "<h2>Log for: ${name%.log}</h2>"
202 if [ -f "$log" ]; then
203 if fgrep -q "Summary" $log; then
204 echo '<pre>'
205 grep -A 20 "^Summary" $log | sed /^$/d | \
206 syntax_highlighter log
207 echo '</pre>'
208 fi
209 echo '<pre>'
210 cat $log | syntax_highlighter log
211 echo '</pre>'
212 else
213 echo "<pre>No log file: $log</pre>"
214 fi ;;
215 esac ;;
216 receipt=*)
217 pkg=${QUERY_STRING#receipt=}
218 echo "<h2>Receipt for: $pkg</h2>"
219 if [ -f "$wok/$pkg/receipt" ]; then
220 echo '<pre>'
221 cat $wok/$pkg/receipt | syntax_highlighter receipt
222 echo '</pre>'
223 else
224 echo "<pre>No receipt for: $pkg</pre>"
225 fi ;;
226 files=*)
227 pkg=${QUERY_STRING#files=}
228 echo "<h2>Installed files by: $pkg</h2>"
229 dir=$(ls -d $WOK/$pkg/taz/$pkg-*)
230 if [ -d "$dir/fs" ]; then
231 echo '<pre>'
232 find $dir/fs -not -type d | xargs ls -ld | \
233 sed "s|$dir/fs||" | syntax_highlighter log
234 echo '</pre>'
235 else
236 echo "<pre>No files list for: $pkg</pre>"
237 fi ;;
238 *)
239 # Main page with summary.
240 inwok=$(ls $WOK | wc -l)
241 cooked=$(ls $PKGS/*.tazpkg | wc -l)
242 unbuilt=$(($inwok - $cooked))
243 pct=0
244 [ $inwok -gt 0 ] && pct=$(( ($cooked * 100) / $inwok ))
245 cat << EOT
246 <div style="float: right;">
247 <form method="get" action="$SCRIPT_NAME">
248 Package:
249 <input type="text" name="pkg" />
250 </form>
251 </div>
253 <h2>Summary</h2>
255 <pre>
256 Running command : $([ -s "$command" ] && cat $command || echo "Not running")
257 Wok revision : <a href="$WOK_URL">$(cat $wokrev)</a>
258 Commits to cook : $(cat $commits | wc -l)
259 Current cooklist : $(cat $cooklist | wc -l)
260 Broken packages : $(cat $broken | wc -l)
261 Blocked packages : $(cat $blocked | wc -l)
262 </pre>
264 <p>
265 Packages: $inwok in the wok - $cooked cooked - $unbuilt unbuilt -
266 Server date: $(date '+%Y-%m-%d %H:%M')
267 </p>
268 <div class="pctbar">
269 <div class="pct" style="width: ${pct}%;">${pct}%</div>
270 </div>
272 <p>
273 Latest:
274 <a href="cooker.cgi?file=cookorder.log">cookorder.log</a>
275 <a href="cooker.cgi?file=commits.log">commits.log</a>
276 <a href="cooker.cgi?file=installed.diff">installed.diff</a>
277 - Architecture $ARCH:
278 <a href="cooker.cgi?pkg=slitaz-toolchain">toolchain.log</a>
279 </p>
281 <a name="activity"></a>
282 <h2>Activity</h2>
283 <pre>
284 $(tac $CACHE/activity | head -n 12 | syntax_highlighter activity)
285 </pre>
286 <a class="button" href="cooker.cgi?file=activity">More activity</a>
288 <a name="cooknotes"></a>
289 <h2>Cooknotes</h2>
290 <pre>
291 $(tac $cooknotes | head -n 12 | syntax_highlighter activity)
292 </pre>
293 <a class="button" href="cooker.cgi?file=cooknotes">More notes</a>
295 <a name="commits"></a>
296 <h2>Commits</h2>
297 <pre>
298 $(cat $commits)
299 </pre>
301 <a name="cooklist"></a>
302 <h2>Cooklist</h2>
303 <pre>
304 $(cat $cooklist | head -n 20)
305 </pre>
306 <a class="button" href="cooker.cgi?file=cooklist">Full cooklist</a>
308 <a name="broken"></a>
309 <h2>Broken</h2>
310 <pre>
311 $(cat $broken | head -n 20 | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
312 </pre>
313 <a class="button" href="cooker.cgi?file=broken">All broken packages</a>
315 <a name="blocked"></a>
316 <h2>Blocked</h2>
317 <pre>
318 $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
319 </pre>
321 <a name="lastcook"></a>
322 <h2>Latest cook</h2>
323 <pre>
324 $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
325 </pre>
326 EOT
327 ;;
328 esac
330 # Close xHTML page
331 cat << EOT
332 </div>
334 <div id="footer">
335 <a href="http://www.slitaz.org/">SliTaz Website</a>
336 <a href="cooker.cgi">Cooker</a>
337 <a href="http://hg.slitaz.org/cookutils/raw-file/tip/doc/cookutils.en.html">
338 Documentation</a>
339 </div>
341 </body>
342 </html>
343 EOT
345 exit 0