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

Add the web interface
author Christophe Lincoln <pankso@slitaz.org>
date Sat Mar 24 23:12:44 2012 +0100 (2012-03-24)
parents
children a5164f0bb461
line source
1 #!/bin/sh
2 #
3 # SliTaz Pizza CGI/web interface - Let's me 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 "Chosse your distribution name and the one you want to use as
70 base. We need our mail to notify you when your SliTaz Flavor is built
71 and if any things 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 note to
129 your receipt flavor, this will be displayed on your flavor ID page
130 and can be used to give more infos 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 "Ther is \$inqueue flavors in queue"
212 fi
213 echo ""
214 echo "New flavor added to queue: <a href='?id=$id'>$id</a>" | 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 found 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 <p>
261 $(gettext "Flavor description:") $SHORT_DESC
262 </p>
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 *)
319 #
320 # Main page
321 #
322 inqueue=$(ls $queue | wc -l)
323 builds=$(cat $builds)
324 pubiso=$(ls -1 public | wc -l)
325 [ "$builds" ] || builds=0
326 cat << EOT
327 <h2>$(gettext "Welcome")</h2>
328 <p>
329 SliTaz Pizza let you create your own SliTaz ISO flavor online. The
330 ISO image can be burnt on a cdrom or installed on an USB media.
331 Please read the SliTaz Pizza
332 <a href="?help">Help</a> before starting a new flavor.
333 </p>
334 <pre>
335 Flavors: $inqueue in queue - $builds builds - $pubiso public
336 </pre>
338 <div class="start">
339 <form method="get" action="./">
340 <input type="hidden" name="start" value="flavor" />
341 <input type="submit" value="$(gettext "Create a new flavor")">
342 </form>
343 </div>
345 <h2>Activity</h2>
346 <pre>
347 $(tac $activity | head -n 12 | highlighter activity)
348 </pre>
350 EOT
351 echo "<h2>$(gettext "Latest builds")</h2>"
352 echo '<pre>'
353 for flavor in $(ls -1t public | head -n 12)
354 do
355 if [ -f "public/$flavor/receipt" ]; then
356 . ./public/$flavor/receipt
357 [ -f "public/$flavor/$FLAVOR.iso" ] && \
358 cat << EOT
359 $VERSION : <a href="public/$flavor/$FLAVOR.iso">$FLAVOR.iso</a> ($ISO_SIZE)
360 EOT
361 fi
362 done
363 echo '</pre>' ;;
364 esac
366 # HTML footer.
367 cat lib/footer.html
369 exit 0