cookutils view web/cooker.cgi @ rev 258

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