cookutils view web/cooker.cgi @ rev 86

Fix packge status (must use greo not fgrep)
author Christophe Lincoln <pankso@slitaz.org>
date Sun May 08 03:00:38 2011 +0200 (2011-05-08)
parents 923bd9254ecf
children 28d08d97a6ec
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 fgrep -q "Summary " $LOGS/$pkg.log; then
100 if grep -q "cook:$pkg$" $command; then
101 echo "<pre>The Cooker is currently cooking: $pkg</pre>"
102 else
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 fi
110 if fgrep -q "Debug " $LOGS/$pkg.log; then
111 echo "<h3>Cook failed</h3>"
112 echo '<pre>'
113 grep -A 8 "^Debug " $LOGS/$pkg.log | sed /^$/d | \
114 syntax_highlighter log
115 echo '</pre>'
116 fi
117 echo "<h3>Cook log</h3>"
118 echo '<pre>'
119 cat $log | syntax_highlighter log
120 echo '</pre>'
121 else
122 echo "<pre>No log: $pkg</pre>"
123 fi ;;
124 file=*)
125 # Dont allown all files on the system for security reason.
126 file=${QUERY_STRING#file=}
127 case "$file" in
128 activity|cooknotes)
129 echo "<h2>DB: $file</h2>"
130 echo '<pre>'
131 tac $CACHE/$file | \
132 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g
133 echo '</pre>' ;;
134 broken)
135 nb=$(cat $broken | wc -l)
136 echo "<h2>Broken packages: $nb</h2>"
137 echo '<pre>'
138 tac $CACHE/$file | \
139 sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g
140 echo '</pre>' ;;
141 *.log)
142 log=$LOGS/$file
143 name=$(basename $log)
144 echo "<h2>Log for: ${name%.log}</h2>"
145 if [ -f "$log" ]; then
146 if fgrep -q "Summary" $log; then
147 echo '<pre>'
148 grep -A 20 "^Summary" $log | sed /^$/d | \
149 syntax_highlighter log
150 echo '</pre>'
151 fi
152 echo '<pre>'
153 cat $log | syntax_highlighter log
154 echo '</pre>'
155 else
156 echo "<pre>No log file: $log</pre>"
157 fi ;;
158 esac ;;
159 receipt=*)
160 pkg=${QUERY_STRING#receipt=}
161 echo "<h2>Receipt for: $pkg</h2>"
162 if [ -f "$wok/$pkg/receipt" ]; then
163 echo '<pre>'
164 cat $wok/$pkg/receipt | syntax_highlighter receipt
165 echo '</pre>'
166 else
167 echo "<pre>No receipt for: $log</pre>"
168 fi ;;
169 *)
170 # Main page with summary.
171 cooked=$(ls $PKGS/*.tazpkg | wc -l)
172 inwok=$(ls $WOK | wc -l)
173 div=$(($inwok / 100))
174 pct=$(($cooked / $div))
175 cat << EOT
176 <div style="float: right;">
177 <form method="get" action="$SCRIPT_NAME">
178 Package:
179 <input type="text" name="pkg" />
180 </form>
181 </div>
183 <h2>Summary</h2>
186 <pre>
187 Running command : $([ -s "$command" ] && cat $command || echo "Not running")
188 Wok revision : <a href="http://hg.slitaz.org/wok">$(cd $WOK && hg head --template '{rev}\n')</a>
189 Commits to cook : $(cat $commits | wc -l)
190 Current cooklist : $(cat $cooklist | wc -l)
191 Broken packages : $(cat $broken | wc -l)
192 </pre>
194 <p>
195 Packages: $cooked cooked on $inwok in the wok.
196 </p>
197 <div class="pctbar">
198 <div class="pct" style="width: ${pct}%;">${pct}%</div>
199 </div>
201 <p>
202 Latest logs:
203 <a href="cooker.cgi?file=cookorder.log">cookorder</a>
204 <a href="cooker.cgi?file=commits.log">commits</a>
205 </p>
207 <h2>Activity</h2>
208 <pre>
209 $(tac $CACHE/activity | head -n 12 | \
210 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g)
211 </pre>
212 <a class="button" href="cooker.cgi?file=activity">More activity</a>
214 <h2>Cooknotes</h2>
215 <pre>
216 $(tac $cooknotes | head -n 12 | \
217 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g)
218 </pre>
219 <a class="button" href="cooker.cgi?file=cooknotes">More notes</a>
221 <h2>Commits</h2>
222 <pre>
223 $(cat $commits)
224 </pre>
226 <h2>Cooklist</h2>
227 <pre>
228 $(cat $cooklist)
229 </pre>
231 <h2>Broken</h2>
232 <pre>
233 $(cat $broken | head -n 20 | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
234 </pre>
235 <a class="button" href="cooker.cgi?file=broken">All broken packages</a>
237 <h2>Blocked</h2>
238 <pre>
239 $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
240 </pre>
242 <h2>Latest cook</h2>
243 <pre>
244 $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
245 </pre>
246 EOT
247 ;;
248 esac
250 # Close xHTML page
251 cat << EOT
252 </div>
254 <div id="footer">
255 <a href="cooker.cgi">SliTaz Cooker</a>
256 </div>
258 </body>
259 </html>
260 EOT
262 exit 0