tazlito view live.cgi @ rev 509

Take care of installed /boot/isolinux/efi.img
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Jun 03 14:17:50 2018 +0200 (13 months ago)
parents da648e687bb6
children 7c8e4ca19511
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" data-root>$(_ '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 custom=""
108 [ -n "$(GET extracmdline)" ] &&
109 custom="$custom -a \\\"$(GET extracmdline)\\\" "
110 [ -n "$(GET extrainitrd)" ] &&
111 custom="$custom -i \\\"$(GET extrainitrd)\\\" "
112 export output='raw'
113 DISPLAY=':0.0' XAUTHORITY='/var/run/slim.auth' \
114 $TERMINAL $TERM_OPTS \
115 -T "$(_ 'Create a hybrid ISO')" \
116 -e iso2exe $custom$(GET input) -f &
117 ;;
118 esac
121 #
122 # Commands
123 #
125 case " $(GET) " in
127 *\ create\ *)
128 #
129 # Create a flavor file and ISO in options with all settings
130 # Step by step interface and store files in cache.
131 #
132 xhtml_header
133 _ 'TODO'
134 ;;
136 *\ liveusb\ *)
137 TITLE="$(_ 'SliTaz LiveUSB')"
138 xhtml_header "$(_ 'Create Live USB SliTaz systems')"
139 cat <<EOT
140 <section>
141 <header>$(_ 'SliTaz LiveUSB')</header>
143 <form method="get" action="$SCRIPT_NAME" class="wide">
144 <div>
145 $(_ "Generate SliTaz LiveUSB media and boot in RAM! Insert a Live CD \
146 into the CD-ROM drive, select the correct device and press Generate.")
147 </div>
149 <input type="hidden" name="liveusb" />
150 <footer>
151 $(_ 'USB Media to use:')
152 <select name="gen" id="gen">
153 EOT
154 # List disk if there is a plugged USB device
155 if [ -d /proc/scsi/usb-storage ]; then
156 for dev in /sys/block/sd*; do
157 # removable writable sd* device:
158 if [ "$(cat $dev/removable)" == '1' -a "$(cat $dev/ro)" == '0' ]; then
159 echo "<optgroup label='$(cat $dev/device/vendor) $(cat $dev/device/model):'>"
160 for part in $dev/sd*; do
161 [ ! -d "$part" ] && break
162 linuxdev=$(readlink -f /dev/block/$(cat $part/dev))
163 cat <<EOT
164 <option value='$linuxdev'>$(basename $linuxdev) [$(blkid -o value -s TYPE "$linuxdev")]
165 $(blkid -o value -s LABEL "$linuxdev") ($(cat $part/size | blk2h))</option>
166 EOT
167 done
168 echo '</optgroup>'
169 fi
170 done
171 else
172 echo "<option value=''>$(_ 'Not found')</option>"
173 fi
175 cat <<EOT
176 </select>
177 <button type="submit" data-icon="removable">$(_ 'Generate')</button>
178 </footer>
179 </form>
180 </section>
181 EOT
183 gen="$(GET gen)"
184 if [ -n "$gen" ]; then
185 cat <<EOT
186 <script>document.getElementById("gen").value = "$gen";</script>
188 <section>
189 <header>tazusb gen-liveusb $gen</header>
190 <pre>
191 EOT
192 # No pipe here so output is displayed in realtime
193 yes | tazusb gen-liveusb $gen
194 cat <<EOT
195 </pre>
196 </section>
197 EOT
198 fi
200 ;;
202 *\ write_iso\ *)
203 xhtml_header
205 LaunchedByTazpanel="y" \
206 tazlito writeiso $(GET write_iso) > /tmp/tazlitowriteiso 2>&1 &
208 until [ -f /rootfs.gz ]; do
209 sleep 1
210 done
211 cat <<EOT
212 <fieldset>
213 $(head /tmp/tazlitowriteiso | sed "s|$|<p></p>|g" | sed '/.gvfs/d')
214 <li id="fssize"> </li>
215 EOT
216 until [ ! -f /rootfs.gz ]; do
217 sleep 1
218 cat <<EOT
219 <script type="text/javascript">
220 document.getElementById('fssize').innerHTML = "<h4>$(boldify $(du -mh /rootfs.gz | cut -f1))</h4>";
221 </script>
222 EOT
223 done
224 if [ -f /rootfs.gz ]; then
225 until [ ! -f /rootfs.gz ]; do
226 sleep 1
227 done
228 fi
229 cat <<EOT
230 <script type="text/javascript">
231 document.getElementById('fssize').innerHTML = "$(boldify $(du -mh /home/slitaz/distro/rootcd/boot/rootfs.gz | cut -f1))";
232 </script>
233 /home/slitaz/distro/rootcd/boot/rootfs.gz
234 </fieldset>
235 EOT
236 ls -l /home/slitaz/distro/rootcd/boot/rootfs.gz
237 until [ -f /tmp/.write-iso* ]; do
238 sleep 1
239 done
240 echo "<fieldset>"
241 if [ -f /tmp/.write-iso ]; then
242 newline
243 tail /tmp/tazlitowriteiso | grep ISO
244 while [ -f /tmp/.write-iso ]; do sleep 1 ; done
245 elif [ -f /tmp/.write-iso-error ]; then
246 tail -n8 /tmp/tazlitowriteiso | grep -vE 'ENTER|----'
247 fi
248 tail -n5 /tmp/tazlitowriteiso | sed "s|$|<p></p>|g"
249 ls -l /home/slitaz/distro
250 echo "</fieldset>"
251 echo "Use ' <code>tazlito emu-iso</code> ' to check it"
252 ;;
254 *)
255 #
256 # Default xHTML content
257 #
258 TITLE="$(_ 'SliTaz Live Systems')"
259 xhtml_header "$(_ 'Create and manage Live CD or USB SliTaz systems')"
261 [ $(id -u) -eq 0 ] && cat <<EOT
263 <section id="liveiso">
264 <header>$(_ 'Write a Live CD')</header>
266 <form method="get" action="$SCRIPT_NAME" class="wide">
267 <div>
268 $(_ "The command writeiso will generate an ISO image of the current \
269 filesystem as is, including all files in the /home directory. It is an easy \
270 way to remaster a SliTaz Live system, you just have to: boot, modify, \
271 writeiso.")
272 </div>
274 <table>
275 <tr><td>
276 $(_ 'Compression type:')
277 <select name="write_iso">
278 <option value="lzma">lzma</option>
279 <option value="gzip">gzip</option>
280 <option value="none">$(_ 'none')</option>
281 </select>
282 </td></tr>
283 </table>
284 EOT
286 if [ $(id -u) -eq 0 -a ! -d /media/cdrom/boot/isolinux ]; then
287 msg warn "$(_ 'Cannot find SliTaz ISO/CD mounted in /media/cdrom (You will get only rootfs.gz)')"
288 fi
290 inputiso="$(GET input)"; inputiso="${inputiso:-/root/}"
291 loramoutput="$(GET loramoutput)"; loramoutput="${loramoutput:-/root/loram.iso}"
293 [ $(id -u) -eq 0 ] && cat <<EOT
294 <footer>
295 <button type="submit" data-icon="cd">$(_ 'Write ISO')</button>
296 </footer>
297 </form>
298 </section>
301 <section><header>$(_ 'Live CD tools')</header>
304 <section id="loram">
305 <header>$(_ 'Convert ISO to loram')</header>
307 <form method="get" action="$SCRIPT_NAME#loram" class="wide">
308 <div>
309 $(_ "This command will convert an ISO image of a SliTaz Live CD to a \
310 new ISO image requiring less RAM to run.") (-30%)
311 </div>
313 <table>
314 <tr><td>
315 $(_ 'ISO to convert')
316 $(file_chooser 'input' "$inputiso" 'cd' 'application/x-cd-image')
317 </td></tr>
318 <tr><td>
319 <input type="radio" name="type" value="ram" id="type1" checked />
320 <label for="type1">$(_ 'The filesystem is always in RAM')</label>
321 </td></tr>
322 <tr><td>
323 <input type="radio" name="type" value="smallcdrom" id="type2" />
324 <label for="type2">$(_ 'The filesystem may be on a small CD-ROM')</label>
325 </td></tr>
326 <tr><td>
327 <input type="radio" name="type" value="cdrom" id="type3" />
328 <label for="type3">$(_ 'The filesystem may be on a large CD-ROM')</label>
329 </td></tr>
330 <tr><td>
331 $(_ 'ISO to create')
332 <input type="text" accept=".iso" name="loramoutput" value="$loramoutput" />
333 </td></tr>
334 </table>
336 <script>
337 EOT
338 case "$(GET type)" in
339 smallcdrom) sel='type2';;
340 cdrom) sel='type3';;
341 *) sel='type1';;
342 esac
343 [ $(id -u) -eq 0 ] echo "document.getElementById('$sel').checked = true;"
344 [ $(id -u) -eq 0 ] && cat <<EOT
345 </script>
347 <footer>
348 <button type="submit" data-icon="cd">$(_ 'Convert ISO to loram')</button>
349 </footer>
350 </form>
351 </section>
353 EOT
354 cat <<EOT
356 <section id="hybrid">
357 <header>$(_ 'Build a hybrid ISO')</header>
359 <form method="get" action="$SCRIPT_NAME#hybrid" class="wide">
360 <div>
361 $(_ "Add a master boot sector and an EXE header to the ISO image.")
362 <ul>
363 <li>$(_ "Create a bootable image for a USB key, a memory card, a harddisk or a SSD.")</li>
364 <li>$(_ "With the .EXE suffix, it will run under DOS (16 bits) or Windows (32 bits).")</li>
365 <li>$(_ "Add the ISO filesystem md5 digest and the boot CRC in the ISO boot area.")</li>
366 <li>$(_ "Does not alter the ISO filesystem or the ISO image size.")</li>
367 </ul>
368 </div>
370 <table>
371 <tr><td>
372 $(_ 'ISO to convert')
373 $(file_chooser 'input' '' 'cd' 'application/x-cd-image')
374 </td></tr>
375 </table>
376 <div>
377 $(_ "By the way, you can customize the ISO image to your needs.")
378 <ul>
379 <li>$(_ "Append the kernel command line.")<span data-img="info"
380 title="$(_ "Examples: add your locales")
381 (lang=fr_FR kmap=fr-latin1 tz=Europe/Paris) $(_ "or modify the init script")
382 (rdinit=/myowninit.sh)"></span><input type="text" name="extracmdline" /></li>
383 <li>$(_ "Load an extra initrd with your settings.")<span data-img="info"
384 title="$(_ "Examples: add your wifi/ssh/vpn keys or your applications")">
385 </span>$(file_chooser extrainitrd)</li>
386 </ul>
387 </div>
389 <footer>
390 <button type="submit" name="hybrid" data-icon="cd">$(_ 'Build a hybrid ISO')</button>
391 </footer>
392 </form>
393 </section>
395 EOT
396 [ $(id -u) -eq 0 ] && cat <<EOT
398 <section id="meta">
399 <header>$(_ 'Build a meta ISO')</header>
401 <form method="get" action="$SCRIPT_NAME#meta">
402 <div>
403 $(_ "Combines several ISO flavors like nested Russian dolls. The \
404 amount of RAM available at startup will be used to select the utmost one.")
405 </div>
407 <table class="wide">
408 EOT
409 i=''
410 while [ -n "$(GET addmeta)" ]; do
411 [ -n "$(GET input$i)" ] || break
412 j=$(($i + 1))
413 [ $(id -u) -eq 0 ] && cat <<EOT
414 <tr>
415 <td>
416 $(_ 'ISO number %s:' "$j") $(GET input$i)
417 <input type="hidden" name="input$j" value="$(GET input$i)" />
418 </td>
419 <td>
420 $(_ 'Minimum RAM:') $(GET ram$i)
421 <input type="hidden" name="ram$j" value="$(GET ram$i)" />
422 </td>
423 </tr>
424 EOT
425 i=$j
426 done
427 metaoutput="$(GET metaoutput)"
428 [ -n "$metaoutput" ] || metaoutput="/root/meta.iso"
430 [ $(id -u) -eq 0 ] && cat <<EOT
431 <tr>
432 <td>
433 $(_ 'ISO to add')
434 $(file_chooser 'input' '' 'cd' 'application/x-cd-image')
435 </td>
436 <td>
437 $(_ 'Minimum RAM:')
438 <input type="text" name="ram" value="128M" />
439 <button type="submit" name="addmeta" value="addmeta" data-icon="add">$(_ 'Add to the list')</button>
440 </td>
441 </tr>
442 <tr>
443 <td>
444 $(_ 'ISO to create')
445 <input type="text" name="metaoutput" value="$metaoutput" />
446 </td>
447 <td>
448 </td>
449 </tr>
450 </table>
452 <footer>
453 <button type="submit" name="meta" value="meta" data-icon="cd">$(_ 'Build a meta ISO')</button>
454 </footer>
455 </form>
456 </section>
458 </section>
459 EOT
460 ;;
461 esac
463 xhtml_footer
464 exit 0