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

pizza.cgi: notes should not be executable
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Jan 28 09:30:48 2013 +0100 (2013-01-28)
parents b40b5c7e5955
children e4bf1581a71b
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="25" /></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\"" | \
185 sed 's/\$/\\$/g;s/`/\\`/g;s/\\/\\\\/g' >> $receipt
186 fi
188 # The rootcd README
189 echo -n "Creating SliTaz cdrom README..."
190 date=$(date '+%Y-%m-%d %H:%M')
191 mkdir -p $tmpdir/slitaz-$id/rootcd
192 cp $DATA/README.distro $tmpdir/slitaz-$id/rootcd/README
193 sed -i s"/_DATE_/$date/" $tmpdir/slitaz-$id/rootcd/README
194 status
196 echo -n "Creating flavor tarball..."
197 cd $tmpdir && tar cjf $FLAVOR.tar.bz2 slitaz-$id
198 mkdir -p $public/slitaz-$id
199 mv $FLAVOR.tar.bz2 $public/slitaz-$id
200 status
202 # Keep a public receipt copy and move everything from tmp to queue.
203 echo "Flavor packed : $(date '+%Y-%m-%d %H:%M')" | tee -a $log
204 echo -n "Moving $id to Pizza build queue..."
205 mv -f $tmpdir/slitaz-$id/distro.log $public/slitaz-$id
206 cp -f $tmpdir/slitaz-$id/receipt $public/slitaz-$id
207 mv $tmpdir/slitaz-$id $queue
208 status
210 if [ "$inqueue" == "1" ]; then
211 gettext "Your ISO will be built on next Pizza Bot run"
212 else
213 eval_gettext "There are \$inqueue flavors in queue"
214 fi
215 echo ""
216 echo "New flavor added to queue: <a href='?id=$id'>$id</a> ($FLAVOR)" | log
217 cat << EOT
218 </pre>
219 <div>
220 <img src="images/archive.png" alt="[ tarball ]" />
221 $(gettext "Download tarball: ")
222 <a href="public/slitaz-$id/$FLAVOR.tar.bz2">$FLAVOR.tar.bz2</a>
223 - Browse <a href="public/slitaz-$id/">the flavor</a>
224 </div>
225 <div class="next">
226 <form method="get" action="./">
227 <input type="hidden" name="id" value="$id" />
228 <input type="submit" value="$(gettext "Status")">
229 </form>
230 </div>
231 EOT
232 ;;
233 *\ id\ *)
234 #
235 # ID Status page
236 #
237 id="$(GET id)"
238 [ -f "$queue/slitaz-$id/receipt" ] && . $queue/slitaz-$id/receipt
239 [ -f "public/slitaz-$id/receipt" ] && . public/slitaz-$id/receipt
240 log="$public/slitaz-$id/distro.log"
241 if [ ! -d "public/slitaz-$id" ]; then
242 echo "Sorry, can't find flavor ID: $id"
243 cat lib/footer.html && exit 0
244 fi
245 if [ -f "$public/slitaz-$id/$FLAVOR.iso" ]; then
246 dir="public/slitaz-$id"
247 list="$dir/packages.list"
248 iso="$dir/$FLAVOR.iso"
249 msg="$(gettext "Download ISO:") <a href='$dir/$FLAVOR.iso'>$FLAVOR.iso</a>
250 [ <a href='$dir/$FLAVOR.md5'>md5</a> ]"
251 else
252 list="$queue/slitaz-$id/packages.list"
253 msg="$(gettext "Flavor is building or still in the build queue")"
254 fi
255 pkgslist=$(cat $list | wc -l)
256 pkgsinst=$(cat $installed | wc -l)
257 [ "$pkgsinst" ] || pkgsinst=0
258 [ "$ISO_SIZE" ] || ISO_SIZE="N/A"
259 [ "$ROOTFS_SIZE" ] || ROOTFS_SIZE="N/A"
260 cat << EOT
261 <h2>$(gettext "Status for:") $FLAVOR</h2>
262 <div>
263 $(get_gravatar $MAINTAINER) $(gettext "Flavor description:") $SHORT_DESC
264 </div>
265 <pre>
266 Uniq ID : $id
267 Flavor : $FLAVOR
268 Packages : $pkgslist in list - $pkgsinst installed
269 Rootfs size : $ROOTFS_SIZE
270 ISO size : $ISO_SIZE
271 </pre>
273 <div>
274 <img src="images/iso.png" alt="[ iso ]" /> $(echo $msg)
275 </div>
276 <div>
277 <img src="images/archive.png" alt="[ tarball ]" />
278 $(gettext "Download tarball:")
279 <a href="public/slitaz-$id/$FLAVOR.tar.bz2">$FLAVOR.tar.bz2</a>
280 EOT
281 if [ -f "$public/slitaz-$id/$FLAVOR.flavor" ]; then
282 cat << EOT
283 - Flavor file: <a href="public/slitaz-$id/$FLAVOR.flavor">$FLAVOR.flavor</a>
284 EOT
285 fi
286 cat << EOT
287 - Browse <a href="public/slitaz-$id/">the flavor</a>
288 </div>
289 EOT
290 if [ "$NOTE" ]; then
291 echo "<div class="note">$NOTE</div>"
292 fi
293 if [ -f "$log" ]; then
294 echo '<h2>Distro log</h2>'
295 echo '<pre>'
296 fgrep 'Build time' $log
297 cat $log | highlighter log
298 echo '</pre>'
299 fi ;;
300 *\ help\ *)
301 echo "<h2>$(gettext "Help")</h2>"
302 cat /usr/share/doc/pizza/help.en.html
303 cat /usr/share/doc/pizza/faq.en.html
304 echo '<h3>README</h3>'
305 echo '<pre>'
306 cat /usr/share/doc/pizza/README
307 echo '</pre>' ;;
308 *\ info\ *)
309 # English only :-)
310 if mount | fgrep -q slitaz/public; then
311 mounted="Public is mounted"
312 else
313 mounted="WARRNING: Public is not mounted"
314 fi
315 echo '<h2><img src="images/monitor.png" alt="" />Pizza Info</h2>'
316 echo '<pre>'
317 [ "$mounted" ] && echo "$mounted"
318 echo -n "Public flavors : " && ls -1 public | wc -l
319 echo -n "Public size : " && du -sh public | awk '{print $1}'
320 echo -n "Tmp size : " && du -sh $tmpdir | awk '{print $1}'
321 echo '</pre>' ;;
322 *\ activity\ *)
323 cat << EOT
324 <h2><img src="images/monitor.png" alt="" />$(gettext "Activity")</h2>
326 <pre>
327 $(tac $activity | highlighter activity)
328 </pre>
330 EOT
331 ;;
332 *)
333 #
334 # Main page
335 #
336 inqueue=$(ls $queue | wc -l)
337 builds=$(cat $builds)
338 pubiso=$(ls -1 public | wc -l)
339 [ "$builds" ] || builds=0
340 cat << EOT
341 <h2>$(gettext "Welcome")</h2>
342 <form method="get" action="./">
343 <p>
344 $(gettext "SliTaz Pizza lets you create your own SliTaz ISO flavor
345 online. The ISO image can be burnt on a cdrom or installed on USB media.
346 Please read the SliTaz Pizza <a href="?help">Help</a> before starting
347 a new flavor.")
348 </p>
349 <pre>
350 Flavors: $inqueue in queue - $builds builds - $pubiso <a href="/public">public</a>
351 </pre>
353 <div class="start">
354 <input type="submit" name="start" value="$(gettext "Create a new flavor")">
355 </div>
357 EOT
358 echo "<h2>$(gettext "Latest builds")</h2>"
359 echo '<pre>'
360 for flavor in $(ls -1t public | head -n 5)
361 do
362 if [ -f "public/$flavor/receipt" ]; then
363 . ./public/$flavor/receipt
364 [ -f "public/$flavor/$FLAVOR.iso" ] && \
365 cat << EOT
366 $(get_gravatar $MAINTAINER 24) <a href="?id=$ID">$VERSION</a> : \
367 <a href="public/$flavor/$FLAVOR.iso">$FLAVOR.iso</a> ($ISO_SIZE)
368 EOT
369 fi
370 done
371 echo '</pre>'
372 cat << EOT
373 <h2>$(gettext "Activity")</h2>
374 <pre>
375 $(tac $activity | head -n 12 | highlighter activity)
376 </pre>
377 <input type="submit" name="activity" value="$(gettext "More activity")">
378 </form>
379 EOT
380 ;;
381 esac
383 # HTML footer.
384 cat lib/footer.html
386 exit 0