tazlito view live.cgi @ rev 406

Store receipt in flavor info
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Nov 29 12:59:59 2015 +0100 (2015-11-29)
parents 6c738e349722
children 2d5ed83ee463
line source
1 #!/bin/sh
2 #
3 # CGI interface for SliTaz Live systems using Tazlito and TazUSB.
4 #
5 # Copyright (C) 2011-2015 SliTaz GNU/Linux - BSD License
6 #
8 if [ "$1" == 'call' ]; then
9 case "$2" in
10 merge_cleanup)
11 mv -f $3.merged $3
12 for i in $4/*; do
13 umount -d $i
14 done
15 rm -rf $4
16 exit ;;
17 esac
18 fi
21 # Common functions from libtazpanel
23 . lib/libtazpanel
24 get_config
27 #------
28 # menu
29 #------
31 case "$1" in
32 menu)
33 TEXTDOMAIN_original="$TEXTDOMAIN"
34 export TEXTDOMAIN='tazlito'
35 cat <<EOT
36 <li><a data-icon="cd" href="live.cgi">$(_ 'Live')</a>
37 <menu>
38 <li><a data-icon="" href="live.cgi?liveusb" data-root>$(_ 'Create a live USB key')</a></li>
39 <li><a data-icon="" href="live.cgi#liveiso" data-root>$(_ 'Create a live CD-ROM')</a></li>
40 <li><a data-icon="" href="live.cgi#hybrid">$(_ 'Create a hybrid ISO')</a></li>
41 <li><a data-icon="" href="live.cgi#loram" data-root>$(_ 'Convert ISO to loram')</a></li>
42 <li><a data-icon="" href="live.cgi#meta" data-root>$(_ 'Build a meta ISO')</a></li>
43 </menu>
44 </li>
45 EOT
46 export TEXTDOMAIN="$TEXTDOMAIN_original"
47 exit
48 esac
51 TEXTDOMAIN='tazlito'
52 TITLE=$(_ 'Live')
53 header
56 # Build arguments to create a meta iso using 'tazlito merge' command
58 merge_args() {
59 tmp="$1"
60 first=true
61 i=1
62 while [ -n "$(GET input$i)" ]; do
63 echo "$(stat -c "%s" $(GET input$i)) $(GET input$i) $(GET ram$i)"
64 $((i++))
65 done | sort -nr | \
66 while read size file ram; do
67 if $first; then
68 cp $file $(GET metaoutput)
69 echo -n "$ram $(GET metaoutput) "
70 first=false
71 continue
72 fi
73 dir="$tmp/$(basename $file)"
74 mkdir "$dir"
75 mount -o loop,ro "$file" "$dir"
76 echo -n "$ram $dir/boot/rootfs.gz "
77 done
78 }
81 #
82 # Commands executed in Xterm first
83 #
85 case " $(GET) " in
86 *\ loramoutput\ *)
87 export output='raw'
88 DISPLAY=':0.0' XAUTHORITY='/var/run/slim.auth' \
89 $TERMINAL $TERM_OPTS \
90 -T "$(_ 'Convert ISO to loram')" \
91 -e "tazlito build-loram $(GET input) $(GET loramoutput) $(GET type)" &
92 ;;
94 *\ meta\ *)
95 tmp=/tmp/$(basename $0).$$
96 cleanup="sh $0 call merge_cleanup $(GET output) $tmp"
97 export output='raw'
98 DISPLAY=':0.0' XAUTHORITY='/var/run/slim.auth' \
99 $TERMINAL $TERM_OPTS \
100 -T "$(_ 'Build a meta ISO')" \
101 -e "tazlito merge $(merge_args $tmp); \
102 _ 'ENTER to quit'; read i; \
103 $cleanup" &
104 ;;
106 *\ hybrid\ *)
107 export output='raw'
108 DISPLAY=':0.0' XAUTHORITY='/var/run/slim.auth' \
109 $TERMINAL $TERM_OPTS \
110 -T "$(_ 'Create a hybrid ISO')" \
111 -e "iso2exe $(GET input)" &
112 ;;
113 esac
116 #
117 # Commands
118 #
120 case " $(GET) " in
122 *\ create\ *)
123 #
124 # Create a flavor file and ISO in options with all settings
125 # Step by step interface and store files in cache.
126 #
127 xhtml_header
128 _ 'TODO'
129 ;;
131 *\ liveusb\ *)
132 TITLE="$(_ 'SliTaz LiveUSB')"
133 xhtml_header "$(_ 'Create Live USB SliTaz systems')"
134 cat <<EOT
135 <section>
136 <header>$(_ 'SliTaz LiveUSB')</header>
138 <form method="get" action="$SCRIPT_NAME" class="wide">
139 <div>
140 $(_ "Generate SliTaz LiveUSB media and boot in RAM! Insert a Live CD \
141 into the CD-ROM drive, select the correct device and press Generate.")
142 </div>
144 <input type="hidden" name="liveusb" />
145 <footer>
146 $(_ 'USB Media to use:')
147 <select name="gen" id="gen">
148 EOT
149 # List disk if there is a plugged USB device
150 if [ -d /proc/scsi/usb-storage ]; then
151 for dev in /sys/block/sd*; do
152 # removable writable sd* device:
153 if [ "$(cat $dev/removable)" == '1' -a "$(cat $dev/ro)" == '0' ]; then
154 echo "<optgroup label='$(cat $dev/device/vendor) $(cat $dev/device/model):'>"
155 for part in $dev/sd*; do
156 [ ! -d "$part" ] && break
157 linuxdev=$(readlink -f /dev/block/$(cat $part/dev))
158 cat <<EOT
159 <option value='$linuxdev'>$(basename $linuxdev) [$(blkid -o value -s TYPE "$linuxdev")]
160 $(blkid -o value -s LABEL "$linuxdev") ($(cat $part/size | blk2h))</option>
161 EOT
162 done
163 echo '</optgroup>'
164 fi
165 done
166 else
167 echo "<option value=''>$(_ 'Not found')</option>"
168 fi
170 cat <<EOT
171 </select>
172 <button type="submit" data-icon="removable">$(_ 'Generate')</button>
173 </footer>
174 </form>
175 </section>
176 EOT
178 gen="$(GET gen)"
179 if [ -n "$gen" ]; then
180 cat <<EOT
181 <script>document.getElementById("gen").value = "$gen";</script>
183 <section>
184 <header>tazusb gen-liveusb $gen</header>
185 <pre>
186 EOT
187 # No pipe here so output is displayed in realtime
188 yes | tazusb gen-liveusb $gen
189 cat <<EOT
190 </pre>
191 </section>
192 EOT
193 fi
195 ;;
197 *\ write_iso\ *)
198 xhtml_header
200 LaunchedByTazpanel="y" \
201 tazlito writeiso $(GET write_iso) > /tmp/tazlitowriteiso 2>&1 &
203 until [ -f /rootfs.gz ]; do
204 sleep 1
205 done
206 cat <<EOT
207 <fieldset>
208 $(head /tmp/tazlitowriteiso | sed "s|$|<p></p>|g" | sed '/.gvfs/d')
209 <li id="fssize"> </li>
210 EOT
211 until [ ! -f /rootfs.gz ]; do
212 sleep 1
213 cat <<EOT
214 <script type="text/javascript">
215 document.getElementById('fssize').innerHTML = "<h4>$(boldify $(du -mh /rootfs.gz | cut -f1))</h4>";
216 </script>
217 EOT
218 done
219 if [ -f /rootfs.gz ]; then
220 until [ ! -f /rootfs.gz ]; do
221 sleep 1
222 done
223 fi
224 cat <<EOT
225 <script type="text/javascript">
226 document.getElementById('fssize').innerHTML = "$(boldify $(du -mh /home/slitaz/distro/rootcd/boot/rootfs.gz | cut -f1))";
227 </script>
228 /home/slitaz/distro/rootcd/boot/rootfs.gz
229 </fieldset>
230 EOT
231 ls -l /home/slitaz/distro/rootcd/boot/rootfs.gz
232 until [ -f /tmp/.write-iso* ]; do
233 sleep 1
234 done
235 echo "<fieldset>"
236 if [ -f /tmp/.write-iso ]; then
237 newline
238 tail /tmp/tazlitowriteiso | grep ISO
239 while [ -f /tmp/.write-iso ]; do sleep 1 ; done
240 elif [ -f /tmp/.write-iso-error ]; then
241 tail -n8 /tmp/tazlitowriteiso | grep -vE 'ENTER|----'
242 fi
243 tail -n5 /tmp/tazlitowriteiso | sed "s|$|<p></p>|g"
244 ls -l /home/slitaz/distro
245 echo "</fieldset>"
246 echo "Use ' <code>tazlito emu-iso</code> ' to check it"
247 ;;
249 *)
250 #
251 # Default xHTML content
252 #
253 TITLE="$(_ 'SliTaz Live Systems')"
254 xhtml_header "$(_ 'Create and manage Live CD or USB SliTaz systems')"
256 [ $(id -u) -eq 0 ] && cat <<EOT
258 <section id="liveiso">
259 <header>$(_ 'Write a Live CD')</header>
261 <form method="get" action="$SCRIPT_NAME" class="wide">
262 <div>
263 $(_ "The command writeiso will generate an ISO image of the current \
264 filesystem as is, including all files in the /home directory. It is an easy \
265 way to remaster a SliTaz Live system, you just have to: boot, modify, \
266 writeiso.")
267 </div>
269 <table>
270 <tr><td>
271 $(_ 'Compression type:')
272 <select name="write_iso">
273 <option value="lzma">lzma</option>
274 <option value="gzip">gzip</option>
275 <option value="none">$(_ 'none')</option>
276 </select>
277 </td></tr>
278 </table>
279 EOT
281 if [ $(id -u) -eq 0 -a ! -d /media/cdrom/boot/isolinux -a ! -f /boot/*slitaz* ]; then
282 msg warn "$(_ 'Cannot find SliTaz ISO/CD mounted in /media/cdrom (You will get only rootfs.gz)')"
283 fi
285 inputiso="$(GET input)"; inputiso="${inputiso:-/root/}"
286 loramoutput="$(GET loramoutput)"; loramoutput="${loramoutput:-/root/loram.iso}"
288 [ $(id -u) -eq 0 ] && cat <<EOT
289 <footer>
290 <button type="submit" data-icon="cd">$(_ 'Write ISO')</button>
291 </footer>
292 </form>
293 </section>
296 <section><header>$(_ 'Live CD tools')</header>
299 <section id="loram">
300 <header>$(_ 'Convert ISO to loram')</header>
302 <form method="get" action="$SCRIPT_NAME#loram" class="wide">
303 <div>
304 $(_ "This command will convert an ISO image of a SliTaz Live CD to a \
305 new ISO image requiring less RAM to run.") (-30%)
306 </div>
308 <table>
309 <tr><td>
310 $(_ 'ISO to convert')
311 $(file_chooser "input" "$inputiso" "cd")
312 </td></tr>
313 <tr><td>
314 <input type="radio" name="type" value="ram" id="type1" checked />
315 <label for="type1">$(_ 'The filesystem is always in RAM')</label>
316 </td></tr>
317 <tr><td>
318 <input type="radio" name="type" value="smallcdrom" id="type2" />
319 <label for="type2">$(_ 'The filesystem may be on a small CD-ROM')</label>
320 </td></tr>
321 <tr><td>
322 <input type="radio" name="type" value="cdrom" id="type3" />
323 <label for="type3">$(_ 'The filesystem may be on a large CD-ROM')</label>
324 </td></tr>
325 <tr><td>
326 $(_ 'ISO to create')
327 <input type="text" accept=".iso" name="loramoutput" value="$loramoutput" />
328 </td></tr>
329 </table>
331 <script>
332 EOT
333 case "$(GET type)" in
334 smallcdrom) sel='type2';;
335 cdrom) sel='type3';;
336 *) sel='type1';;
337 esac
338 [ $(id -u) -eq 0 ] echo "document.getElementById('$sel').checked = true;"
339 [ $(id -u) -eq 0 ] && cat <<EOT
340 </script>
342 <footer>
343 <button type="submit" data-icon="cd">$(_ 'Convert ISO to loram')</button>
344 </footer>
345 </form>
346 </section>
348 EOT
349 cat <<EOT
351 <section id="hybrid">
352 <header>$(_ 'Build a hybrid ISO')</header>
354 <form method="get" action="$SCRIPT_NAME#hybrid" class="wide">
355 <div>
356 $(_ "Add a master boot sector and an EXE header to the ISO image.")
357 <ul>
358 <li>$(_ "Create a bootable image for a USB key, a memory card, a harddisk or a SSD.")</li>
359 <li>$(_ "With the .EXE suffix, it will run under DOS (16 bits) or Windows (32 bits).")</li>
360 <li>$(_ "Add the ISO filesystem md5 digest and the boot CRC in the ISO boot area.")</li>
361 <li>$(_ "Does not alter the ISO filesystem or the ISO image size.")</li>
362 </ul>
363 </div>
365 <table>
366 <tr><td>
367 $(_ 'ISO to convert')
368 $(file_chooser "input" "" "cd")
369 </td></tr>
370 </table>
372 <footer>
373 <button type="submit" name="hybrid" data-icon="cd">$(_ 'Build a hybrid ISO')</button>
374 </footer>
375 </form>
376 </section>
378 EOT
379 [ $(id -u) -eq 0 ] && cat <<EOT
381 <section id="meta">
382 <header>$(_ 'Build a meta ISO')</header>
384 <form method="get" action="$SCRIPT_NAME#meta">
385 <div>
386 $(_ "Combines several ISO flavors like nested Russian dolls. The \
387 amount of RAM available at startup will be used to select the utmost one.")
388 </div>
390 <table class="wide">
391 EOT
392 i=''
393 while [ -n "$(GET addmeta)" ]; do
394 [ -n "$(GET input$i)" ] || break
395 j=$(($i + 1))
396 [ $(id -u) -eq 0 ] && cat <<EOT
397 <tr>
398 <td>
399 $(_ 'ISO number %s:' "$j") $(GET input$i)
400 <input type="hidden" name="input$j" value="$(GET input$i)" />
401 </td>
402 <td>
403 $(_ 'Minimum RAM:') $(GET ram$i)
404 <input type="hidden" name="ram$j" value="$(GET ram$i)" />
405 </td>
406 </tr>
407 EOT
408 i=$j
409 done
410 metaoutput="$(GET metaoutput)"
411 [ -n "$metaoutput" ] || metaoutput="/root/meta.iso"
413 [ $(id -u) -eq 0 ] && cat <<EOT
414 <tr>
415 <td>
416 $(_ 'ISO to add')
417 $(file_chooser "input" "" "cd")
418 </td>
419 <td>
420 $(_ 'Minimum RAM:')
421 <input type="text" name="ram" value="128M" />
422 <button type="submit" name="addmeta" value="addmeta" data-icon="add">$(_ 'Add to the list')</button>
423 </td>
424 </tr>
425 <tr>
426 <td>
427 $(_ 'ISO to create')
428 <input type="text" name="metaoutput" value="$metaoutput" />
429 </td>
430 <td>
431 </td>
432 </tr>
433 </table>
435 <footer>
436 <button type="submit" name="meta" value="meta" data-icon="cd">$(_ 'Build a meta ISO')</button>
437 </footer>
438 </form>
439 </section>
441 </section>
442 EOT
443 ;;
444 esac
446 xhtml_footer
447 exit 0