cookutils view web/cooker.cgi @ rev 256

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