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

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