slitaz-pizza view web/pizza.cgi @ rev 19

pizza web display only last 5 builded flavor
author Christophe Lincoln <pankso@slitaz.org>
date Mon Mar 26 15:00:24 2012 +0200 (2012-03-26)
parents a6b8d65c19a2
children 5c9d080960ce
line source
1 #!/bin/sh
2 #
3 # SliTaz Pizza CGI/web interface - Let's have a pizza :-)
4 # Please KISS, it is important and keep speed in mind. Thanks, Pankso.
5 #
7 # Output a RSS feed of latest build isos.
8 if [ "$QUERY_STRING" == "rss" ]; then
9 . /etc/slitaz/pizza.conf
10 pubdate=$(date "+%a, %d %b %Y %X")
11 cat << EOT
12 Content-Type: text/xml
14 <?xml version="1.0" encoding="utf-8" ?>
15 <rss version="2.0">
16 <channel>
17 <title>SliTaz Pizza</title>
18 <description>The SliTaz Pizza cooker feed</description>
19 <link>$PIZZA_URL</link>
20 <lastBuildDate>$pubdate GMT</lastBuildDate>
21 <pubDate>$pubdate GMT</pubDate>
22 EOT
23 for rss in $(ls -1t $PIZZA/chroot${SLITAZ}/xml/*.xml | head -n 12)
24 do
25 cat $rss
26 done
27 cat << EOT
28 </channel>
29 </rss>
30 EOT
31 exit 0
32 fi
34 # Content negotiation for Gettext
35 IFS=","
36 for lang in $HTTP_ACCEPT_LANGUAGE
37 do
38 lang=${lang%;*} lang=${lang# } lang=${lang%-*}
39 [ -d "$lang" ] && break
40 case "$lang" in
41 en) lang="C" ;;
42 fr) lang="fr_FR" ;;
43 esac
44 done
45 unset IFS
46 export LANG=$lang LC_ALL=$lang
48 # Internationalization: $(gettext "")
49 . /usr/bin/gettext.sh
50 TEXTDOMAIN='pizza'
51 export TEXTDOMAIN
53 . lib/libpizza
55 #
56 # Commands
57 #
59 case " $(GET) " in
60 *\ start\ *)
61 #
62 # First step
63 #
64 date=$(date "+%Y%m%d")
65 id=$date-$$
66 cat << EOT
67 <h2>$(gettext "First step")</h2>
68 <p>
69 $(gettext "Choose your distribution name and the one you want to use as
70 base. We need your mail to notify you when your SliTaz Flavor is built
71 and if anything goes wrong.")
72 </p>
73 <form method="get" action="pkgs.cgi" name="pizza" onsubmit="return checkForm();">
74 <table>
75 <tbody>
76 <tr>
77 <td>$(gettext "Flavor name")</td>
78 <td><input type="text" name="flavor" size="40" /></td>
79 </tr>
80 <tr>
81 <td>$(gettext "Short description")</td>
82 <td><input type="text" name="desc" size="40" /></td>
83 </tr>
84 <tr>
85 <td>$(gettext "Email")</td>
86 <td><input type="text" name="mail" size="40" /></td>
87 </tr>
88 <tr>
89 <td>$(gettext "Based on")</td>
90 <td>
91 <select name="skel">
92 <option value="base">
93 Base - $(gettext "Text mode system")</option>
94 <option value="justx">
95 Justx - $(gettext "X without GTK or QT")</option>
96 <option value="gtkonly">
97 Gtkonly - $(gettext "Clean GTK desktop")</option>
98 <option value="core">
99 Core - $(gettext "Default SliTaz desktop")</option>
100 </select>
101 </td>
102 </tr>
103 </tbody>
104 </table>
105 <pre>
106 Uniq ID : $id
107 </pre>
108 <div class="next">
109 <input type="hidden" name="id" value="$id" />
110 <input type="submit" value="$(gettext "Continue")">
111 </div>
112 </form>
113 EOT
114 ;;
115 *\ gen\ *)
116 #
117 # Generate step
118 #
119 id="$(GET id)"
120 . $tmpdir/slitaz-$id/receipt
121 addfiles=$(find $tmpdir/slitaz-$id/addfiles -type f | wc -l)
122 [ "$addfiles" ] || addfiles=0
123 packages=$(cat $tmpdir/slitaz-$id/packages.list | wc -l)
124 cat << EOT
125 <h2>$(gettext "Generate")</h2>
126 <p>
127 Last chance to stop process or start over. Next step will pack your
128 flavor and add it to the build queue. Here you can also add a note to
129 your receipt flavor, this will be displayed on your flavor ID page
130 and can be used to give more info to other users and SliTaz developers.
131 </p>
132 <pre>
133 Uniq ID : $id
134 Flavor : $FLAVOR
135 Short desc : $SHORT_DESC
136 Maintainer : $MAINTAINER
137 Packages : $packages
138 Addfiles : $addfiles
139 </pre>
140 <form method="get" action="./">
141 <div class="box">
142 Note:
143 <input type="text" name="note" style="width: 720px;" />
144 </div>
145 <div class="next">
146 <input type="submit" name="cancel" value="$(gettext "Cancel")">
147 <input type="hidden" name="addfiles" value="$addfiles" />
148 <input type="hidden" name="id" value="$id" />
149 <input type="submit" name="pack" value="$(gettext "Build flavor")">
150 </div>
151 </form>
152 EOT
153 ;;
154 *\ cancel\ *)
155 id="$(GET id)"
156 echo "<p>Removing temporary files for: $id</p>"
157 [ -d "$tmpdir/slitaz-$id" ] && rm -rf $tmpdir/slitaz-$id/
158 cat << EOT
159 <form method="get" action="./">
160 <input type="submit" name="start" value="$(gettext "Start over")">
161 </form>
162 EOT
163 ;;
164 *\ pack\ *)
165 #
166 # Pack distro step
167 #
168 id="$(GET id)"
169 receipt="$tmpdir/slitaz-$id/receipt"
170 addfiles="$(GET addfiles)"
171 log="$tmpdir/slitaz-$id/distro.log"
172 note="$(GET note)"
173 inqueue=$(ls $queue | wc -l)
174 . $receipt
175 cat << EOT
176 <h2>$(gettext "Packing:") $FLAVOR</h2>
177 <pre>
178 EOT
179 if ! fgrep ADDFILES $receipt; then
180 echo "ADDFILES=\"$addfiles\"" >> $receipt
181 fi
182 if ! fgrep NOTE $receipt; then
183 echo "NOTE=\"$note\"" >> $receipt
184 fi
186 # The rootcd README
187 echo -n "Creating SliTaz cdrom README..."
188 date=$(date '+%Y-%m-%d %H:%M')
189 mkdir -p $tmpdir/slitaz-$id/rootcd
190 cp $DATA/README.distro $tmpdir/slitaz-$id/rootcd/README
191 sed -i s"/_DATE_/$date/" $tmpdir/slitaz-$id/rootcd/README
192 status
194 echo -n "Creating flavor tarball..."
195 cd $tmpdir && tar cjf $FLAVOR.tar.bz2 slitaz-$id
196 mkdir -p $public/slitaz-$id
197 mv $FLAVOR.tar.bz2 $public/slitaz-$id
198 status
200 # Keep a public receipt copy and move everything from tmp to queue.
201 echo "Flavor packed : $(date '+%Y-%m-%d %H:%M')" | tee -a $log
202 echo -n "Moving $id to Pizza build queue..."
203 mv -f $tmpdir/slitaz-$id/distro.log $public/slitaz-$id
204 cp -f $tmpdir/slitaz-$id/receipt $public/slitaz-$id
205 mv $tmpdir/slitaz-$id $queue
206 status
208 if [ "$inqueue" == "1" ]; then
209 gettext "Your ISO will be built on next Pizza Bot run"
210 else
211 eval_gettext "There is \$inqueue flavors in queue"
212 fi
213 echo ""
214 echo "New flavor added to queue: <a href='?id=$id'>$id</a> ($FLAVOR)" | log
215 cat << EOT
216 </pre>
217 <div>
218 <img src="images/archive.png" alt="[ tarball ]" />
219 $(gettext "Download tarball: ")
220 <a href="public/slitaz-$id/$FLAVOR.tar.bz2">$FLAVOR.tar.bz2</a>
221 - Browse <a href="public/slitaz-$id/">the flavor</a>
222 </div>
223 <div class="next">
224 <form method="get" action="./">
225 <input type="hidden" name="id" value="$id" />
226 <input type="submit" value="$(gettext "Status")">
227 </form>
228 </div>
229 EOT
230 ;;
231 *\ id\ *)
232 #
233 # ID Status page
234 #
235 id="$(GET id)"
236 [ -f "$queue/slitaz-$id/receipt" ] && . $queue/slitaz-$id/receipt
237 [ -f "public/slitaz-$id/receipt" ] && . public/slitaz-$id/receipt
238 log="$public/slitaz-$id/distro.log"
239 if [ ! -d "public/slitaz-$id" ]; then
240 echo "Sorry, can't find flavor ID: $id"
241 cat lib/footer.html && exit 0
242 fi
243 if [ -f "$public/slitaz-$id/$FLAVOR.iso" ]; then
244 dir="public/slitaz-$id"
245 list="$dir/packages.list"
246 iso="$dir/$FLAVOR.iso"
247 msg="$(gettext "Download ISO:") <a href='$dir/$FLAVOR.iso'>$FLAVOR.iso</a>
248 [ <a href='$dir/$FLAVOR.md5'>md5</a> ]"
249 else
250 list="$queue/slitaz-$id/packages.list"
251 msg="$(gettext "Flavor is building or still in the build queue")"
252 fi
253 pkgslist=$(cat $list | wc -l)
254 pkgsinst=$(cat $installed | wc -l)
255 [ "$pkgsinst" ] || pkgsinst=0
256 [ "$ISO_SIZE" ] || ISO_SIZE="N/A"
257 [ "$ROOTFS_SIZE" ] || ROOTFS_SIZE="N/A"
258 cat << EOT
259 <h2>$(gettext "Status for:") $FLAVOR</h2>
260 <div>
261 $(get_gravatar $MAINTAINER) $(gettext "Flavor description:") $SHORT_DESC
262 </div>
263 <pre>
264 Uniq ID : $id
265 Flavor : $FLAVOR
266 Packages : $pkgslist in list - $pkgsinst installed
267 Rootfs size : $ROOTFS_SIZE
268 ISO size : $ISO_SIZE
269 </pre>
271 <div>
272 <img src="images/iso.png" alt="[ iso ]" /> $(echo $msg)
273 </div>
274 <div>
275 <img src="images/archive.png" alt="[ tarball ]" />
276 $(gettext "Download tarball:")
277 <a href="public/slitaz-$id/$FLAVOR.tar.bz2">$FLAVOR.tar.bz2</a>
278 EOT
279 if [ -f "$public/slitaz-$id/$FLAVOR.flavor" ]; then
280 cat << EOT
281 - Flavor file: <a href="public/slitaz-$id/$FLAVOR.flavor">$FLAVOR.flavor</a>
282 EOT
283 fi
284 cat << EOT
285 - Browse <a href="public/slitaz-$id/">the flavor</a>
286 </div>
287 EOT
288 if [ "$NOTE" ]; then
289 echo "<div class="note">$NOTE</div>"
290 fi
291 if [ -f "$log" ]; then
292 echo '<h2>Distro log</h2>'
293 echo '<pre>'
294 fgrep 'Build time' $log
295 cat $log | highlighter log
296 echo '</pre>'
297 fi ;;
298 *\ help\ *)
299 echo "<h2>$(gettext "Help")</h2>"
300 echo "<b>TODO: HTML faq/doc</b>"
301 echo '<pre>'
302 cat /usr/share/doc/pizza/README
303 echo '</pre>' ;;
304 *\ info\ *)
305 # English only :-)
306 if mount | fgrep -q slitaz/public; then
307 mounted="Public is mounted"
308 else
309 mounted="WARRNING: Public is not mounted"
310 fi
311 echo '<h2><img src="images/monitor.png" alt="" />Pizza Info</h2>'
312 echo '<pre>'
313 [ "$mounted" ] && echo "$mounted"
314 echo -n "Public flavors : " && ls -1 public | wc -l
315 echo -n "Public size : " && du -sh public | awk '{print $1}'
316 echo -n "Tmp size : " && du -sh $tmpdir | awk '{print $1}'
317 echo '</pre>' ;;
318 *\ activity\ *)
319 cat << EOT
320 <h2><img src="images/monitor.png" alt="" />$(gettext "Activity")</h2>
322 <pre>
323 $(tac $activity | highlighter activity)
324 </pre>
326 EOT
327 ;;
328 *)
329 #
330 # Main page
331 #
332 inqueue=$(ls $queue | wc -l)
333 builds=$(cat $builds)
334 pubiso=$(ls -1 public | wc -l)
335 [ "$builds" ] || builds=0
336 cat << EOT
337 <h2>$(gettext "Welcome")</h2>
338 <form method="get" action="./">
339 <p>
340 SliTaz Pizza lets you create your own SliTaz ISO flavor online. The
341 ISO image can be burnt on a cdrom or installed on USB media.
342 Please read the SliTaz Pizza
343 <a href="?help">Help</a> before starting a new flavor.
344 </p>
345 <pre>
346 Flavors: $inqueue in queue - $builds builds - $pubiso public
347 </pre>
349 <div class="start">
350 <input type="submit" name="start" value="$(gettext "Create a new flavor")">
351 </div>
353 EOT
354 echo "<h2>$(gettext "Latest builds")</h2>"
355 echo '<pre>'
356 for flavor in $(ls -1t public | head -n 5)
357 do
358 if [ -f "public/$flavor/receipt" ]; then
359 . ./public/$flavor/receipt
360 [ -f "public/$flavor/$FLAVOR.iso" ] && \
361 cat << EOT
362 $(get_gravatar $MAINTAINER 24) <a href="?id=$ID">$VERSION</a> : \
363 <a href="public/$flavor/$FLAVOR.iso">$FLAVOR.iso</a> ($ISO_SIZE)
364 EOT
365 fi
366 done
367 echo '</pre>'
368 cat << EOT
369 <h2>$(gettext "Activity")</h2>
370 <pre>
371 $(tac $activity | head -n 12 | highlighter activity)
372 </pre>
373 <input type="submit" name="activity" value="$(gettext "More activity")">
374 </form>
375 EOT
376 ;;
377 esac
379 # HTML footer.
380 cat lib/footer.html
382 exit 0