cookutils view web/cooker.cgi @ rev 92

web: fix last commit typo
author Christophe Lincoln <pankso@slitaz.org>
date Sun May 08 14:15:30 2011 +0200 (2011-05-08)
parents 947b89e7f402
children bbcefe9f3642
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 building: $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 allow all files on the system for security reasons.
125 file=${QUERY_STRING#file=}
126 case "$file" in
127 activity|cooknotes|cooklist)
128 [ "$file" == "cooklist" ] && \
129 nb="packages: $(cat $cooklist | wc -l)"
130 echo "<h2>DB: $file $nb</h2>"
131 echo '<pre>'
132 tac $CACHE/$file | \
133 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g
134 echo '</pre>' ;;
135 broken)
136 nb=$(cat $broken | wc -l)
137 echo "<h2>DB: broken packages: $nb</h2>"
138 echo '<pre>'
139 tac $CACHE/$file | \
140 sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g
141 echo '</pre>' ;;
142 *.log)
143 log=$LOGS/$file
144 name=$(basename $log)
145 echo "<h2>Log for: ${name%.log}</h2>"
146 if [ -f "$log" ]; then
147 if fgrep -q "Summary" $log; then
148 echo '<pre>'
149 grep -A 20 "^Summary" $log | sed /^$/d | \
150 syntax_highlighter log
151 echo '</pre>'
152 fi
153 echo '<pre>'
154 cat $log | syntax_highlighter log
155 echo '</pre>'
156 else
157 echo "<pre>No log file: $log</pre>"
158 fi ;;
159 esac ;;
160 receipt=*)
161 pkg=${QUERY_STRING#receipt=}
162 echo "<h2>Receipt for: $pkg</h2>"
163 if [ -f "$wok/$pkg/receipt" ]; then
164 echo '<pre>'
165 cat $wok/$pkg/receipt | syntax_highlighter receipt
166 echo '</pre>'
167 else
168 echo "<pre>No receipt for: $log</pre>"
169 fi ;;
170 *)
171 # Main page with summary.
172 cooked=$(ls $PKGS/*.tazpkg | wc -l)
173 inwok=$(ls $WOK | wc -l)
174 div=$(($inwok / 100))
175 pct=$(($cooked / $div))
176 cat << EOT
177 <div style="float: right;">
178 <form method="get" action="$SCRIPT_NAME">
179 Package:
180 <input type="text" name="pkg" />
181 </form>
182 </div>
184 <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 Bloked packages : $(cat $bloked | wc -l)
193 </pre>
195 <p>
196 Packages: $cooked cooked on $inwok in the wok.
197 </p>
198 <div class="pctbar">
199 <div class="pct" style="width: ${pct}%;">${pct}%</div>
200 </div>
202 <p>
203 Latest logs:
204 <a href="cooker.cgi?file=cookorder.log">cookorder</a>
205 <a href="cooker.cgi?file=commits.log">commits</a>
206 </p>
208 <h2>Activity</h2>
209 <pre>
210 $(tac $CACHE/activity | head -n 12 | \
211 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g)
212 </pre>
213 <a class="button" href="cooker.cgi?file=activity">More activity</a>
215 <h2>Cooknotes</h2>
216 <pre>
217 $(tac $cooknotes | head -n 12 | \
218 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g)
219 </pre>
220 <a class="button" href="cooker.cgi?file=cooknotes">More notes</a>
222 <h2>Commits</h2>
223 <pre>
224 $(cat $commits)
225 </pre>
227 <h2>Cooklist</h2>
228 <pre>
229 $(cat $cooklist | head -n 20)
230 </pre>
231 <a class="button" href="cooker.cgi?file=cooklist">Full cooklist</a>
233 <h2>Broken</h2>
234 <pre>
235 $(cat $broken | head -n 20 | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
236 </pre>
237 <a class="button" href="cooker.cgi?file=broken">All broken packages</a>
239 <h2>Blocked</h2>
240 <pre>
241 $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
242 </pre>
244 <h2>Latest cook</h2>
245 <pre>
246 $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
247 </pre>
248 EOT
249 ;;
250 esac
252 # Close xHTML page
253 cat << EOT
254 </div>
256 <div id="footer">
257 <a href="cooker.cgi">SliTaz Cooker</a>
258 </div>
260 </body>
261 </html>
262 EOT
264 exit 0