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

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