cookutils view web/cooker.cgi @ rev 277
cook: limit permission change for slitaz group
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sun Jan 08 12:25:34 2012 +0100 (2012-01-08) |
parents | d08b14d49e15 |
children | 47462be366b7 |
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'|&|\&|g' -e 's|<|\<|g' -e 's|>|\>|'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|&|\&|g' -e 's|<|\<|g' -e 's|>|\>|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 unset WEB_SITE
112 . $wok/$pkg/receipt
113 [ -n "$WEB_SITE" ] && busybox wget -s $WEB_SITE &&
114 echo "<a href='$WEB_SITE'>home</a>"
115 else
116 echo "No package named: $pkg"
117 fi
118 echo '</div>'
120 # Check for a log file and display summary if it exists.
121 if [ -f "$log" ]; then
122 if grep -q "cook:$pkg$" $command; then
123 echo "<pre>The Cooker is currently building: $pkg</pre>"
124 fi
125 if fgrep -q "Summary for:" $LOGS/$pkg.log; then
126 echo "<h3>Cook summary</h3>"
127 echo '<pre>'
128 grep -A 8 "^Summary for:" $LOGS/$pkg.log | sed /^$/d | \
129 syntax_highlighter log
130 echo '</pre>'
131 fi
132 if fgrep -q "Debug information" $LOGS/$pkg.log; then
133 echo "<h3>Cook failed</h3>"
134 echo '<pre>'
135 grep -A 8 "^Debug information" $LOGS/$pkg.log | sed /^$/d | \
136 syntax_highlighter log
137 echo '</pre>'
138 fi
139 echo "<h3>Cook log</h3>"
140 echo '<pre>'
141 cat $log | syntax_highlighter log
142 echo '</pre>'
143 else
144 echo "<pre>No log: $pkg</pre>"
145 fi ;;
146 file=*)
147 # Dont allow all files on the system for security reasons.
148 file=${QUERY_STRING#file=}
149 case "$file" in
150 activity|cooknotes|cooklist)
151 [ "$file" == "cooklist" ] && \
152 nb="- Packages: $(cat $cooklist | wc -l)"
153 echo "<h2>DB: $file $nb</h2>"
154 echo '<pre>'
155 tac $CACHE/$file | syntax_highlighter activity
156 echo '</pre>' ;;
157 broken)
158 nb=$(cat $broken | wc -l)
159 echo "<h2>DB: broken - Packages: $nb</h2>"
160 echo '<pre>'
161 cat $CACHE/$file | sort | \
162 sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g
163 echo '</pre>' ;;
164 *.diff)
165 diff=$CACHE/$file
166 echo "<h2>Diff for: ${file%.diff}</h2>"
167 [ "$file" == "installed.diff" ] && echo \
168 "<p>This is the latest diff between installed packages \
169 and installed build dependencies to cook.</p>"
170 echo '<pre>'
171 cat $diff | syntax_highlighter diff
172 echo '</pre>' ;;
173 *.log)
174 log=$LOGS/$file
175 name=$(basename $log)
176 echo "<h2>Log for: ${name%.log}</h2>"
177 if [ -f "$log" ]; then
178 if fgrep -q "Summary" $log; then
179 echo '<pre>'
180 grep -A 20 "^Summary" $log | sed /^$/d | \
181 syntax_highlighter log
182 echo '</pre>'
183 fi
184 echo '<pre>'
185 cat $log | syntax_highlighter log
186 echo '</pre>'
187 else
188 echo "<pre>No log file: $log</pre>"
189 fi ;;
190 esac ;;
191 receipt=*)
192 pkg=${QUERY_STRING#receipt=}
193 echo "<h2>Receipt for: $pkg</h2>"
194 if [ -f "$wok/$pkg/receipt" ]; then
195 echo '<pre>'
196 cat $wok/$pkg/receipt | syntax_highlighter receipt
197 echo '</pre>'
198 else
199 echo "<pre>No receipt for: $log</pre>"
200 fi ;;
201 *)
202 # Main page with summary.
203 inwok=$(ls $WOK | wc -l)
204 cooked=$(ls $PKGS/*.tazpkg | wc -l)
205 unbuilt=$(($inwok - $cooked))
206 pct=0
207 [ $inwok -gt 0 ] && pct=$(( ($cooked * 100) / $inwok ))
208 cat << EOT
209 <div style="float: right;">
210 <form method="get" action="$SCRIPT_NAME">
211 Package:
212 <input type="text" name="pkg" />
213 </form>
214 </div>
216 <h2>Summary</h2>
218 <pre>
219 Running command : $([ -s "$command" ] && cat $command || echo "Not running")
220 Wok revision : <a href="http://hg.slitaz.org/wok">$(cat $wokrev)</a>
221 Commits to cook : $(cat $commits | wc -l)
222 Current cooklist : $(cat $cooklist | wc -l)
223 Broken packages : $(cat $broken | wc -l)
224 Blocked packages : $(cat $blocked | wc -l)
225 </pre>
227 <p>
228 Packages: $inwok in the wok - $cooked cooked - $unbuilt unbuilt -
229 Server date: $(date '+%Y-%m-%d %H:%M')
230 </p>
231 <div class="pctbar">
232 <div class="pct" style="width: ${pct}%;">${pct}%</div>
233 </div>
235 <p>
236 Latest:
237 <a href="cooker.cgi?file=cookorder.log">cookorder.log</a>
238 <a href="cooker.cgi?file=commits.log">commits.log</a>
239 <a href="cooker.cgi?file=installed.diff">installed.diff</a>
240 - Architecture $ARCH:
241 <a href="cooker.cgi?pkg=slitaz-toolchain">toolchain.log</a>
242 </p>
244 <a name="activity"></a>
245 <h2>Activity</h2>
246 <pre>
247 $(tac $CACHE/activity | head -n 12 | syntax_highlighter activity)
248 </pre>
249 <a class="button" href="cooker.cgi?file=activity">More activity</a>
251 <a name="cooknotes"></a>
252 <h2>Cooknotes</h2>
253 <pre>
254 $(tac $cooknotes | head -n 12 | syntax_highlighter activity)
255 </pre>
256 <a class="button" href="cooker.cgi?file=cooknotes">More notes</a>
258 <a name="commits"></a>
259 <h2>Commits</h2>
260 <pre>
261 $(cat $commits)
262 </pre>
264 <a name="cooklist"></a>
265 <h2>Cooklist</h2>
266 <pre>
267 $(cat $cooklist | head -n 20)
268 </pre>
269 <a class="button" href="cooker.cgi?file=cooklist">Full cooklist</a>
271 <a name="broken"></a>
272 <h2>Broken</h2>
273 <pre>
274 $(cat $broken | head -n 20 | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
275 </pre>
276 <a class="button" href="cooker.cgi?file=broken">All broken packages</a>
278 <a name="blocked"></a>
279 <h2>Blocked</h2>
280 <pre>
281 $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
282 </pre>
284 <a name="lastcook"></a>
285 <h2>Latest cook</h2>
286 <pre>
287 $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
288 </pre>
289 EOT
290 ;;
291 esac
293 # Close xHTML page
294 cat << EOT
295 </div>
297 <div id="footer">
298 <a href="http://www.slitaz.org/">SliTaz Website</a>
299 <a href="cooker.cgi">Cooker</a>
300 <a href="http://hg.slitaz.org/cookutils/raw-file/tip/doc/cookutils.en.html">
301 Documentation</a>
302 </div>
304 </body>
305 </html>
306 EOT
308 exit 0