cookutils view web/cooker.cgi @ rev 16

Cant use tazpkg to pack since it dont handle EXTRAVERSION and improving CGI
author Christophe Lincoln <pankso@slitaz.org>
date Thu May 05 17:05:19 2011 +0200 (2011-05-05)
parents b6bbe55cd15e
children c3c30b1506b8
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 sed -e 's#OK$#<span class="span-ok">OK</span>#g' \
30 -e 's#yes$#<span class="span-ok">yes</span>#g' \
31 -e 's#no$#<span class="span-no">no</span>#g' \
32 -e 's#error$#<span class="span-error">error</span>#g' \
33 -e 's#ERROR:#<span class="span-error">ERROR:</span>#g' \
34 -e s"#^Executing:\([^']*\).#<span class='span-sky'>\0</span>#"g \
35 -e s"#^====\([^']*\).#<span class='span-line'>\0</span>#"g \
36 -e s"#ftp://\([^']*\).*#<a href='\0'>\0</a>#"g \
37 -e s"#http://\([^']*\).*#<a href='\0'>\0</a>#"g \
38 -e s"#^\#\([^']*\)#<span class='sh-comment'>\0</span>#"g
39 #-e s"#\"\([^']*\)\"#<span class='sh-val'>\0</span>#"g
40 }
42 # Latest build pkgs.
43 list_packages() {
44 cd $PKGS
45 ls -1t *.tazpkg | head -20 | \
46 while read file
47 do
48 echo -n $(stat -c '%y' $PKGS/$file | cut -d . -f 1 | sed s/:[0-9]*$//)
49 echo " : $file"
50 done
51 }
53 # xHTML header
54 cat << EOT
55 <!DOCTYPE html>
56 <html xmlns="http://www.w3.org/1999/xhtml">
57 <head>
58 <title>SliTaz Cooker</title>
59 <meta charset="utf-8" />
60 <link rel="stylesheet" type="text/css" href="style.css" />
61 </head>
62 <body>
64 <div id="header">
65 <h1><a href="cooker.cgi">SliTaz Cooker</a></h1>
66 </div>
68 <!-- Content -->
69 <div id="content">
70 EOT
72 #
73 # Load requested page
74 #
76 case "${QUERY_STRING}" in
77 pkg=*)
78 pkg=${QUERY_STRING#pkg=}
79 log=$LOGS/$pkg.log
80 echo "<h2>Package: $pkg</h2>"
82 # Package info
83 if [ -f "$wok/$pkg/receipt" ]; then
84 . $wok/$pkg/receipt
85 tazpkg=$PKGS/$pkg-${VERSION}.tazpkg
86 if [ -f "$tazpkg" ]; then
88 cooked=$(stat -c '%y' $tazpkg | cut -d . -f 1 | sed s/:[0-9]*$//)
89 echo $cooked
90 fi
91 echo "<a href='cooker.cgi?receipt=$pkg'>receipt</a>"
92 else
93 echo "<p>No package named: $pkg<p>"
94 fi
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
106 echo '</pre>'
107 fi
108 fi
109 if fgrep -q "ERROR:" $LOGS/$pkg.log; then
110 fgrep "ERROR:" $LOGS/$pkg.log
111 fi
112 echo "<h3>Cook log</h3>"
113 echo '<pre>'
114 cat $log | syntax_highlighter
115 echo '</pre>'
116 else
117 echo "<pre>No log: $pkg</pre>"
118 fi ;;
119 log=*)
120 log=${QUERY_STRING#log=}
121 file=$LOGS/$log.log
122 echo "<h2>Log for: $log</h2>"
123 if [ -f "$LOGS/$log.log" ]; then
124 echo '<pre>'
125 cat $file | syntax_highlighter
126 echo '</pre>'
127 else
128 echo "<pre>No log for: $log</pre>"
129 fi ;;
130 receipt=*)
131 pkg=${QUERY_STRING#receipt=}
132 echo "<h2>Receipt: $pkg</h2>"
133 if [ -f "$wok/$pkg/receipt" ]; then
134 echo '<pre>'
135 cat $wok/$pkg/receipt | syntax_highlighter
136 echo '</pre>'
137 else
138 echo "<pre>No receipt for: $log</pre>"
139 fi ;;
140 *)
141 cat << EOT
142 <div style="float: right;">
143 <form method="get" action="$SCRIPT_NAME">
144 Package:
145 <input type="text" name="pkg" />
146 </form>
147 </div>
149 <h2>Summary</h2>
150 <pre>
151 Running command : $([ -s "$command" ] && cat $command || echo "Not running")
152 Cooked packages : $(ls $PKGS/*.tazpkg | wc -l)
153 Packages in wok : $(ls $WOK | wc -l)
154 Wok revision : <a href="http://hg.slitaz.org/wok">$(cd $WOK && hg head --template '{rev}\n')</a>
155 Commits to cook : $(cat $commits | wc -l)
156 Broken packages : $(cat $broken | wc -l)
157 </pre>
159 <div>
160 Latest logs: <a href="cooker.cgi?log=cookorder">cookorder</a>
161 <a href="cooker.cgi?log=commits">commits</a>
162 </div>
164 <h2>Activity</h2>
165 <pre>
166 $(tac $CACHE/activity | sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g)
167 </pre>
169 <h2>Commits</h2>
170 <pre>
171 $(cat $commits)
172 </pre>
174 <h2>Broken</h2>
175 <pre>
176 $(cat $broken | sed s"#^[^']*#<a href='cooker.cgi?log=\0'>\0</a>#"g)
177 </pre>
179 <h2>Bloked</h2>
180 <pre>
181 $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?log=\0'>\0</a>#"g)
182 </pre>
184 <h2>Latest cook</h2>
185 <pre>
186 $(list_packages | sed s"#^\([^']* \)#<span class='span-date'>\0</span>#"g)
187 </pre>
188 EOT
189 ;;
190 esac
192 # Close xHTML page
193 cat << EOT
194 </div>
196 <div id="footer">
197 <a href="cooker.cgi">SliTaz Cooker</a>
198 </div>
200 </body>
201 </html>
202 EOT
204 exit 0