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