wok-current view syslinux/stuff/iso2exe/init @ rev 17492

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