cookutils view web/cooker.cgi @ rev 250

cook: use wget -O to get output file with TARBAL name (Thank Godane)
author Christophe Lincoln <pankso@slitaz.org>
date Sat May 28 23:53:54 2011 +0200 (2011-05-28)
parents c2d64a309431
children 4f97a0834221
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 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
72 cat << EOT
73 <!DOCTYPE html>
74 <html xmlns="http://www.w3.org/1999/xhtml">
75 <head>
76 <title>SliTaz Cooker</title>
77 <meta charset="utf-8" />
78 <link rel="stylesheet" type="text/css" href="style.css" />
79 </head>
80 <body>
82 <div id="header">
83 <h1><a href="cooker.cgi">SliTaz Cooker</a></h1>
84 </div>
86 <!-- Content -->
87 <div id="content">
88 EOT
90 #
91 # Load requested page
92 #
94 case "${QUERY_STRING}" in
95 pkg=*)
96 pkg=${QUERY_STRING#pkg=}
97 log=$LOGS/$pkg.log
98 echo "<h2>Package: $pkg</h2>"
100 # Package info.
101 echo '<div id="info">'
102 if [ -f "$wok/$pkg/receipt" ]; then
103 echo "<a href='cooker.cgi?receipt=$pkg'>receipt</a>"
104 else
105 echo "No package named: $pkg"
106 fi
107 echo '</div>'
109 # Check for a log file and display summary if it exists.
110 if [ -f "$log" ]; then
111 if grep -q "cook:$pkg$" $command; then
112 echo "<pre>The Cooker is currently building: $pkg</pre>"
113 fi
114 if fgrep -q "Summary for:" $LOGS/$pkg.log; then
115 echo "<h3>Cook summary</h3>"
116 echo '<pre>'
117 grep -A 8 "^Summary for:" $LOGS/$pkg.log | sed /^$/d | \
118 syntax_highlighter log
119 echo '</pre>'
120 fi
121 if fgrep -q "Debug information" $LOGS/$pkg.log; then
122 echo "<h3>Cook failed</h3>"
123 echo '<pre>'
124 grep -A 8 "^Debug information" $LOGS/$pkg.log | sed /^$/d | \
125 syntax_highlighter log
126 echo '</pre>'
127 fi
128 echo "<h3>Cook log</h3>"
129 echo '<pre>'
130 cat $log | syntax_highlighter log
131 echo '</pre>'
132 else
133 echo "<pre>No log: $pkg</pre>"
134 fi ;;
135 file=*)
136 # Dont allow all files on the system for security reasons.
137 file=${QUERY_STRING#file=}
138 case "$file" in
139 activity|cooknotes|cooklist)
140 [ "$file" == "cooklist" ] && \
141 nb="- Packages: $(cat $cooklist | wc -l)"
142 echo "<h2>DB: $file $nb</h2>"
143 echo '<pre>'
144 tac $CACHE/$file | syntax_highlighter activity
145 echo '</pre>' ;;
146 broken)
147 nb=$(cat $broken | wc -l)
148 echo "<h2>DB: broken - Packages: $nb</h2>"
149 echo '<pre>'
150 cat $CACHE/$file | sort | \
151 sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g
152 echo '</pre>' ;;
153 *.diff)
154 diff=$CACHE/$file
155 echo "<h2>Diff for: ${file%.diff}</h2>"
156 [ "$file" == "installed.diff" ] && echo \
157 "<p>This is the latest diff between installed packages \
158 and installed build dependencies to cook.</p>"
159 echo '<pre>'
160 cat $diff | syntax_highlighter diff
161 echo '</pre>' ;;
162 *.log)
163 log=$LOGS/$file
164 name=$(basename $log)
165 echo "<h2>Log for: ${name%.log}</h2>"
166 if [ -f "$log" ]; then
167 if fgrep -q "Summary" $log; then
168 echo '<pre>'
169 grep -A 20 "^Summary" $log | sed /^$/d | \
170 syntax_highlighter log
171 echo '</pre>'
172 fi
173 echo '<pre>'
174 cat $log | syntax_highlighter log
175 echo '</pre>'
176 else
177 echo "<pre>No log file: $log</pre>"
178 fi ;;
179 esac ;;
180 receipt=*)
181 pkg=${QUERY_STRING#receipt=}
182 echo "<h2>Receipt for: $pkg</h2>"
183 if [ -f "$wok/$pkg/receipt" ]; then
184 echo '<pre>'
185 cat $wok/$pkg/receipt | syntax_highlighter receipt
186 echo '</pre>'
187 else
188 echo "<pre>No receipt for: $log</pre>"
189 fi ;;
190 *)
191 # Main page with summary.
192 inwok=$(ls $WOK | wc -l)
193 cooked=$(ls $PKGS/*.tazpkg | wc -l)
194 unbuilt=$(($inwok - $cooked))
195 pct=0
196 [ $inwok -gt 0 ] && pct=$(( ($cooked * 100) / $inwok ))
197 cat << EOT
198 <div style="float: right;">
199 <form method="get" action="$SCRIPT_NAME">
200 Package:
201 <input type="text" name="pkg" />
202 </form>
203 </div>
205 <h2>Summary</h2>
207 <pre>
208 Running command : $([ -s "$command" ] && cat $command || echo "Not running")
209 Wok revision : <a href="http://hg.slitaz.org/wok">$(cat $wokrev)</a>
210 Commits to cook : $(cat $commits | wc -l)
211 Current cooklist : $(cat $cooklist | wc -l)
212 Broken packages : $(cat $broken | wc -l)
213 Blocked packages : $(cat $blocked | wc -l)
214 </pre>
216 <p>
217 Packages: $inwok in the wok - $cooked cooked - $unbuilt unbuilt -
218 Server date: $(date '+%Y-%m-%d %H:%M')
219 </p>
220 <div class="pctbar">
221 <div class="pct" style="width: ${pct}%;">${pct}%</div>
222 </div>
224 <p>
225 Latest:
226 <a href="cooker.cgi?file=cookorder.log">cookorder.log</a>
227 <a href="cooker.cgi?file=commits.log">commits.log</a>
228 <a href="cooker.cgi?file=installed.diff">installed.diff</a>
229 - Architecture $ARCH:
230 <a href="cooker.cgi?pkg=slitaz-toolchain">toolchain.log</a>
231 </p>
233 <h2>Activity</h2>
234 <pre>
235 $(tac $CACHE/activity | head -n 12 | syntax_highlighter activity)
236 </pre>
237 <a class="button" href="cooker.cgi?file=activity">More activity</a>
239 <h2>Cooknotes</h2>
240 <pre>
241 $(tac $cooknotes | head -n 12 | syntax_highlighter activity)
242 </pre>
243 <a class="button" href="cooker.cgi?file=cooknotes">More notes</a>
245 <h2>Commits</h2>
246 <pre>
247 $(cat $commits)
248 </pre>
250 <h2>Cooklist</h2>
251 <pre>
252 $(cat $cooklist | head -n 20)
253 </pre>
254 <a class="button" href="cooker.cgi?file=cooklist">Full cooklist</a>
256 <h2>Broken</h2>
257 <pre>
258 $(cat $broken | head -n 20 | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
259 </pre>
260 <a class="button" href="cooker.cgi?file=broken">All broken packages</a>
262 <h2>Blocked</h2>
263 <pre>
264 $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
265 </pre>
267 <h2>Latest cook</h2>
268 <pre>
269 $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
270 </pre>
271 EOT
272 ;;
273 esac
275 # Close xHTML page
276 cat << EOT
277 </div>
279 <div id="footer">
280 <a href="http://www.slitaz.org/">SliTaz Website</a>
281 <a href="cooker.cgi">Cooker</a>
282 <a href="http://hg.slitaz.org/cookutils/raw-file/tip/doc/cookutils.en.html">
283 Documentation</a>
284 </div>
286 </body>
287 </html>
288 EOT
290 exit 0