cookutils view web/cooker.cgi @ rev 245

cooker: add Pascal patch to cgi web so it display better pct and TZ
author Christophe Lincoln <pankso@slitaz.org>
date Sat May 28 15:00:17 2011 +0200 (2011-05-28)
parents f8cb94efb7e6
children c2d64a309431
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 #
26 # Functions
27 #
29 # Put some colors in log and DB files.
30 syntax_highlighter() {
31 case $1 in
32 log)
33 sed -e 's#OK$#<span class="span-ok">OK</span>#g' \
34 -e 's#yes$#<span class="span-ok">yes</span>#g' \
35 -e 's#no$#<span class="span-no">no</span>#g' \
36 -e 's#error$#<span class="span-red">error</span>#g' \
37 -e 's#ERROR:#<span class="span-red">ERROR:</span>#g' \
38 -e 's#WARNING:#<span class="span-red">WARNING:</span>#g' \
39 -e s"#^Executing:\([^']*\).#<span class='sh-val'>\0</span>#"g \
40 -e s"#^====\([^']*\).#<span class='span-line'>\0</span>#"g \
41 -e s"#^[a-zA-Z0-9]\([^']*\) :: #<span class='span-sky'>\0</span>#"g \
42 -e s"#ftp://\([^']*\).*#<a href='\0'>\0</a>#"g \
43 -e s"#http://\([^']*\).*#<a href='\0'>\0</a>#"g ;;
44 receipt)
45 sed -e s"#^\#\([^']*\)#<span class='sh-comment'>\0</span>#"g \
46 -e s"#\"\([^']*\)\"#<span class='sh-val'>\0</span>#"g ;;
47 diff)
48 sed -e 's|&|\&amp;|g' -e 's|<|\&lt;|g' -e 's|>|\&gt;|g' \
49 -e s"#^-\([^']*\).#<span class='span-red'>\0</span>#"g \
50 -e s"#^+\([^']*\).#<span class='span-ok'>\0</span>#"g \
51 -e s"#@@\([^']*\)@@#<span class='span-sky'>@@\1@@</span>#"g ;;
52 activity)
53 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g ;;
54 esac
55 }
57 # Latest build pkgs.
58 list_packages() {
59 cd $PKGS
60 ls -1t *.tazpkg | head -20 | \
61 while read file
62 do
63 echo -n $(stat -c '%y' $PKGS/$file | cut -d . -f 1 | sed s/:[0-9]*$//)
64 echo " : $file"
65 done
66 }
68 # xHTML header
69 cat << EOT
70 <!DOCTYPE html>
71 <html xmlns="http://www.w3.org/1999/xhtml">
72 <head>
73 <title>SliTaz Cooker</title>
74 <meta charset="utf-8" />
75 <link rel="stylesheet" type="text/css" href="style.css" />
76 </head>
77 <body>
79 <div id="header">
80 <h1><a href="cooker.cgi">SliTaz Cooker</a></h1>
81 </div>
83 <!-- Content -->
84 <div id="content">
85 EOT
87 #
88 # Load requested page
89 #
91 case "${QUERY_STRING}" in
92 pkg=*)
93 pkg=${QUERY_STRING#pkg=}
94 log=$LOGS/$pkg.log
95 echo "<h2>Package: $pkg</h2>"
97 # Package info.
98 echo '<div id="info">'
99 if [ -f "$wok/$pkg/receipt" ]; then
100 echo "<a href='cooker.cgi?receipt=$pkg'>receipt</a>"
101 else
102 echo "No package named: $pkg"
103 fi
104 echo '</div>'
106 # Check for a log file and display summary if it exists.
107 if [ -f "$log" ]; then
108 if grep -q "cook:$pkg$" $command; then
109 echo "<pre>The Cooker is currently building: $pkg</pre>"
110 fi
111 if fgrep -q "Summary for:" $LOGS/$pkg.log; then
112 echo "<h3>Cook summary</h3>"
113 echo '<pre>'
114 grep -A 8 "^Summary for:" $LOGS/$pkg.log | sed /^$/d | \
115 syntax_highlighter log
116 echo '</pre>'
117 fi
118 if fgrep -q "Debug information" $LOGS/$pkg.log; then
119 echo "<h3>Cook failed</h3>"
120 echo '<pre>'
121 grep -A 8 "^Debug information" $LOGS/$pkg.log | sed /^$/d | \
122 syntax_highlighter log
123 echo '</pre>'
124 fi
125 echo "<h3>Cook log</h3>"
126 echo '<pre>'
127 cat $log | syntax_highlighter log
128 echo '</pre>'
129 else
130 echo "<pre>No log: $pkg</pre>"
131 fi ;;
132 file=*)
133 # Dont allow all files on the system for security reasons.
134 file=${QUERY_STRING#file=}
135 case "$file" in
136 activity|cooknotes|cooklist)
137 [ "$file" == "cooklist" ] && \
138 nb="- Packages: $(cat $cooklist | wc -l)"
139 echo "<h2>DB: $file $nb</h2>"
140 echo '<pre>'
141 tac $CACHE/$file | syntax_highlighter activity
142 echo '</pre>' ;;
143 broken)
144 nb=$(cat $broken | wc -l)
145 echo "<h2>DB: broken - Packages: $nb</h2>"
146 echo '<pre>'
147 cat $CACHE/$file | sort | \
148 sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g
149 echo '</pre>' ;;
150 *.diff)
151 diff=$CACHE/$file
152 echo "<h2>Diff for: ${file%.diff}</h2>"
153 [ "$file" == "installed.diff" ] && echo \
154 "<p>This is the latest diff between installed packages \
155 and installed build dependencies to cook.</p>"
156 echo '<pre>'
157 cat $diff | syntax_highlighter diff
158 echo '</pre>' ;;
159 *.log)
160 log=$LOGS/$file
161 name=$(basename $log)
162 echo "<h2>Log for: ${name%.log}</h2>"
163 if [ -f "$log" ]; then
164 if fgrep -q "Summary" $log; then
165 echo '<pre>'
166 grep -A 20 "^Summary" $log | sed /^$/d | \
167 syntax_highlighter log
168 echo '</pre>'
169 fi
170 echo '<pre>'
171 cat $log | syntax_highlighter log
172 echo '</pre>'
173 else
174 echo "<pre>No log file: $log</pre>"
175 fi ;;
176 esac ;;
177 receipt=*)
178 pkg=${QUERY_STRING#receipt=}
179 echo "<h2>Receipt for: $pkg</h2>"
180 if [ -f "$wok/$pkg/receipt" ]; then
181 echo '<pre>'
182 cat $wok/$pkg/receipt | syntax_highlighter receipt
183 echo '</pre>'
184 else
185 echo "<pre>No receipt for: $log</pre>"
186 fi ;;
187 *)
188 # Main page with summary.
189 inwok=$(ls $WOK | wc -l)
190 cooked=$(ls $PKGS/*.tazpkg | wc -l)
191 unbuilt=$(($inwok - $cooked))
192 pct=0
193 [ $inwok -gt 0 ] && pct=$(( ($cooked * 100) / $inwok ))
194 cat << EOT
195 <div style="float: right;">
196 <form method="get" action="$SCRIPT_NAME">
197 Package:
198 <input type="text" name="pkg" />
199 </form>
200 </div>
202 <h2>Summary</h2>
204 <pre>
205 Running command : $([ -s "$command" ] && cat $command || echo "Not running")
206 Wok revision : <a href="http://hg.slitaz.org/wok">$(cat $wokrev)</a>
207 Commits to cook : $(cat $commits | wc -l)
208 Current cooklist : $(cat $cooklist | wc -l)
209 Broken packages : $(cat $broken | wc -l)
210 Blocked packages : $(cat $blocked | wc -l)
211 </pre>
213 <p>
214 $(date '+%Y-%M-%d %H:%M') Packages: $inwok in the wok - $cooked cooked - $unbuilt unbuilt
215 </p>
216 <div class="pctbar">
217 <div class="pct" style="width: ${pct}%;">${pct}%</div>
218 </div>
220 <p>
221 Latest:
222 <a href="cooker.cgi?file=cookorder.log">cookorder.log</a>
223 <a href="cooker.cgi?file=commits.log">commits.log</a>
224 <a href="cooker.cgi?file=installed.diff">installed.diff</a>
225 - Architecture $ARCH:
226 <a href="cooker.cgi?pkg=slitaz-toolchain">toolchain.log</a>
227 </p>
229 <h2>Activity</h2>
230 <pre>
231 $(tac $CACHE/activity | head -n 12 | syntax_highlighter activity)
232 </pre>
233 <a class="button" href="cooker.cgi?file=activity">More activity</a>
235 <h2>Cooknotes</h2>
236 <pre>
237 $(tac $cooknotes | head -n 12 | syntax_highlighter activity)
238 </pre>
239 <a class="button" href="cooker.cgi?file=cooknotes">More notes</a>
241 <h2>Commits</h2>
242 <pre>
243 $(cat $commits)
244 </pre>
246 <h2>Cooklist</h2>
247 <pre>
248 $(cat $cooklist | head -n 20)
249 </pre>
250 <a class="button" href="cooker.cgi?file=cooklist">Full cooklist</a>
252 <h2>Broken</h2>
253 <pre>
254 $(cat $broken | head -n 20 | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
255 </pre>
256 <a class="button" href="cooker.cgi?file=broken">All broken packages</a>
258 <h2>Blocked</h2>
259 <pre>
260 $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
261 </pre>
263 <h2>Latest cook</h2>
264 <pre>
265 $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
266 </pre>
267 EOT
268 ;;
269 esac
271 # Close xHTML page
272 cat << EOT
273 </div>
275 <div id="footer">
276 <a href="http://www.slitaz.org/">SliTaz Website</a>
277 <a href="cooker.cgi">Cooker</a>
278 <a href="http://hg.slitaz.org/cookutils/raw-file/tip/doc/cookutils.en.html">
279 Documentation</a>
280 </div>
282 </body>
283 </html>
284 EOT
286 exit 0