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

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