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

syslinux/iso2exe: add knoppix support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Jan 01 22:09:19 2015 +0100 (2015-01-01)
parents 877def710e44
children 2c2a6dd5ba40
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 clear()
22 {
23 echo -e "\x1B[1;1H\x1B[J"
24 }
26 tinydialog()
27 {
28 clear
29 label=""
30 while [ "$1" ]; do
31 case "$1" in
32 --title) title=" \x1B[30;47m$2\x1B[37;40m\n"
33 echo -e $title; shift ;;
34 --yes-label) label="$2" ; shift ;;
35 --textbox)
36 less "$2" < /dev/tty0 > /dev/tty0
37 break;;
38 --gauge)
39 t=" "
40 echo -e "$t$2\n"
41 while read pct ; do
42 s=" "
43 s="$s$pct%$s"
44 pct=$((($pct*63)/100))
45 echo -en "\r$t\x1B[30;47m$(echo "$s" | cut -c-$pct)\x1B[37;40m$(echo "$s" | cut -c$(($pct+1))-)"
46 done
47 break;;
48 --yesno)
49 while true; do
50 clear
51 echo "$2" | sed 's/\\n/\n/g'
52 echo -en "\n <- 1:${label:-Yes} 2:Cancel\r"
53 read x
54 case "$x" in
55 ''|Y*|y*|1) return 0;;
56 N*|n*|2|0) return 1;;
57 esac
58 done ;;
59 --menu|--radiolist)
60 label="$2"
61 shift 5
62 echo -e "$title\n$label\n0 Cancel" > /tmp/data
63 n=1
64 while [ "$1" ]; do
65 eval key_$n='$1'
66 echo "$((n++)) $2"
67 case "$3" in on|off) shift;; esac
68 shift 2
69 done >> /tmp/data
70 while ! grep -q "^$n " /tmp/data ; do
71 clear
72 [ $(wc -l < /tmp/data) -gt 20 ] &&
73 less /tmp/data || cat /tmp/data
74 echo -en "\n <- Enter the selection number\r"
75 read n
76 done 2> /dev/null
77 rm -f /tmp/data
78 [ $n -eq 0 ] && return 1
79 eval echo -n \$key_$n 1>&2
80 return 0;;
81 esac
82 shift
83 done
84 }
86 mount_proc()
87 {
88 mount -t proc /proc /proc
89 mount -t sysfs /sys /sys
90 udevd --daemon 2> /dev/null && udevadm trigger && sleep 5
91 }
93 umount_proc()
94 {
95 killall udevd 2> /dev/null
96 umount /sys/fs/fuse/connections 2> /dev/null
97 umount /sys
98 umount /proc
99 }
101 bytes2bin()
102 {
103 for i in $@ ; do
104 printf '\\\\x%02X' $(($i&255)) | xargs echo -en
105 done
106 }
108 words2bin()
109 {
110 for i in $@ ; do
111 printf '\\\\x%02X\\\\x%02X' $(($i&255)) $((($i>>8)&255)) | \
112 xargs echo -en
113 done
114 }
116 gettazboot()
117 {
118 echo "Creating $(basename $1) ..."
119 O=$(($(get 66 /mnt/$ISO) - 0xC0))
120 L=$((0x7EE0 - $(get 24 /mnt/$ISO) - $O))
121 S=$((32+$L))
122 P=$((($S+511)/512))
123 E=$((4096-(32*$P)))
124 words2bin 0x5A4D $(($S%512)) $P 0 2 $E -1 $((${2:-0}-16)) \
125 -2 0 256 -16 28 0x6C53 0x5469 0x7A61 > $1
126 ddq bs=1 count=$L skip=$(echo $O) if=/mnt/$ISO >> $1
127 }
129 checkmagic()
130 {
131 [ -s $1 ] && [ $(getarg magic) == $(get 24 $1 4) ]
132 }
134 getiso()
135 {
136 mkdir -p /media/cdrom
137 for dev in /sys/block/?d?/?d??* ; do
138 mount /dev/$(basename $dev) /mnt
139 if checkmagic /mnt/$ISO; then
140 mount -o loop,ro /mnt/$ISO /media/cdrom
141 echo "Found $ISO on $(basename $dev)"
142 break
143 fi
144 umount /mnt
145 done
146 }
148 uncpio()
149 {
150 [ -s "$1" ] || return
151 echo -en "\n Extracting $(basename $1) ..."
152 case $(get 0 $1) in
153 *35615) ( zcat || gunzip ) ;;
154 *14333) unxz ;;
155 *\ 93) unlzma ;;
156 *) cat ;;
157 esac < $1 | ( cd ${2:-/} ; cpio -idmu > /dev/null 2>&1 )
158 }
160 dotwait()
161 {
162 echo -n "${1:-Install filesystem}.."
163 touch /tmp/wait
164 while [ -e /tmp/wait ]; do
165 echo -n "." > /dev/tty0
166 sleep 1
167 done &
168 }
170 getuuid()
171 {
172 dev=$(mount | sed '/ \/mnt /!d;s/ .*//;s|/dev/||;q')
173 blkid | sed "/$dev:/!d;s/.* UUID=.\\([^ ]*\\)\".*/\\1/"
174 }
176 tazusbinitfs()
177 {
178 PAD=$(($(stat -c %s $1) % 4))
179 [ $PAD -ne 0 ] && ddq if=/dev/zero bs=1 count=$((4 - $PAD)) >> $1
180 mkdir -p /tmp/fs/etc /tmp/fs/lib /tmp/fs/home
181 cp -a /etc/locale.conf /tmp/fs/etc 2> /dev/null
182 cp -a /etc/keymap.conf /tmp/fs/etc 2> /dev/null
183 sed 's/ .*//' /proc/modules | while read mod ; do
184 find /lib/modules/ | grep $mod.ko | \
185 sed 's|.*|cp & /tmp/fs/lib|' | sh
186 done
187 cat > /tmp/fs/init1 <<EOT
188 #!/bin/sh
189 sed -i 's|sbin/init|init2|' /init
190 exec /init
191 EOT
192 cat > /tmp/fs/init2 <<EOT
193 #!/bin/sh
195 mount -t proc /proc /proc
196 grep -q debug /proc/cmdline && debug=true && set -x
197 for i in /lib/*.ko* ; do insmod \$i 2> /dev/null ; done; sleep 2
198 v=\$(sed '/\\/home=/!d;s|.*/home=\\([^ ]*\\).*|\\1|' /proc/cmdline /cmdline 2> /dev/null)
199 mount / -o remount,rw
200 mkdir /mnt/dos
201 rm -f /cmdline 2> /dev/null
202 mount / -o remount,ro
203 mnt=/mnt/dos/\${v#*/}
204 dev=\$( (blkid /dev/[sh]d* || blkid) | grep \${v%%/*} | sed 's/:.*//;q')
205 echo "Mount \$dev in /mnt/dos for \$v..." | tee -a /run/boot.log
206 mount \$dev /mnt/dos
207 mount.posixovl -F \$mnt -- -oallow_other -odefault_permissions -osuid
208 mount --bind \$mnt /home
209 [ "\$debug" = "true" ] && sh
210 umount /proc
211 exec /sbin/init
212 EOT
213 chmod 755 /tmp/fs/init?
214 cp -a /tmp/fs/* /
215 ( cd /tmp/fs ; find * | cpio -o -H newc ) | gzip -9 >> $1
216 }
218 mkinitrd()
219 {
220 dotwait "Creating $(basename $1) "
221 for i in bin lib dev proc tmp mnt etc ; do
222 mkdir -p /tmp/fs/$i
223 done
224 for i in /dev/console /dev/null /dev/tty /dev/tty0 /dev/tty1 /dev/tty2 \
225 /dev/fuse /dev/hd* /dev/sd* ; do
226 cp -a $i /tmp/fs$i
227 done
228 for i in /bin/busybox $(which mount.posixovl) $(which blkid); do
229 cp $(LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $i | \
230 sed 's|.*=> \(.*/lib/l[^ ]*\).*|\1|;/^\//!d') /tmp/fs/lib
231 cp $i /tmp/fs/bin
232 done
233 cp -a /lib/ld-* /tmp/fs/lib
234 for i in $(busybox | sed '/Current/,$!d'); do
235 [ -e /tmp/fs/bin/${i%,} ] || ln -s busybox /tmp/fs/bin/${i%,}
236 done
237 ln -s /proc/mounts /tmp/fs/etc/mtab
238 sed 's/ .*//' /proc/modules | while read mod ; do
239 find /lib/modules/ | grep $mod.ko | \
240 sed 's|.*|cp & /tmp/fs/lib|' | sh
241 done
242 cat > /tmp/fs/init <<EOT
243 #!/bin/sh
245 arg()
246 {
247 grep -q \$1 /proc/cmdline &&
248 val="\$(sed "s/.*\$1=\\([^ ]*\\).*/\\1/" < /proc/cmdline)" &&
249 echo "\$2 \$val"
250 }
252 mount -t proc /proc /proc
253 arg debug "shell" && debug=true && set -x
254 for i in /lib/*.ko* ; do insmod \$i 2> /dev/null ; done; sleep 2
255 arg mount "Mount device"
256 mount \$( (blkid /dev/[sh]d* || blkid) | grep \$val | sed 's/:.*//;q') /mnt
257 arg subroot "Change root to directory"
258 mount.posixovl -F /mnt/\$val -- -oallow_other -odefault_permissions -osuid
259 mount --bind /mnt /mnt/\$val/mnt/dos
260 mount -o size=0 -t tmpfs tmpfs /mnt/\$val/mnt/dos/\$val
261 LDSO=\$(ls /mnt/\$val/lib/ld-* | sed q)
262 export LD_LIBRARY_PATH=\$val/lib:\$val/usr/lib:/lib
263 [ "$debug" = "true" ] && sh
264 umount /proc
265 exec /bin/switch_root /mnt \${LDSO#/mnt/} \$val/usr/sbin/chroot \$val /sbin/init
266 EOT
267 chmod +x /tmp/fs/init
268 ( cd /tmp/fs ; find * | cpio -o -H newc ) | lzma e $1 -si 2> /dev/null
269 rm -rf /tmp/fs /tmp/wait
270 }
272 is_loram()
273 {
274 [ -s /lib/squashfs.ko* ]
275 }
277 ls_r()
278 {
279 ls -r $@ 2> /dev/null || ls $@
280 }
282 doinstall()
283 {
284 mkdir -p /mnt/slitaz/boot /mnt/slitaz/mnt/dos
285 if ! mount.posixovl -F /mnt/slitaz -- \
286 -oallow_other -odefault_permissions -osuid; then
287 echo "Can't install SliTaz. Abort."
288 sleep 5
289 return 1
290 fi
291 dowait "Install root filesystem in /slitaz.."
292 if [ "$1" ]; then
293 if [ -d /media/cdrom/fs ]; then
294 ( cd /mnt/slitaz/fs; find | cpio -o -H newc ) | gzip -9
295 else
296 ls_r /media/cdrom/boot/rootfs* | xargs cat
297 fi > /mnt/slitaz/boot/rootfs.gz
298 tazusbinitfs /mnt/slitaz/boot/rootfs.gz
299 initrd=rootfs.gz
300 extraargs="/home=$(getuuid)/slitaz rdinit=/init1"
301 else
302 if [ -d /media/cdrom/fs ]; then
303 cp -a /media/cdrom/fs/. /mnt/slitaz
304 elif is_loram ; then
305 for i in /media/cdrom/boot/rootfs?*.* ; do
306 [ -s $(basename $i) ] && continue
307 cpio -i $i
308 done
309 for i in $(ls_r /media/cdrom/boot/rootfs*); do
310 mount -o loop,ro $i /sqfs/mnt
311 cp -a /sqfs/mnt/. /mnt/slitaz
312 umount -d /sqfs/mnt
313 done
314 else
315 for i in $(ls_r /media/cdrom/boot/rootfs*); do
316 uncpio $i /mnt/slitaz
317 done
318 fi
319 cp -a /etc/locale.conf /tmp/slitaz/etc 2> /dev/null
320 cp -a /etc/keymap.conf /tmp/slitaz/etc 2> /dev/null
321 mkinitrd /mnt/slitaz/boot/initrd
322 initrd=initrd
323 extraargs="mount=$(getuuid) subroot=slitaz"
324 fi
325 echo -en "\nInstall boot files..."
326 for i in /media/cdrom/boot/bzImage /media/cdrom/boot/*pxe* \
327 /media/cdrom/boot/isolinux/he* /media/cdrom/boot/isolinux/opt* \
328 /media/cdrom/README /media/cdrom/boot/memtest* ; do
329 [ -s $i ] && cp $i /mnt/slitaz/boot
330 done
331 for i in /mnt/slitaz/boot/memtest /mnt/slitaz/boot/*pxe* ; do
332 [ $(get 0 $i 2> /dev/null || echo 0) -eq 23117 ] &&
333 mv $i $i.exe
334 done
335 gettazboot /mnt/slitaz/boot/tazboot.exe
336 unix2dos > /mnt/slitaz/boot/tazboot.cmd <<EOT
337 kernel=/slitaz/boot/bzimage
338 initrd=/slitaz/boot/$initrd
339 rw root=/dev/null $extraargs autologin
340 EOT
341 unix2dos /mnt/slitaz/boot/he* /mnt/slitaz/boot/opt* \
342 /mnt/slitaz/boot/README
343 [ -d /mnt/slitaz/usr/sbin -a ! -x /mnt/slitaz/usr/sbin/mount.posixovl ] &&
344 cp $(which mount.posixovl) /mnt/slitaz/usr/sbin
345 rm -f /tmp/wait
346 false &&
347 [ -s /mnt/boot.ini ] && ! grep -qs tazboot /mnt/boot.ini &&
348 echo "Update boot.ini ..." && unix2dos >> /mnt/boot.ini <<EOT
349 C:\\slitaz\\boot\\tazboot.exe="SliTaz"
350 EOT
351 false &&
352 grep -qis menuitem /mnt/config.sys && ! grep -qi tazboot /mnt/config.sys &&
353 echo "Update config.sys ..." &&
354 sed -i 's/menudefault/menuitem SLITAZ, SliTaz\r\n&/' /mnt/config.sys &&
355 unix2dos >> /mnt/config.sys <<EOT
356 [SLITAZ]
357 install=\\slitaz\\boot\\tazboot.exe
358 EOT
359 return 0
360 }
362 install()
363 {
364 $DIALOG --clear \
365 --title " SliTaz UMSDOS way installation " \
366 --yes-label "Install" --yesno \
367 "\nSliTaz will be installed in the subdirectory \\slitaz of the current
368 DOS/Windows partition. You will see your files from /mnt/dos.\n\n
369 You can start SliTaz with \\slitaz\\boot\\tazboot.exe\n\n
370 To uninstall SliTaz, you have only to remove this directory.
371 The file \\boot.ini or \\config.sys may be modified too.\n\n
372 SliTaz may run slowly on 'UMSDOS way' installation due to the
373 posixovl filesystem. The 'TAZUSB way' installation runs faster.\n\n
374 To do a traditional installation with disk partitioning,
375 start SliTaz Live with 'SliTaz RAM boot' menu.\n
376 " 19 70
377 [ $? -eq 0 ] || return
378 doinstall || return
379 [ -x /mnt/slitaz/sbin/init ] || return
380 umount -d /media/cdrom
381 umount_proc
382 exec chroot /mnt/slitaz /sbin/init
383 }
385 installtaz()
386 {
387 $DIALOG --clear \
388 --title " SliTaz TAZUSB way installation " \
389 --yes-label "Install" --yesno \
390 "\nSliTaz will be installed in the subdirectory \\slitaz of the current
391 DOS/Windows partition. You will see your files from /mnt/dos.\n\n
392 You can start SliTaz with \\slitaz\\boot\\tazboot.exe\n\n
393 To uninstall SliTaz, you have only to remove this directory.
394 The file \\boot.ini or \\config.sys may be modified too.\n\n
395 The filesystem is loaded entirely into memory upon boot to
396 increase responsiveness. Only /home lands on hard disk.\n\n
397 To do a traditional installation with disk partitioning,
398 start SliTaz Live with 'SliTaz RAM boot' menu.\n
399 " 19 70
400 [ $? -eq 0 ] || return
401 doinstall tazusblike || return
402 dotwait
403 if [ -d /media/cdrom/fs ]; then
404 cp -a /media/cdrom/fs/. /
405 else
406 for i in $(ls_r /media/cdrom/boot/rootfs*); do
407 uncpio $i
408 done
409 fi
410 cp /tmp/fs/etc/* /etc
411 echo "/home=$(getuuid)/slitaz" > /cmdline
412 rm -f /tmp/wait
413 [ -x /init1 ] || return
414 umount -d /media/cdrom
415 umount /mnt/slitaz
416 rm -f /dev/cdrom
417 umount /mnt
418 mkdir /mnt/dos
419 umount_proc
420 exec /init1
421 }
423 tazboot()
424 {
425 $DIALOG --clear \
426 --title " SliTaz bootloader for DOS " \
427 --yes-label "Install" --yesno \
428 "\nThe file TAZBOOT.EXE will be created in the top directory. It supports
429 any linux kernel, multiple initramfs, a kernel command line and
430 an ISO image file loopback (retrieves files from an ISO file).\n\n
431 Usage: tazboot.exe [[@commands]|[kernel=<bzimage>]
432 [initrd=<rootfs>[,<rootfs2>...]] [bootfrom=<isofile>] cmdline args ...]\n\n
433 Defaults: tazboot @tazboot.cmd or tazboot kernel=bzImage auto\n\n\
434 Examples for tazboot.cmd:\n\n\
435 bootfrom=\\isos\\slitaz-4.0.iso\n\
436 kernel=boot/bzImage\n\
437 initrd=boot/rootfs4.gz,boot/rootfs3.gz,boot/rootfs2.gz,boot/rootfs1.gz\n\
438 rw root=/dev/null autologin\n\n\
439 kernel=\\slitaz\\vmlinuz root=/dev/sda5 ro\n\n
440 Unlike GRUB4DOS, it doesn't require unfragmented ISO image files.\n
441 " 24 78
442 [ $? -eq 0 ] || return
443 gettazboot /mnt/tazboot.exe
444 }
446 md5()
447 {
448 dotwait "Checking files"
449 ( cd /media/cdrom ; ${1:-md5sum -c md5sum*} ) > /tmp/data
450 rm -f /tmp/wait
451 $DIALOG --clear \
452 --title " Checked files " \
453 --textbox /tmp/data 24 78
454 rm -f /tmp/data
455 }
457 sha()
458 {
459 gotcdfile sha*sum*
460 sha=$(basename $file)
461 md5 "${sha%sum*}sum -c ${file#/media/cdrom/}"
462 }
464 readme()
465 {
466 gotcdfile README*
467 $DIALOG --clear \
468 --title " Readme " \
469 --textbox $file 24 78
470 }
472 bootlog()
473 {
474 $DIALOG --clear \
475 --title " Linux boot messages " \
476 --textbox /tmp/dmesg 24 78
477 }
479 bzimage()
480 {
481 $DIALOG --clear \
482 --title " Create linux.exe ? " \
483 --yes-label "Install" --yesno \
484 "\nLinux.exe launches the linux kernel under DOS (in real mode only).
485 The cmdline arguments are supported except initrd=, vga= (you can try 'rdev -v')
486 and mem= (partially).\n\nExample:\nC:\\> linux.exe root=/dev/hda2 ro panic=60\n
487 " 12 70
488 [ $? -eq 0 ] || return
489 cp /media/cdrom/boot/bzImage /mnt/linux.exe
490 }
492 memtest()
493 {
494 $DIALOG --clear \
495 --title " Create memtest.exe ? " \
496 --yes-label "Install" --yesno \
497 "\nMemtest86 is a thorough, stand alone memory test for x86 architecture
498 computers. BIOS based memory tests are a quick, cursory check and often
499 miss many of the failures that are detected by Memtest86.\n
500 " 12 70
501 [ $? -eq 0 ] && gotcdfile memtest* && cp $file /mnt/memtest.exe
502 }
504 mkfat12()
505 {
506 [ $(($(get 0 $1) - 0x5A4D)) -eq 0 ] || return
507 J=$(($(get 3 $1 1) + 0x02))
508 R=$((1 + $(get 497 $1 1) + 1 + ($(get 500 $1)-1)/32))
509 [ $R -lt 2500 ] || return
510 [ $((($(get 500 $1)-1) & 31)) -lt 30 ] &&
511 ddq if=$file bs=32 count=1 seek=$(($R*16 - 1)) of=/dev/fd0
512 G="18 0 2 0 0 0 0 0"
513 [ $J -gt 25 ] || G=""
514 F=0
515 for i in 1 2 3; do
516 F=$((((2880-$R-$F-$F)*3+1023)/1024))
517 done
518 bytes2bin 0xEB $J 0x90 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 \
519 0 2 2 $(($R%256)) $(($R/256)) 2 64 0 64 11 0xF0 $F 0 \
520 $G | ddq bs=1 of=/dev/fd0
521 ddq if=/dev/zero bs=512 count=$((4+$F+$F)) seek=$R of=/dev/fd0
522 for i in $R $(($R+$F)) ; do
523 bytes2bin 0xF0 0xFF 0xFF | ddq bs=512 seek=$i of=/dev/fd0
524 done
525 echo -n $(basename $1) | ddq bs=1 seek=3 count=8 of=/dev/fd0
526 }
528 mkfloppy()
529 {
530 dotwait "Create a $(basename $1) boot floppy"
531 ddq if=$1 of=/dev/fd0
532 mkfat12 $1
533 rm -f /tmp/wait
534 }
536 fdmemtest()
537 {
538 $DIALOG --clear \
539 --title " Create a Memtest86 boot floppy " \
540 --yes-label "Create floppy" --yesno \
541 "\nMemtest86 is a thorough, stand alone memory test for x86 architecture
542 computers. BIOS based memory tests are a quick, cursory check and often
543 miss many of the failures that are detected by Memtest86.\n\n
544 Please insert a blank disk in floppy drive.\n
545 " 12 70
546 [ $? -eq 0 ] && gotcdfile memtest* && mkfloppy $file
547 }
549 pxe()
550 {
551 gotcdfile ?pxe
552 pxe=$(ls $file)
553 $DIALOG --clear \
554 --title " Create $(basename $pxe).exe ? " \
555 --yes-label "Install" --yesno \
556 "\nBoot your operating system from the internet and enjoy a full system
557 working entirely in RAM with speed and stability in mind. The Linux Kernel
558 and the complete SliTaz compressed root filesystem will be loaded into RAM
559 from the Web using PXE and HTTP protocols.\n
560 " 12 70
561 [ $? -eq 0 ] || return
562 cp $pxe /mnt/$(basename $pxe).exe
563 }
565 fdpxe()
566 {
567 $DIALOG --clear \
568 --title " Create a SliTaz Web boot floppy " \
569 --yes-label "Create floppy" --yesno \
570 "\nBoot your operating system from the internet and enjoy a full system
571 working entirely in RAM with speed and stability in mind. The Linux Kernel
572 and the complete SliTaz compressed root filesystem will be loaded into RAM
573 from the Web using PXE and HTTP protocols.\n\n
574 Please insert a blank disk in floppy drive.\n
575 " 12 70
576 [ $? -eq 0 ] && gotcdfile ?pxe && mkfloppy $file
577 }
579 gotposixovl()
580 {
581 mount.posixovl 2>&1 | grep -qi usage &&
582 echo -en "\"$1\" \"$2\""
583 }
585 xfile()
586 {
587 [ "$(which $1)" ] && echo -en "\"$2\" \"$3\""
588 }
590 gotcdfile()
591 {
592 for file in /media/cdrom/$1 /media/cdrom/*/$1 \
593 /media/cdrom/*/isolinux/$1 ; do
594 [ -s $file ] && break
595 done
596 }
598 cdfile()
599 {
600 gotcdfile "$1" && echo -en "\"$2\" \"$3\""
601 }
603 cdfilex()
604 {
605 [ "$(which kexec)" ] && cdfile "$@"
606 }
608 cdexe()
609 {
610 gotcdfile "$1" &&
611 [ $(get 0 $file 2>/dev/null || echo 0) -eq 23117 ] &&
612 echo -en "\"$2\" \"$3\""
613 }
615 fddata()
616 {
617 [ $(get 28 /mnt/$ISO 1 2> /dev/null || echo 0) -ne 0 ] &&
618 echo -en "\"$1\" \"$2\""
619 }
621 fdbootstrap()
622 {
623 sz=$((512 * $(echo $(get 28 /mnt/$ISO 1))))
624 $DIALOG --clear \
625 --title " Create a floppy bootstrap " \
626 --yes-label "Continue" --yesno \
627 "\nThe floppy will install a driver to access the ISO file
628 on your hard disk and will emulate a CD-ROM during the boot process.\n\n
629 Please insert a floppy in drive now.\n
630 " 10 70
631 [ $? -eq 0 ] || return
632 ddq if=/mnt/$ISO of=/tmp/bootiso bs=1 count=512 \
633 skip=$(( $(get 66 /mnt/$ISO) - $sz ))
634 echo "$ISO" | ddq of=/tmp/bootiso bs=512 seek=1 count=1
635 ddq if=/mnt/$ISO of=/tmp/bootiso bs=1 count=$sz seek=2 \
636 skip=$(( $(get 66 /mnt/$ISO) - $sz + 512 ))
637 mkfloppy /tmp/bootiso
638 rm -f /tmp/bootiso
639 }
641 usbdev()
642 {
643 dotwait "Wait 5 seconds for USB devices"
644 sleep 5
645 rm -f /tmp/wait
646 DEV="$(grep -l 1 /sys/block/*/removable | \
647 sed 's|/sys/block/\(.*\)/removable|\1|')"
648 [ "$DEV" ] || return
649 exec 3>&1
650 device=`$DIALOG --clear \
651 --title " Select your USB key " \
652 --menu "\nPlease select the USB key according to its known size.\n\n" \
653 14 70 4 \
654 $(for i in $DEV ; do
655 echo "/dev/$i $(( $(cat /sys/block/$i/size) / 1024 ))MB"
656 done) \
657 2>&1 1>&3`
658 retval=$?
659 exec 3>&-
660 [ $retval -eq 0 ]
661 }
663 usbbootkey()
664 {
665 $DIALOG --clear \
666 --title " Create a USB boot key " \
667 --yes-label "Continue" --yesno \
668 "\nThe USB key will be used like a CD-ROM. You will not be able to write
669 any data on the boot partition.\n\n
670 An extra FAT32 partition will be created with the remaining free space.\n\n
671 You should choose 'USB key read/write installation' to be
672 able to save the package updates or your own configuration and data files.\n\n
673 Please plug your USB stick in now.\n
674 " 16 70
675 [ $? -eq 0 ] || return
676 usbdev || return
678 # perform dd in progess bar
679 max=$(($(stat -c %s /mnt/$ISO)/1024/1024))
680 i=0; ddq if=/mnt/$ISO bs=1024k | (
681 while ddq bs=1024k count=1 ; do
682 i=$(($i + 1))
683 [ $i -gt $max ] && break
684 echo $((($i*100)/$max)) | dialog --gauge \
685 " The ISO image transfer can be long. Please wait..." \
686 6 70 0 > /dev/tty0 2>&1
687 done ) > $device
689 # partition + fat32 format for the remining space
690 od -j 466 -N 12 -t u2 -An $device | { read dx cx ol oh ll lh
691 if [ $dx -eq $((0x3F17)) ]; then
692 cx=$(($cx & 0xFF00))
693 ofs=$(($ll+($lh<<16)))
694 n=$(($(cat /sys/block/${device#/dev/}/size)-$ofs))
695 m=$(($cx+($n/8)))
696 [ $m -gt $((0x3FF00)) ] && m=$((0x3FF00))
697 m=$((($m & 0xFF00)+(($m>>16)<<6)))
698 words2bin 0 $((0x101+$cx)) 0x3F0B $((32+$m)) \
699 $ll $lh $(($n & 0xFFFF)) $(($n >> 16)) | \
700 ddq bs=1 seek=446 of=$device
701 if [ "$(which mkdosfs 2> /dev/null)" ]; then
702 losetup -o $((512*$ofs)) /dev/loop0 $device
703 mkdosfs -n "SLITAZ BOOT" /dev/loop0
704 words2bin $(($ofs & 0xFFFF)) $(($ofs >> 16)) | \
705 ddq bs=1 seek=28 of=/dev/loop0
706 losetup -d /dev/loop0
707 fi
708 fi ; }
709 }
711 usbkey()
712 {
713 $DIALOG --clear \
714 --title " Create a SliTaz USB key " \
715 --yes-label "Continue" --yesno \
716 "\nUnlike a hard drive install, the filesystem is kept in a compressed
717 rootfs.gz. The filesystem is loaded entirely into memory upon boot.
718 This should increase responsiveness, protect the filesystem against
719 accidental corruption and reduce read/writes to the USB drive.
720 Once setup, the tazusb utility can rewrite the root filesystem
721 with any changes you have made since booting up,
722 giving the effective benefits of a hard drive install.\n\n
723 /home is mounted on boot using the UUID of your particular flash drive.
724 Unlike a device name, the UUID has the benefit of never changing from machine
725 to machine.\n\n
726 Please plug your USB stick in now.\n
727 " 19 70
728 [ $? -eq 0 ] || return
729 usbdev || return
730 exec 3>&1
731 format=`$DIALOG --clear \
732 --title " Select the filesystem " \
733 --radiolist "\nPlease select the filesystem type to create.\n\n\
734 The filesystem creation will erase all the data \
735 in the USB key." 14 70 4 \
736 "none" "Do not erase the USB key" on \
737 "ext3" "Ext3 journaling filesystem" off \
738 "ext2" "Ext2 filesystem" off \
739 "fat32" "Windows FAT32 filesystem" off \
740 2>&1 1>&3`
741 retval=$?
742 exec 3>&-
743 [ $retval -eq 0 ] || return
744 [ "$format" != "none" ] && tazusb format $device "SliTaz" $format
745 tazusb gen-iso2usb /mnt/$ISO $device
746 }
748 mount_loram()
749 {
750 is_loram || return
751 insmod /lib/squashfs.ko* 2> /dev/null
752 if [ -d /media/cdrom/fs ]; then
753 ln -s /media/cdrom/fs /sqfs
754 else
755 mkdir /sqfs
756 mount -o loop,ro -t squashfs /rootfs*.gz /sqfs
757 fi
758 ln -s /sqfs/lib/* lib
759 ln -s /sqfs/usr /sqfs/var /
760 for i in dmesg basename tr od reboot poweroff getty sync ; do
761 ln -s /sqfs/bin/busybox /bin/$i
762 done
763 }
765 umount_loram()
766 {
767 is_loram || return
768 rm /var /usr
769 umount -d /sqfs
770 rmdir /sqfs
771 }
773 text()
774 {
775 umount_loram
776 umount -d /media/cdrom
777 rm -f /dev/cdrom
778 umount /mnt
779 umount_proc
780 exec /init
781 }
783 live()
784 {
785 n=0
786 dotwait "Extract filesystem..."
787 for i in $(ls_r /media/cdrom/boot/rootfs*); do
788 [ $((n++)) -eq 0 ] || uncpio $i
789 done
790 rm -f /tmp/wait
791 text
792 }
794 dosync()
795 {
796 sync
797 [ ! -L /sqfs ] && umount -d /media/cdrom && umount /mnt
798 }
800 restart()
801 {
802 dosync
803 reboot -f
804 }
806 stop()
807 {
808 dosync
809 poweroff -f
810 }
812 dokexec()
813 {
814 kexec -l $file
815 dosync
816 kexec -e
817 }
819 runmemtest()
820 {
821 gotcdfile memtest* && dokexec
822 }
824 runpxe()
825 {
826 gotcdfile ?pxe && dokexec
827 }
829 shell()
830 {
831 getty -n -l /bin/ash 38400 tty1 || sh
832 }
834 BIN=bin/mount.posixovl
835 [ -x /usr/s$BIN ] || mv /bin/mount.posixovl.iso2exe \
836 /usr/s$BIN 2> /dev/null || mv /bin/mount.posixovl.iso2exe /$BIN 2> /dev/null
837 mount_proc
838 ISO="$(getarg bootfrom | sed 's/.://;s|\\|/|g')"
839 getiso
840 mount_loram
841 case "${ISO##*/}$(getarg mode)" in
842 *install*|*INSTALL*) install ;;
843 *live*|*LIVE*) live ;;
844 *text*|*TEXT*) text ;;
845 esac
846 which $DIALOG 2> /dev/null || DIALOG=tinydialog
847 dmesg > /tmp/dmesg
849 while true; do
850 keymap="$(cat /etc/keymap.conf 2> /dev/null)"
851 locale="$(sed '/^LANG=/!d;s/.*=//' /etc/locale.conf 2> /dev/null)"
852 cat > /tmp/dialog <<EOT
853 $DIALOG --clear \
854 --title " Welcome to Linux " \
855 --menu "" 23 70 17 \
856 $(xfile tazkeymap "tazkeymap" "Select keyboard (${keymap:-none})") \
857 $(xfile tazlocale "tazlocale" "Select locale (${locale:-none})") \
858 $(cdfile boot/bzImage "live" "Linux RAM boot (full desktop)") \
859 "text" "Linux RAM boot" \
860 $(cdfile README* "readme" "Show the README file") \
861 $(cdfile md5sum* "md5" "Check ISO files") \
862 $(cdfile sha*sum* "sha" "Check ISO files") \
863 $(gotposixovl "install" "Hard disk installation (UMSDOS way)") \
864 $(gotposixovl "installtaz" "Hard disk installation (TAZUSB way)") \
865 $(xfile tazusb "usbkey" "USB key read/write installation") \
866 $(cdfile boot/bzImage "usbbootkey" "USB boot key (read only)") \
867 $(fddata "fdbootstrap" "Create a floppy bootstrap") \
868 $(cdfile boot/bzImage "tazboot" "Get tazboot.exe Linux loader") \
869 $(cdexe boot/bzImage "bzimage" "Get linux DOS/EXE file") \
870 $(cdexe memtest* "memtest" "Get Memtest86 DOS/EXE file") \
871 $(cdfile memtest* "fdmemtest" "Create a Memtest86 boot floppy") \
872 $(cdfilex memtest* "runmemtest" "Start Memtest86") \
873 $(cdexe ?pxe "pxe" "Get SliTaz Web boot DOS/EXE utility") \
874 $(cdfile ?pxe "fdpxe" "Create a SliTaz Web boot floppy") \
875 $(cdfilex ?pxe "runpxe" "Start the SliTaz Web boot utility") \
876 $(xfile reboot "restart" "Restart the computer") \
877 $(xfile poweroff "stop" "Power off") \
878 "bootlog" "Linux boot messages" \
879 "shell" "Shell prompt" \
881 EOT
882 exec 3>&1
883 value=$(. /tmp/dialog 2>&1 1>&3)
884 retval=$?
885 exec 3>&-
886 [ $retval -eq 0 ] || continue
887 $value
888 done