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

syslinux/iso2exe: check ISO md5 (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Jan 05 12:38:18 2015 +0100 (2015-01-05)
parents aa46cf9cc35a
children 00bb1e4137c6
line source
1 #!/bin/sh
3 DIALOG=dialog
5 ddq()
6 {
7 dd $@ 2> /dev/null
8 }
10 get()
11 {
12 od -v -j $1 -N ${4:-${3:-2}} -t u${3:-2} -w${3:-2} -An $2 2>/dev/null ||
13 hexdump -v -s $1 -n ${4:-${3:-2}} -e "\"\" 1/${3:-2} \" %d\n\"" $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=$(($(get 20 /mnt/$ISO) - 0xC0 - $(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 gotisomd5()
639 {
640 [ $(get 18 /dev/loop0) -ne 0 ] && echo -en "\"$1\" \"$2\""
641 }
643 isomd5()
644 {
645 dotwait "Checking iso image"
646 [ "$(ddq if=/dev/loop0 bs=32k skip=1 | md5sum)" == \
647 "$(ddq if=/dev/loop0 bs=16 count=1 skip=2047 | od -N 16 -t x1 -An | \
648 sed 's/ //g') -" ] && echo "OK" || echo "ERROR"
649 echo -n "Checking iso hybrid boot"
650 n=$(($(get 2 /dev/loop0)-1+($(get 4 /dev/loop0)-1)*512))
651 s=$(get 0 /dev/loop0 2 $n | awk '{ i+= $0 } END { print i }')
652 [ $(((1+$s+$(get $(($n+1)) /dev/loop0 1)) % 65536)) -eq 0 ] &&
653 echo "OK" || echo "ERROR"
654 rm -f /tmp/wait
655 echo "Press RETURN to continue."
656 read n
657 }
659 fdbootstrap()
660 {
661 sz=$((512 * $(echo $(get 28 /mnt/$ISO 1))))
662 $DIALOG --clear \
663 --title " Create a floppy bootstrap " \
664 --yes-label "Continue" --yesno \
665 "\nThe floppy will install a driver to access the ISO file
666 on your hard disk and will emulate a CD-ROM during the boot process.\n\n
667 Please insert a floppy in drive now.\n
668 " 10 70
669 [ $? -eq 0 ] || return
670 ddq if=/mnt/$ISO of=/tmp/bootiso bs=1 count=512 \
671 skip=$(( $(get 66 /mnt/$ISO) - $sz ))
672 echo "$ISO" | ddq of=/tmp/bootiso bs=512 seek=1 count=1
673 ddq if=/mnt/$ISO of=/tmp/bootiso bs=1 count=$sz seek=2 \
674 skip=$(( $(get 66 /mnt/$ISO) - $sz + 512 ))
675 mkfloppy /tmp/bootiso
676 rm -f /tmp/bootiso
677 }
679 usbdev()
680 {
681 dotwait "Wait 5 seconds for USB devices"
682 sleep 5
683 rm -f /tmp/wait
684 DEV="$(grep -l 1 /sys/block/*/removable | \
685 sed 's|/sys/block/\(.*\)/removable|\1|')"
686 grep -qs 1 /sys/block/$DEV/ro && return
687 [ "$DEV" ] || return
688 cat > /tmp/dialog <<EOT
689 $DIALOG --clear \
690 --title " Select your USB key " \
691 --menu "\nPlease select the USB key according to its known size.\n\n" \
692 14 70 4 \
693 $(for i in $DEV ; do
694 echo -n "/dev/$i \"$(($(cat /sys/block/$i/size)/2048))MB $(cat /sys/block/$i/device/model 2> /dev/null)\" "
695 done) \
697 EOT
698 exec 3>&1
699 device=$(. /tmp/dialog 2>&1 1>&3)
700 retval=$?
701 exec 3>&-
702 [ $retval -eq 0 ]
703 }
705 tazusbmsg()
706 {
707 [ "$(which tazusb 2> /dev/null)" ] || return
708 echo "You should choose 'USB key read/write installation' to be
709 able to save the package updates or your own configuration and data files.\n\n"
710 }
712 usbbootkey()
713 {
714 $DIALOG --clear \
715 --title " Create a USB boot key " \
716 --yes-label "Continue" --yesno \
717 "\nThe USB key will be used like a CD-ROM. You will not be able to write
718 any data on the boot partition.\n\n
719 An extra FAT32 partition will be created with the remaining free space.\n\n
720 $(tazusbmsg)Please plug your USB stick in now.\n
721 " 16 70
722 [ $? -eq 0 ] || return
723 usbdev || return
725 # perform dd in progess bar
726 max=$(($(cat /sys/block/loop0/size)/2048))
727 i=0; ddq if=/mnt/$ISO bs=1024k | (
728 while ddq bs=1024k count=1 ; do
729 i=$(($i + 1))
730 [ $i -gt $max ] && break
731 echo $((($i*100)/$max)) | dialog --gauge \
732 " The ISO image transfer can be long. Please wait..." \
733 6 70 0 > /dev/tty0 2>&1
734 done ) > $device
736 # partition + fat32 format for the remining space
737 get 446 $device 2 12 | xargs echo | { read dx cx ol oh ll lh
738 if [ $dx -eq $((0x3F17)) ]; then
739 cx=$(($cx & 0xFF00))
740 ofs=$(($ll+($lh<<16)))
741 n=$(($(cat /sys/block/${device#/dev/}/size)-$ofs))
742 m=$(($cx+($n/8)))
743 [ $m -gt $((0x3FF00)) ] && m=$((0x3FF00))
744 m=$((($m & 0xFF00)+(($m>>16)<<6)))
745 words2bin 0 $((0x101+$cx)) 0x3F0B $((32+$m)) \
746 $ll $lh $(($n & 0xFFFF)) $(($n >> 16)) | \
747 ddq bs=1 seek=446 of=$device
748 if [ "$(which mkdosfs 2> /dev/null)" ]; then
749 losetup -o $((512*$ofs)) /dev/loop0 $device
750 mkdosfs -n "SLITAZ BOOT" /dev/loop0
751 words2bin $(($ofs & 0xFFFF)) $(($ofs >> 16)) | \
752 ddq bs=1 seek=28 of=/dev/loop0
753 losetup -d /dev/loop0
754 fi
755 fi ; }
756 }
758 usbkey()
759 {
760 $DIALOG --clear \
761 --title " Create a SliTaz USB key " \
762 --yes-label "Continue" --yesno \
763 "\nUnlike a hard drive install, the filesystem is kept in a compressed
764 rootfs.gz. The filesystem is loaded entirely into memory upon boot.
765 This should increase responsiveness, protect the filesystem against
766 accidental corruption and reduce read/writes to the USB drive.
767 Once setup, the tazusb utility can rewrite the root filesystem
768 with any changes you have made since booting up,
769 giving the effective benefits of a hard drive install.\n\n
770 /home is mounted on boot using the UUID of your particular flash drive.
771 Unlike a device name, the UUID has the benefit of never changing from machine
772 to machine.\n\n
773 Please plug your USB stick in now.\n
774 " 19 70
775 [ $? -eq 0 ] || return
776 usbdev || return
777 exec 3>&1
778 format=`$DIALOG --clear \
779 --title " Select the filesystem " \
780 --radiolist "\nPlease select the filesystem type to create.\n\n\
781 The filesystem creation will erase all the data \
782 in the USB key." 14 70 4 \
783 "none" "Do not erase the USB key" on \
784 "ext3" "Ext3 journaling filesystem" off \
785 "ext2" "Ext2 filesystem" off \
786 "fat32" "Windows FAT32 filesystem" off \
787 2>&1 1>&3`
788 retval=$?
789 exec 3>&-
790 [ $retval -eq 0 ] || return
791 [ "$format" != "none" ] && tazusb format $device "SliTaz" $format
792 tazusb gen-iso2usb /mnt/$ISO $device
793 }
795 mount_loram()
796 {
797 is_loram || return
798 insmod /lib/squashfs.ko* 2> /dev/null
799 if [ -d /media/cdrom/fs ]; then
800 ln -s /media/cdrom/fs /sqfs
801 else
802 mkdir /sqfs
803 mount -o loop,ro -t squashfs /rootfs*.gz /sqfs
804 fi
805 ln -s /sqfs/lib/* lib
806 ln -s /sqfs/usr /sqfs/var /
807 for i in dmesg basename tr od reboot poweroff getty sync ; do
808 ln -s /sqfs/bin/busybox /bin/$i
809 done
810 }
812 umount_loram()
813 {
814 is_loram || return
815 rm /var /usr
816 umount -d /sqfs
817 rmdir /sqfs
818 }
820 text()
821 {
822 umount_loram
823 umount -d /media/cdrom
824 rm -f /dev/cdrom
825 umount /mnt
826 umount_proc
827 exec /init
828 }
830 live()
831 {
832 n=0
833 dotwait "Extract filesystem..."
834 for i in $(ls_r /media/cdrom/boot/rootfs*); do
835 [ $((n++)) -eq 0 ] || uncpio $i
836 done
837 rm -f /tmp/wait
838 text
839 }
841 dosync()
842 {
843 sync
844 [ ! -L /sqfs ] && umount -d /media/cdrom && umount /mnt
845 }
847 restart()
848 {
849 dosync
850 reboot -f
851 }
853 stop()
854 {
855 dosync
856 poweroff -f
857 }
859 dokexec()
860 {
861 kexec -l $file
862 dosync
863 kexec -e
864 }
866 runmemtest()
867 {
868 gotcdfile memtest* && dokexec
869 }
871 runpxe()
872 {
873 gotcdfile ?pxe && dokexec
874 }
876 shell()
877 {
878 trap text 2
879 getty -n -l /bin/ash 38400 tty1 || sh
880 }
882 BIN=bin/mount.posixovl
883 [ -x /usr/s$BIN ] || mv /bin/mount.posixovl.iso2exe \
884 /usr/s$BIN 2> /dev/null || mv /bin/mount.posixovl.iso2exe /$BIN 2> /dev/null
885 mount_proc
886 ISO="$(getarg bootfrom | sed 's/.://;s|\\|/|g')"
887 getiso
888 mount_loram
889 case "${ISO##*/}$(getarg mode)" in
890 *install*|*INSTALL*) install ;;
891 *live*|*LIVE*) live ;;
892 *text*|*TEXT*) text ;;
893 esac
894 which $DIALOG 2> /dev/null || DIALOG=tinydialog
895 dmesg > /tmp/dmesg
897 while true; do
898 trap shell 2
899 keymap="$(cat /etc/keymap.conf 2> /dev/null)"
900 locale="$(sed '/^LANG=/!d;s/.*=//' /etc/locale.conf 2> /dev/null)"
901 cat > /tmp/dialog <<EOT
902 $DIALOG --clear \
903 --title " Welcome to Linux " \
904 --menu "" 23 70 17 \
905 $(xfile tazkeymap "tazkeymap" "Select keyboard (${keymap:-none})") \
906 $(xfile tazlocale "tazlocale" "Select locale (${locale:-none})") \
907 $(cdfile boot/bzImage "live" "Linux RAM boot (full desktop)") \
908 "text" "Linux RAM boot" \
909 $(cdfile README* "readme" "Show the README file") \
910 $(gotisomd5 "isomd5" "Check the ISO image") \
911 $(cdfile md5sum* "md5" "Check the ISO files") \
912 $(cdfile sha*sum* "sha" "Check the ISO files") \
913 $(gotposixovl "install" "Hard disk installation (UMSDOS way)") \
914 $(gotposixovl "installtaz" "Hard disk installation (TAZUSB way)") \
915 $(xfile tazusb "usbkey" "USB key read/write installation") \
916 $(ishybrid "usbbootkey" "USB boot key (read only)") \
917 $(fddata "fdbootstrap" "Create a floppy bootstrap") \
918 "tazboot" "Get tazboot.exe Linux loader" \
919 $(cdexe boot/bzImage "bzimage" "Get linux DOS/EXE file") \
920 $(cdexe memtest* "memtest" "Get Memtest86 DOS/EXE file") \
921 $(cdfilef memtest* "fdmemtest" "Create a Memtest86 boot floppy") \
922 $(cdfilex memtest* "runmemtest" "Start Memtest86") \
923 $(cdexe ?pxe "pxe" "Get SliTaz Web boot DOS/EXE utility") \
924 $(cdfilef ?pxe "fdpxe" "Create a SliTaz Web boot floppy") \
925 $(cdfilex ?pxe "runpxe" "Start the SliTaz Web boot utility") \
926 $(xfile reboot "restart" "Restart the computer") \
927 $(xfile poweroff "stop" "Power off") \
928 "bootlog" "Linux boot messages" \
929 "shell" "Shell prompt" \
931 EOT
932 exec 3>&1
933 value=$(. /tmp/dialog 2>&1 1>&3)
934 retval=$?
935 exec 3>&-
936 [ $retval -eq 0 ] || continue
937 $value
938 done