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

pizza.cgi: Limit user input on Desc and flavor name.
author Eric Joseph-Alexandre <erjo@slitaz.org>
date Tue Oct 30 13:50:10 2012 +0100 (2012-10-30)
parents 93993b66f8ce
children f3cb89e93bec
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" maxlength="40" /></td>
79 </tr>
80 <tr>
81 <td>$(gettext "Short description")</td>
82 <td><input type="text" name="desc" size="40" maxlength="60" /></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 $(gettext "Last chance to stop process or start over. Next step will pack
128 your 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 and
130 can be used to give more info to other users and SliTaz developers.")
131 </p>
133 <pre>
134 Uniq ID : $id
135 Flavor : $FLAVOR
136 Short desc : $SHORT_DESC
137 Maintainer : $MAINTAINER
138 Packages : $packages
139 Addfiles : $addfiles
140 </pre>
141 <form method="get" action="./">
142 <div class="box">
143 Note:
144 <input type="text" name="note" style="width: 720px;" />
145 </div>
146 <div class="next">
147 <input type="submit" name="cancel" value="$(gettext "Cancel")">
148 <input type="hidden" name="addfiles" value="$addfiles" />
149 <input type="hidden" name="id" value="$id" />
150 <input type="submit" name="pack" value="$(gettext "Build flavor")">
151 </div>
152 </form>
153 EOT
154 ;;
155 *\ cancel\ *)
156 id="$(GET id)"
157 echo "<p>$(gettext "Removing temporary files for:") $id</p>"
158 [ -d "$tmpdir/slitaz-$id" ] && rm -rf $tmpdir/slitaz-$id/
159 cat << EOT
160 <form method="get" action="./">
161 <input type="submit" name="start" value="$(gettext "Start over")">
162 </form>
163 EOT
164 ;;
165 *\ pack\ *)
166 #
167 # Pack distro step
168 #
169 id="$(GET id)"
170 receipt="$tmpdir/slitaz-$id/receipt"
171 addfiles="$(GET addfiles)"
172 log="$tmpdir/slitaz-$id/distro.log"
173 note="$(GET note)"
174 inqueue=$(ls $queue | wc -l)
175 . $receipt
176 cat << EOT
177 <h2>$(gettext "Packing:") $FLAVOR</h2>
178 <pre>
179 EOT
180 if ! fgrep ADDFILES $receipt; then
181 echo "ADDFILES=\"$addfiles\"" >> $receipt
182 fi
183 if ! fgrep NOTE $receipt; then
184 echo "NOTE=\"$note\"" >> $receipt
185 fi
187 # The rootcd README
188 echo -n "Creating SliTaz cdrom README..."
189 date=$(date '+%Y-%m-%d %H:%M')
190 mkdir -p $tmpdir/slitaz-$id/rootcd
191 cp $DATA/README.distro $tmpdir/slitaz-$id/rootcd/README
192 sed -i s"/_DATE_/$date/" $tmpdir/slitaz-$id/rootcd/README
193 status
195 echo -n "Creating flavor tarball..."
196 cd $tmpdir && tar cjf $FLAVOR.tar.bz2 slitaz-$id
197 mkdir -p $public/slitaz-$id
198 mv $FLAVOR.tar.bz2 $public/slitaz-$id
199 status
201 # Keep a public receipt copy and move everything from tmp to queue.
202 echo "Flavor packed : $(date '+%Y-%m-%d %H:%M')" | tee -a $log
203 echo -n "Moving $id to Pizza build queue..."
204 mv -f $tmpdir/slitaz-$id/distro.log $public/slitaz-$id
205 cp -f $tmpdir/slitaz-$id/receipt $public/slitaz-$id
206 mv $tmpdir/slitaz-$id $queue
207 status
209 if [ "$inqueue" == "1" ]; then
210 gettext "Your ISO will be built on next Pizza Bot run"
211 else
212 eval_gettext "There are \$inqueue flavors in queue"
213 fi
214 echo ""
215 echo "New flavor added to queue: <a href='?id=$id'>$id</a> ($FLAVOR)" | log
216 cat << EOT
217 </pre>
218 <div>
219 <img src="images/archive.png" alt="[ tarball ]" />
220 $(gettext "Download tarball: ")
221 <a href="public/slitaz-$id/$FLAVOR.tar.bz2">$FLAVOR.tar.bz2</a>
222 - Browse <a href="public/slitaz-$id/">the flavor</a>
223 </div>
224 <div class="next">
225 <form method="get" action="./">
226 <input type="hidden" name="id" value="$id" />
227 <input type="submit" value="$(gettext "Status")">
228 </form>
229 </div>
230 EOT
231 ;;
232 *\ id\ *)
233 #
234 # ID Status page
235 #
236 id="$(GET id)"
237 [ -f "$queue/slitaz-$id/receipt" ] && . $queue/slitaz-$id/receipt
238 [ -f "public/slitaz-$id/receipt" ] && . public/slitaz-$id/receipt
239 log="$public/slitaz-$id/distro.log"
240 if [ ! -d "public/slitaz-$id" ]; then
241 echo "Sorry, can't find flavor ID: $id"
242 cat lib/footer.html && exit 0
243 fi
244 if [ -f "$public/slitaz-$id/$FLAVOR.iso" ]; then
245 dir="public/slitaz-$id"
246 list="$dir/packages.list"
247 iso="$dir/$FLAVOR.iso"
248 msg="$(gettext "Download ISO:") <a href='$dir/$FLAVOR.iso'>$FLAVOR.iso</a>
249 [ <a href='$dir/$FLAVOR.md5'>md5</a> ]"
250 else
251 list="$queue/slitaz-$id/packages.list"
252 msg="$(gettext "Flavor is building or still in the build queue")"
253 fi
254 pkgslist=$(cat $list | wc -l)
255 pkgsinst=$(cat $installed | wc -l)
256 [ "$pkgsinst" ] || pkgsinst=0
257 [ "$ISO_SIZE" ] || ISO_SIZE="N/A"
258 [ "$ROOTFS_SIZE" ] || ROOTFS_SIZE="N/A"
259 cat << EOT
260 <h2>$(gettext "Status for:") $FLAVOR</h2>
261 <div>
262 $(get_gravatar $MAINTAINER) $(gettext "Flavor description:") $SHORT_DESC
263 </div>
264 <pre>
265 Uniq ID : $id
266 Flavor : $FLAVOR
267 Packages : $pkgslist in list - $pkgsinst installed
268 Rootfs size : $ROOTFS_SIZE
269 ISO size : $ISO_SIZE
270 </pre>
272 <div>
273 <img src="images/iso.png" alt="[ iso ]" /> $(echo $msg)
274 </div>
275 <div>
276 <img src="images/archive.png" alt="[ tarball ]" />
277 $(gettext "Download tarball:")
278 <a href="public/slitaz-$id/$FLAVOR.tar.bz2">$FLAVOR.tar.bz2</a>
279 EOT
280 if [ -f "$public/slitaz-$id/$FLAVOR.flavor" ]; then
281 cat << EOT
282 - Flavor file: <a href="public/slitaz-$id/$FLAVOR.flavor">$FLAVOR.flavor</a>
283 EOT
284 fi
285 cat << EOT
286 - Browse <a href="public/slitaz-$id/">the flavor</a>
287 </div>
288 EOT
289 if [ "$NOTE" ]; then
290 echo "<div class="note">$NOTE</div>"
291 fi
292 if [ -f "$log" ]; then
293 echo '<h2>Distro log</h2>'
294 echo '<pre>'
295 fgrep 'Build time' $log
296 cat $log | highlighter log
297 echo '</pre>'
298 fi ;;
299 *\ help\ *)
300 echo "<h2>$(gettext "Help")</h2>"
301 cat /usr/share/doc/pizza/help.en.html
302 cat /usr/share/doc/pizza/faq.en.html
303 echo '<h3>README</h3>'
304 echo '<pre>'
305 cat /usr/share/doc/pizza/README
306 echo '</pre>' ;;
307 *\ info\ *)
308 # English only :-)
309 if mount | fgrep -q slitaz/public; then
310 mounted="Public is mounted"
311 else
312 mounted="WARRNING: Public is not mounted"
313 fi
314 echo '<h2><img src="images/monitor.png" alt="" />Pizza Info</h2>'
315 echo '<pre>'
316 [ "$mounted" ] && echo "$mounted"
317 echo -n "Public flavors : " && ls -1 public | wc -l
318 echo -n "Public size : " && du -sh public | awk '{print $1}'
319 echo -n "Tmp size : " && du -sh $tmpdir | awk '{print $1}'
320 echo '</pre>' ;;
321 *\ activity\ *)
322 cat << EOT
323 <h2><img src="images/monitor.png" alt="" />$(gettext "Activity")</h2>
325 <pre>
326 $(tac $activity | highlighter activity)
327 </pre>
329 EOT
330 ;;
331 *)
332 #
333 # Main page
334 #
335 inqueue=$(ls $queue | wc -l)
336 builds=$(cat $builds)
337 pubiso=$(ls -1 public | wc -l)
338 [ "$builds" ] || builds=0
339 cat << EOT
340 <h2>$(gettext "Welcome")</h2>
341 <form method="get" action="./">
342 <p>
343 $(gettext "SliTaz Pizza lets you create your own SliTaz ISO flavor
344 online. The ISO image can be burnt on a cdrom or installed on USB media.
345 Please read the SliTaz Pizza <a href="?help">Help</a> before starting
346 a new flavor.")
347 </p>
348 <pre>
349 Flavors: $inqueue in queue - $builds builds - $pubiso public
350 </pre>
352 <div class="start">
353 <input type="submit" name="start" value="$(gettext "Create a new flavor")">
354 </div>
356 EOT
357 echo "<h2>$(gettext "Latest builds")</h2>"
358 echo '<pre>'
359 for flavor in $(ls -1t public | head -n 5)
360 do
361 if [ -f "public/$flavor/receipt" ]; then
362 . ./public/$flavor/receipt
363 [ -f "public/$flavor/$FLAVOR.iso" ] && \
364 cat << EOT
365 $(get_gravatar $MAINTAINER 24) <a href="?id=$ID">$VERSION</a> : \
366 <a href="public/$flavor/$FLAVOR.iso">$FLAVOR.iso</a> ($ISO_SIZE)
367 EOT
368 fi
369 done
370 echo '</pre>'
371 cat << EOT
372 <h2>$(gettext "Activity")</h2>
373 <pre>
374 $(tac $activity | head -n 12 | highlighter activity)
375 </pre>
376 <input type="submit" name="activity" value="$(gettext "More activity")">
377 </form>
378 EOT
379 ;;
380 esac
382 # HTML footer.
383 cat lib/footer.html
385 exit 0