wok-current view syslinux/stuff/iso2exe/taziso @ rev 17933

syslinux/taziso: fix ishybrid
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Apr 13 11:52:40 2015 +0200 (2015-04-13)
parents aece1721c14f
children d522b4dd300b
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 $([ "$2" ] || echo '# ')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 $([ "$3" ] || echo '# ')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 unset useposixovl
203 blkid | grep $(df /mnt | sed '$!d;s/ .*/:/') | \
204 grep -qiE "(msdos|vfat|ntfs)" && useposixovl=YES
206 mkdir -p $mnt/slitaz/boot $mnt/slitaz/mnt/dos
207 [ "$useposixovl" ] &&
208 if ! mount.posixovl -F $mnt/slitaz -- \
209 -oallow_other -odefault_permissions -osuid; then
210 echo "Can't install SliTaz. Abort."
211 sleep 5
212 return 1
213 fi
214 dotwait "Install root filesystem in /slitaz.."
215 if [ "$1" ]; then
216 ls_r /media/cdrom/boot/rootfs*gz | \
217 xargs cat > $mnt/slitaz/boot/rootfs.gz
218 tazusbinitfs $mnt/slitaz/boot/rootfs.gz $useposixovl
219 initrd=rootfs.gz
220 extraargs="/home=$(getuuid)/slitaz rdinit=/init1"
221 else
222 for i in $(ls_r /media/cdrom/boot/rootfs*gz); do
223 uncpio $i $mnt/slitaz
224 done
225 for i in $packages_list; do
226 tazpkg get-install $i --root=$mnt/slitaz
227 done
228 for i in $packages_dir/*.tazpkg; do
229 [ -s "$i" ] &&
230 tazpkg install $i --root=$mnt/slitaz
231 done
232 cp -a /etc/locale.conf $mnt/slitaz/etc 2> /dev/null
233 cp -a /etc/keymap.conf $mnt/slitaz/etc 2> /dev/null
234 mkinitrd $mnt/slitaz/boot/initrd $mnt/slitaz $useposixovl
235 initrd=initrd
236 extraargs="mount=$(getuuid) subroot=slitaz"
237 fi
238 echo -en "\nInstall boot files..."
239 for i in /media/cdrom/boot/bzImage /media/cdrom/boot/*pxe* \
240 /media/cdrom/boot/isolinux/he* /media/cdrom/boot/isolinux/opt* \
241 /media/cdrom/README /media/cdrom/boot/memtest* ; do
242 [ -s $i ] && cp $i $mnt/slitaz/boot
243 done
244 for i in $mnt/slitaz/boot/memtest $mnt/slitaz/boot/*pxe* ; do
245 [ $(get 0 $i 2> /dev/null || echo 0) -eq 23117 ] &&
246 mv $i $i.exe
247 done
248 gettazboot $mnt/slitaz/boot/tazboot.exe
249 unix2dos > $mnt/slitaz/boot/tazboot.cmd <<EOT
250 kernel=/slitaz/boot/bzimage
251 initrd=/slitaz/boot/$initrd
252 rw root=/dev/null $extraargs autologin
253 EOT
254 unix2dos $mnt/slitaz/boot/he* $mnt/slitaz/boot/opt* \
255 $mnt/slitaz/boot/README
256 [ -d $mnt/slitaz/usr/sbin -a ! -x $mnt/slitaz/usr/sbin/mount.posixovl ] &&
257 cp $(which mount.posixovl) $mnt/slitaz/usr/sbin
258 if "$useposixovl" && grep -qs " $mnt " /proc/mounts &&
259 [ ! -d $mnt/boot/grub ]; then
260 mkdir -p $mnt/boot/grub
261 echo -en "\nInstall grub in /boot/grub..."
262 cp -a /usr/lib/grub/*/* $mnt/boot/grub
263 cat > $mnt/boot/grub/menu.lst <<EOT
264 # /boot/grub/menu.lst: GRUB boot loader configuration.
266 # By default, boot the first entry.
267 default 0
269 # Boot automatically after 8 secs.
270 timeout 8
272 title Microsoft Windows
273 chainloader +1
275 EOT
276 dev=$(grep " $mnt " /proc/mounts | awk '{ print $1 }')
277 base=${dev//[0-9]/}
278 dd if=$base bs=32k count=1 of=$mnt/boot/grub/$(basename $base)
279 cat > $mnt/boot/grub/uninstall-grub.sh <<EOT
280 #!/bin/sh
282 [ -s /boot/grub/$(basename $base) ] &&
283 dd if=/boot/grub/$(basename $base) of=$base
284 EOT
285 grub-install --no-floppy --root-directory=$mnt $base
286 fi
287 if [ -s $mnt/boot/grub/menu.lst ] &&
288 ! grep -q /slitaz/boot/bzimage $mnt/boot/grub/menu.lst; then
289 echo -en "\nUpdate /boot/grub/menu/lst..."
290 cat >> $mnt/boot/grub/menu.lst <<EOT
291 title SliTaz GNU/Linux $(cat $mnt/slitaz/etc/slitaz-release)
292 kernel /slitaz/boot/bzimage rw root=/dev/null $extraargs autologin
293 initrd /slitaz/boot/$initrd
295 EOT
296 fi
297 rm -f /tmp/wait
298 [ "$useposixovl" ] && umount $mnt/slitaz
299 return 0
300 }
302 windev()
303 {
304 if [ -b "$1" ]; then
305 device=$1
306 elif [ "$1" ]; then
307 echo "Invalid Linux/Windows partition"
308 return 1
309 else
310 DEV="$(blkid | grep -iE "(msdos|vfat|ntfs|ext[234]|xfs|btrfs)" | sed 's/:.*//;s|/dev/||')"
311 [ "$DEV" ] || return
312 cat > /tmp/dialog$$ <<EOT
313 $DIALOG --clear \
314 --title " Select your Linux/Windows partition " \
315 --menu "\nPlease select the Linux/Windows partition according to its known size.
316 The data will be kept untouched.\n" \
317 17 70 8 \
318 $(for i in $DEV ; do
319 label="$(blkid | sed "/$i:/!d;s/.*://;s/[^ ]*UUID=[^ ]* //g;s/LABEL=//")"
320 echo -n "/dev/$i \"$(($(cat /sys/block/*/$i/size)/2048))MB $label\" "
321 done)
322 EOT
323 exec 3>&1
324 [ $? -eq 0 ] || return
325 device=$(. /tmp/dialog$$ 2>&1 1>&3)
326 exec 3>&-
327 rm -f /tmp/dialog$$
328 fi
329 mnt=/tmp/mnt$$
330 mkdir -p $mnt && mount $device $mnt
331 }
333 extra_packages()
334 {
335 packages_list=
336 packages_dir=
337 $DIALOG --clear \
338 --title " Extra packages " \
339 --defaultno --yesno \
340 "
341 Do you want to add extra packages ?
342 " 7 70
343 [ $? -eq 0 ] || return
344 [ -s /var/lib/tazpkg/packages.txt ] || tazpkg recharge
345 if [ -s /media/cdrom/boot/vmlinuz-$(uname -r) ]; then
346 cat > /tmp/dialog$$ <<EOT
347 $DIALOG --clear \
348 --title " Select the packages " \
349 --separate-output \
350 --cancel-label "Skip" \
351 --checklist "Please select the packages you want to install. Try with the first letter." \
352 23 78 20 \\
353 EOT
354 awk -F\| '{ printf "%s \"%s\" off ",$1,$3 }' \
355 /var/lib/tazpkg/packages.desc >> /tmp/dialog$$
356 sh /tmp/dialog$$ 2> /tmp/dialog.out$$
357 [ $? -eq 0 ] && packages_list="$(cat /tmp/dialog.out$$)"
358 fi
359 cat > /tmp/dialog$$ <<EOT
360 $DIALOG --clear \
361 --title "Please select the directory with every custom package to install." \
362 --cancel-label "Skip" \
363 --dselect $PWD 13 78
364 EOT
365 sh /tmp/dialog$$ 2> /tmp/dialog.out$$
366 [ $? -eq 0 ] && packages_dir="$(cat /tmp/dialog.out$$)"
367 rm -f /tmp/dialog$$ /tmp/dialog.out$$
368 }
370 _install()
371 {
372 extra_packages
373 $DIALOG --clear \
374 --title " SliTaz UMSDOS way installation " \
375 --yes-label "Install" --yesno \
376 "\nSliTaz will be installed in the subdirectory \\slitaz of the current
377 Linux/DOS/Windows partition. You will see your files from /mnt/dos.\n\n
378 You can start SliTaz with \\slitaz\\boot\\tazboot.exe\n\n
379 To uninstall SliTaz, you have only to remove this directory.
380 The file \\boot.ini or \\config.sys may be modified too.\n\n
381 SliTaz may run slowly on 'UMSDOS way' installation due to the
382 posixovl filesystem. The 'TAZUSB way' installation runs faster.\n\n
383 To do a traditional installation with disk partitioning,
384 start SliTaz Live with 'SliTaz RAM boot' menu.\n
385 " 19 70
386 [ $? -eq 0 ] || return
387 doinstall
388 }
390 readtazbootconf()
391 {
392 kernel="$(sed '/^kernel=/!d;s/.*=//' $mnt/slitaz/boot/tazboot.cmd)"
393 initrd="$(sed '/^initrd=/!d;s/.*=//' $mnt/slitaz/boot/tazboot.cmd)"
394 cmdline="$(sed '/^kernel=/d;/^initrd=/d' $mnt/slitaz/boot/tazboot.cmd)"
395 }
397 bootinstalled()
398 {
399 [ "$(which kexec)" ] || return
400 [ -x $mnt/slitaz$1 ] || return
401 [ -s $mnt/slitaz/boot/tazboot.cmd ] || return
402 readtazbootconf
403 kexec -l $kernel --initrd $initrd --command-line "$cmdline" || return
404 umount $mnt
405 rm -rf $mnt
406 umount -d /media/cdrom
407 kexec -e
408 }
410 mkzip()
411 {
412 device=
413 packages_list=
414 packages_dir=
415 mnt=/tmp/mnt$$
416 mkdir -p $mnt
417 $1 $2 || return
418 wget -O $mnt/slitaz/boot/grldr http://mirror.slitaz.org/boot/grldr
419 readtazbootconf
420 cat > $mnt/slitaz/boot/menu.lst <<EOT
421 title SliTaz
422 kernel $kernel $cmdline
423 initrd $initrd
425 EOT
426 while read file title; do
427 file=$(ls $mnt/slitaz/boot/*$file* 2> /dev/null)
428 [ -s "$file" ] && cat >> $mnt/slitaz/boot/menu.lst <<EOT
429 title $title
430 kernel ${file#$mnt}
432 EOT
433 done <<EOT
434 memtest MemTest
435 pxe Web boot
436 EOT
437 unix2dos $mnt/slitaz/boot/menu.lst
438 unix2dos > $mnt/slitaz/boot/install.txt <<EOT
439 For DOS users (real mode only):
441 Start SliTaz with \\slitaz\\boot\\tazboot.exe
444 For NT/2000/XP users:
446 1- Move the files grldr and menu.lst into the root directory
448 C:\\> copy \\slitaz\\boot\\grldr \\
449 C:\\> copy \\slitaz\\boot\\menu.lst \\
451 2- Remove boot.ini attributes
453 C:\\> attrib -r -h -s boot.ini
455 3- Append the following line to boot.init
457 C:\\grldr="slitaz"
459 4- Restore boot.ini attributes
461 C:\\> attrib +r +h +s boot.ini
463 See http://diddy.boot-land.net/grub4dos/files/README_GRUB4DOS.txt
464 EOT
465 ( cd $mnt ; zip -r9 $(basename $ISO .iso).zip slitaz )
466 [ "$(which advzip)" ] && advzip -z4 $mnt/*.zip
467 mv $mnt/*.zip .
468 ls -l $PWD/$(basename $ISO .iso).zip
469 umount $mnt
470 rm -rf $mnt
471 }
473 install()
474 {
475 windev $1 || return
476 packages_list=
477 packages_dir=
478 if [ "$1" ]; then
479 doinstall
480 else
481 _install && bootinstalled /sbin/init
482 fi
483 umount $mnt
484 rm -rf $mnt
485 }
487 inst2zip()
488 {
489 if [ "$1" ]; then
490 mkzip doinstall
491 else
492 mkzip _install
493 fi
494 }
496 _installtaz()
497 {
498 $DIALOG --clear \
499 --title " SliTaz TAZUSB way installation " \
500 --yes-label "Install" --yesno \
501 "\nSliTaz will be installed in the subdirectory \\slitaz of the current
502 Linux/DOS/Windows partition. You will see your files from /mnt/dos.\n\n
503 You can start SliTaz with \\slitaz\\boot\\tazboot.exe\n\n
504 To uninstall SliTaz, you have only to remove this directory.
505 The file \\boot.ini or \\config.sys may be modified too.\n\n
506 The filesystem is loaded entirely into memory upon boot to
507 increase responsiveness. Only /home lands on hard disk.\n\n
508 To do a traditional installation with disk partitioning,
509 start SliTaz Live with 'SliTaz RAM boot' menu.\n
510 " 19 70
511 [ $? -eq 0 ] || return
512 doinstall tazusblike
513 }
515 installtaz()
516 {
517 windev $1 || return
518 packages_list=
519 packages_dir=
520 if [ "$1" ]; then
521 doinstall tazusblike
522 else
523 _installtaz && bootinstalled /boot/bzimage
524 fi
525 umount $mnt
526 rm -rf $mnt
527 }
529 insttaz2zip()
530 {
531 if [ "$1" ]; then
532 mkzip doinstall tazusblike
533 else
534 mkzip _installtaz
535 fi
536 }
538 bootiso()
539 {
540 for i in $(ls_r /media/cdrom/boot/rootfs*gz); do
541 grep -q ' lm ' /proc/cpuinfo && [ -s ${i}64 ] && i=${i}64
542 cat $i
543 n=$((4 - ($(stat -c %s $i) % 4)))
544 [ $n -eq 4 ] || dd if=/dev/zero bs=1 count=$n
545 done > /tmp/initrd$$
546 kernel=/media/cdrom/boot/bzImage
547 grep -q ' lm ' /proc/cpuinfo && [ -s ${kernel}64 ] && kernel=${kernel}64
548 . /etc/locale.conf
549 kexec -l $kernel --initrd /tmp/initrd$$ --command-line \
550 "root=/dev/null autologin lang=$LANG kmap=$(cat /etc/keymap.conf)" &&
551 umount -d /media/cdrom
552 rm -f /tmp/initrd$$
553 kexec -e
554 }
556 tazboot()
557 {
558 if [ -z "$1" ]; then
559 $DIALOG --clear \
560 --title " SliTaz bootloader for DOS " \
561 --yes-label "Install" --yesno \
562 "\nThe file TAZBOOT.EXE will be created in the top directory. It supports
563 any linux kernel, multiple initramfs, a kernel command line and
564 an ISO image file loopback (retrieves files from an ISO file).\n\n
565 Usage: tazboot.exe [[@commands]|[kernel=<bzimage>]
566 [initrd=<rootfs>[,<rootfs2>...]] [bootfrom=<isofile>] cmdline args ...]\n\n
567 Defaults: tazboot @tazboot.cmd or tazboot kernel=bzImage auto\n\n\
568 Examples for tazboot.cmd:\n\n\
569 bootfrom=\\isos\\slitaz-4.0.iso\n\
570 kernel=boot/bzImage\n\
571 initrd=boot/rootfs4.gz,boot/rootfs3.gz,boot/rootfs2.gz,boot/rootfs1.gz\n\
572 rw root=/dev/null autologin\n\n\
573 kernel=\\slitaz\\vmlinuz root=/dev/sda5 ro\n\n
574 Unlike GRUB4DOS, it doesn't require unfragmented ISO image files.\n
575 " 24 78
576 [ $? -eq 0 ] || return
577 fi
578 gettazboot tazboot.exe
579 ls -l $PWD/tazboot.exe
580 }
582 md5()
583 {
584 dotwait "Checking files"
585 ( cd /media/cdrom ; ${md5sum:-md5sum -c md5sum*} ) > /tmp/data
586 unset md5sum
587 rm -f /tmp/wait
588 if [ "$1" ]; then
589 cat /tmp/data
590 else
591 $DIALOG --clear \
592 --title " Checked files " \
593 --textbox /tmp/data 24 78
594 fi
595 rm -f /tmp/data
596 }
598 gotcdfile()
599 {
600 for i in "/media/cdrom/$1" "/media/cdrom/*/$1" \
601 "/media/cdrom/*/isolinux/$1" ; do
602 file=$(ls $i 2> /dev/null | sed q)
603 [ -s "$file" ] && break
604 done
605 }
607 sha()
608 {
609 gotcdfile 'sha*sum*'
610 sha=$(basename $file)
611 md5sum="${sha%sum*}sum -c ${file#/media/cdrom/}"
612 md5 $@
613 }
615 readme()
616 {
617 gotcdfile 'README*'
618 if [ "$1" ]; then
619 cat $file
620 else
621 $DIALOG --clear \
622 --title " Readme " \
623 --textbox $file 24 78
624 fi
625 }
627 bzimage()
628 {
629 if [ -z "$1" ]; then
630 $DIALOG --clear \
631 --title " Create linux.exe ? " \
632 --yes-label "Install" --yesno \
633 "\nLinux.exe launches the linux kernel under DOS (in real mode only).
634 The cmdline arguments are supported except initrd=,
635 vga= (you can try 'rdev -v') and mem= (partially).
636 \nExample:\nC:\\> linux.exe root=/dev/hda2 ro panic=60\n
637 " 12 70
638 [ $? -eq 0 ] || return
639 fi
640 cp /media/cdrom/boot/bzImage linux.exe
641 ls -l $PWD/linux.exe
642 }
644 memtest()
645 {
646 if [ -z "$1" ]; then
647 $DIALOG --clear \
648 --title " Create memtest.exe ? " \
649 --yes-label "Install" --yesno \
650 "\nMemtest86 is a thorough, stand alone memory test for x86 architecture
651 computers. BIOS based memory tests are a quick, cursory check and often
652 miss many of the failures that are detected by Memtest86.\n
653 " 12 70
654 [ $? -eq 0 ] || return
655 fi
656 gotcdfile 'memtest*' && cp $file memtest.exe
657 ls -l $PWD/memtest.exe
658 }
660 mkfat12()
661 {
662 [ $(($(get 0 $1) - 0x5A4D)) -eq 0 ] || return
663 J=$(($(get 3 $1 1) + 0x02))
664 R=$((1 + $(get 497 $1 1) + 1 + ($(get 500 $1)-1)/32))
665 [ $R -lt 2500 ] || return
666 [ $((($(get 500 $1)-1) & 31)) -lt 30 ] &&
667 ddq if=$file bs=32 count=1 seek=$(($R*16 - 1)) of=/dev/fd0
668 G="18 0 2 0 0 0 0 0"
669 [ $J -gt 25 ] || G=""
670 F=0
671 for i in 1 2 3; do
672 F=$((((2880-$R-$F-$F)*3+1023)/1024))
673 done
674 bytes2bin 0xEB $J 0x90 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 \
675 0 2 2 $(($R%256)) $(($R/256)) 2 64 0 64 11 0xF0 $F 0 \
676 $G | ddq bs=1 of=/dev/fd0
677 ddq if=/dev/zero bs=512 count=$((4+$F+$F)) seek=$R of=/dev/fd0
678 for i in $R $(($R+$F)) ; do
679 bytes2bin 0xF0 0xFF 0xFF | ddq bs=512 seek=$i of=/dev/fd0
680 done
681 echo -n $(basename $1) | ddq bs=1 seek=3 count=8 of=/dev/fd0
682 }
684 mkfloppy()
685 {
686 dotwait "Create a $(basename $1) boot floppy"
687 ddq if=$1 of=/dev/fd0
688 mkfat12 $1
689 rm -f /tmp/wait
690 }
692 fdmemtest()
693 {
694 if [ -z "$1" ]; then
695 $DIALOG --clear \
696 --title " Create a Memtest86 boot floppy " \
697 --yes-label "Create floppy" --yesno \
698 "\nMemtest86 is a thorough, stand alone memory test for x86 architecture
699 computers. BIOS based memory tests are a quick, cursory check and often
700 miss many of the failures that are detected by Memtest86.\n\n
701 Please insert a blank disk in floppy drive.\n
702 " 12 70
703 [ $? -eq 0 ] || return
704 fi
705 gotcdfile 'memtest*' && mkfloppy $file
706 }
708 pxe()
709 {
710 gotcdfile '?pxe'
711 if [ -z "$1" ]; then
712 $DIALOG --clear \
713 --title " Create $(basename $file).exe ? " \
714 --yes-label "Install" --yesno \
715 "\nBoot your operating system from the internet and enjoy a full system
716 working entirely in RAM with speed and stability in mind. The Linux Kernel
717 and the complete SliTaz compressed root filesystem will be loaded into RAM
718 from the Web using PXE and HTTP protocols.\n
719 " 12 70
720 [ $? -eq 0 ] || return
721 fi
722 cp $file $(basename $file).exe
723 ls -l $PWD/$(basename $file).exe
724 }
726 fdpxe()
727 {
728 if [ -z "$1" ]; then
729 $DIALOG --clear \
730 --title " Create a SliTaz Web boot floppy " \
731 --yes-label "Create floppy" --yesno \
732 "\nBoot your operating system from the internet and enjoy a full system
733 working entirely in RAM with speed and stability in mind. The Linux Kernel
734 and the complete SliTaz compressed root filesystem will be loaded into RAM
735 from the Web using PXE and HTTP protocols.\n\n
736 Please insert a blank disk in floppy drive.\n
737 " 12 70
738 [ $? -eq 0 ] || return
739 fi
740 gotcdfile '?pxe' && mkfloppy $file
741 }
743 menuitem()
744 {
745 [ "$3" ] && shift
746 echo -en "\"$1\" \"$2\""
747 }
749 gotposixovl()
750 {
751 mount.posixovl 2>&1 | grep -qi usage && menuitem "$@"
752 }
754 gotposixovlzip()
755 {
756 [ "$(which zip)" ] && gotposixovl "$1" "$2"
757 }
759 xfile()
760 {
761 [ "$(which $1)" ] && menuitem "$@"
762 }
764 cdfile()
765 {
766 gotcdfile "$1" && menuitem "$@"
767 }
769 isbzImage()
770 {
771 [ $(get 514 $file 4) -eq 1400005704 ] &&
772 [ $(($(get 529 $file 1) & 1)) -eq 1 ]
773 }
775 cdfilex()
776 {
777 gotcdfile "$1" && [ "$(which kexec)" ] && isbzImage && menuitem "$@"
778 }
780 cdfilef()
781 {
782 [ -e /sys/block/fd0 ] && cdfile "$@"
783 }
785 cdexe()
786 {
787 gotcdfile "$1" &&
788 [ $(get 0 $file 2>/dev/null || echo 0) -eq 23117 ] &&
789 menuitem "$@"
790 }
792 misspkg()
793 {
794 for i in zip kexec-tools posixovl ; do
795 [ -d /var/lib/tazpkg/installed/$i/ ] && continue
796 [ "$1" != "install" ] && menuitem "$@" && return
797 tazpkg get-install $i
798 done
799 }
801 missing()
802 {
803 misspkg install
804 }
806 ishybrid()
807 {
808 [ $(get 510 $ISO) -eq 43605 ] || return
809 C=$((2048*$(get $(((17*2048) + 71)) $ISO 4)))
810 [ $(get $C $ISO 4) -eq 1 ] || return
811 [ $(get $(($C+30)) $ISO 4) -eq $((0x88AA55)) ] || return
812 C=$((2048*$(get $(($C+40)) $ISO 4)))
813 [ $(get $(($C+64)) $ISO 4) -eq 1886961915 ] && menuitem "$@"
814 }
816 isiso()
817 {
818 [ $(get 32769 $ISO 4) -eq 808469571 ] && menuitem "$@"
819 }
821 gotisomd5()
822 {
823 [ "$(which md5sum 2> /dev/null)" ] &&
824 [ $(get 0 $ISO) -eq 23117 ] &&
825 [ $(get 18 $ISO) -ne 0 ] && menuitem "$@"
826 }
828 isomd5()
829 {
830 dotwait "Checking iso image"
831 [ "$(ddq if=$ISO bs=2k skip=16 \
832 count=$(echo $(get 32848 $ISO 4)) | md5sum)" == \
833 "$(ddq if=$ISO bs=16 count=1 skip=2047 | od -N 16 -t x1 -An | \
834 sed 's/ //g') -" ] && echo "OK" || echo "ERROR"
835 echo -en "\rChecking iso hybrid boot..."
836 n=$(($(get 2 $ISO)-1+($(get 4 $ISO)-1)*512))
837 if [ $n -lt 40000 -a $n -gt 32768 ]; then
838 s=$(get 0 $ISO 2 $n | awk '{ i+= $0 } END { print i }')
839 [ $(((1+$s+$(get $(($n+1)) $ISO 1)) % 65536)) -eq 0 ] &&
840 echo "OK" || echo "ERROR"
841 fi
842 rm -f /tmp/wait
843 [ "$1" ] && return 0
844 echo -e "\rPress RETURN to continue."
845 read n
846 }
848 usbdev()
849 {
850 dotwait "Wait 5 seconds for USB devices"
851 sleep 5
852 rm -f /tmp/wait
853 DEV="$(grep -l 1 /sys/block/*/removable | \
854 sed 's|/sys/block/\(.*\)/removable|\1|')"
855 grep -qs 1 /sys/block/$DEV/ro && return
856 [ "$DEV" ] || return
857 cat > /tmp/dialog$$ <<EOT
858 $DIALOG --clear \
859 --title " Select your USB key " \
860 --menu "\nPlease select the USB key according to its known size.\n\n" \
861 14 70 4 \
862 $(for i in $DEV ; do
863 echo -n "/dev/$i \"$(($(cat /sys/block/$i/size)/2048))MB $(cat /sys/block/$i/device/model 2> /dev/null)\" "
864 done) \
866 EOT
867 exec 3>&1
868 device=$(. /tmp/dialog$$ 2>&1 1>&3)
869 rm -f /tmp/dialog$$
870 retval=$?
871 exec 3>&-
872 rm -f /tmp/dialog$$
873 [ $retval -eq 0 ]
874 }
876 tazusbmsg()
877 {
878 [ "$(which tazusb 2> /dev/null)" ] || return
879 echo "You should choose 'USB key read/write installation' to be
880 able to save the package updates or your own configuration and data files.\n\n"
881 }
883 usbbootkey()
884 {
885 if [ -b "$1" ]; then
886 device=$1
887 elif [ "$1" ]; then
888 echo "Invalid USB key device"
889 return 1
890 else
891 $DIALOG --clear \
892 --title " Create a USB boot key " \
893 --yes-label "Continue" --yesno \
894 "\nThe USB key will be used like a CD-ROM. You will not be able to write
895 any data on the boot partition.\n\n
896 An extra FAT32 partition will be created with the remaining free space.\n\n
897 $(tazusbmsg)Please plug your USB stick in now.\n
898 " 16 70
899 [ $? -eq 0 ] || return
900 usbdev || return
902 # perform dd in progress bar
903 max=$(($(stat -c %s $ISO)/2048))
904 i=0; ddq if=$ISO bs=1024k | (
905 while ddq bs=1024k count=1 ; do
906 i=$(($i + 1))
907 [ $i -gt $max ] && break
908 echo $((($i*100)/$max)) | dialog --gauge \
909 " The ISO image transfer can be long. Please wait..." \
910 6 70 0 > /dev/tty 2>&1
911 done ) > $device
912 fi
914 # partition + fat32 format for the remaining space
915 for p in 0 16; do
916 get $((450+$p)) $device 2 12 | xargs echo | {
917 read dx cx ol oh ll lh
918 [ $dx -eq $((0x3F17)) ] || continue
919 cx=$(($cx & 0xFF00))
920 ofs=$(($ll+($lh<<16)))
921 n=$(($(cat /sys/block/${device#/dev/}/size)-$ofs))
922 m=$(($cx+($n/8)))
923 [ $m -gt $((0x3FF00)) ] && m=$((0x3FF00))
924 m=$((($m & 0xFF00)+(($m>>16)<<6)))
925 words2bin 0 $((0x101+$cx)) 0x3F0B $((32+$m)) \
926 $ll $lh $(($n & 0xFFFF)) $(($n >> 16)) | \
927 ddq bs=1 seek=$((462-$p)) of=$device
928 if [ "$(which mkdosfs 2> /dev/null)" ]; then
929 losetup -o $((512*$ofs)) /dev/loop2 $device
930 mkdosfs -n "SLITAZ BOOT" /dev/loop2
931 words2bin $(($ofs & 0xFFFF)) $(($ofs >> 16)) | \
932 ddq bs=1 seek=28 of=/dev/loop2
933 sync
934 losetup -d /dev/loop2
935 fi
936 }
937 done
938 }
940 usbkey()
941 {
942 $DIALOG --clear \
943 --title " Create a SliTaz USB key " \
944 --yes-label "Continue" --yesno \
945 "\nUnlike a hard drive install, the filesystem is kept in a compressed
946 rootfs.gz. The filesystem is loaded entirely into memory upon boot.
947 This should increase responsiveness, protect the filesystem against
948 accidental corruption and reduce read/writes to the USB drive.
949 Once setup, the tazusb utility can rewrite the root filesystem
950 with any changes you have made since booting up,
951 giving the effective benefits of a hard drive install.\n\n
952 /home is mounted on boot using the UUID of your particular flash drive.
953 Unlike a device name, the UUID has the benefit of never changing from machine
954 to machine.\n\n
955 Please plug your USB stick in now.\n
956 " 19 70
957 [ $? -eq 0 ] || return
958 usbdev || return
959 exec 3>&1
960 format=`$DIALOG --clear \
961 --title " Select the filesystem " \
962 --radiolist "\nPlease select the filesystem type to create.\n\n\
963 The filesystem creation will erase all the data \
964 in the USB key." 14 70 4 \
965 "none" "Do not erase the USB key" on \
966 "ext3" "Ext3 journaling filesystem" off \
967 "ext2" "Ext2 filesystem" off \
968 "fat32" "Windows FAT32 filesystem" off \
969 2>&1 1>&3`
970 retval=$?
971 exec 3>&-
972 [ $retval -eq 0 ] || return
973 [ "$format" != "none" ] && tazusb format $device "SliTaz" $format
974 tazusb gen-iso2usb $ISO $device
975 }
977 dokexec()
978 {
979 kexec -l $file || return
980 umount -d /media/cdrom
981 kexec -e
982 }
984 runmemtest()
985 {
986 gotcdfile 'memtest*' && dokexec
987 }
989 runpxe()
990 {
991 gotcdfile '?pxe' && dokexec
992 }
994 flavdata()
995 {
996 [ $(get 512 $ISO) -eq 35615 ] && n=1 || n=$((1+$(get 417 $ISO 1)))
997 dd if=$ISO bs=512 skip=$n count=20 2>/dev/null | zcat 2>/dev/null
998 }
1000 hasflavinfo()
1002 [ "$(flavdata | dd bs=1 count=8 2> /dev/null | strings)" == \
1003 "07070100" ] && menuitem "$@"
1006 showfavinfo()
1008 mkdir -p /tmp/data
1009 flavdata | ( cd /tmp/data ; cpio -i )
1010 file=/tmp/data/info
1011 cat /tmp/data/*desc > $file
1012 for i in /tmp/data/*list* ; do
1013 echo "=== extra ${i#*list} files"
1014 cat $i
1015 done >> $file
1016 if [ "$1" ]; then
1017 cat $file
1018 else
1019 $DIALOG --clear \
1020 --title " Flavor infos " \
1021 --textbox $file 24 78
1022 fi
1023 rm -rf /tmp/data
1026 quit()
1028 umount -d /media/cdrom
1029 exit
1032 ISO="$1"
1033 [ -z "$(isiso 2> /dev/null)" ] && echo "Usage : $0 file.iso" && exit 1
1034 mount -o loop,ro $ISO /media/cdrom
1036 if [ "$2" == "list" ]; then
1037 sed '/^\$(.*") \\/!d;s/^\$(\(.*\)").*/\1"/' $0 | while read line; do
1038 eval $line
1039 echo
1040 done | sed '/^$/d;/"usbkey"/d'
1041 quit
1042 fi
1043 if grep -q "^$2()" $0; then
1044 exe=$2
1045 shift 2
1046 if [ "$(eval $(grep "\"$exe\"" $0 | \
1047 sed '/^\$/!d;s/.(\(.*\)[\t ]*".*"[\t ]*".*/\1/'))" ]; then
1048 grep "\"$exe\"" $0 | sed '/^\$/!d;s/.*"[\t ]*"\(.*\)".*/\1/'
1049 $exe "$@"
1050 fi
1051 quit
1052 fi
1054 while true; do
1055 cat > /tmp/dialog$$ <<EOT
1056 $DIALOG --clear \
1057 --title " SliTaz ISO tool " \
1058 --menu "" 23 70 17 \
1059 $(cdfile 'README*' "readme" "Show the README file") \
1060 $(gotisomd5 "isomd5" "Check the ISO image") \
1061 $(cdfile 'md5sum*' "md5" "Check the ISO files") \
1062 $(cdfile 'sha*sum*' "sha" "Check the ISO files") \
1063 $(cdfilex boot/bzImage "bootiso" "Boot the ISO image") \
1064 $(gotposixovl "install" "Hard disk installation (UMSDOS way)") \
1065 $(gotposixovl "installtaz" "Hard disk installation (TAZUSB way)") \
1066 $(gotposixovlzip "inst2zip" "ZIP installation archive (UMSDOS way)") \
1067 $(gotposixovlzip "insttaz2zip" "ZIP installation archive (TAZUSB way)") \
1068 $(xfile tazusb "usbkey" "USB key read/write installation") \
1069 $(ishybrid "usbbootkey" "USB boot key (read only)") \
1070 $(hasflavinfo "showfavinfo" "Show flavor extra infos") \
1071 $(menuitem "tazboot" "Get tazboot.exe Linux loader") \
1072 $(cdexe boot/bzImage "bzimage" "Get linux DOS/EXE file") \
1073 $(cdexe 'memtest*' "memtest" "Get Memtest86 DOS/EXE file") \
1074 $(cdfilef 'memtest*' "fdmemtest" "Create a Memtest86 boot floppy") \
1075 $(cdfilex 'memtest*' "runmemtest" "Start Memtest86") \
1076 $(cdexe '?pxe' "pxe" "Get SliTaz Web boot DOS/EXE utility") \
1077 $(cdfilef '?pxe' "fdpxe" "Create a SliTaz Web boot floppy") \
1078 $(cdfilex '?pxe' "runpxe" "Start the SliTaz Web boot utility") \
1079 $(misspkg "missing" "Install packages to get more options") \
1080 $(menuitem "quit" "Quit this utility")
1081 EOT
1082 exec 3>&1
1083 value=$(. /tmp/dialog$$ 2>&1 1>&3)
1084 retval=$?
1085 exec 3>&-
1086 rm -f /tmp/dialog$$
1087 [ $retval -eq 0 ] || continue
1088 $value
1089 done