wok view syslinux/stuff/iso2exe/init @ rev 17455

syslinux/iso2exe: avoid a possible deadlock in progress bar
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Dec 18 12:32:12 2014 +0100 (2014-12-18)
parents aa3f469a31d7
children 6aed6fc5819d
line source
1 #!/bin/sh
3 DIALOG=dialog
5 ddq()
6 {
7 dd $@ 2> /dev/null
8 }
10 get()
11 {
12 od -j $1 -N ${3:-2} -t u${3:-2} -An $2 2> /dev/null ||
13 hexdump -s $1 -n ${3:-2} -e "\"\" 1/${3:-2} \"%d\"" $2
14 }
16 getarg()
17 {
18 sed "/$1=/!d;s/.*$1=\\([^ ]*\\).*/\\1/" /proc/cmdline
19 }
21 mount_proc()
22 {
23 mount -t proc /proc /proc
24 mount -t sysfs /sys /sys
25 udevd --daemon 2> /dev/null && udevadm trigger && sleep 5
26 }
28 umount_proc()
29 {
30 killall udevd 2> /dev/null
31 umount /sys/fs/fuse/connections 2> /dev/null
32 umount /sys
33 umount /proc
34 }
36 words2bin()
37 {
38 for i in $@ ; do
39 printf '\\\\x%02X\\\\x%02X' $(($i&255)) $((($i>>8)&255)) | \
40 xargs echo -en
41 done
42 }
44 gettazboot()
45 {
46 echo "Creating $(basename $1) ..."
47 O=$(($(get 66 /mnt/$ISO) - 0xC0))
48 L=$((0x7EE0 - $(get 24 /mnt/$ISO) - $O))
49 S=$((32+$L))
50 P=$((($S+511)/512))
51 E=$((4096-(32*$P)))
52 words2bin 0x5A4D $(($S%512)) $P 0 2 $E -1 $((${2:-0}-16)) \
53 -2 0 256 -16 28 0x6C53 0x5469 0x7A61 > $1
54 ddq bs=1 count=$L skip=$(echo $O) if=/mnt/$ISO >> $1
55 }
57 checkmagic()
58 {
59 [ -s $1 ] && [ $(getarg magic) == $(get 24 $1 4) ]
60 }
62 getiso()
63 {
64 mkdir -p /media/cdrom
65 blkid | while read dev info ; do
66 mount ${dev%:} /mnt
67 if checkmagic /mnt/$ISO; then
68 mount -o loop,ro /mnt/$ISO /media/cdrom
69 echo "Found $ISO on ${dev%:}"
70 break
71 fi
72 umount /mnt
73 done
74 }
76 uncpio()
77 {
78 echo "Extracting $(basename $1) ..."
79 case $(get 0 $1) in
80 *35615) ( zcat || gunzip ) ;;
81 *\ 93) unlzma ;;
82 *) cat ;;
83 esac < $1 | ( cd ${2:-/} ; cpio -idmu > /dev/null 2>&1 )
84 }
86 getuuid()
87 {
88 dev=$(mount | sed '/ \/mnt /!d;s/ .*//;s|/dev/||;q')
89 blkid | sed "/$dev:/!d;s/.* UUID=.\\([^ ]*\\)\".*/\\1/"
90 }
92 tazusbinitfs()
93 {
94 PAD=$(($(stat -c %s $1) % 4))
95 [ $PAD -ne 0 ] && ddq if=/dev/zero bs=1 count=$((4 - $PAD)) >> $1
96 mkdir -p /tmp/fs/etc /tmp/fs/lib /tmp/fs/home
97 cp -a /etc/locale.conf /tmp/fs/etc 2> /dev/null
98 cp -a /etc/keymap.conf /tmp/fs/etc 2> /dev/null
99 sed 's/ .*//' /proc/modules | while read mod ; do
100 find /lib/modules/ | grep $mod.ko | \
101 sed 's|.*|cp & /tmp/fs/lib|' | sh
102 done
103 cat > /tmp/fs/init1 <<EOT
104 #!/bin/sh
105 sed -i 's|sbin/init|init2|' /init
106 exec /init
107 EOT
108 cat > /tmp/fs/init2 <<EOT
109 #!/bin/sh
111 mount -t proc /proc /proc
112 grep -q debug /proc/cmdline && debug=true && set -x
113 for i in /lib/*.ko* ; do insmod \$i 2> /dev/null ; done; sleep 2
114 v=\$(sed '/\\/home=/!d;s|.*/home=\\([^ ]*\\).*|\\1|' /proc/cmdline /cmdline 2> /dev/null)
115 mount / -o remount,rw
116 mkdir /mnt/dos
117 rm -f /cmdline 2> /dev/null
118 mount / -o remount,ro
119 mnt=/mnt/dos/\${v#*/}
120 dev=\$( (blkid /dev/[sh]d* || blkid) | grep \${v%%/*} | sed 's/:.*//;q')
121 echo "Mount \$dev in /mnt/dos for \$v..." | tee -a /run/boot.log
122 mount \$dev /mnt/dos
123 mount.posixovl -F \$mnt -- -oallow_other -odefault_permissions -osuid
124 mount --bind \$mnt /home
125 [ "\$debug" = "true" ] && sh
126 umount /proc
127 exec /sbin/init
128 EOT
129 chmod 755 /tmp/fs/init?
130 cp -a /tmp/fs/* /
131 ( cd /tmp/fs ; find * | cpio -o -H newc ) | gzip -9 >> $1
132 }
134 mkinitrd()
135 {
136 echo "Creating $(basename $1) ..."
137 for i in bin lib dev proc tmp mnt etc ; do
138 mkdir -p /tmp/fs/$i
139 done
140 for i in /dev/console /dev/null /dev/tty /dev/tty1 /dev/tty2 /dev/fuse \
141 /dev/hd* /dev/sd* ; do
142 cp -a $i /tmp/fs$i
143 done
144 for i in /bin/busybox $(which mount.posixovl) $(which blkid); do
145 cp $(LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $i | \
146 sed 's|.*=> \(.*/lib/l[^ ]*\).*|\1|;/^\//!d') /tmp/fs/lib
147 cp $i /tmp/fs/bin
148 done
149 cp -a /lib/ld-* /tmp/fs/lib
150 for i in $(busybox | sed '/Current/,$!d'); do
151 [ -e /tmp/fs/bin/${i%,} ] || ln -s busybox /tmp/fs/bin/${i%,}
152 done
153 ln -s /proc/mounts /tmp/fs/etc/mtab
154 sed 's/ .*//' /proc/modules | while read mod ; do
155 find /lib/modules/ | grep $mod.ko | \
156 sed 's|.*|cp & /tmp/fs/lib|' | sh
157 done
158 cat > /tmp/fs/init <<EOT
159 #!/bin/sh
161 arg()
162 {
163 grep -q \$1 /proc/cmdline &&
164 val="\$(sed "s/.*\$1=\\([^ ]*\\).*/\\1/" < /proc/cmdline)" &&
165 echo "\$2 \$val"
166 }
168 mount -t proc /proc /proc
169 arg debug "shell" && debug=true && set -x
170 for i in /lib/*.ko* ; do insmod \$i 2> /dev/null ; done; sleep 2
171 arg mount "Mount device"
172 mount \$( (blkid /dev/[sh]d* || blkid) | grep \$val | sed 's/:.*//;q') /mnt
173 arg subroot "Change root to directory"
174 mount.posixovl -F /mnt/\$val -- -oallow_other -odefault_permissions -osuid
175 mount --bind /mnt /mnt/\$val/mnt/dos
176 mount -o size=0 -t tmpfs tmpfs /mnt/\$val/mnt/dos/\$val
177 LDSO=\$(ls /mnt/\$val/lib/ld-* | sed q)
178 export LD_LIBRARY_PATH=\$val/lib:\$val/usr/lib:/lib
179 [ "$debug" = "true" ] && sh
180 umount /proc
181 exec /bin/switch_root /mnt \${LDSO#/mnt/} \$val/usr/sbin/chroot \$val /sbin/init
182 EOT
183 chmod +x /tmp/fs/init
184 ( cd /tmp/fs ; find * | cpio -o -H newc ) | lzma e $1 -si 2> /dev/null
185 rm -rf /tmp/fs
186 }
188 is_loram()
189 {
190 [ -s /lib/squashfs.ko* ]
191 }
193 ls_r()
194 {
195 ls -r $@ 2> /dev/null || ls $@
196 }
198 doinstall()
199 {
200 mkdir -p /mnt/slitaz/boot /mnt/slitaz/mnt/dos
201 if ! mount.posixovl -F /mnt/slitaz -- \
202 -oallow_other -odefault_permissions -osuid; then
203 echo "Can't install SliTaz. Abort."
204 sleep 5
205 return 1
206 fi
207 echo "Install root filesystem in /slitaz..."
208 if [ "$1" ]; then
209 if [ -d /media/cdrom/fs ]; then
210 ( cd /mnt/slitaz/fs; find | cpio -o -H newc ) | gzip -9
211 else
212 ls_r /media/cdrom/boot/rootfs* | xargs cat
213 fi > /mnt/slitaz/boot/rootfs.gz
214 tazusbinitfs /mnt/slitaz/boot/rootfs.gz
215 initrd=rootfs.gz
216 extraargs="/home=$(getuuid)/slitaz rdinit=/init1"
217 else
218 if [ -d /media/cdrom/fs ]; then
219 cp -a /media/cdrom/fs/. /mnt/slitaz
220 elif is_loram ; then
221 for i in /media/cdrom/boot/rootfs?.* ; do
222 [ -s $(basename $i) ] && continue
223 cpio -i $i
224 done
225 for i in $(ls_r /media/cdrom/boot/rootfs*); do
226 mount -o loop,ro $i /sqfs/mnt
227 cp -a /sqfs/mnt/. /mnt/slitaz
228 umount -d /sqfs/mnt
229 done
230 else
231 for i in $(ls_r /media/cdrom/boot/rootfs*); do
232 uncpio $i /mnt/slitaz
233 done
234 fi
235 cp -a /etc/locale.conf /tmp/slitaz/etc 2> /dev/null
236 cp -a /etc/keymap.conf /tmp/slitaz/etc 2> /dev/null
237 mkinitrd /mnt/slitaz/boot/initrd
238 initrd=initrd
239 extraargs="mount=$(getuuid) subroot=slitaz"
240 fi
241 echo "Install boot files..."
242 for i in /media/cdrom/boot/bzImage /media/cdrom/boot/*pxe* \
243 /media/cdrom/boot/isolinux/he* /media/cdrom/boot/isolinux/opt* \
244 /media/cdrom/README /media/cdrom/boot/memtest* ; do
245 [ -s $i ] && cp $i /mnt/slitaz/boot
246 done
247 for i in /mnt/slitaz/boot/memtest /mnt/slitaz/boot/*pxe* ; do
248 [ $(get 0 $i 2> /dev/null || echo 0) -eq 23117 ] &&
249 mv $i $i.exe
250 done
251 gettazboot /mnt/slitaz/boot/tazboot.exe
252 unix2dos > /mnt/slitaz/boot/tazboot.cmd <<EOT
253 kernel=/slitaz/boot/bzimage
254 initrd=/slitaz/boot/$initrd
255 rw root=/dev/null $extraargs autologin
256 EOT
257 unix2dos /mnt/slitaz/boot/he* /mnt/slitaz/boot/opt* \
258 /mnt/slitaz/boot/README
259 [ -d /mnt/slitaz/usr/sbin -a ! -x /mnt/slitaz/usr/sbin/mount.posixovl ] &&
260 cp $(which mount.posixovl) /mnt/slitaz/usr/sbin
261 false &&
262 ! grep -qs tazboot /mnt/boot.ini && echo "Update boot.ini ..." &&
263 unix2dos >> /mnt/boot.ini <<EOT
264 C:\\slitaz\\boot\\tazboot.exe="SliTaz"
265 EOT
266 false &&
267 grep -qis menuitem /mnt/config.sys && ! grep -qi tazboot /mnt/config.sys &&
268 echo "Update config.sys ..." &&
269 sed -i 's/menudefault/menuitem SLITAZ, SliTaz\r\n&/' /mnt/config.sys &&
270 unix2dos >> /mnt/config.sys <<EOT
271 [SLITAZ]
272 install=\\slitaz\\boot\\tazboot.exe
273 EOT
274 return 0
275 }
277 install()
278 {
279 $DIALOG --clear \
280 --title " SliTaz UMSDOS way installation " \
281 --yes-label "Install" --yesno \
282 "\nSliTaz will be installed in the subdirectory \\slitaz of the current
283 DOS/Windows partition. You will see your files from /mnt/dos.\n\n
284 You can start SliTaz with \\slitaz\\boot\\tazboot.exe\n\n
285 To uninstall SliTaz, you have only to remove this directory.
286 The file \\boot.ini or \\config.sys may be modified too.\n\n
287 SliTaz may run slowly on 'UMSDOS way' installation due to the
288 posixovl filesystem. The 'TAZUSB way' installation runs faster.\n\n
289 To do a traditional installation with disk partitioning,
290 start SliTaz Live with 'SliTaz RAM boot' menu.\n
291 " 19 70
292 [ $? -eq 0 ] || return
293 doinstall || return
294 [ -x /mnt/slitaz/sbin/init ] || return
295 umount -d /media/cdrom
296 umount_proc
297 exec chroot /mnt/slitaz /sbin/init
298 }
300 installtaz()
301 {
302 $DIALOG --clear \
303 --title " SliTaz TAZUSB way installation " \
304 --yes-label "Install" --yesno \
305 "\nSliTaz will be installed in the subdirectory \\slitaz of the current
306 DOS/Windows partition. You will see your files from /mnt/dos.\n\n
307 You can start SliTaz with \\slitaz\\boot\\tazboot.exe\n\n
308 To uninstall SliTaz, you have only to remove this directory.
309 The file \\boot.ini or \\config.sys may be modified too.\n\n
310 The filesystem is loaded entirely into memory upon boot to
311 increase responsiveness. Only /home lands on hard disk.\n\n
312 To do a traditional installation with disk partitioning,
313 start SliTaz Live with 'SliTaz RAM boot' menu.\n
314 " 19 70
315 [ $? -eq 0 ] || return
316 doinstall tazusblike || return
317 if [ -d /media/cdrom/fs ]; then
318 cp -a /media/cdrom/fs/. /
319 else
320 for i in $(ls_r /media/cdrom/boot/rootfs*); do
321 uncpio $i
322 done
323 fi
324 cp /tmp/fs/etc/* /etc
325 echo "/home=$(getuuid)/slitaz" > /cmdline
326 [ -x /init1 ] || return
327 umount -d /media/cdrom
328 umount /mnt/slitaz
329 rm -f /dev/cdrom
330 umount /mnt
331 mkdir /mnt/dos
332 umount_proc
333 exec /init1
334 }
336 tazboot()
337 {
338 $DIALOG --clear \
339 --title " SliTaz bootloader for DOS " \
340 --yes-label "Install" --yesno \
341 "\nThe file TAZBOOT.EXE will be created in the top directory. It supports
342 a bzImage linux kernel, multiple initramfs, a kernel command line and
343 an ISO image file loopback (retrieves files from an ISO file).\n\n
344 Usage: tazboot.exe [[@commands]|[kernel=<bzimage>]
345 [initrd=<rootfs>[,<rootfs2>...]] [iso=<isofile>] cmdline args ...]\n\n
346 Defaults: tazboot @tazboot.cmd or tazboot kernel=bzImage auto\n\n\
347 Examples for tazboot.cmd:\n\n\
348 iso=\\isos\\slitaz-4.0.iso\n\
349 kernel=boot/bzImage\n\
350 initrd=boot/rootfs4.gz,boot/rootfs3.gz,boot/rootfs2.gz,boot/rootfs1.gz\n\
351 rw root=/dev/null autologin\n\n\
352 kernel=\\slitaz\\vmlinuz root=/dev/sda5 ro\n\n
353 Unlike GRUB4DOS, it doesn't require unfragmented ISO image files.\n
354 " 24 78
355 [ $? -eq 0 ] || return
356 gettazboot /mnt/tazboot.exe
357 }
359 md5()
360 {
361 echo "Checking files..."
362 ( cd /media/cdrom ; md5sum -c md5sum ) > /tmp/data
363 $DIALOG --clear \
364 --title " Checked files " \
365 --textbox /tmp/data 24 78
366 rm -f /tmp/data
367 }
369 readme()
370 {
371 $DIALOG --clear \
372 --title " Readme " \
373 --textbox /media/cdrom/README 24 78
374 }
376 bootlog()
377 {
378 $DIALOG --clear \
379 --title " Linux boot messages " \
380 --textbox /tmp/dmesg 24 78
381 }
383 memtest()
384 {
385 $DIALOG --clear \
386 --title " Memtest86 " \
387 --yes-label "Install" --yesno \
388 "\nMemtest86 is a thorough, stand alone memory test for x86 architecture
389 computers. BIOS based memory tests are a quick, cursory check and often
390 miss many of the failures that are detected by Memtest86.\n
391 " 12 70
392 [ $? -eq 0 ] || return
393 cp /media/cdrom/boot/memtest /mnt/memtest.exe
394 }
396 fdmemtest()
397 {
398 $DIALOG --clear \
399 --title " Create a Memtest86 boot floppy " \
400 --yes-label "Create floppy" --yesno \
401 "\nMemtest86 is a thorough, stand alone memory test for x86 architecture
402 computers. BIOS based memory tests are a quick, cursory check and often
403 miss many of the failures that are detected by Memtest86.\n\n
404 Please insert a blank disk in floppy drive.\n
405 " 12 70
406 [ $? -eq 0 ] || return
407 ddq if=/media/cdrom/boot/memtest of=/dev/fd0
408 }
410 pxe()
411 {
412 $DIALOG --clear \
413 --title " SliTaz Web boot " \
414 --yes-label "Install" --yesno \
415 "\nBoot your operating system from the internet and enjoy a full system
416 working entirely in RAM with speed and stability in mind. The Linux Kernel
417 and the complete SliTaz compressed root filesystem will be loaded into RAM
418 from the Web using PXE and HTTP protocols.\n
419 " 12 70
420 [ $? -eq 0 ] || return
421 pxe=$(ls /media/cdrom/boot/?pxe)
422 cp $pxe /mnt/$(basename $pxe).exe
423 }
425 fdpxe()
426 {
427 $DIALOG --clear \
428 --title " Create a SliTaz Web boot floppy " \
429 --yes-label "Create floppy" --yesno \
430 "\nBoot your operating system from the internet and enjoy a full system
431 working entirely in RAM with speed and stability in mind. The Linux Kernel
432 and the complete SliTaz compressed root filesystem will be loaded into RAM
433 from the Web using PXE and HTTP protocols.\n\n
434 Please insert a blank disk in floppy drive.\n
435 " 12 70
436 [ $? -eq 0 ] || return
437 ddq if=/media/cdrom/boot/?pxe of=/dev/fd0
438 }
440 gotposixovl()
441 {
442 mount.posixovl 2>&1 | grep -qi usage &&
443 echo -en "\"$1\" \"$2\""
444 }
446 xfile()
447 {
448 [ "$(which $1)" ] && echo -en "\"$2\" \"$3\""
449 }
451 cdfile()
452 {
453 [ -s /media/cdrom/$1 ] && echo -en "\"$2\" \"$3\""
454 }
456 cdexe()
457 {
458 [ $(get 0 /media/cdrom/$1 2> /dev/null || echo 0) -eq 23117 ] &&
459 echo -en "\"$2\" \"$3\""
460 }
462 fddata()
463 {
464 [ $(get 28 /mnt/$ISO 1 2> /dev/null || echo 0) -ne 0 ] &&
465 echo -en "\"$1\" \"$2\""
466 }
468 fdbootstrap()
469 {
470 sz=$((512 * $(echo $(get 28 /mnt/$ISO 1))))
471 $DIALOG --clear \
472 --title " Create a floppy bootstrap " \
473 --yes-label "Continue" --yesno \
474 "\nThe floppy will install a driver to access the ISO file
475 on your hard disk and will emulate a CD-ROM during the boot process.\n\n
476 Please insert a floppy in drive now.\n
477 " 10 70
478 [ $? -eq 0 ] || return
479 ddq if=/mnt/$ISO of=/dev/fd0 bs=1 count=512 \
480 skip=$(( $(get 66 /mnt/$ISO) - $sz ))
481 echo "$ISO" | ddq of=/dev/fd0 bs=512 seek=1 count=1
482 ddq if=/mnt/$ISO of=/dev/fd0 bs=1 count=$sz seek=2 \
483 skip=$(( $(get 66 /mnt/$ISO) - $sz + 512 ))
484 }
486 usbdev()
487 {
488 echo "Wait 5 seconds for USB devices..."
489 sleep 5
490 DEV="$(grep -l 1 /sys/block/*/removable | \
491 sed 's|/sys/block/\(.*\)/removable|\1|')"
492 [ "$DEV" ] || return
493 exec 3>&1
494 device=`$DIALOG --clear \
495 --title " Select your USB key " \
496 --menu "\nPlease select the USB key according to its known size.\n\n" \
497 14 70 4 \
498 $(for i in $DEV ; do
499 echo "/dev/$i $(( $(cat /sys/block/$i/size) / 1024 ))MB"
500 done) \
501 2>&1 1>&3`
502 retval=$?
503 exec 3>&-
504 [ $retval -eq 0 ]
505 }
507 usbbootkey()
508 {
509 $DIALOG --clear \
510 --title " Create a USB boot key " \
511 --yes-label "Continue" --yesno \
512 "\nThe USB key will be used like a CD-ROM. You will not be able to write
513 any data on the boot partition.\n\n
514 An extra FAT32 partition will be created with the remaining free space.\n\n
515 You should choose 'USB key read/write installation' to be
516 able to save the package updates or your own configuration and data files.\n\n
517 Please plug your USB stick in now.\n
518 " 16 70
519 [ $? -eq 0 ] || return
520 usbdev || return
522 # perform dd in progess bar
523 max=$(($(stat -c %s /mnt/$ISO)/1024/1024))
524 i=0; ddq if=/mnt/$ISO bs=1024k | (
525 while ddq bs=1024k count=1 ; do
526 i=$(($i + 1))
527 [ $i -gt $max ] && break
528 echo $((($i*100)/$max)) | dialog --gauge \
529 " The ISO image transfer can be long. Please wait..." \
530 6 70 0 > /dev/tty 2>&1
531 done ) > $device
533 # partition + fat32 format for the remining space
534 od -j 466 -N 12 -t u2 -An $device | { read dx cx ol oh ll lh
535 if [ $dx -eq $((0x3F17)) ]; then
536 cx=$(($cx & 0xFF00))
537 ofs=$(($ll+($lh<<16)))
538 n=$(($(cat /sys/block/${device#/dev/}/size)-$ofs))
539 m=$(($cx+($n/8)))
540 [ $m -gt $((0x3FF00)) ] && m=$((0x3FF00))
541 m=$((($m & 0xFF00)+(($m>>16)<<6)))
542 words2bin 0 $((0x101+$cx)) 0x3F0B $((32+$m)) \
543 $ll $lh $(($n & 0xFFFF)) $(($n >> 16)) | \
544 ddq bs=1 seek=446 of=$device
545 if [ "$(which mkdosfs 2> /dev/null)" ]; then
546 losetup -o $((512*$ofs)) /dev/loop0 $device
547 mkdosfs -n "SLITAZ BOOT" /dev/loop0
548 words2bin $(($ofs & 0xFFFF)) $(($ofs >> 16)) | \
549 ddq bs=1 seek=28 of=/dev/loop0
550 losetup -d /dev/loop0
551 fi
552 fi ; }
553 }
555 usbkey()
556 {
557 $DIALOG --clear \
558 --title " Create a SliTaz USB key " \
559 --yes-label "Continue" --yesno \
560 "\nUnlike a hard drive install, the filesystem is kept in a compressed
561 rootfs.gz. The filesystem is loaded entirely into memory upon boot.
562 This should increase responsiveness, protect the filesystem against
563 accidental corruption and reduce read/writes to the USB drive.
564 Once setup, the tazusb utility can rewrite the root filesystem
565 with any changes you have made since booting up,
566 giving the effective benefits of a hard drive install.\n\n
567 /home is mounted on boot using the UUID of your particular flash drive.
568 Unlike a device name, the UUID has the benefit of never changing from machine
569 to machine.\n\n
570 Please plug your USB stick in now.\n
571 " 19 70
572 [ $? -eq 0 ] || return
573 usbdev || return
574 exec 3>&1
575 format=`$DIALOG --clear \
576 --title " Select the filesystem " \
577 --radiolist "\nPlease select the filesystem type to create.\n\n\
578 The filesystem creation will erase all the data \
579 in the USB key." 14 70 4 \
580 "none" "Do not erase the USB key" on \
581 "ext3" "Ext3 journaling filesystem" off \
582 "ext2" "Ext2 filesystem" off \
583 "fat32" "Windows FAT32 filesystem" off \
584 2>&1 1>&3`
585 retval=$?
586 exec 3>&-
587 [ $retval -eq 0 ] || return
588 [ "$format" != "none" ] && tazusb format $device "SliTaz" $format
589 tazusb gen-iso2usb /mnt/$ISO $device
590 }
592 mount_loram()
593 {
594 is_loram || return
595 insmod /lib/squashfs.ko* 2> /dev/null
596 if [ -d /media/cdrom/fs ]; then
597 ln -s /media/cdrom/fs /sqfs
598 else
599 mkdir /sqfs
600 mount -o loop,ro -t squashfs /rootfs*.gz /sqfs
601 fi
602 ln -s /sqfs/lib/* lib
603 ln -s /sqfs/usr /sqfs/var /
604 for i in dmesg basename tr od reboot poweroff getty sync ; do
605 ln -s /sqfs/bin/busybox /bin/$i
606 done
607 }
609 umount_loram()
610 {
611 is_loram || return
612 rm /var /usr
613 umount -d /sqfs
614 rmdir /sqfs
615 }
617 text()
618 {
619 umount_loram
620 umount -d /media/cdrom
621 rm -f /dev/cdrom
622 umount /mnt
623 umount_proc
624 exec /init
625 }
627 live()
628 {
629 n=0
630 for i in $(ls_r /media/cdrom/boot/rootfs* 2> /dev/null); do
631 [ $((n++)) -eq 0 ] || uncpio $i
632 done
633 text
634 }
636 restart()
637 {
638 sync
639 [ ! -L /sqfs ] && umount -d /media/cdrom && umount /mnt
640 reboot -f
641 }
643 stop()
644 {
645 sync
646 [ ! -L /sqfs ] && umount -d /media/cdrom && umount /mnt
647 poweroff -f
648 }
650 shell()
651 {
652 getty -n -l /bin/ash 38400 tty1 || sh
653 }
655 BIN=bin/mount.posixovl
656 [ -x /usr/s$BIN ] || mv /bin/mount.posixovl.iso2exe \
657 /usr/s$BIN 2> /dev/null || mv /bin/mount.posixovl.iso2exe /$BIN
658 mount_proc
659 ISO="$(getarg iso | sed 's/.://;s|\\|/|g')"
660 getiso
661 mount_loram
662 case "${ISO##*/}$(getarg mode)" in
663 *install*|*INSTALL*) install ;;
664 *live*|*LIVE*) live ;;
665 *text*|*TEXT*) text ;;
666 esac
667 which $DIALOG 2> /dev/null || live
668 dmesg > /tmp/dmesg
670 while true; do
671 keymap="$(cat /etc/keymap.conf 2> /dev/null)"
672 locale="$(sed '/^LANG=/!d;s/.*=//' /etc/locale.conf 2> /dev/null)"
673 cat > /tmp/dialog <<EOT
674 $DIALOG --clear \
675 --title " Welcome to SliTaz " \
676 --menu "" 23 70 17 \
677 $(xfile tazkeymap "tazkeymap" "Select keyboard ($keymap)") \
678 $(xfile tazlocale "tazlocale" "Select locale ($locale)") \
679 $(cdfile boot/bzImage "live" "SliTaz RAM boot") \
680 "text" "SliTaz RAM boot (text mode only)" \
681 $(cdfile README "readme" "Show the README file") \
682 $(cdfile md5sum "md5" "Check ISO files") \
683 $(gotposixovl "install" "Hard disk installation (UMSDOS way)") \
684 $(gotposixovl "installtaz" "Hard disk installation (TAZUSB way)") \
685 $(xfile tazusb "usbkey" "USB key read/write installation") \
686 $(cdfile boot/bzImage "usbbootkey" "USB boot key (read only)") \
687 $(fddata "fdbootstrap" "Floppy bootstrap") \
688 $(cdfile boot/bzImage "tazboot" "Get tazboot.exe Linux loader") \
689 $(cdexe boot/memtest "memtest" "Get Memtest86") \
690 $(cdfile boot/memtest "fdmemtest" "Create a Memtest86 boot floppy") \
691 $(cdexe boot/gpxe "pxe" "Get SliTaz Web boot utility") \
692 $(cdfile boot/gpxe "fdpxe" "Create a SliTaz Web boot floppy") \
693 $(cdexe boot/ipxe "pxe" "Get SliTaz Web boot utility") \
694 $(cdfile boot/ipxe "fdpxe" "Create a SliTaz Web boot floppy") \
695 $(xfile reboot "restart" "Restart the computer") \
696 $(xfile poweroff "stop" "Power off") \
697 "bootlog" "Linux boot messages" \
698 "shell" "Shell prompt" \
700 EOT
701 exec 3>&1
702 value=$(sh /tmp/dialog 2>&1 1>&3)
703 retval=$?
704 exec 3>&-
705 [ $retval -eq 0 ] || continue
706 $value
707 done