cookutils view web/cooker.cgi @ rev 23

Fix broken function in cook (Thanks Erjo) + add cooknotes feature
author Christophe Lincoln <pankso@slitaz.org>
date Fri May 06 00:05:14 2011 +0200 (2011-05-06)
parents 90ec7271d772
children 8fc5b2a08f0e
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"#ftp://\([^']*\).*#<a href='\0'>\0</a>#"g \
40 -e s"#http://\([^']*\).*#<a href='\0'>\0</a>#"g ;;
41 receipt)
42 sed -e s"#^\#\([^']*\)#<span class='sh-comment'>\0</span>#"g \
43 -e s"#\"\([^']*\)\"#<span class='sh-val'>\0</span>#"g ;;
44 esac
45 }
47 # Latest build pkgs.
48 list_packages() {
49 cd $PKGS
50 ls -1t *.tazpkg | head -20 | \
51 while read file
52 do
53 echo -n $(stat -c '%y' $PKGS/$file | cut -d . -f 1 | sed s/:[0-9]*$//)
54 echo " : $file"
55 done
56 }
58 # xHTML header
59 cat << EOT
60 <!DOCTYPE html>
61 <html xmlns="http://www.w3.org/1999/xhtml">
62 <head>
63 <title>SliTaz Cooker</title>
64 <meta charset="utf-8" />
65 <link rel="stylesheet" type="text/css" href="style.css" />
66 </head>
67 <body>
69 <div id="header">
70 <h1><a href="cooker.cgi">SliTaz Cooker</a></h1>
71 </div>
73 <!-- Content -->
74 <div id="content">
75 EOT
77 #
78 # Load requested page
79 #
81 case "${QUERY_STRING}" in
82 pkg=*)
83 pkg=${QUERY_STRING#pkg=}
84 log=$LOGS/$pkg.log
85 echo "<h2>Package: $pkg</h2>"
87 # Package info.
88 echo '<div id="info">'
89 if [ -f "$wok/$pkg/receipt" ]; then
90 echo "<a href='cooker.cgi?receipt=$pkg'>receipt</a>"
91 else
92 echo "No package named: $pkg"
93 fi
94 echo '</div>'
96 # Check for a log file and display summary if exist.
97 if [ -f "$log" ]; then
98 if fgrep -q "Summary " $LOGS/$pkg.log; then
99 if fgrep -q "cook:$pkg$" $command; then
100 echo "<pre>The Cooker is currently cooking: $pkg</pre>"
101 else
102 echo "<h3>Cook summary</h3>"
103 echo '<pre>'
104 grep -A 8 "^Summary " $LOGS/$pkg.log | sed /^$/d | \
105 syntax_highlighter log
106 echo '</pre>'
107 fi
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 log=*)
124 log=${QUERY_STRING#log=}
125 file=$LOGS/$log.log
126 echo "<h2>Log for: $log</h2>"
127 if [ -f "$LOGS/$log.log" ]; then
128 if fgrep -q "Summary" $file; then
129 echo '<pre>'
130 grep -A 8 "^Summary" $file | sed /^$/d | \
131 syntax_highlighter log
132 echo '</pre>'
133 fi
134 echo '<pre>'
135 cat $file | syntax_highlighter log
136 echo '</pre>'
137 else
138 echo "<pre>No log for: $log</pre>"
139 fi ;;
140 receipt=*)
141 pkg=${QUERY_STRING#receipt=}
142 echo "<h2>Receipt for: $pkg</h2>"
143 if [ -f "$wok/$pkg/receipt" ]; then
144 echo '<pre>'
145 cat $wok/$pkg/receipt | syntax_highlighter receipt
146 echo '</pre>'
147 else
148 echo "<pre>No receipt for: $log</pre>"
149 fi ;;
150 *)
151 cat << EOT
152 <div style="float: right;">
153 <form method="get" action="$SCRIPT_NAME">
154 Package:
155 <input type="text" name="pkg" />
156 </form>
157 </div>
159 <h2>Summary</h2>
160 <pre>
161 Running command : $([ -s "$command" ] && cat $command || echo "Not running")
162 Cooked packages : $(ls $PKGS/*.tazpkg | wc -l)
163 Packages in wok : $(ls $WOK | wc -l)
164 Wok revision : <a href="http://hg.slitaz.org/wok">$(cd $WOK && hg head --template '{rev}\n')</a>
165 Commits to cook : $(cat $commits | wc -l)
166 Broken packages : $(cat $broken | wc -l)
167 </pre>
169 <div id="info">
170 Latest logs: <a href="cooker.cgi?log=cookorder">cookorder</a>
171 <a href="cooker.cgi?log=commits">commits</a>
172 </div>
174 <h2>Activity</h2>
175 <pre>
176 $(tac $CACHE/activity | sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g)
177 </pre>
179 <h2>Cooknotes</h2>
180 <pre>
181 $(cat $cooknotes)
182 </pre>
184 <h2>Commits</h2>
185 <pre>
186 $(cat $commits)
187 </pre>
189 <h2>Cooklist</h2>
190 <pre>
191 $(cat $cooklist)
192 </pre>
194 <h2>Broken</h2>
195 <pre>
196 $(cat $broken | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
197 </pre>
199 <h2>Blocked</h2>
200 <pre>
201 $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
202 </pre>
204 <h2>Latest cook</h2>
205 <pre>
206 $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
207 </pre>
208 EOT
209 ;;
210 esac
212 # Close xHTML page
213 cat << EOT
214 </div>
216 <div id="footer">
217 <a href="cooker.cgi">SliTaz Cooker</a>
218 </div>
220 </body>
221 </html>
222 EOT
224 exit 0