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

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