cookutils view web/cooker.cgi @ rev 87

Fix packge status (again)
author Christophe Lincoln <pankso@slitaz.org>
date Sun May 08 03:20:33 2011 +0200 (2011-05-08)
parents 6323bfa2e2fc
children 68447a52614f
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"
24 #
25 # Functions
26 #
28 # Put some colors in log and DB files.
29 syntax_highlighter() {
30 case $1 in
31 log)
32 sed -e 's#OK$#<span class="span-ok">OK</span>#g' \
33 -e 's#yes$#<span class="span-ok">yes</span>#g' \
34 -e 's#no$#<span class="span-no">no</span>#g' \
35 -e 's#error$#<span class="span-error">error</span>#g' \
36 -e 's#ERROR:#<span class="span-error">ERROR:</span>#g' \
37 -e s"#^Executing:\([^']*\).#<span class='sh-val'>\0</span>#"g \
38 -e s"#^====\([^']*\).#<span class='span-line'>\0</span>#"g \
39 -e s"#^[a-zA-Z0-9]\([^']*\) :: #<span class='span-sky'>\0</span>#"g \
40 -e s"#ftp://\([^']*\).*#<a href='\0'>\0</a>#"g \
41 -e s"#http://\([^']*\).*#<a href='\0'>\0</a>#"g ;;
42 receipt)
43 sed -e s"#^\#\([^']*\)#<span class='sh-comment'>\0</span>#"g \
44 -e s"#\"\([^']*\)\"#<span class='sh-val'>\0</span>#"g ;;
45 esac
46 }
48 # Latest build pkgs.
49 list_packages() {
50 cd $PKGS
51 ls -1t *.tazpkg | head -20 | \
52 while read file
53 do
54 echo -n $(stat -c '%y' $PKGS/$file | cut -d . -f 1 | sed s/:[0-9]*$//)
55 echo " : $file"
56 done
57 }
59 # xHTML header
60 cat << EOT
61 <!DOCTYPE html>
62 <html xmlns="http://www.w3.org/1999/xhtml">
63 <head>
64 <title>SliTaz Cooker</title>
65 <meta charset="utf-8" />
66 <link rel="stylesheet" type="text/css" href="style.css" />
67 </head>
68 <body>
70 <div id="header">
71 <h1><a href="cooker.cgi">SliTaz Cooker</a></h1>
72 </div>
74 <!-- Content -->
75 <div id="content">
76 EOT
78 #
79 # Load requested page
80 #
82 case "${QUERY_STRING}" in
83 pkg=*)
84 pkg=${QUERY_STRING#pkg=}
85 log=$LOGS/$pkg.log
86 echo "<h2>Package: $pkg</h2>"
88 # Package info.
89 echo '<div id="info">'
90 if [ -f "$wok/$pkg/receipt" ]; then
91 echo "<a href='cooker.cgi?receipt=$pkg'>receipt</a>"
92 else
93 echo "No package named: $pkg"
94 fi
95 echo '</div>'
97 # Check for a log file and display summary if it exists.
98 if [ -f "$log" ]; then
99 if grep -q "cook:$pkg$" $command; then
100 echo "<pre>The Cooker is currently cooking: $pkg</pre>"
101 fi
102 if fgrep -q "Summary " $LOGS/$pkg.log; then
103 echo "<h3>Cook summary</h3>"
104 echo '<pre>'
105 grep -A 8 "^Summary " $LOGS/$pkg.log | sed /^$/d | \
106 syntax_highlighter log
107 echo '</pre>'
108 fi
109 if fgrep -q "Debug " $LOGS/$pkg.log; then
110 echo "<h3>Cook failed</h3>"
111 echo '<pre>'
112 grep -A 8 "^Debug " $LOGS/$pkg.log | sed /^$/d | \
113 syntax_highlighter log
114 echo '</pre>'
115 fi
116 echo "<h3>Cook log</h3>"
117 echo '<pre>'
118 cat $log | syntax_highlighter log
119 echo '</pre>'
120 else
121 echo "<pre>No log: $pkg</pre>"
122 fi ;;
123 file=*)
124 # Dont allown all files on the system for security reason.
125 file=${QUERY_STRING#file=}
126 case "$file" in
127 activity|cooknotes)
128 echo "<h2>DB: $file</h2>"
129 echo '<pre>'
130 tac $CACHE/$file | \
131 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g
132 echo '</pre>' ;;
133 broken)
134 nb=$(cat $broken | wc -l)
135 echo "<h2>Broken packages: $nb</h2>"
136 echo '<pre>'
137 tac $CACHE/$file | \
138 sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g
139 echo '</pre>' ;;
140 *.log)
141 log=$LOGS/$file
142 name=$(basename $log)
143 echo "<h2>Log for: ${name%.log}</h2>"
144 if [ -f "$log" ]; then
145 if fgrep -q "Summary" $log; then
146 echo '<pre>'
147 grep -A 20 "^Summary" $log | sed /^$/d | \
148 syntax_highlighter log
149 echo '</pre>'
150 fi
151 echo '<pre>'
152 cat $log | syntax_highlighter log
153 echo '</pre>'
154 else
155 echo "<pre>No log file: $log</pre>"
156 fi ;;
157 esac ;;
158 receipt=*)
159 pkg=${QUERY_STRING#receipt=}
160 echo "<h2>Receipt for: $pkg</h2>"
161 if [ -f "$wok/$pkg/receipt" ]; then
162 echo '<pre>'
163 cat $wok/$pkg/receipt | syntax_highlighter receipt
164 echo '</pre>'
165 else
166 echo "<pre>No receipt for: $log</pre>"
167 fi ;;
168 *)
169 # Main page with summary.
170 cooked=$(ls $PKGS/*.tazpkg | wc -l)
171 inwok=$(ls $WOK | wc -l)
172 div=$(($inwok / 100))
173 pct=$(($cooked / $div))
174 cat << EOT
175 <div style="float: right;">
176 <form method="get" action="$SCRIPT_NAME">
177 Package:
178 <input type="text" name="pkg" />
179 </form>
180 </div>
182 <h2>Summary</h2>
185 <pre>
186 Running command : $([ -s "$command" ] && cat $command || echo "Not running")
187 Wok revision : <a href="http://hg.slitaz.org/wok">$(cd $WOK && hg head --template '{rev}\n')</a>
188 Commits to cook : $(cat $commits | wc -l)
189 Current cooklist : $(cat $cooklist | wc -l)
190 Broken packages : $(cat $broken | wc -l)
191 </pre>
193 <p>
194 Packages: $cooked cooked on $inwok in the wok.
195 </p>
196 <div class="pctbar">
197 <div class="pct" style="width: ${pct}%;">${pct}%</div>
198 </div>
200 <p>
201 Latest logs:
202 <a href="cooker.cgi?file=cookorder.log">cookorder</a>
203 <a href="cooker.cgi?file=commits.log">commits</a>
204 </p>
206 <h2>Activity</h2>
207 <pre>
208 $(tac $CACHE/activity | head -n 12 | \
209 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g)
210 </pre>
211 <a class="button" href="cooker.cgi?file=activity">More activity</a>
213 <h2>Cooknotes</h2>
214 <pre>
215 $(tac $cooknotes | head -n 12 | \
216 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g)
217 </pre>
218 <a class="button" href="cooker.cgi?file=cooknotes">More notes</a>
220 <h2>Commits</h2>
221 <pre>
222 $(cat $commits)
223 </pre>
225 <h2>Cooklist</h2>
226 <pre>
227 $(cat $cooklist)
228 </pre>
230 <h2>Broken</h2>
231 <pre>
232 $(cat $broken | head -n 20 | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
233 </pre>
234 <a class="button" href="cooker.cgi?file=broken">All broken packages</a>
236 <h2>Blocked</h2>
237 <pre>
238 $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
239 </pre>
241 <h2>Latest cook</h2>
242 <pre>
243 $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
244 </pre>
245 EOT
246 ;;
247 esac
249 # Close xHTML page
250 cat << EOT
251 </div>
253 <div id="footer">
254 <a href="cooker.cgi">SliTaz Cooker</a>
255 </div>
257 </body>
258 </html>
259 EOT
261 exit 0