cookutils view web/cooker.cgi @ rev 29

Better output for cookorder, add SETUP_PKGS in cook.conf to share list with the cooker + small improvments
author Christophe Lincoln <pankso@slitaz.org>
date Fri May 06 16:14:39 2011 +0200 (2011-05-06)
parents a7f0d97a9ccc
children c49e394e87d3
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='span-sky'>\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 exist.
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 log=*)
125 log=${QUERY_STRING#log=}
126 file=$LOGS/$log.log
127 echo "<h2>Log for: $log</h2>"
128 if [ -f "$LOGS/$log.log" ]; then
129 if fgrep -q "Summary" $file; then
130 echo '<pre>'
131 grep -A 8 "^Summary" $file | sed /^$/d | \
132 syntax_highlighter log
133 echo '</pre>'
134 fi
135 echo '<pre>'
136 cat $file | syntax_highlighter log
137 echo '</pre>'
138 else
139 echo "<pre>No log for: $log</pre>"
140 fi ;;
141 receipt=*)
142 pkg=${QUERY_STRING#receipt=}
143 echo "<h2>Receipt for: $pkg</h2>"
144 if [ -f "$wok/$pkg/receipt" ]; then
145 echo '<pre>'
146 cat $wok/$pkg/receipt | syntax_highlighter receipt
147 echo '</pre>'
148 else
149 echo "<pre>No receipt for: $log</pre>"
150 fi ;;
151 *)
152 cat << EOT
153 <div style="float: right;">
154 <form method="get" action="$SCRIPT_NAME">
155 Package:
156 <input type="text" name="pkg" />
157 </form>
158 </div>
160 <h2>Summary</h2>
161 <pre>
162 Running command : $([ -s "$command" ] && cat $command || echo "Not running")
163 Cooked packages : $(ls $PKGS/*.tazpkg | wc -l)
164 Packages in wok : $(ls $WOK | wc -l)
165 Wok revision : <a href="http://hg.slitaz.org/wok">$(cd $WOK && hg head --template '{rev}\n')</a>
166 Commits to cook : $(cat $commits | wc -l)
167 Broken packages : $(cat $broken | wc -l)
168 </pre>
170 <div id="info">
171 Latest logs: <a href="cooker.cgi?log=cookorder">cookorder</a>
172 <a href="cooker.cgi?log=commits">commits</a>
173 </div>
175 <h2>Activity</h2>
176 <pre>
177 $(tac $CACHE/activity | sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g)
178 </pre>
180 <h2>Cooknotes</h2>
181 <pre>
182 $(cat $cooknotes)
183 </pre>
185 <h2>Commits</h2>
186 <pre>
187 $(cat $commits)
188 </pre>
190 <h2>Cooklist</h2>
191 <pre>
192 $(cat $cooklist)
193 </pre>
195 <h2>Broken</h2>
196 <pre>
197 $(cat $broken | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
198 </pre>
200 <h2>Blocked</h2>
201 <pre>
202 $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
203 </pre>
205 <h2>Latest cook</h2>
206 <pre>
207 $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
208 </pre>
209 EOT
210 ;;
211 esac
213 # Close xHTML page
214 cat << EOT
215 </div>
217 <div id="footer">
218 <a href="cooker.cgi">SliTaz Cooker</a>
219 </div>
221 </body>
222 </html>
223 EOT
225 exit 0