cookutils view web/cooker.cgi @ rev 65

Improve web interface, keep and show more activity and cooknote
author Christophe Lincoln <pankso@slitaz.org>
date Sat May 07 17:38:17 2011 +0200 (2011-05-07)
parents c49e394e87d3
children af6305b2076b
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 fgrep -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 *.log)
135 file=$LOGS/$file
136 name=$(basename $file)
137 echo "<h2>Log for: ${name%.log}</h2>"
138 if [ -f "$LOGS/$log.log" ]; then
139 if fgrep -q "Summary" $file; then
140 echo '<pre>'
141 grep -A 8 "^Summary" $file | sed /^$/d | \
142 syntax_highlighter log
143 echo '</pre>'
144 fi
145 echo '<pre>'
146 cat $file | syntax_highlighter log
147 echo '</pre>'
148 else
149 echo "<pre>No log for: $log</pre>"
150 fi ;;
151 esac ;;
152 receipt=*)
153 pkg=${QUERY_STRING#receipt=}
154 echo "<h2>Receipt for: $pkg</h2>"
155 if [ -f "$wok/$pkg/receipt" ]; then
156 echo '<pre>'
157 cat $wok/$pkg/receipt | syntax_highlighter receipt
158 echo '</pre>'
159 else
160 echo "<pre>No receipt for: $log</pre>"
161 fi ;;
162 *)
163 cat << EOT
164 <div style="float: right;">
165 <form method="get" action="$SCRIPT_NAME">
166 Package:
167 <input type="text" name="pkg" />
168 </form>
169 </div>
171 <h2>Summary</h2>
172 <pre>
173 Running command : $([ -s "$command" ] && cat $command || echo "Not running")
174 Cooked packages : $(ls $PKGS/*.tazpkg | wc -l)
175 Packages in wok : $(ls $WOK | wc -l)
176 Wok revision : <a href="http://hg.slitaz.org/wok">$(cd $WOK && hg head --template '{rev}\n')</a>
177 Commits to cook : $(cat $commits | wc -l)
178 Current cooklist : $(cat $cooklist | wc -l)
179 Broken packages : $(cat $broken | wc -l)
180 </pre>
182 <div id="info">
183 Logs:
184 <a class="button" href="cooker.cgi?file=cookorder.log">cookorder</a>
185 <a class="button" href="cooker.cgi?file=commits.log">commits</a>
186 </div>
188 <h2>Activity</h2>
189 <pre>
190 $(tac $CACHE/activity | head -n 12 | \
191 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g)
192 </pre>
193 <a class="button" href="cooker.cgi?file=activity">More activity</a>
195 <h2>Cooknotes</h2>
196 <pre>
197 $(tac $cooknotes | head -n 12 | \
198 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g)
199 </pre>
200 <a class="button" href="cooker.cgi?file=cooknotes">More notes</a>
202 <h2>Commits</h2>
203 <pre>
204 $(cat $commits)
205 </pre>
207 <h2>Cooklist</h2>
208 <pre>
209 $(cat $cooklist)
210 </pre>
212 <h2>Broken</h2>
213 <pre>
214 $(cat $broken | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
215 </pre>
217 <h2>Blocked</h2>
218 <pre>
219 $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
220 </pre>
222 <h2>Latest cook</h2>
223 <pre>
224 $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
225 </pre>
226 EOT
227 ;;
228 esac
230 # Close xHTML page
231 cat << EOT
232 </div>
234 <div id="footer">
235 <a href="cooker.cgi">SliTaz Cooker</a>
236 </div>
238 </body>
239 </html>
240 EOT
242 exit 0