wok view syslinux/stuff/iso2exe/taziso @ rev 17924

syslinux/taziso: batch mode
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Apr 11 11:09:49 2015 +0200 (2015-04-11)
parents 9822e51d7c2e
children 7034b53ca07c
line source
1 #!/bin/sh
3 [ $(id -u) -eq 0 ] || exec su -c "$0 $@"
5 DIALOG=dialog
7 ddq()
8 {
9 dd $@ 2> /dev/null
10 }
12 get()
13 {
14 od -v -j $1 -N ${4:-${3:-2}} -t u${3:-2} -w${3:-2} -An $2 2>/dev/null ||
15 hexdump -v -s $1 -n ${4:-${3:-2}} -e "\"\" 1/${3:-2} \" %d\n\"" $2
16 }
18 bytes2bin()
19 {
20 for i in $@ ; do
21 printf '\\\\x%02X' $(($i&255))
22 done | xargs echo -en
23 }
25 words2bin()
26 {
27 for i in $@ ; do
28 printf '\\\\x%02X\\\\x%02X' $(($i&255)) $((($i>>8)&255))
29 done | xargs echo -en
30 }
32 gettazboot()
33 {
34 echo "Creating $(basename $1) ..."
35 if [ $(get 0 $ISO) -eq 23117 ]; then
36 O=$(($(get 64 $ISO) - 0xC0))
37 L=$(($(get 20 $ISO) - 0xC0 - $(get 24 $ISO) - $O))
38 S=$((32+$L))
39 P=$((($S+511)/512))
40 E=$((4096-(32*$P)))
41 words2bin 0x5A4D $(($S%512)) $P 0 2 $E -1 $((${2:-0}-16)) \
42 -2 0 256 -16 28 0x6C53 0x5469 0x7A61 > $1
43 ddq bs=1 count=$L skip=$(echo $O) if=$ISO >> $1
44 else
45 wget -O $1 http://mirror.slitaz.org/boot/tazboot.exe
46 fi
47 }
49 uncpio()
50 {
51 [ -s "$1" ] || return
52 echo -en "\n Extracting $(basename $1) ..."
53 case $(get 0 $1) in
54 *35615) ( zcat || gunzip ) ;;
55 *14333) unxz ;;
56 *\ 93) unlzma ;;
57 *) cat ;;
58 esac < $1 | ( cd ${2:-/} ; cpio -idmu > /dev/null 2>&1 )
59 }
61 dotwait()
62 {
63 echo -n "${1:-Install filesystem}.."
64 touch /tmp/wait
65 while [ -e /tmp/wait ]; do
66 echo -n "." > /dev/tty
67 sleep 1
68 done &
69 }
71 getuuid()
72 {
73 dev=$(mount | sed "/ $(echo $mnt | sed 's|/|\\/|g') /!d;s/ .*//;s|/dev/||;q")
74 [ "$dev" ] &&
75 blkid | sed "/$dev:/!d;s/.* UUID=.\\([^ ]*\\)\".*/\\1/" ||
76 echo "/dev/hda1"
77 }
79 tazusbinitfs()
80 {
81 PAD=$(($(stat -c %s $1) % 4))
82 [ $PAD -ne 0 ] && ddq if=/dev/zero bs=1 count=$((4 - $PAD)) >> $1
83 mkdir -p /tmp/fs$$/etc /tmp/fs$$/lib /tmp/fs$$/home
84 cp -a /etc/locale.conf /tmp/fs$$/etc 2> /dev/null
85 cp -a /etc/keymap.conf /tmp/fs$$/etc 2> /dev/null
86 cat > /tmp/fs$$/init1 <<EOT
87 #!/bin/sh
88 sed -i 's|sbin/init|init2|' /init
89 exec /init
90 EOT
91 cat > /tmp/fs$$/init2 <<EOT
92 #!/bin/sh
94 mount -t proc /proc /proc
95 for i in /lib/*.ko* ; do insmod \$i 2> /dev/null ; done; sleep 2
96 v=\$(sed '/\\/home=/!d;s|.*/home=\\([^ ]*\\).*|\\1|' /proc/cmdline /cmdline 2> /dev/null)
97 mount / -o remount,rw
98 mkdir /mnt/dos
99 rm -f /cmdline 2> /dev/null
100 mount / -o remount,ro
101 mnt=/mnt/dos/\${v#*/}
102 dev=\$( (blkid /dev/[sh]d* || blkid) | grep \${v%%/*} | sed 's/:.*//;q')
103 echo "Mount \$dev in /mnt/dos for \$v..." | tee -a /run/boot.log
104 mount \$dev /mnt/dos
105 if [ ! -d /mnt/dos/slitaz ]; then
106 umount /mnt/dos 2> /dev/null
107 (blkid /dev/[sh]d* || blkid) | while read dev line; do
108 case "\$line" in
109 *ntfs*|*vfat*|*msdos*) ;;
110 *) continue ;;
111 esac
112 mount \${dev%:} /mnt/dos
113 [ -d /mnt/dos/slitaz ] && break
114 umount /mnt/dos
115 done
116 fi
117 mount.posixovl -F \$mnt -- -oallow_other -odefault_permissions -osuid
118 mount --bind \$mnt /home
119 umount /proc
120 exec /sbin/init
121 EOT
122 chmod 755 /tmp/fs$$/init?
123 ( cd /tmp/fs$$ ; find * | cpio -o -H newc ) | gzip -9 >> $1
124 rm -rf /tmp/fs$$
125 }
127 mkinitrd()
128 {
129 echo -en "\nCreating $(basename $1) "
130 fs=/tmp/fs$$
131 for i in bin lib dev proc tmp mnt etc ; do
132 mkdir -p $fs/$i
133 done
134 for i in /dev/console /dev/null /dev/tty /dev/tty0 /dev/tty1 /dev/tty2 \
135 /dev/fuse /dev/hd* /dev/sd* ; do
136 cp -a $2$i $fs/dev/
137 done
138 for i in /bin/busybox $(which mount.posixovl) $(which blkid); do
139 cp $(LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $i | \
140 sed 's|.*=> \(.*/lib/l[^ ]*\).*|\1|;/^\//!d') $fs/lib
141 cp $i $fs/bin
142 done
143 cp -a /lib/ld-* $fs/lib
144 for i in $(busybox | sed '/Current/,$!d'); do
145 [ -e $fs/bin/${i%,} ] || ln -s busybox $fs/bin/${i%,}
146 done
147 ln -s /proc/mounts $fs/etc/mtab
148 sed 's/ .*//' /proc/modules | while read mod ; do
149 find /lib/modules/ | grep $mod.ko | \
150 sed 's|.*|cp & $fs/lib|' | sh
151 done
152 cat > $fs/init <<EOT
153 #!/bin/sh
155 arg()
156 {
157 grep -q \$1 /proc/cmdline &&
158 val="\$(sed "s/.*\$1=\\([^ ]*\\).*/\\1/" < /proc/cmdline)" &&
159 echo "\$2 \$val"
160 }
162 mount -t proc /proc /proc
163 arg debug "shell" && debug=true && set -x
164 for i in /lib/*.ko* ; do insmod \$i 2> /dev/null ; done; sleep 2
165 arg mount "Mount device"
166 mount \$( (blkid /dev/[sh]d* || blkid) | grep \$val | sed 's/:.*//;q') /mnt
167 arg subroot "Change root to directory"
168 if [ -d /mnt/\$val ]; then
169 umount /mnt 2> /dev/null
170 (blkid /dev/[sh]d* || blkid) | while read dev line; do
171 case "\$line" in
172 *ntfs*|*vfat*|*msdos*) ;;
173 *) continue ;;
174 esac
175 mount \${dev%:} /mnt
176 [ -d /mnt/\$val ] && break
177 umount /mnt
178 done
179 fi
180 mount.posixovl -F /mnt/\$val -- -oallow_other -odefault_permissions -osuid
181 mount --bind /mnt /mnt/\$val/mnt/dos
182 mount -o size=0 -t tmpfs tmpfs /mnt/\$val/mnt/dos/\$val
183 LDSO=\$(ls /mnt/\$val/lib/ld-* | sed q)
184 export LD_LIBRARY_PATH=\$val/lib:\$val/usr/lib:/lib
185 [ "$debug" = "true" ] && sh
186 umount /proc
187 exec /bin/switch_root /mnt \${LDSO#/mnt/} \$val/usr/sbin/chroot \$val /sbin/init
188 EOT
189 chmod +x $fs/init
190 ( cd $fs ; find * | cpio -o -H newc ) | lzma e $1 -si 2> /dev/null
191 rm -rf $fs /tmp/wait
192 }
194 ls_r()
195 {
196 ls -r $@ 2> /dev/null || ls $@
197 }
199 doinstall()
200 {
201 mkdir -p $mnt/slitaz/boot $mnt/slitaz/mnt/dos
202 if ! mount.posixovl -F $mnt/slitaz -- \
203 -oallow_other -odefault_permissions -osuid; then
204 echo "Can't install SliTaz. Abort."
205 sleep 5
206 return 1
207 fi
208 dotwait "Install root filesystem in /slitaz.."
209 if [ "$1" ]; then
210 ls_r /media/cdrom/boot/rootfs*gz | \
211 xargs cat > $mnt/slitaz/boot/rootfs.gz
212 tazusbinitfs $mnt/slitaz/boot/rootfs.gz
213 initrd=rootfs.gz
214 extraargs="/home=$(getuuid)/slitaz rdinit=/init1"
215 else
216 for i in $(ls_r /media/cdrom/boot/rootfs*gz); do
217 uncpio $i $mnt/slitaz
218 done
219 for i in $packages_list; do
220 tazpkg get-install $i --root=$mnt/slitaz
221 done
222 for i in $packages_dir/*.tazpkg; do
223 [ -s "$i" ] &&
224 tazpkg install $i --root=$mnt/slitaz
225 done
226 cp -a /etc/locale.conf $mnt/slitaz/etc 2> /dev/null
227 cp -a /etc/keymap.conf $mnt/slitaz/etc 2> /dev/null
228 mkinitrd $mnt/slitaz/boot/initrd $mnt/slitaz
229 initrd=initrd
230 extraargs="mount=$(getuuid) subroot=slitaz"
231 fi
232 echo -en "\nInstall boot files..."
233 for i in /media/cdrom/boot/bzImage /media/cdrom/boot/*pxe* \
234 /media/cdrom/boot/isolinux/he* /media/cdrom/boot/isolinux/opt* \
235 /media/cdrom/README /media/cdrom/boot/memtest* ; do
236 [ -s $i ] && cp $i $mnt/slitaz/boot
237 done
238 for i in $mnt/slitaz/boot/memtest $mnt/slitaz/boot/*pxe* ; do
239 [ $(get 0 $i 2> /dev/null || echo 0) -eq 23117 ] &&
240 mv $i $i.exe
241 done
242 gettazboot $mnt/slitaz/boot/tazboot.exe
243 unix2dos > $mnt/slitaz/boot/tazboot.cmd <<EOT
244 kernel=/slitaz/boot/bzimage
245 initrd=/slitaz/boot/$initrd
246 rw root=/dev/null $extraargs autologin
247 EOT
248 unix2dos $mnt/slitaz/boot/he* $mnt/slitaz/boot/opt* \
249 $mnt/slitaz/boot/README
250 [ -d $mnt/slitaz/usr/sbin -a ! -x $mnt/slitaz/usr/sbin/mount.posixovl ] &&
251 cp $(which mount.posixovl) $mnt/slitaz/usr/sbin
252 rm -f /tmp/wait
253 umount $mnt/slitaz
254 return 0
255 }
257 windev()
258 {
259 if [ -b "$1" ]; then
260 device=$1
261 else
262 DEV="$(blkid | grep -iE "(msdos|vfat|ntfs)" | sed 's/:.*//;s|/dev/||')"
263 [ "$DEV" ] || return
264 cat > /tmp/dialog$$ <<EOT
265 $DIALOG --clear \
266 --title " Select your Windows partition " \
267 --menu "\nPlease select the Windows partition according to its known size.
268 The data will be kept untouched.\n" \
269 17 70 8 \
270 $(for i in $DEV ; do
271 label="$(blkid | sed "/$i:/!d;s/.*://;s/[^ ]*UUID=[^ ]* //g;s/LABEL=//")"
272 echo -n "/dev/$i \"$(($(cat /sys/block/*/$i/size)/2048))MB $label\" "
273 done)
274 EOT
275 exec 3>&1
276 [ $? -eq 0 ] || return
277 device=$(. /tmp/dialog$$ 2>&1 1>&3)
278 exec 3>&-
279 rm -f /tmp/dialog$$
280 fi
281 mnt=/tmp/mnt$$
282 mkdir -p $mnt && mount $device $mnt
283 }
285 extra_packages()
286 {
287 packages_list=
288 packages_dir=
289 $DIALOG --clear \
290 --title " Extra packages " \
291 --defaultno --yesno \
292 "
293 Do you want to add extra packages ?
294 " 7 70
295 [ $? -eq 0 ] || return
296 [ -s /var/lib/tazpkg/packages.txt ] || tazpkg recharge
297 if [ -s /media/cdrom/boot/vmlinuz-$(uname -r) ]; then
298 cat > /tmp/dialog$$ <<EOT
299 $DIALOG --clear \
300 --title " Select the packages " \
301 --separate-output \
302 --cancel-label "Skip" \
303 --checklist "Please select the packages you want to install. Try with the first letter." \
304 23 78 20 \\
305 EOT
306 awk -F\| '{ printf "%s \"%s\" off ",$1,$3 }' \
307 /var/lib/tazpkg/packages.desc >> /tmp/dialog$$
308 sh /tmp/dialog$$ 2> /tmp/dialog.out$$
309 [ $? -eq 0 ] && packages_list="$(cat /tmp/dialog.out$$)"
310 fi
311 cat > /tmp/dialog$$ <<EOT
312 $DIALOG --clear \
313 --title "Please select the directory with every custom package to install." \
314 --cancel-label "Skip" \
315 --dselect $PWD 13 78
316 EOT
317 sh /tmp/dialog$$ 2> /tmp/dialog.out$$
318 [ $? -eq 0 ] && packages_dir="$(cat /tmp/dialog.out$$)"
319 rm -f /tmp/dialog$$ /tmp/dialog.out$$
320 }
322 _install()
323 {
324 extra_packages
325 $DIALOG --clear \
326 --title " SliTaz UMSDOS way installation " \
327 --yes-label "Install" --yesno \
328 "\nSliTaz will be installed in the subdirectory \\slitaz of the current
329 DOS/Windows partition. You will see your files from /mnt/dos.\n\n
330 You can start SliTaz with \\slitaz\\boot\\tazboot.exe\n\n
331 To uninstall SliTaz, you have only to remove this directory.
332 The file \\boot.ini or \\config.sys may be modified too.\n\n
333 SliTaz may run slowly on 'UMSDOS way' installation due to the
334 posixovl filesystem. The 'TAZUSB way' installation runs faster.\n\n
335 To do a traditional installation with disk partitioning,
336 start SliTaz Live with 'SliTaz RAM boot' menu.\n
337 " 19 70
338 [ $? -eq 0 ] || return
339 doinstall
340 }
342 readtazbootconf()
343 {
344 kernel="$(sed '/^kernel=/!d;s/.*=//' $mnt/slitaz/boot/tazboot.cmd)"
345 initrd="$(sed '/^initrd=/!d;s/.*=//' $mnt/slitaz/boot/tazboot.cmd)"
346 cmdline="$(sed '/^kernel=/d;/^initrd=/d' $mnt/slitaz/boot/tazboot.cmd)"
347 }
349 bootinstalled()
350 {
351 [ "$(which kexec)" ] || return
352 [ -x $mnt/slitaz$1 ] || return
353 [ -s $mnt/slitaz/boot/tazboot.cmd ] || return
354 readtazbootconf
355 kexec -l $kernel --initrd $initrd --command-line "$cmdline" || return
356 umount $mnt
357 rm -rf $mnt
358 umount -d /media/cdrom
359 kexec -e
360 }
362 mkzip()
363 {
364 device=
365 packages_list=
366 packages_dir=
367 mnt=/tmp/mnt$$
368 mkdir -p $mnt
369 $1 || return
370 wget -O $mnt/slitaz/boot/grldr http://mirror.slitaz.org/boot/grldr
371 readtazbootconf
372 cat > $mnt/slitaz/boot/menu.lst <<EOT
373 title SliTaz
374 kernel $kernel $cmdline
375 initrd $initrd
377 EOT
378 while read file title; do
379 file=$(ls $mnt/slitaz/boot/*$file* 2> /dev/null)
380 [ -s "$file" ] && cat >> $mnt/slitaz/boot/menu.lst <<EOT
381 title $title
382 kernel ${file#$mnt}
384 EOT
385 done <<EOT
386 memtest MemTest
387 pxe Web boot
388 EOT
389 unix2dos $mnt/slitaz/boot/menu.lst
390 unix2dos > $mnt/slitaz/boot/install.txt <<EOT
391 For DOS users (real mode only):
393 Start SliTaz with \\slitaz\\boot\\tazboot.exe
396 For NT/2000/XP users:
398 1- Move the files grldr and menu.lst into the root directory
400 C:\\> copy \\slitaz\\boot\\grldr \\
401 C:\\> copy \\slitaz\\boot\\menu.lst \\
403 2- Remove boot.ini attributes
405 C:\\> attrib -r -h -s boot.ini
407 3- Append the following line to boot.init
409 C:\\grldr="slitaz"
411 4- Restore boot.ini attributes
413 C:\\> attrib +r +h +s boot.ini
415 See http://diddy.boot-land.net/grub4dos/files/README_GRUB4DOS.txt
416 EOT
417 ( cd $mnt ; zip -r9 $(basename $ISO .iso).zip slitaz )
418 [ "$(which advzip)" ] && advzip -z4 $mnt/*.zip
419 mv $mnt/*.zip .
420 umount $mnt
421 rm -rf $mnt
422 }
424 install()
425 {
426 windev $1 || return
427 packages_list=
428 packages_dir=
429 if [ "$1" ]; then
430 doinstall
431 else
432 _install && bootinstalled /sbin/init
433 fi
434 umount $mnt
435 rm -rf $mnt
436 }
438 inst2zip()
439 {
440 if [ "$1" ]; then
441 doinstall
442 else
443 mkzip _install
444 fi
445 }
447 _installtaz()
448 {
449 $DIALOG --clear \
450 --title " SliTaz TAZUSB way installation " \
451 --yes-label "Install" --yesno \
452 "\nSliTaz will be installed in the subdirectory \\slitaz of the current
453 DOS/Windows partition. You will see your files from /mnt/dos.\n\n
454 You can start SliTaz with \\slitaz\\boot\\tazboot.exe\n\n
455 To uninstall SliTaz, you have only to remove this directory.
456 The file \\boot.ini or \\config.sys may be modified too.\n\n
457 The filesystem is loaded entirely into memory upon boot to
458 increase responsiveness. Only /home lands on hard disk.\n\n
459 To do a traditional installation with disk partitioning,
460 start SliTaz Live with 'SliTaz RAM boot' menu.\n
461 " 19 70
462 [ $? -eq 0 ] || return
463 doinstall tazusblike
464 }
466 installtaz()
467 {
468 windev $1 || return
469 packages_list=
470 packages_dir=
471 if [ "$1" ]; then
472 doinstall tazusblike
473 else
474 _installtaz && bootinstalled /boot/bzimage
475 fi
476 umount $mnt
477 rm -rf $mnt
478 }
480 insttaz2zip()
481 {
482 if [ "$1" ]; then
483 doinstall tazusblike
484 else
485 mkzip _installtaz
486 fi
487 }
489 bootiso()
490 {
491 for i in $(ls_r /media/cdrom/boot/rootfs*gz); do
492 grep -q ' lm ' /proc/cpuinfo && [ -s ${i}64 ] && i=${i}64
493 cat $i
494 n=$((4 - ($(stat -c %s $i) % 4)))
495 [ $n -eq 4 ] || dd if=/dev/zero bs=1 count=$n
496 done > /tmp/initrd$$
497 kernel=/media/cdrom/boot/bzImage
498 grep -q ' lm ' /proc/cpuinfo && [ -s ${kernel}64 ] && kernel=${kernel}64
499 . /etc/locale.conf
500 kexec -l $kernel --initrd /tmp/initrd$$ --command-line \
501 "root=/dev/null autologin lang=$LANG kmap=$(cat /etc/keymap.conf)" &&
502 umount -d /media/cdrom
503 rm -f /tmp/initrd$$
504 kexec -e
505 }
507 tazboot()
508 {
509 $DIALOG --clear \
510 --title " SliTaz bootloader for DOS " \
511 --yes-label "Install" --yesno \
512 "\nThe file TAZBOOT.EXE will be created in the top directory. It supports
513 any linux kernel, multiple initramfs, a kernel command line and
514 an ISO image file loopback (retrieves files from an ISO file).\n\n
515 Usage: tazboot.exe [[@commands]|[kernel=<bzimage>]
516 [initrd=<rootfs>[,<rootfs2>...]] [bootfrom=<isofile>] cmdline args ...]\n\n
517 Defaults: tazboot @tazboot.cmd or tazboot kernel=bzImage auto\n\n\
518 Examples for tazboot.cmd:\n\n\
519 bootfrom=\\isos\\slitaz-4.0.iso\n\
520 kernel=boot/bzImage\n\
521 initrd=boot/rootfs4.gz,boot/rootfs3.gz,boot/rootfs2.gz,boot/rootfs1.gz\n\
522 rw root=/dev/null autologin\n\n\
523 kernel=\\slitaz\\vmlinuz root=/dev/sda5 ro\n\n
524 Unlike GRUB4DOS, it doesn't require unfragmented ISO image files.\n
525 " 24 78
526 [ $? -eq 0 ] || return
527 gettazboot tazboot.exe
528 }
530 md5()
531 {
532 dotwait "Checking files"
533 ( cd /media/cdrom ; ${1:-md5sum -c md5sum*} ) > /tmp/data
534 rm -f /tmp/wait
535 if [ "$1 "]; then
536 cat /tmp/data
537 else
538 $DIALOG --clear \
539 --title " Checked files " \
540 --textbox /tmp/data 24 78
541 fi
542 rm -f /tmp/data
543 }
545 gotcdfile()
546 {
547 for i in "/media/cdrom/$1" "/media/cdrom/*/$1" \
548 "/media/cdrom/*/isolinux/$1" ; do
549 file=$(ls $i 2> /dev/null | sed q)
550 [ -s "$file" ] && break
551 done
552 }
554 sha()
555 {
556 gotcdfile 'sha*sum*'
557 sha=$(basename $file)
558 md5 "${sha%sum*}sum -c ${file#/media/cdrom/}" $@
559 }
561 readme()
562 {
563 gotcdfile 'README*'
564 if [ "$1" ]; then
565 cat $file
566 else
567 $DIALOG --clear \
568 --title " Readme " \
569 --textbox $file 24 78
570 fi
571 }
573 bzimage()
574 {
575 if [ "$1" ]; then
576 $DIALOG --clear \
577 --title " Create linux.exe ? " \
578 --yes-label "Install" --yesno \
579 "\nLinux.exe launches the linux kernel under DOS (in real mode only).
580 The cmdline arguments are supported except initrd=,
581 vga= (you can try 'rdev -v') and mem= (partially).
582 \nExample:\nC:\\> linux.exe root=/dev/hda2 ro panic=60\n
583 " 12 70
584 [ $? -eq 0 ] || return
585 fi
586 cp /media/cdrom/boot/bzImage linux.exe
587 }
589 memtest()
590 {
591 if [ -z "$1" ]; then
592 $DIALOG --clear \
593 --title " Create memtest.exe ? " \
594 --yes-label "Install" --yesno \
595 "\nMemtest86 is a thorough, stand alone memory test for x86 architecture
596 computers. BIOS based memory tests are a quick, cursory check and often
597 miss many of the failures that are detected by Memtest86.\n
598 " 12 70
599 [ $? -eq 0 ] || return
600 fi
601 gotcdfile 'memtest*' && cp $file memtest.exe
602 }
604 mkfat12()
605 {
606 [ $(($(get 0 $1) - 0x5A4D)) -eq 0 ] || return
607 J=$(($(get 3 $1 1) + 0x02))
608 R=$((1 + $(get 497 $1 1) + 1 + ($(get 500 $1)-1)/32))
609 [ $R -lt 2500 ] || return
610 [ $((($(get 500 $1)-1) & 31)) -lt 30 ] &&
611 ddq if=$file bs=32 count=1 seek=$(($R*16 - 1)) of=/dev/fd0
612 G="18 0 2 0 0 0 0 0"
613 [ $J -gt 25 ] || G=""
614 F=0
615 for i in 1 2 3; do
616 F=$((((2880-$R-$F-$F)*3+1023)/1024))
617 done
618 bytes2bin 0xEB $J 0x90 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 \
619 0 2 2 $(($R%256)) $(($R/256)) 2 64 0 64 11 0xF0 $F 0 \
620 $G | ddq bs=1 of=/dev/fd0
621 ddq if=/dev/zero bs=512 count=$((4+$F+$F)) seek=$R of=/dev/fd0
622 for i in $R $(($R+$F)) ; do
623 bytes2bin 0xF0 0xFF 0xFF | ddq bs=512 seek=$i of=/dev/fd0
624 done
625 echo -n $(basename $1) | ddq bs=1 seek=3 count=8 of=/dev/fd0
626 }
628 mkfloppy()
629 {
630 dotwait "Create a $(basename $1) boot floppy"
631 ddq if=$1 of=/dev/fd0
632 mkfat12 $1
633 rm -f /tmp/wait
634 }
636 fdmemtest()
637 {
638 if [ -z "$1" ]; then
639 $DIALOG --clear \
640 --title " Create a Memtest86 boot floppy " \
641 --yes-label "Create floppy" --yesno \
642 "\nMemtest86 is a thorough, stand alone memory test for x86 architecture
643 computers. BIOS based memory tests are a quick, cursory check and often
644 miss many of the failures that are detected by Memtest86.\n\n
645 Please insert a blank disk in floppy drive.\n
646 " 12 70
647 [ $? -eq 0 ] || return
648 fi
649 gotcdfile 'memtest*' && mkfloppy $file
650 }
652 pxe()
653 {
654 gotcdfile '?pxe'
655 $DIALOG --clear \
656 --title " Create $(basename $file).exe ? " \
657 --yes-label "Install" --yesno \
658 "\nBoot your operating system from the internet and enjoy a full system
659 working entirely in RAM with speed and stability in mind. The Linux Kernel
660 and the complete SliTaz compressed root filesystem will be loaded into RAM
661 from the Web using PXE and HTTP protocols.\n
662 " 12 70
663 [ $? -eq 0 ] || return
664 cp $file $(basename $file).exe
665 }
667 fdpxe()
668 {
669 if [ -z "$1" ]; then
670 $DIALOG --clear \
671 --title " Create a SliTaz Web boot floppy " \
672 --yes-label "Create floppy" --yesno \
673 "\nBoot your operating system from the internet and enjoy a full system
674 working entirely in RAM with speed and stability in mind. The Linux Kernel
675 and the complete SliTaz compressed root filesystem will be loaded into RAM
676 from the Web using PXE and HTTP protocols.\n\n
677 Please insert a blank disk in floppy drive.\n
678 " 12 70
679 [ $? -eq 0 ] || return
680 fi
681 gotcdfile '?pxe' && mkfloppy $file
682 }
684 menuitem()
685 {
686 [ "$3" ] && shift
687 echo -en "\"$1\" \"$2\""
688 }
690 gotposixovl()
691 {
692 mount.posixovl 2>&1 | grep -qi usage && menuitem "$@"
693 }
695 gotposixovlzip()
696 {
697 [ "$(which zip)" ] && gotposixovl "$1" "$2"
698 }
700 xfile()
701 {
702 [ "$(which $1)" ] && menuitem "$@"
703 }
705 cdfile()
706 {
707 gotcdfile "$1" && menuitem "$@"
708 }
710 isbzImage()
711 {
712 [ $(get 514 $file 4) -eq 1400005704 ] &&
713 [ $(($(get 529 $file 1) & 1)) -eq 1 ]
714 }
716 cdfilex()
717 {
718 gotcdfile "$1" && [ "$(which kexec)" ] && isbzImage && menuitem "$@"
719 }
721 cdfilef()
722 {
723 [ -e /sys/block/fd0 ] && cdfile "$@"
724 }
726 cdexe()
727 {
728 gotcdfile "$1" &&
729 [ $(get 0 $file 2>/dev/null || echo 0) -eq 23117 ] &&
730 menuitem "$@"
731 }
733 misspkg()
734 {
735 for i in zip kexec-tools posixovl ; do
736 [ -d /var/lib/tazpkg/installed/$i/ ] && continue
737 [ "$1" != "install" ] && menuitem "$@" && return
738 tazpkg get-install $i
739 done
740 }
742 missing()
743 {
744 misspkg install
745 }
747 ishybrid()
748 {
749 C=$((2048*$(get $(((17*2048) + 71)) $ISO 4)))
750 [ $(get $C $ISO 4) -eq 1 ] || return
751 [ $(get $(($C+30)) $ISO 4) -eq $((0x88AA55)) ] || return
752 C=$((2048*$(get $(($C+40)) $ISO 4)))
753 [ $(get $(($C+64)) $ISO 4) -eq 1886961915 ] && menuitem "$@"
754 }
756 isiso()
757 {
758 [ $(get 32769 $ISO 4) -eq 808469571 ] && menuitem "$@"
759 }
761 gotisomd5()
762 {
763 [ "$(which md5sum 2> /dev/null)" ] &&
764 [ $(get 0 $ISO) -eq 23117 ] &&
765 [ $(get 18 $ISO) -ne 0 ] && menuitem "$@"
766 }
768 isomd5()
769 {
770 dotwait "Checking iso image"
771 [ "$(ddq if=$ISO bs=2k skip=16 \
772 count=$(echo $(get 32848 $ISO 4)) | md5sum)" == \
773 "$(ddq if=$ISO bs=16 count=1 skip=2047 | od -N 16 -t x1 -An | \
774 sed 's/ //g') -" ] && echo "OK" || echo "ERROR"
775 echo -en "\rChecking iso hybrid boot..."
776 n=$(($(get 2 $ISO)-1+($(get 4 $ISO)-1)*512))
777 if [ $n -lt 40000 -a $n -gt 32768 ]; then
778 s=$(get 0 $ISO 2 $n | awk '{ i+= $0 } END { print i }')
779 [ $(((1+$s+$(get $(($n+1)) $ISO 1)) % 65536)) -eq 0 ] &&
780 echo "OK" || echo "ERROR"
781 fi
782 rm -f /tmp/wait
783 [ "$1" ] || return 0
784 echo -e "\rPress RETURN to continue."
785 read n
786 }
788 usbdev()
789 {
790 dotwait "Wait 5 seconds for USB devices"
791 sleep 5
792 rm -f /tmp/wait
793 DEV="$(grep -l 1 /sys/block/*/removable | \
794 sed 's|/sys/block/\(.*\)/removable|\1|')"
795 grep -qs 1 /sys/block/$DEV/ro && return
796 [ "$DEV" ] || return
797 cat > /tmp/dialog$$ <<EOT
798 $DIALOG --clear \
799 --title " Select your USB key " \
800 --menu "\nPlease select the USB key according to its known size.\n\n" \
801 14 70 4 \
802 $(for i in $DEV ; do
803 echo -n "/dev/$i \"$(($(cat /sys/block/$i/size)/2048))MB $(cat /sys/block/$i/device/model 2> /dev/null)\" "
804 done) \
806 EOT
807 exec 3>&1
808 device=$(. /tmp/dialog$$ 2>&1 1>&3)
809 rm -f /tmp/dialog$$
810 retval=$?
811 exec 3>&-
812 rm -f /tmp/dialog$$
813 [ $retval -eq 0 ]
814 }
816 tazusbmsg()
817 {
818 [ "$(which tazusb 2> /dev/null)" ] || return
819 echo "You should choose 'USB key read/write installation' to be
820 able to save the package updates or your own configuration and data files.\n\n"
821 }
823 usbbootkey()
824 {
825 if [ -b "$1" ]; then
826 device=$1
827 else
828 $DIALOG --clear \
829 --title " Create a USB boot key " \
830 --yes-label "Continue" --yesno \
831 "\nThe USB key will be used like a CD-ROM. You will not be able to write
832 any data on the boot partition.\n\n
833 An extra FAT32 partition will be created with the remaining free space.\n\n
834 $(tazusbmsg)Please plug your USB stick in now.\n
835 " 16 70
836 [ $? -eq 0 ] || return
837 usbdev || return
839 # perform dd in progress bar
840 max=$(($(stat -c %s $ISO)/2048))
841 i=0; ddq if=$ISO bs=1024k | (
842 while ddq bs=1024k count=1 ; do
843 i=$(($i + 1))
844 [ $i -gt $max ] && break
845 echo $((($i*100)/$max)) | dialog --gauge \
846 " The ISO image transfer can be long. Please wait..." \
847 6 70 0 > /dev/tty 2>&1
848 done ) > $device
849 fi
851 # partition + fat32 format for the remaining space
852 for p in 0 16; do
853 get $((450+$p)) $device 2 12 | xargs echo | {
854 read dx cx ol oh ll lh
855 [ $dx -eq $((0x3F17)) ] || continue
856 cx=$(($cx & 0xFF00))
857 ofs=$(($ll+($lh<<16)))
858 n=$(($(cat /sys/block/${device#/dev/}/size)-$ofs))
859 m=$(($cx+($n/8)))
860 [ $m -gt $((0x3FF00)) ] && m=$((0x3FF00))
861 m=$((($m & 0xFF00)+(($m>>16)<<6)))
862 words2bin 0 $((0x101+$cx)) 0x3F0B $((32+$m)) \
863 $ll $lh $(($n & 0xFFFF)) $(($n >> 16)) | \
864 ddq bs=1 seek=$((462-$p)) of=$device
865 if [ "$(which mkdosfs 2> /dev/null)" ]; then
866 losetup -o $((512*$ofs)) /dev/loop2 $device
867 mkdosfs -n "SLITAZ BOOT" /dev/loop2
868 words2bin $(($ofs & 0xFFFF)) $(($ofs >> 16)) | \
869 ddq bs=1 seek=28 of=/dev/loop2
870 sync
871 losetup -d /dev/loop2
872 fi
873 }
874 done
875 }
877 usbkey()
878 {
879 $DIALOG --clear \
880 --title " Create a SliTaz USB key " \
881 --yes-label "Continue" --yesno \
882 "\nUnlike a hard drive install, the filesystem is kept in a compressed
883 rootfs.gz. The filesystem is loaded entirely into memory upon boot.
884 This should increase responsiveness, protect the filesystem against
885 accidental corruption and reduce read/writes to the USB drive.
886 Once setup, the tazusb utility can rewrite the root filesystem
887 with any changes you have made since booting up,
888 giving the effective benefits of a hard drive install.\n\n
889 /home is mounted on boot using the UUID of your particular flash drive.
890 Unlike a device name, the UUID has the benefit of never changing from machine
891 to machine.\n\n
892 Please plug your USB stick in now.\n
893 " 19 70
894 [ $? -eq 0 ] || return
895 usbdev || return
896 exec 3>&1
897 format=`$DIALOG --clear \
898 --title " Select the filesystem " \
899 --radiolist "\nPlease select the filesystem type to create.\n\n\
900 The filesystem creation will erase all the data \
901 in the USB key." 14 70 4 \
902 "none" "Do not erase the USB key" on \
903 "ext3" "Ext3 journaling filesystem" off \
904 "ext2" "Ext2 filesystem" off \
905 "fat32" "Windows FAT32 filesystem" off \
906 2>&1 1>&3`
907 retval=$?
908 exec 3>&-
909 [ $retval -eq 0 ] || return
910 [ "$format" != "none" ] && tazusb format $device "SliTaz" $format
911 tazusb gen-iso2usb $ISO $device
912 }
914 dokexec()
915 {
916 kexec -l $file || return
917 umount -d /media/cdrom
918 kexec -e
919 }
921 runmemtest()
922 {
923 gotcdfile 'memtest*' && dokexec
924 }
926 runpxe()
927 {
928 gotcdfile '?pxe' && dokexec
929 }
931 quit()
932 {
933 umount -d /media/cdrom
934 exit
935 }
937 ISO="$1"
938 [ -z "$(isiso 2> /dev/null)" ] && echo "Usage : $0 file.iso" && exit 1
939 mount -o loop,ro $ISO /media/cdrom
941 if grep -q "^$2()" $0; then
942 exe=$2
943 shift 2
944 if [ "$(eval $(grep "\"$exe\"" $0 | \
945 sed '/^\$/!d;s/.(\(.*\)[\t ]*".*"[\t ]*".*/\1/'))" ]; then
946 grep "\"$exe\"" $0 | sed '/^\$/!d;s/.*"[\t ]*"\(.*\)".*/\1/'
947 $exe "$@"
948 fi
949 quit
950 fi
952 while true; do
953 cat > /tmp/dialog$$ <<EOT
954 $DIALOG --clear \
955 --title " SliTaz ISO tool " \
956 --menu "" 23 70 17 \
957 $(cdfile 'README*' "readme" "Show the README file") \
958 $(gotisomd5 "isomd5" "Check the ISO image") \
959 $(cdfile 'md5sum*' "md5" "Check the ISO files") \
960 $(cdfile 'sha*sum*' "sha" "Check the ISO files") \
961 $(cdfilex boot/bzImage "bootiso" "Boot the ISO image") \
962 $(gotposixovl "install" "Hard disk installation (UMSDOS way)") \
963 $(gotposixovl "installtaz" "Hard disk installation (TAZUSB way)") \
964 $(gotposixovlzip "inst2zip" "ZIP installation archive (UMSDOS way)") \
965 $(gotposixovlzip "insttaz2zip" "ZIP installation archive (TAZUSB way)") \
966 $(xfile tazusb "usbkey" "USB key read/write installation") \
967 $(ishybrid "usbbootkey" "USB boot key (read only)") \
968 $(menuitem "tazboot" "Get tazboot.exe Linux loader") \
969 $(cdexe boot/bzImage "bzimage" "Get linux DOS/EXE file") \
970 $(cdexe 'memtest*' "memtest" "Get Memtest86 DOS/EXE file") \
971 $(cdfilef 'memtest*' "fdmemtest" "Create a Memtest86 boot floppy") \
972 $(cdfilex 'memtest*' "runmemtest" "Start Memtest86") \
973 $(cdexe '?pxe' "pxe" "Get SliTaz Web boot DOS/EXE utility") \
974 $(cdfilef '?pxe' "fdpxe" "Create a SliTaz Web boot floppy") \
975 $(cdfilex '?pxe' "runpxe" "Start the SliTaz Web boot utility") \
976 $(misspkg "missing" "Install packages to get more options") \
977 $(menuitem "quit" "Quit this utility")
978 EOT
979 exec 3>&1
980 value=$(. /tmp/dialog$$ 2>&1 1>&3)
981 retval=$?
982 exec 3>&-
983 rm -f /tmp/dialog$$
984 [ $retval -eq 0 ] || continue
985 $value
986 done