cookutils view web/cooker.cgi @ rev 252

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