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

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