cookutils view web/cooker.cgi @ rev 20

Explain receipt variable in README and small fix to CGI
author Christophe Lincoln <pankso@slitaz.org>
date Thu May 05 22:27:09 2011 +0200 (2011-05-05)
parents 58496d7c2c18
children 90ec7271d772
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"
23 #
24 # Functions
25 #
27 # Put some colors in log and DB files.
28 syntax_highlighter() {
29 case $1 in
30 log)
31 sed -e 's#OK$#<span class="span-ok">OK</span>#g' \
32 -e 's#yes$#<span class="span-ok">yes</span>#g' \
33 -e 's#no$#<span class="span-no">no</span>#g' \
34 -e 's#error$#<span class="span-error">error</span>#g' \
35 -e 's#ERROR:#<span class="span-error">ERROR:</span>#g' \
36 -e s"#^Executing:\([^']*\).#<span class='span-sky'>\0</span>#"g \
37 -e s"#^====\([^']*\).#<span class='span-line'>\0</span>#"g \
38 -e s"#ftp://\([^']*\).*#<a href='\0'>\0</a>#"g \
39 -e s"#http://\([^']*\).*#<a href='\0'>\0</a>#"g ;;
40 receipt)
41 sed -e s"#^\#\([^']*\)#<span class='sh-comment'>\0</span>#"g \
42 -e s"#\"\([^']*\)\"#<span class='sh-val'>\0</span>#"g ;;
43 esac
44 }
46 # Latest build pkgs.
47 list_packages() {
48 cd $PKGS
49 ls -1t *.tazpkg | head -20 | \
50 while read file
51 do
52 echo -n $(stat -c '%y' $PKGS/$file | cut -d . -f 1 | sed s/:[0-9]*$//)
53 echo " : $file"
54 done
55 }
57 # xHTML header
58 cat << EOT
59 <!DOCTYPE html>
60 <html xmlns="http://www.w3.org/1999/xhtml">
61 <head>
62 <title>SliTaz Cooker</title>
63 <meta charset="utf-8" />
64 <link rel="stylesheet" type="text/css" href="style.css" />
65 </head>
66 <body>
68 <div id="header">
69 <h1><a href="cooker.cgi">SliTaz Cooker</a></h1>
70 </div>
72 <!-- Content -->
73 <div id="content">
74 EOT
76 #
77 # Load requested page
78 #
80 case "${QUERY_STRING}" in
81 pkg=*)
82 pkg=${QUERY_STRING#pkg=}
83 log=$LOGS/$pkg.log
84 echo "<h2>Package: $pkg</h2>"
86 # Package info.
87 echo '<div id="info">'
88 if [ -f "$wok/$pkg/receipt" ]; then
89 echo "<a href='cooker.cgi?receipt=$pkg'>receipt</a>"
90 else
91 echo "No package named: $pkg"
92 fi
93 echo '</div>'
95 # Check for a log file and display summary if exist.
96 if [ -f "$log" ]; then
97 if fgrep -q "Summary " $LOGS/$pkg.log; then
98 if fgrep -q "cook:$pkg$" $command; then
99 echo "<pre>The Cooker is currently cooking: $pkg</pre>"
100 else
101 echo "<h3>Cook summary</h3>"
102 echo '<pre>'
103 grep -A 8 "^Summary " $LOGS/$pkg.log | sed /^$/d | \
104 syntax_highlighter log
105 echo '</pre>'
106 fi
107 fi
108 if fgrep -q "Debug " $LOGS/$pkg.log; then
109 echo "<h3>Cook failed</h3>"
110 echo '<pre>'
111 grep -A 8 "^Debug " $LOGS/$pkg.log | sed /^$/d | \
112 syntax_highlighter log
113 echo '</pre>'
114 fi
115 echo "<h3>Cook log</h3>"
116 echo '<pre>'
117 cat $log | syntax_highlighter log
118 echo '</pre>'
119 else
120 echo "<pre>No log: $pkg</pre>"
121 fi ;;
122 log=*)
123 log=${QUERY_STRING#log=}
124 file=$LOGS/$log.log
125 echo "<h2>Log for: $log</h2>"
126 if [ -f "$LOGS/$log.log" ]; then
127 if fgrep -q "Summary" $file; then
128 echo '<pre>'
129 grep -A 8 "^Summary" $file | sed /^$/d | \
130 syntax_highlighter log
131 echo '</pre>'
132 fi
133 echo '<pre>'
134 cat $file | syntax_highlighter log
135 echo '</pre>'
136 else
137 echo "<pre>No log for: $log</pre>"
138 fi ;;
139 receipt=*)
140 pkg=${QUERY_STRING#receipt=}
141 echo "<h2>Receipt for: $pkg</h2>"
142 if [ -f "$wok/$pkg/receipt" ]; then
143 echo '<pre>'
144 cat $wok/$pkg/receipt | syntax_highlighter receipt
145 echo '</pre>'
146 else
147 echo "<pre>No receipt for: $log</pre>"
148 fi ;;
149 *)
150 cat << EOT
151 <div style="float: right;">
152 <form method="get" action="$SCRIPT_NAME">
153 Package:
154 <input type="text" name="pkg" />
155 </form>
156 </div>
158 <h2>Summary</h2>
159 <pre>
160 Running command : $([ -s "$command" ] && cat $command || echo "Not running")
161 Cooked packages : $(ls $PKGS/*.tazpkg | wc -l)
162 Packages in wok : $(ls $WOK | wc -l)
163 Wok revision : <a href="http://hg.slitaz.org/wok">$(cd $WOK && hg head --template '{rev}\n')</a>
164 Commits to cook : $(cat $commits | wc -l)
165 Broken packages : $(cat $broken | wc -l)
166 </pre>
168 <div id="info">
169 Latest logs: <a href="cooker.cgi?log=cookorder">cookorder</a>
170 <a href="cooker.cgi?log=commits">commits</a>
171 </div>
173 <h2>Activity</h2>
174 <pre>
175 $(tac $CACHE/activity | sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g)
176 </pre>
178 <h2>Commits</h2>
179 <pre>
180 $(cat $commits)
181 </pre>
183 <h2>Cooklist</h2>
184 <pre>
185 $(cat $cooklist)
186 </pre>
188 <h2>Broken</h2>
189 <pre>
190 $(cat $broken | sed s"#^[^']*#<a href='cooker.cgi?log=\0'>\0</a>#"g)
191 </pre>
193 <h2>Bloked</h2>
194 <pre>
195 $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?log=\0'>\0</a>#"g)
196 </pre>
198 <h2>Latest cook</h2>
199 <pre>
200 $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
201 </pre>
202 EOT
203 ;;
204 esac
206 # Close xHTML page
207 cat << EOT
208 </div>
210 <div id="footer">
211 <a href="cooker.cgi">SliTaz Cooker</a>
212 </div>
214 </body>
215 </html>
216 EOT
218 exit 0