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

Up to latest: tazinst-gui, tazinst, tazpanel
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Apr 11 17:40:38 2015 +0200 (2015-04-11)
parents 250b01dd3a54
children 08aeb1a2f744
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 elif [ "$1" ]; then
262 echo "Invalid Windows partition"
263 return 1
264 else
265 DEV="$(blkid | grep -iE "(msdos|vfat|ntfs)" | sed 's/:.*//;s|/dev/||')"
266 [ "$DEV" ] || return
267 cat > /tmp/dialog$$ <<EOT
268 $DIALOG --clear \
269 --title " Select your Windows partition " \
270 --menu "\nPlease select the Windows partition according to its known size.
271 The data will be kept untouched.\n" \
272 17 70 8 \
273 $(for i in $DEV ; do
274 label="$(blkid | sed "/$i:/!d;s/.*://;s/[^ ]*UUID=[^ ]* //g;s/LABEL=//")"
275 echo -n "/dev/$i \"$(($(cat /sys/block/*/$i/size)/2048))MB $label\" "
276 done)
277 EOT
278 exec 3>&1
279 [ $? -eq 0 ] || return
280 device=$(. /tmp/dialog$$ 2>&1 1>&3)
281 exec 3>&-
282 rm -f /tmp/dialog$$
283 fi
284 mnt=/tmp/mnt$$
285 mkdir -p $mnt && mount $device $mnt
286 }
288 extra_packages()
289 {
290 packages_list=
291 packages_dir=
292 $DIALOG --clear \
293 --title " Extra packages " \
294 --defaultno --yesno \
295 "
296 Do you want to add extra packages ?
297 " 7 70
298 [ $? -eq 0 ] || return
299 [ -s /var/lib/tazpkg/packages.txt ] || tazpkg recharge
300 if [ -s /media/cdrom/boot/vmlinuz-$(uname -r) ]; then
301 cat > /tmp/dialog$$ <<EOT
302 $DIALOG --clear \
303 --title " Select the packages " \
304 --separate-output \
305 --cancel-label "Skip" \
306 --checklist "Please select the packages you want to install. Try with the first letter." \
307 23 78 20 \\
308 EOT
309 awk -F\| '{ printf "%s \"%s\" off ",$1,$3 }' \
310 /var/lib/tazpkg/packages.desc >> /tmp/dialog$$
311 sh /tmp/dialog$$ 2> /tmp/dialog.out$$
312 [ $? -eq 0 ] && packages_list="$(cat /tmp/dialog.out$$)"
313 fi
314 cat > /tmp/dialog$$ <<EOT
315 $DIALOG --clear \
316 --title "Please select the directory with every custom package to install." \
317 --cancel-label "Skip" \
318 --dselect $PWD 13 78
319 EOT
320 sh /tmp/dialog$$ 2> /tmp/dialog.out$$
321 [ $? -eq 0 ] && packages_dir="$(cat /tmp/dialog.out$$)"
322 rm -f /tmp/dialog$$ /tmp/dialog.out$$
323 }
325 _install()
326 {
327 extra_packages
328 $DIALOG --clear \
329 --title " SliTaz UMSDOS way installation " \
330 --yes-label "Install" --yesno \
331 "\nSliTaz will be installed in the subdirectory \\slitaz of the current
332 DOS/Windows partition. You will see your files from /mnt/dos.\n\n
333 You can start SliTaz with \\slitaz\\boot\\tazboot.exe\n\n
334 To uninstall SliTaz, you have only to remove this directory.
335 The file \\boot.ini or \\config.sys may be modified too.\n\n
336 SliTaz may run slowly on 'UMSDOS way' installation due to the
337 posixovl filesystem. The 'TAZUSB way' installation runs faster.\n\n
338 To do a traditional installation with disk partitioning,
339 start SliTaz Live with 'SliTaz RAM boot' menu.\n
340 " 19 70
341 [ $? -eq 0 ] || return
342 doinstall
343 }
345 readtazbootconf()
346 {
347 kernel="$(sed '/^kernel=/!d;s/.*=//' $mnt/slitaz/boot/tazboot.cmd)"
348 initrd="$(sed '/^initrd=/!d;s/.*=//' $mnt/slitaz/boot/tazboot.cmd)"
349 cmdline="$(sed '/^kernel=/d;/^initrd=/d' $mnt/slitaz/boot/tazboot.cmd)"
350 }
352 bootinstalled()
353 {
354 [ "$(which kexec)" ] || return
355 [ -x $mnt/slitaz$1 ] || return
356 [ -s $mnt/slitaz/boot/tazboot.cmd ] || return
357 readtazbootconf
358 kexec -l $kernel --initrd $initrd --command-line "$cmdline" || return
359 umount $mnt
360 rm -rf $mnt
361 umount -d /media/cdrom
362 kexec -e
363 }
365 mkzip()
366 {
367 device=
368 packages_list=
369 packages_dir=
370 mnt=/tmp/mnt$$
371 mkdir -p $mnt
372 $1 || return
373 wget -O $mnt/slitaz/boot/grldr http://mirror.slitaz.org/boot/grldr
374 readtazbootconf
375 cat > $mnt/slitaz/boot/menu.lst <<EOT
376 title SliTaz
377 kernel $kernel $cmdline
378 initrd $initrd
380 EOT
381 while read file title; do
382 file=$(ls $mnt/slitaz/boot/*$file* 2> /dev/null)
383 [ -s "$file" ] && cat >> $mnt/slitaz/boot/menu.lst <<EOT
384 title $title
385 kernel ${file#$mnt}
387 EOT
388 done <<EOT
389 memtest MemTest
390 pxe Web boot
391 EOT
392 unix2dos $mnt/slitaz/boot/menu.lst
393 unix2dos > $mnt/slitaz/boot/install.txt <<EOT
394 For DOS users (real mode only):
396 Start SliTaz with \\slitaz\\boot\\tazboot.exe
399 For NT/2000/XP users:
401 1- Move the files grldr and menu.lst into the root directory
403 C:\\> copy \\slitaz\\boot\\grldr \\
404 C:\\> copy \\slitaz\\boot\\menu.lst \\
406 2- Remove boot.ini attributes
408 C:\\> attrib -r -h -s boot.ini
410 3- Append the following line to boot.init
412 C:\\grldr="slitaz"
414 4- Restore boot.ini attributes
416 C:\\> attrib +r +h +s boot.ini
418 See http://diddy.boot-land.net/grub4dos/files/README_GRUB4DOS.txt
419 EOT
420 ( cd $mnt ; zip -r9 $(basename $ISO .iso).zip slitaz )
421 [ "$(which advzip)" ] && advzip -z4 $mnt/*.zip
422 mv $mnt/*.zip .
423 umount $mnt
424 rm -rf $mnt
425 }
427 install()
428 {
429 windev $1 || return
430 packages_list=
431 packages_dir=
432 if [ "$1" ]; then
433 doinstall
434 else
435 _install && bootinstalled /sbin/init
436 fi
437 umount $mnt
438 rm -rf $mnt
439 }
441 inst2zip()
442 {
443 if [ "$1" ]; then
444 doinstall
445 else
446 mkzip _install
447 fi
448 }
450 _installtaz()
451 {
452 $DIALOG --clear \
453 --title " SliTaz TAZUSB way installation " \
454 --yes-label "Install" --yesno \
455 "\nSliTaz will be installed in the subdirectory \\slitaz of the current
456 DOS/Windows partition. You will see your files from /mnt/dos.\n\n
457 You can start SliTaz with \\slitaz\\boot\\tazboot.exe\n\n
458 To uninstall SliTaz, you have only to remove this directory.
459 The file \\boot.ini or \\config.sys may be modified too.\n\n
460 The filesystem is loaded entirely into memory upon boot to
461 increase responsiveness. Only /home lands on hard disk.\n\n
462 To do a traditional installation with disk partitioning,
463 start SliTaz Live with 'SliTaz RAM boot' menu.\n
464 " 19 70
465 [ $? -eq 0 ] || return
466 doinstall tazusblike
467 }
469 installtaz()
470 {
471 windev $1 || return
472 packages_list=
473 packages_dir=
474 if [ "$1" ]; then
475 doinstall tazusblike
476 else
477 _installtaz && bootinstalled /boot/bzimage
478 fi
479 umount $mnt
480 rm -rf $mnt
481 }
483 insttaz2zip()
484 {
485 if [ "$1" ]; then
486 doinstall tazusblike
487 else
488 mkzip _installtaz
489 fi
490 }
492 bootiso()
493 {
494 for i in $(ls_r /media/cdrom/boot/rootfs*gz); do
495 grep -q ' lm ' /proc/cpuinfo && [ -s ${i}64 ] && i=${i}64
496 cat $i
497 n=$((4 - ($(stat -c %s $i) % 4)))
498 [ $n -eq 4 ] || dd if=/dev/zero bs=1 count=$n
499 done > /tmp/initrd$$
500 kernel=/media/cdrom/boot/bzImage
501 grep -q ' lm ' /proc/cpuinfo && [ -s ${kernel}64 ] && kernel=${kernel}64
502 . /etc/locale.conf
503 kexec -l $kernel --initrd /tmp/initrd$$ --command-line \
504 "root=/dev/null autologin lang=$LANG kmap=$(cat /etc/keymap.conf)" &&
505 umount -d /media/cdrom
506 rm -f /tmp/initrd$$
507 kexec -e
508 }
510 tazboot()
511 {
512 if [ -z "$1" ]; then
513 $DIALOG --clear \
514 --title " SliTaz bootloader for DOS " \
515 --yes-label "Install" --yesno \
516 "\nThe file TAZBOOT.EXE will be created in the top directory. It supports
517 any linux kernel, multiple initramfs, a kernel command line and
518 an ISO image file loopback (retrieves files from an ISO file).\n\n
519 Usage: tazboot.exe [[@commands]|[kernel=<bzimage>]
520 [initrd=<rootfs>[,<rootfs2>...]] [bootfrom=<isofile>] cmdline args ...]\n\n
521 Defaults: tazboot @tazboot.cmd or tazboot kernel=bzImage auto\n\n\
522 Examples for tazboot.cmd:\n\n\
523 bootfrom=\\isos\\slitaz-4.0.iso\n\
524 kernel=boot/bzImage\n\
525 initrd=boot/rootfs4.gz,boot/rootfs3.gz,boot/rootfs2.gz,boot/rootfs1.gz\n\
526 rw root=/dev/null autologin\n\n\
527 kernel=\\slitaz\\vmlinuz root=/dev/sda5 ro\n\n
528 Unlike GRUB4DOS, it doesn't require unfragmented ISO image files.\n
529 " 24 78
530 [ $? -eq 0 ] || return
531 fi
532 gettazboot tazboot.exe
533 }
535 md5()
536 {
537 dotwait "Checking files"
538 ( cd /media/cdrom ; ${md5sum:-md5sum -c md5sum*} ) > /tmp/data
539 unset md5sum
540 rm -f /tmp/wait
541 if [ "$1" ]; then
542 cat /tmp/data
543 else
544 $DIALOG --clear \
545 --title " Checked files " \
546 --textbox /tmp/data 24 78
547 fi
548 rm -f /tmp/data
549 }
551 gotcdfile()
552 {
553 for i in "/media/cdrom/$1" "/media/cdrom/*/$1" \
554 "/media/cdrom/*/isolinux/$1" ; do
555 file=$(ls $i 2> /dev/null | sed q)
556 [ -s "$file" ] && break
557 done
558 }
560 sha()
561 {
562 gotcdfile 'sha*sum*'
563 sha=$(basename $file)
564 md5sum="${sha%sum*}sum -c ${file#/media/cdrom/}"
565 md5 $@
566 }
568 readme()
569 {
570 gotcdfile 'README*'
571 if [ "$1" ]; then
572 cat $file
573 else
574 $DIALOG --clear \
575 --title " Readme " \
576 --textbox $file 24 78
577 fi
578 }
580 bzimage()
581 {
582 if [ -z "$1" ]; then
583 $DIALOG --clear \
584 --title " Create linux.exe ? " \
585 --yes-label "Install" --yesno \
586 "\nLinux.exe launches the linux kernel under DOS (in real mode only).
587 The cmdline arguments are supported except initrd=,
588 vga= (you can try 'rdev -v') and mem= (partially).
589 \nExample:\nC:\\> linux.exe root=/dev/hda2 ro panic=60\n
590 " 12 70
591 [ $? -eq 0 ] || return
592 fi
593 cp /media/cdrom/boot/bzImage linux.exe
594 }
596 memtest()
597 {
598 if [ -z "$1" ]; then
599 $DIALOG --clear \
600 --title " Create memtest.exe ? " \
601 --yes-label "Install" --yesno \
602 "\nMemtest86 is a thorough, stand alone memory test for x86 architecture
603 computers. BIOS based memory tests are a quick, cursory check and often
604 miss many of the failures that are detected by Memtest86.\n
605 " 12 70
606 [ $? -eq 0 ] || return
607 fi
608 gotcdfile 'memtest*' && cp $file memtest.exe
609 }
611 mkfat12()
612 {
613 [ $(($(get 0 $1) - 0x5A4D)) -eq 0 ] || return
614 J=$(($(get 3 $1 1) + 0x02))
615 R=$((1 + $(get 497 $1 1) + 1 + ($(get 500 $1)-1)/32))
616 [ $R -lt 2500 ] || return
617 [ $((($(get 500 $1)-1) & 31)) -lt 30 ] &&
618 ddq if=$file bs=32 count=1 seek=$(($R*16 - 1)) of=/dev/fd0
619 G="18 0 2 0 0 0 0 0"
620 [ $J -gt 25 ] || G=""
621 F=0
622 for i in 1 2 3; do
623 F=$((((2880-$R-$F-$F)*3+1023)/1024))
624 done
625 bytes2bin 0xEB $J 0x90 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 \
626 0 2 2 $(($R%256)) $(($R/256)) 2 64 0 64 11 0xF0 $F 0 \
627 $G | ddq bs=1 of=/dev/fd0
628 ddq if=/dev/zero bs=512 count=$((4+$F+$F)) seek=$R of=/dev/fd0
629 for i in $R $(($R+$F)) ; do
630 bytes2bin 0xF0 0xFF 0xFF | ddq bs=512 seek=$i of=/dev/fd0
631 done
632 echo -n $(basename $1) | ddq bs=1 seek=3 count=8 of=/dev/fd0
633 }
635 mkfloppy()
636 {
637 dotwait "Create a $(basename $1) boot floppy"
638 ddq if=$1 of=/dev/fd0
639 mkfat12 $1
640 rm -f /tmp/wait
641 }
643 fdmemtest()
644 {
645 if [ -z "$1" ]; then
646 $DIALOG --clear \
647 --title " Create a Memtest86 boot floppy " \
648 --yes-label "Create floppy" --yesno \
649 "\nMemtest86 is a thorough, stand alone memory test for x86 architecture
650 computers. BIOS based memory tests are a quick, cursory check and often
651 miss many of the failures that are detected by Memtest86.\n\n
652 Please insert a blank disk in floppy drive.\n
653 " 12 70
654 [ $? -eq 0 ] || return
655 fi
656 gotcdfile 'memtest*' && mkfloppy $file
657 }
659 pxe()
660 {
661 gotcdfile '?pxe'
662 if [ -z "$1" ]; then
663 $DIALOG --clear \
664 --title " Create $(basename $file).exe ? " \
665 --yes-label "Install" --yesno \
666 "\nBoot your operating system from the internet and enjoy a full system
667 working entirely in RAM with speed and stability in mind. The Linux Kernel
668 and the complete SliTaz compressed root filesystem will be loaded into RAM
669 from the Web using PXE and HTTP protocols.\n
670 " 12 70
671 [ $? -eq 0 ] || return
672 fi
673 cp $file $(basename $file).exe
674 }
676 fdpxe()
677 {
678 if [ -z "$1" ]; then
679 $DIALOG --clear \
680 --title " Create a SliTaz Web boot floppy " \
681 --yes-label "Create floppy" --yesno \
682 "\nBoot your operating system from the internet and enjoy a full system
683 working entirely in RAM with speed and stability in mind. The Linux Kernel
684 and the complete SliTaz compressed root filesystem will be loaded into RAM
685 from the Web using PXE and HTTP protocols.\n\n
686 Please insert a blank disk in floppy drive.\n
687 " 12 70
688 [ $? -eq 0 ] || return
689 fi
690 gotcdfile '?pxe' && mkfloppy $file
691 }
693 menuitem()
694 {
695 [ "$3" ] && shift
696 echo -en "\"$1\" \"$2\""
697 }
699 gotposixovl()
700 {
701 mount.posixovl 2>&1 | grep -qi usage && menuitem "$@"
702 }
704 gotposixovlzip()
705 {
706 [ "$(which zip)" ] && gotposixovl "$1" "$2"
707 }
709 xfile()
710 {
711 [ "$(which $1)" ] && menuitem "$@"
712 }
714 cdfile()
715 {
716 gotcdfile "$1" && menuitem "$@"
717 }
719 isbzImage()
720 {
721 [ $(get 514 $file 4) -eq 1400005704 ] &&
722 [ $(($(get 529 $file 1) & 1)) -eq 1 ]
723 }
725 cdfilex()
726 {
727 gotcdfile "$1" && [ "$(which kexec)" ] && isbzImage && menuitem "$@"
728 }
730 cdfilef()
731 {
732 [ -e /sys/block/fd0 ] && cdfile "$@"
733 }
735 cdexe()
736 {
737 gotcdfile "$1" &&
738 [ $(get 0 $file 2>/dev/null || echo 0) -eq 23117 ] &&
739 menuitem "$@"
740 }
742 misspkg()
743 {
744 for i in zip kexec-tools posixovl ; do
745 [ -d /var/lib/tazpkg/installed/$i/ ] && continue
746 [ "$1" != "install" ] && menuitem "$@" && return
747 tazpkg get-install $i
748 done
749 }
751 missing()
752 {
753 misspkg install
754 }
756 ishybrid()
757 {
758 C=$((2048*$(get $(((17*2048) + 71)) $ISO 4)))
759 [ $(get $C $ISO 4) -eq 1 ] || return
760 [ $(get $(($C+30)) $ISO 4) -eq $((0x88AA55)) ] || return
761 C=$((2048*$(get $(($C+40)) $ISO 4)))
762 [ $(get $(($C+64)) $ISO 4) -eq 1886961915 ] && menuitem "$@"
763 }
765 isiso()
766 {
767 [ $(get 32769 $ISO 4) -eq 808469571 ] && menuitem "$@"
768 }
770 gotisomd5()
771 {
772 [ "$(which md5sum 2> /dev/null)" ] &&
773 [ $(get 0 $ISO) -eq 23117 ] &&
774 [ $(get 18 $ISO) -ne 0 ] && menuitem "$@"
775 }
777 isomd5()
778 {
779 dotwait "Checking iso image"
780 [ "$(ddq if=$ISO bs=2k skip=16 \
781 count=$(echo $(get 32848 $ISO 4)) | md5sum)" == \
782 "$(ddq if=$ISO bs=16 count=1 skip=2047 | od -N 16 -t x1 -An | \
783 sed 's/ //g') -" ] && echo "OK" || echo "ERROR"
784 echo -en "\rChecking iso hybrid boot..."
785 n=$(($(get 2 $ISO)-1+($(get 4 $ISO)-1)*512))
786 if [ $n -lt 40000 -a $n -gt 32768 ]; then
787 s=$(get 0 $ISO 2 $n | awk '{ i+= $0 } END { print i }')
788 [ $(((1+$s+$(get $(($n+1)) $ISO 1)) % 65536)) -eq 0 ] &&
789 echo "OK" || echo "ERROR"
790 fi
791 rm -f /tmp/wait
792 [ "$1" ] && return 0
793 echo -e "\rPress RETURN to continue."
794 read n
795 }
797 usbdev()
798 {
799 dotwait "Wait 5 seconds for USB devices"
800 sleep 5
801 rm -f /tmp/wait
802 DEV="$(grep -l 1 /sys/block/*/removable | \
803 sed 's|/sys/block/\(.*\)/removable|\1|')"
804 grep -qs 1 /sys/block/$DEV/ro && return
805 [ "$DEV" ] || return
806 cat > /tmp/dialog$$ <<EOT
807 $DIALOG --clear \
808 --title " Select your USB key " \
809 --menu "\nPlease select the USB key according to its known size.\n\n" \
810 14 70 4 \
811 $(for i in $DEV ; do
812 echo -n "/dev/$i \"$(($(cat /sys/block/$i/size)/2048))MB $(cat /sys/block/$i/device/model 2> /dev/null)\" "
813 done) \
815 EOT
816 exec 3>&1
817 device=$(. /tmp/dialog$$ 2>&1 1>&3)
818 rm -f /tmp/dialog$$
819 retval=$?
820 exec 3>&-
821 rm -f /tmp/dialog$$
822 [ $retval -eq 0 ]
823 }
825 tazusbmsg()
826 {
827 [ "$(which tazusb 2> /dev/null)" ] || return
828 echo "You should choose 'USB key read/write installation' to be
829 able to save the package updates or your own configuration and data files.\n\n"
830 }
832 usbbootkey()
833 {
834 if [ -b "$1" ]; then
835 device=$1
836 elif [ "$1" ]; then
837 echo "Invalid USB key device"
838 return 1
839 else
840 $DIALOG --clear \
841 --title " Create a USB boot key " \
842 --yes-label "Continue" --yesno \
843 "\nThe USB key will be used like a CD-ROM. You will not be able to write
844 any data on the boot partition.\n\n
845 An extra FAT32 partition will be created with the remaining free space.\n\n
846 $(tazusbmsg)Please plug your USB stick in now.\n
847 " 16 70
848 [ $? -eq 0 ] || return
849 usbdev || return
851 # perform dd in progress bar
852 max=$(($(stat -c %s $ISO)/2048))
853 i=0; ddq if=$ISO bs=1024k | (
854 while ddq bs=1024k count=1 ; do
855 i=$(($i + 1))
856 [ $i -gt $max ] && break
857 echo $((($i*100)/$max)) | dialog --gauge \
858 " The ISO image transfer can be long. Please wait..." \
859 6 70 0 > /dev/tty 2>&1
860 done ) > $device
861 fi
863 # partition + fat32 format for the remaining space
864 for p in 0 16; do
865 get $((450+$p)) $device 2 12 | xargs echo | {
866 read dx cx ol oh ll lh
867 [ $dx -eq $((0x3F17)) ] || continue
868 cx=$(($cx & 0xFF00))
869 ofs=$(($ll+($lh<<16)))
870 n=$(($(cat /sys/block/${device#/dev/}/size)-$ofs))
871 m=$(($cx+($n/8)))
872 [ $m -gt $((0x3FF00)) ] && m=$((0x3FF00))
873 m=$((($m & 0xFF00)+(($m>>16)<<6)))
874 words2bin 0 $((0x101+$cx)) 0x3F0B $((32+$m)) \
875 $ll $lh $(($n & 0xFFFF)) $(($n >> 16)) | \
876 ddq bs=1 seek=$((462-$p)) of=$device
877 if [ "$(which mkdosfs 2> /dev/null)" ]; then
878 losetup -o $((512*$ofs)) /dev/loop2 $device
879 mkdosfs -n "SLITAZ BOOT" /dev/loop2
880 words2bin $(($ofs & 0xFFFF)) $(($ofs >> 16)) | \
881 ddq bs=1 seek=28 of=/dev/loop2
882 sync
883 losetup -d /dev/loop2
884 fi
885 }
886 done
887 }
889 usbkey()
890 {
891 $DIALOG --clear \
892 --title " Create a SliTaz USB key " \
893 --yes-label "Continue" --yesno \
894 "\nUnlike a hard drive install, the filesystem is kept in a compressed
895 rootfs.gz. The filesystem is loaded entirely into memory upon boot.
896 This should increase responsiveness, protect the filesystem against
897 accidental corruption and reduce read/writes to the USB drive.
898 Once setup, the tazusb utility can rewrite the root filesystem
899 with any changes you have made since booting up,
900 giving the effective benefits of a hard drive install.\n\n
901 /home is mounted on boot using the UUID of your particular flash drive.
902 Unlike a device name, the UUID has the benefit of never changing from machine
903 to machine.\n\n
904 Please plug your USB stick in now.\n
905 " 19 70
906 [ $? -eq 0 ] || return
907 usbdev || return
908 exec 3>&1
909 format=`$DIALOG --clear \
910 --title " Select the filesystem " \
911 --radiolist "\nPlease select the filesystem type to create.\n\n\
912 The filesystem creation will erase all the data \
913 in the USB key." 14 70 4 \
914 "none" "Do not erase the USB key" on \
915 "ext3" "Ext3 journaling filesystem" off \
916 "ext2" "Ext2 filesystem" off \
917 "fat32" "Windows FAT32 filesystem" off \
918 2>&1 1>&3`
919 retval=$?
920 exec 3>&-
921 [ $retval -eq 0 ] || return
922 [ "$format" != "none" ] && tazusb format $device "SliTaz" $format
923 tazusb gen-iso2usb $ISO $device
924 }
926 dokexec()
927 {
928 kexec -l $file || return
929 umount -d /media/cdrom
930 kexec -e
931 }
933 runmemtest()
934 {
935 gotcdfile 'memtest*' && dokexec
936 }
938 runpxe()
939 {
940 gotcdfile '?pxe' && dokexec
941 }
943 quit()
944 {
945 umount -d /media/cdrom
946 exit
947 }
949 ISO="$1"
950 [ -z "$(isiso 2> /dev/null)" ] && echo "Usage : $0 file.iso" && exit 1
951 mount -o loop,ro $ISO /media/cdrom
953 if [ "$2" == "list" ]; then
954 sed '/^\$(.*") \\/!d;s/^\$(\(.*\)").*/\1"/' $0 | while read line; do
955 eval $line
956 echo
957 done | sed '/^$/d;/"usbkey"/d'
958 quit
959 fi
960 if grep -q "^$2()" $0; then
961 exe=$2
962 shift 2
963 if [ "$(eval $(grep "\"$exe\"" $0 | \
964 sed '/^\$/!d;s/.(\(.*\)[\t ]*".*"[\t ]*".*/\1/'))" ]; then
965 grep "\"$exe\"" $0 | sed '/^\$/!d;s/.*"[\t ]*"\(.*\)".*/\1/'
966 $exe "$@"
967 fi
968 quit
969 fi
971 while true; do
972 cat > /tmp/dialog$$ <<EOT
973 $DIALOG --clear \
974 --title " SliTaz ISO tool " \
975 --menu "" 23 70 17 \
976 $(cdfile 'README*' "readme" "Show the README file") \
977 $(gotisomd5 "isomd5" "Check the ISO image") \
978 $(cdfile 'md5sum*' "md5" "Check the ISO files") \
979 $(cdfile 'sha*sum*' "sha" "Check the ISO files") \
980 $(cdfilex boot/bzImage "bootiso" "Boot the ISO image") \
981 $(gotposixovl "install" "Hard disk installation (UMSDOS way)") \
982 $(gotposixovl "installtaz" "Hard disk installation (TAZUSB way)") \
983 $(gotposixovlzip "inst2zip" "ZIP installation archive (UMSDOS way)") \
984 $(gotposixovlzip "insttaz2zip" "ZIP installation archive (TAZUSB way)") \
985 $(xfile tazusb "usbkey" "USB key read/write installation") \
986 $(ishybrid "usbbootkey" "USB boot key (read only)") \
987 $(menuitem "tazboot" "Get tazboot.exe Linux loader") \
988 $(cdexe boot/bzImage "bzimage" "Get linux DOS/EXE file") \
989 $(cdexe 'memtest*' "memtest" "Get Memtest86 DOS/EXE file") \
990 $(cdfilef 'memtest*' "fdmemtest" "Create a Memtest86 boot floppy") \
991 $(cdfilex 'memtest*' "runmemtest" "Start Memtest86") \
992 $(cdexe '?pxe' "pxe" "Get SliTaz Web boot DOS/EXE utility") \
993 $(cdfilef '?pxe' "fdpxe" "Create a SliTaz Web boot floppy") \
994 $(cdfilex '?pxe' "runpxe" "Start the SliTaz Web boot utility") \
995 $(misspkg "missing" "Install packages to get more options") \
996 $(menuitem "quit" "Quit this utility")
997 EOT
998 exec 3>&1
999 value=$(. /tmp/dialog$$ 2>&1 1>&3)
1000 retval=$?
1001 exec 3>&-
1002 rm -f /tmp/dialog$$
1003 [ $retval -eq 0 ] || continue
1004 $value
1005 done