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

Update some WEB_SITE
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Feb 26 08:20:18 2019 +0100 (11 months ago)
parents 378b0ba41272
children 02c70d036ea0
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 O=$(($(get 64 "$ISO") - 0xC0))
36 L=$(($(get 20 "$ISO") - 0xC0 - $(get 24 "$ISO") - $O))
37 S=$((32+$L))
38 P=$((($S+511)/512))
39 E=$((4096-(32*$P)))
40 words2bin 0x5A4D $(($S%512)) $P 0 2 $E -1 $((${2:-0}-16)) \
41 -2 0 256 -16 28 0x6C53 0x5469 0x7A61 > $1
42 ddq bs=1 count=$L skip=$(echo $O) if="$ISO" >> $1
43 }
45 uncpio()
46 {
47 [ -s "$1" ] || return
48 echo -en "\n Extracting $(basename $1) ..."
49 case $(get 0 $1) in
50 *35615) ( zcat || gunzip ) ;;
51 *14333) unxz ;;
52 *\ 93) unlzma ;;
53 *) cat ;;
54 esac < $1 | ( cd ${2:-/} ; cpio -idmu > /dev/null 2>&1 )
55 }
57 dotwait()
58 {
59 echo -n "${1:-Install filesystem}.."
60 touch /tmp/wait
61 [ "$REQUEST_URI" ] && return
62 while [ -e /tmp/wait ]; do
63 echo -n "." > /dev/tty
64 sleep 1
65 done &
66 }
68 getuuid()
69 {
70 dev=$(mount | sed "/ $(echo $mnt | sed 's|/|\\/|g') /!d;s/ .*//;s|/dev/||;q")
71 [ "$dev" ] &&
72 blkid | sed "/$dev:/!d;s/.* UUID=.\\([^ ]*\\)\".*/\\1/" ||
73 echo "/dev/hda1"
74 }
76 tazusbinitfs()
77 {
78 PAD=$(($(stat -c %s $1) % 4))
79 [ $PAD -ne 0 ] && ddq if=/dev/zero bs=1 count=$((4 - $PAD)) >> $1
80 mkdir -p /tmp/fs$$/etc /tmp/fs$$/lib /tmp/fs$$/home
81 cp -a /etc/locale.conf /tmp/fs$$/etc 2> /dev/null
82 cp -a /etc/keymap.conf /tmp/fs$$/etc 2> /dev/null
83 cat > /tmp/fs$$/init1 <<EOT
84 #!/bin/sh
85 sed -i 's|sbin/init|init2|' /init
86 exec /init
87 EOT
88 cat > /tmp/fs$$/init2 <<EOT
89 #!/bin/sh
91 mount -t proc /proc /proc
92 for i in /lib/*.ko* ; do insmod \$i 2> /dev/null ; done; sleep 2
93 v=\$(sed '/\\/home=/!d;s|.*/home=\\([^ ]*\\).*|\\1|' /proc/cmdline /cmdline 2> /dev/null)
94 mount / -o remount,rw
95 mkdir /mnt/dos
96 rm -f /cmdline 2> /dev/null
97 mount / -o remount,ro
98 mnt=/mnt/dos/\${v#*/}
99 dev=\$( (blkid /dev/[sh]d* || blkid) | grep \${v%%/*} | sed 's/:.*//;q')
100 echo "Mount \$dev in /mnt/dos for \$v..." | tee -a /run/boot.log
101 mount \$dev /mnt/dos
102 if [ ! -d /mnt/dos/slitaz ]; then
103 umount /mnt/dos 2> /dev/null
104 (blkid /dev/[sh]d* || blkid) | while read dev line; do
105 case "\$line" in
106 *ntfs*|*vfat*|*msdos*) ;;
107 *) continue ;;
108 esac
109 mount \${dev%:} /mnt/dos
110 [ -d /mnt/dos/slitaz ] && break
111 umount /mnt/dos
112 done
113 fi
114 $([ "$2" ] || echo '# ')mount.posixovl -F \$mnt -- -oallow_other -odefault_permissions -osuid
115 mount --bind \$mnt /home
116 umount /proc
117 exec /sbin/init
118 EOT
119 chmod 755 /tmp/fs$$/init?
120 ( cd /tmp/fs$$ ; find * | cpio -o -H newc ) | gzip -9 >> $1
121 rm -rf /tmp/fs$$
122 }
124 mkinitrd()
125 {
126 echo -en "\nCreating $(basename $1) "
127 fs=/tmp/fs$$
128 for i in bin lib dev proc tmp mnt etc ; do
129 mkdir -p $fs/$i
130 done
131 for i in /dev/console /dev/null /dev/tty /dev/tty0 /dev/tty1 /dev/tty2 \
132 /dev/fuse /dev/hd* /dev/sd* ; do
133 cp -a $2$i $fs/dev/
134 done
135 for i in /bin/busybox $(which mount.posixovl) $(which blkid); do
136 cp $(LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $i | \
137 sed 's|.*=> \(.*/lib/l[^ ]*\).*|\1|;/^\//!d') $fs/lib
138 cp $i $fs/bin
139 done
140 cp -a /lib/ld-* $fs/lib
141 for i in $(busybox | sed '/Current/,$!d'); do
142 [ -e $fs/bin/${i%,} ] || ln -s busybox $fs/bin/${i%,}
143 done
144 ln -s /proc/mounts $fs/etc/mtab
145 sed 's/ .*//' /proc/modules | while read mod ; do
146 find /lib/modules/ | grep $mod.ko | \
147 sed 's|.*|cp & $fs/lib|' | sh
148 done
149 cat > $fs/init <<EOT
150 #!/bin/sh
152 arg()
153 {
154 grep -q \$1 /proc/cmdline &&
155 val="\$(sed "s/.*\$1=\\([^ ]*\\).*/\\1/" < /proc/cmdline)" &&
156 echo "\$2 \$val"
157 }
159 mount -t proc /proc /proc
160 arg debug "shell" && debug=true && set -x
161 for i in /lib/*.ko* ; do insmod \$i 2> /dev/null ; done; sleep 2
162 arg mount "Mount device"
163 mount \$( (blkid /dev/[sh]d* || blkid) | grep \$val | sed 's/:.*//;q') /mnt
164 arg subroot "Change root to directory"
165 if [ -d /mnt/\$val ]; then
166 umount /mnt 2> /dev/null
167 (blkid /dev/[sh]d* || blkid) | while read dev line; do
168 case "\$line" in
169 *ntfs*|*vfat*|*msdos*) ;;
170 *) continue ;;
171 esac
172 mount \${dev%:} /mnt
173 [ -d /mnt/\$val ] && break
174 umount /mnt
175 done
176 fi
177 $([ "$3" ] || echo '# ')mount.posixovl -F /mnt/\$val -- -oallow_other -odefault_permissions -osuid
178 mount --bind /mnt /mnt/\$val/mnt/dos
179 mount -o size=0 -t tmpfs tmpfs /mnt/\$val/mnt/dos/\$val
180 LDSO=\$(ls /mnt/\$val/lib/ld-* | sed q)
181 export LD_LIBRARY_PATH=\$val/lib:\$val/usr/lib:/lib
182 [ "$debug" = "true" ] && sh
183 umount /proc
184 exec /bin/switch_root /mnt \${LDSO#/mnt/} \$val/usr/sbin/chroot \$val /sbin/init
185 EOT
186 chmod +x $fs/init
187 ( cd $fs ; find * | cpio -o -H newc ) | lzma e $1 -si 2> /dev/null
188 rm -rf $fs /tmp/wait
189 }
191 ls_r()
192 {
193 ls -r $@ 2> /dev/null || ls $@
194 }
196 doinstall()
197 {
198 unset useposixovl
199 blkid | grep $(df $mnt | sed '$!d;s/ .*/:/') | \
200 grep -qiE "(msdos|vfat|ntfs)" && useposixovl=YES
201 case "$mnt" in
202 *mkzip*) useposixovl=YES
203 esac
204 mkdir -p $mnt/slitaz/boot $mnt/slitaz/mnt/dos
205 [ "$useposixovl" ] &&
206 if ! mount.posixovl -F $mnt/slitaz -- \
207 -oallow_other -odefault_permissions -osuid; then
208 echo "Can't install SliTaz. Abort."
209 sleep 5
210 return 1
211 fi
212 dotwait "Install root filesystem in /slitaz.."
213 if [ "$1" ]; then
214 ls_r $media/boot/rootfs*gz | \
215 xargs cat > $mnt/slitaz/boot/rootfs.gz
216 tazusbinitfs $mnt/slitaz/boot/rootfs.gz $useposixovl
217 initrd=rootfs.gz
218 extraargs="/home=$(getuuid)/slitaz rdinit=/init1"
219 else
220 for i in $(ls_r $media/boot/rootfs*gz); do
221 uncpio $i $mnt/slitaz
222 done
223 for i in $packages_list; do
224 tazpkg get-install $i --root=$mnt/slitaz
225 done
226 for i in $packages_dir/*.tazpkg; do
227 [ -s "$i" ] &&
228 tazpkg install $i --root=$mnt/slitaz
229 done
230 cp -a /etc/locale.conf $mnt/slitaz/etc 2> /dev/null
231 cp -a /etc/keymap.conf $mnt/slitaz/etc 2> /dev/null
232 mkinitrd $mnt/slitaz/boot/initrd $mnt/slitaz $useposixovl
233 initrd=initrd
234 extraargs="mount=$(getuuid) subroot=slitaz"
235 fi
236 echo -en "\nInstall boot files..."
237 for i in $media/boot/bzImage* $media/boot/*pxe* \
238 $media/boot/isolinux/he* $media/boot/isolinux/opt* \
239 $media/README $media/boot/memtest* ; do
240 [ -s $i ] && cp $i $mnt/slitaz/boot
241 done
242 for i in $mnt/slitaz/boot/memtest $mnt/slitaz/boot/*pxe* ; do
243 [ $(get 0 $i 2> /dev/null || echo 0) -eq 23117 ] &&
244 mv $i $i.exe
245 done
246 bzimage=$(cd $mnt/slitaz/boot ; ls bzimage*)
247 gettazboot $mnt/slitaz/boot/tazboot.exe # autoappend 64 suffix
248 unix2dos > $mnt/slitaz/boot/tazboot.cmd <<EOT
249 kernel=/slitaz/boot/bzimage
250 initrd=/slitaz/boot/$initrd
251 rw root=/dev/null $extraargs autologin
252 EOT
253 unix2dos $mnt/slitaz/boot/he* $mnt/slitaz/boot/opt* \
254 $mnt/slitaz/boot/README
255 [ -d $mnt/slitaz/usr/sbin -a ! -x $mnt/slitaz/usr/sbin/mount.posixovl ] &&
256 cp $(which mount.posixovl) $mnt/slitaz/usr/sbin
257 if [ "$useposixovl" ] && grep -qs " $mnt " /proc/mounts &&
258 [ ! -d $mnt/boot/grub ]; then
259 mkdir -p $mnt/boot/grub
260 echo -en "\nInstall grub in /boot/grub..."
261 cp -a /usr/lib/grub/*/* $mnt/boot/grub
262 cat > $mnt/boot/grub/menu.lst <<EOT
263 # /boot/grub/menu.lst: GRUB boot loader configuration.
265 # By default, boot the first entry.
266 default 0
268 # Boot automatically after 8 secs.
269 timeout 8
271 title Microsoft Windows
272 chainloader +1
274 EOT
275 dev=$(grep " $mnt " /proc/mounts | awk '{ print $1 }')
276 base=${dev//[0-9]/}
277 dd if=$base bs=32k count=1 of=$mnt/boot/grub/$(basename $base)
278 cat > $mnt/boot/grub/uninstall-grub.sh <<EOT
279 #!/bin/sh
281 [ -s /boot/grub/$(basename $base) ] &&
282 dd if=/boot/grub/$(basename $base) of=$base
283 EOT
284 grub-install --no-floppy --root-directory=$mnt $base
285 fi
286 if [ -s $mnt/boot/grub/menu.lst ] &&
287 ! grep -q /slitaz/boot/$bzimage $mnt/boot/grub/menu.lst; then
288 echo -en "\nUpdate /boot/grub/menu.lst..."
289 cat >> $mnt/boot/grub/menu.lst <<EOT
290 title SliTaz GNU/Linux $(cat $mnt/slitaz/etc/slitaz-release)
291 kernel /slitaz/boot/$bzimage rw root=/dev/null $extraargs autologin
292 initrd /slitaz/boot/$initrd
294 EOT
295 fi
296 rm -f /tmp/wait
297 [ "$useposixovl" ] && umount $mnt/slitaz
298 return 0
299 }
301 windev()
302 {
303 if [ -b "$1" ]; then
304 device=$1
305 elif [ "$1" ]; then
306 echo "Invalid Linux/Windows partition"
307 return 1
308 else
309 DEV="$(blkid | grep -iE "(msdos|vfat|ntfs|ext[234]|xfs|btrfs)" | sed 's/:.*//;s|/dev/||')"
310 [ "$DEV" ] || return
311 cat > /tmp/dialog$$ <<EOT
312 $DIALOG --clear --title " Select your Linux/Windows partition " \
313 --menu "\nPlease select the Linux/Windows partition according to its known size.
314 The data will be kept untouched.\n" 17 70 8 \
315 $(for i in $DEV ; do
316 label="$(blkid | sed "/$i:/!d;s/.*://;s/[^ ]*UUID=[^ ]* //g;s/LABEL=//")"
317 echo -n "/dev/$i \"$(($(cat /sys/block/*/$i/size)/2048))MB $label\" "
318 done)
319 EOT
320 exec 3>&1
321 [ $? -eq 0 ] || return
322 device=$(. /tmp/dialog$$ 2>&1 1>&3)
323 exec 3>&-
324 rm -f /tmp/dialog$$
325 fi
326 mnt=/tmp/mnt$$
327 mkdir -p $mnt && mount $device $mnt
328 }
330 extra_packages()
331 {
332 packages_list=
333 packages_dir=
334 $DIALOG --clear --title " Extra packages " \
335 --defaultno --yesno \
336 "Do you want to add extra packages ?" 7 70
337 [ $? -eq 0 ] || return
338 [ -s /var/lib/tazpkg/packages.txt ] || tazpkg recharge
339 if [ -s $media/boot/vmlinuz-$(uname -r) ]; then
340 cat > /tmp/dialog$$ <<EOT
341 $DIALOG --clear --title " Select the packages " \
342 --separate-output \
343 --cancel-label "Skip" \
344 --checklist "Please select the packages you want to install. Try with the first letter." \
345 0 0 0 \\
346 EOT
347 awk -F\| '{ printf "%s \"%s\" off ",$1,$3 }' \
348 /var/lib/tazpkg/packages.desc >> /tmp/dialog$$
349 sh /tmp/dialog$$ 2> /tmp/dialog.out$$
350 [ $? -eq 0 ] && packages_list="$(cat /tmp/dialog.out$$)"
351 fi
352 cat > /tmp/dialog$$ <<EOT
353 $DIALOG --clear \
354 --title "Please select the directory with every custom package to install." \
355 --cancel-label "Skip" --dselect $PWD 13 78
356 EOT
357 sh /tmp/dialog$$ 2> /tmp/dialog.out$$
358 [ $? -eq 0 ] && packages_dir="$(cat /tmp/dialog.out$$)"
359 rm -f /tmp/dialog$$ /tmp/dialog.out$$
360 }
362 _install()
363 {
364 extra_packages
365 $DIALOG --clear --title " SliTaz UMSDOS way installation " \
366 --yes-label "Install" --yesno \
367 "\nSliTaz will be installed in the subdirectory \\slitaz of the current
368 Linux/DOS/Windows partition. You can see your files from /mnt/dos.\n\n
369 You can start SliTaz with \\slitaz\\boot\\tazboot.exe\n\n
370 To uninstall SliTaz, you have only to remove this directory.
371 The file \\boot.ini or \\config.sys may be modified too.\n\n
372 SliTaz may run slowly on the 'UMSDOS way' installation due to the
373 posixovl filesystem. The 'TAZUSB way' installation runs faster.\n\n
374 To do a traditional installation with disk partitioning,
375 start SliTaz Live with the 'SliTaz RAM boot' menu.\n" 19 70
376 [ $? -eq 0 ] || return
377 doinstall
378 }
380 readtazbootconf()
381 {
382 kernel="$(sed '/^kernel=/!d;s/.*=//' $mnt/slitaz/boot/tazboot.cmd)"
383 initrd="$(sed '/^initrd=/!d;s/.*=//' $mnt/slitaz/boot/tazboot.cmd)"
384 cmdline="$(sed '/^kernel=/d;/^initrd=/d' $mnt/slitaz/boot/tazboot.cmd)"
385 }
387 bootinstalled()
388 {
389 [ "$(which kexec)" ] || return
390 [ -x $mnt/slitaz$1 ] || return
391 [ -s $mnt/slitaz/boot/tazboot.cmd ] || return
392 readtazbootconf
393 kexec -l $kernel --initrd $initrd --command-line "$cmdline" || return
394 umount $mnt
395 rm -rf $mnt
396 quit "kexec -e"
397 }
399 mkzip()
400 {
401 device=
402 packages_list=
403 packages_dir=
404 mnt=/tmp/mkzipmnt$$
405 mkdir -p $mnt
406 $1 $2 || return
407 for i in bootlace.com grubinst.exe grldr ; do
408 wget -O $mnt/slitaz/boot/$i http://mirror.slitaz.org/boot/$i
409 done
410 readtazbootconf
411 cat > $mnt/slitaz/boot/menu.lst <<EOT
412 title SliTaz
413 kernel $kernel $cmdline
414 initrd $initrd
416 EOT
417 while read file title; do
418 file=$(ls $mnt/slitaz/boot/*$file* 2> /dev/null)
419 [ -s "$file" ] && cat >> $mnt/slitaz/boot/menu.lst <<EOT
420 title $title
421 kernel ${file#$mnt}
423 EOT
424 done <<EOT
425 memtest MemTest
426 pxe Web boot
427 EOT
428 unix2dos $mnt/slitaz/boot/menu.lst
429 unix2dos > $mnt/slitaz/boot/install.txt <<EOT
430 For DOS users (real mode only):
432 Start SliTaz with \\slitaz\\boot\\tazboot.exe
435 For NT/2000/XP users:
437 1- Move the files grldr and menu.lst into the root directory
439 C:\\> copy \\slitaz\\boot\\grldr \\
440 C:\\> copy \\slitaz\\boot\\menu.lst \\
442 2- Remove boot.ini attributes
444 C:\\> attrib -r -h -s boot.ini
446 3- Append the following line to boot.init
448 C:\\grldr="slitaz"
450 4- Restore boot.ini attributes
452 C:\\> attrib +r +h +s boot.ini
454 See http://diddy.boot-land.net/grub4dos/files/README_GRUB4DOS.txt
455 and http://xpt.sourceforge.net/techdocs/nix/disk/boot/boot07-GrubForDosInfo/ar01s03.html
456 EOT
457 ( cd $mnt ; echo 'See \slitaz\boot\install.txt to launch SliTaz.' | \
458 zip -zr9 $(basename "$ISO" .iso).zip slitaz )
459 [ "$(which advzip)" ] &&
460 echo "Recompressing $(basename "$ISO" .iso).zip ..." &&
461 advzip -z4 $mnt/*.zip
462 mv $mnt/*.zip .
463 du -h $PWD/$(basename "$ISO" .iso).zip
464 umount $mnt
465 rm -rf $mnt
466 }
468 install()
469 {
470 windev $1 || return
471 packages_list=
472 packages_dir=
473 if [ "$1" ]; then
474 doinstall
475 else
476 _install && bootinstalled /sbin/init
477 fi
478 umount $mnt
479 rm -rf $mnt
480 }
482 inst2zip()
483 {
484 if [ "$1" ]; then
485 mkzip doinstall
486 else
487 mkzip _install
488 fi
489 }
491 _installtaz()
492 {
493 $DIALOG --clear --title " SliTaz TAZUSB way installation " \
494 --yes-label "Install" --yesno \
495 "\nSliTaz will be installed in the subdirectory \\slitaz of the current
496 Linux/DOS/Windows partition. You can see your files from /mnt/dos.\n\n
497 You can start SliTaz with \\slitaz\\boot\\tazboot.exe\n\n
498 To uninstall SliTaz, you have only to remove this directory.
499 The file \\boot.ini or \\config.sys may be modified too.\n\n
500 The filesystem is loaded entirely into memory upon boot to
501 increase responsiveness. Only /home lands on the hard disk.\n\n
502 To do a traditional installation with disk partitioning,
503 start SliTaz Live with the 'SliTaz RAM boot' menu.\n" 19 70
504 [ $? -eq 0 ] || return
505 doinstall tazusblike
506 }
508 installtaz()
509 {
510 windev $1 || return
511 packages_list=
512 packages_dir=
513 if [ "$1" ]; then
514 doinstall tazusblike
515 else
516 _installtaz && bootinstalled /boot/bzimage
517 fi
518 umount $mnt
519 rm -rf $mnt
520 }
522 insttaz2zip()
523 {
524 if [ "$1" ]; then
525 mkzip doinstall tazusblike
526 else
527 mkzip _installtaz
528 fi
529 }
531 bootiso()
532 {
533 cd /tmp
534 for i in $(ls_r $media/boot/rootfs*gz); do
535 grep -q ' lm ' /proc/cpuinfo && [ -s ${i}64 ] && i=${i}64
536 cat $i
537 n=$((4 - ($(stat -c %s $i) % 4)))
538 [ $n -eq 4 ] || dd if=/dev/zero bs=1 count=$n
539 done > initrd$$
540 cmdline="root=/dev/null autologin lang=$LANG"
541 [ -s /etc/keymap.conf ] && cmdline="$cmdline kmap=$(cat /etc/keymap.conf)"
542 [ -s /etc/TZ ] && cmdline="$cmdline tz=$(cat /etc/TZ)"
543 rm -f cmdline initrd 2> /dev/null
544 getcustomconf kexec >/dev/null
545 [ -s cmdline ] && cmdline="$cmdline $(cat cmdline)" && rm cmdline
546 [ -s initrd ] && cat initrd >> initrd$$ && rm initrd
547 kernel=$media/boot/bzImage
548 grep -q ' lm ' /proc/cpuinfo && [ -s ${kernel}64 ] && kernel=${kernel}64
549 . /etc/locale.conf
550 kexec -l $kernel --initrd initrd$$ --command-line "$cmdline" &&
551 rm -f initrd$$
552 quit "kexec -e"
553 }
555 tazboot()
556 {
557 if [ -z "$1" ]; then
558 $DIALOG --clear --title " SliTaz bootloader for DOS " \
559 --yes-label "Install" --yesno \
560 "\nThe file TAZBOOT.EXE will be created in the top directory. It supports
561 any linux kernel, multiple initramfs, a kernel command line and
562 an ISO image file loopback (retrieves files from an ISO file).\n\n
563 Usage: tazboot.exe [[@commands]|[kernel=<bzimage>]
564 [initrd=<rootfs>[,<rootfs2>...]] [bootfrom=<isofile>] cmdline args ...]\n\n
565 Defaults: tazboot @tazboot.cmd or tazboot kernel=bzImage auto\n\n\
566 Examples for tazboot.cmd:\n\n\
567 bootfrom=\\isos\\slitaz-4.0.iso\n\
568 kernel=boot/bzImage\n\
569 initrd=boot/rootfs4.gz,boot/rootfs3.gz,boot/rootfs2.gz,boot/rootfs1.gz\n\
570 rw root=/dev/null autologin\n\n\
571 kernel=\\slitaz\\vmlinuz root=/dev/sda5 ro\n\n
572 Unlike GRUB4DOS, it doesn't require unfragmented ISO image files.\n" 0 0
573 [ $? -eq 0 ] || return
574 fi
575 gettazboot tazboot.exe
576 du -h $PWD/tazboot.exe
577 }
579 md5()
580 {
581 dotwait "Checking files"
582 ( cd $media ; ${md5sum:-md5sum -c md5sum*} 2>&1 | sort ) > /tmp/data
583 unset md5sum
584 rm -f /tmp/wait
585 if [ "$1" ]; then
586 cat /tmp/data
587 else
588 $DIALOG --clear --title " Checked files " \
589 --textbox /tmp/data 0 0
590 fi
591 rm -f /tmp/data
592 }
594 gotcdfile()
595 {
596 for i in "$media/$1" "$media/*/$1" "$media/*/isolinux/$1" ; do
597 file=$(ls $i 2> /dev/null | sed q)
598 [ -s "$file" ] && break
599 done
600 }
602 sha()
603 {
604 gotcdfile 'sha*sum*'
605 sha=$(basename $file)
606 md5sum="${sha%sum*}sum -c ${file#$media/}"
607 md5 $@
608 }
610 readme()
611 {
612 gotcdfile 'README*'
613 if [ "$1" ]; then
614 cat $file
615 else
616 $DIALOG --clear --title " Readme " --textbox $file 0 0
617 fi
618 }
620 bzimage()
621 {
622 if [ -z "$1" ]; then
623 $DIALOG --clear --title " Create linux.exe ? " \
624 --yes-label "Install" --yesno \
625 "\nLinux.exe launches the linux kernel under DOS (in real mode only).
626 The cmdline arguments are supported except initrd=,
627 vga= (you can try 'rdev -v') and mem= (partially).
628 \nExample:\nC:\\> linux.exe root=/dev/hda2 ro panic=60\n" 12 70
629 [ $? -eq 0 ] || return
630 fi
631 cp $media/boot/bzImage linux.exe
632 du -h $PWD/linux.exe
633 }
635 memtest()
636 {
637 if [ -z "$1" ]; then
638 $DIALOG --clear --title " Create memtest.exe ? " \
639 --yes-label "Install" --yesno \
640 "\nMemtest86 is a thorough, stand alone memory test for x86 architecture
641 computers. BIOS based memory tests are a quick, cursory check and often
642 miss many of the failures that are detected by Memtest86.\n" 0 0
643 [ $? -eq 0 ] || return
644 fi
645 gotcdfile 'memtest*' && cp $file memtest.exe
646 du -h $PWD/memtest.exe
647 }
649 mkfat12()
650 {
651 [ $(($(get 0 $1) - 0x5A4D)) -eq 0 ] || return
652 J=$(($(get 3 $1 1) + 0x02))
653 R=$((1 + $(get 497 $1 1) + 1 + ($(get 500 $1)-1)/32))
654 [ $R -lt 2500 ] || return
655 [ $((($(get 500 $1)-1) & 31)) -lt 30 ] &&
656 ddq if=$file bs=32 count=1 seek=$(($R*16 - 1)) of=/dev/fd0
657 G="18 0 2 0 0 0 0 0"
658 [ $J -gt 25 ] || G=""
659 F=0
660 for i in 1 2 3; do
661 F=$((((2880-$R-$F-$F)*3+1023)/1024))
662 done
663 bytes2bin 0xEB $J 0x90 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 \
664 0 2 2 $(($R%256)) $(($R/256)) 2 64 0 64 11 0xF0 $F 0 \
665 $G | ddq bs=1 of=/dev/fd0
666 ddq if=/dev/zero bs=512 count=$((4+$F+$F)) seek=$R of=/dev/fd0
667 for i in $R $(($R+$F)) ; do
668 bytes2bin 0xF0 0xFF 0xFF | ddq bs=512 seek=$i of=/dev/fd0
669 done
670 echo -n $(basename $1) | ddq bs=1 seek=3 count=8 of=/dev/fd0
671 }
673 mkfloppy()
674 {
675 dotwait "Create a $(basename $1) boot floppy"
676 ddq if=$1 of=/dev/fd0
677 mkfat12 $1
678 rm -f /tmp/wait
679 }
681 fdmemtest()
682 {
683 if [ -z "$1" ]; then
684 $DIALOG --clear --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" 0 0
690 [ $? -eq 0 ] || return
691 fi
692 gotcdfile 'memtest*' && mkfloppy $file
693 }
695 pxe()
696 {
697 gotcdfile '?pxe*'
698 if [ -z "$1" ]; then
699 $DIALOG --clear --title " Create $(basename $file).exe ? " \
700 --yes-label "Install" --yesno \
701 "\nBoot your operating system from the internet and enjoy a full system
702 working entirely in RAM with speed and stability in mind. The Linux Kernel
703 and the complete SliTaz compressed root filesystem will be loaded into RAM
704 from the Web using PXE and HTTP protocols.\n" 0 0
705 [ $? -eq 0 ] || return
706 fi
707 cp $file $(basename $file).exe
708 du -h $PWD/$(basename $file).exe
709 }
711 fdpxe()
712 {
713 if [ -z "$1" ]; then
714 $DIALOG --clear --title " Create a SliTaz Web boot floppy " \
715 --yes-label "Create floppy" --yesno \
716 "\nBoot your operating system from the internet and enjoy a full system
717 working entirely in RAM with speed and stability in mind. The Linux Kernel
718 and the complete SliTaz compressed root filesystem will be loaded into RAM
719 from the Web using PXE and HTTP protocols.\n\n
720 Please insert a blank disk in floppy drive.\n" 0 0
721 [ $? -eq 0 ] || return
722 fi
723 gotcdfile '?pxe*' && mkfloppy $file
724 }
726 menuitem()
727 {
728 [ "$3" ] && shift
729 echo -en "\"$1\" \"$2\""
730 }
732 gotposixovl()
733 {
734 mount.posixovl 2>&1 | grep -qi usage && gotcdfile 'rootfs*.gz' &&
735 menuitem "$@"
736 }
738 gotposixovlzip()
739 {
740 [ "$(which zip)" ] && gotposixovl "$1" "$2"
741 }
743 xfile()
744 {
745 [ "$(which $1)" ] && menuitem "$@"
746 }
748 cdfile()
749 {
750 gotcdfile "$1" && menuitem "$@"
751 }
753 gottazusb()
754 {
755 gotcdfile 'rootfs*.gz' && xfile tazusb "$@"
756 }
758 isbzImage()
759 {
760 [ $(get 514 $file 4) -eq 1400005704 ] &&
761 [ $(($(get 529 $file 1) & 1)) -eq 1 ]
762 }
764 cdfilex()
765 {
766 gotcdfile "$1" && [ "$(which kexec)" ] && isbzImage && menuitem "$@"
767 }
769 cdfilef()
770 {
771 [ -e /sys/block/fd0 ] && cdfile "$@"
772 }
774 cdexe()
775 {
776 gotcdfile "$1" &&
777 [ $(get 0 $file 2>/dev/null || echo 0) -eq 23117 ] &&
778 menuitem "$@"
779 }
781 misspkg()
782 {
783 for i in zip kexec-tools posixovl cdrkit cdrkit-isoinfo ; do
784 [ -d /var/lib/tazpkg/installed/$i/ ] && continue
785 [ "$1" != "install" ] && menuitem "$@" && return
786 tazpkg get-install $i
787 done
788 }
790 missing()
791 {
792 misspkg install
793 }
795 ishybrid()
796 {
797 [ $(get 510 "$ISO") -eq 43605 ] || return
798 C=$((2048*$(get $(((17*2048) + 71)) "$ISO" 4)))
799 [ $(get $C "$ISO" 4) -eq 1 ] || return
800 [ $(get $(($C+30)) "$ISO" 4) -eq $((0x88AA55)) ] || return
801 C=$((2048*$(get $(($C+40)) "$ISO" 4)))
802 [ $(get $(($C+64)) "$ISO" 4) -eq 1886961915 ] && menuitem "$@"
803 }
805 isiso()
806 {
807 [ $(get 32769 "$ISO" 4) -eq 808469571 ] && menuitem "$@"
808 }
810 hastazboot()
811 {
812 [ $(get 0 "$ISO") -eq 23117 ] && menuitem "$@"
813 }
815 burnable()
816 {
817 [ "$(sed '/Can wr.*1$/!d' /proc/sys/dev/cdrom/info 2> /dev/null)" ] &&
818 menuitem "$@"
819 }
821 blankable()
822 {
823 [ "$(sed '/Can wr.*RW.*1$/!d' /proc/sys/dev/cdrom/info 2> /dev/null)" ] &&
824 menuitem "$@"
825 }
827 burniso()
828 {
829 wodim -v speed=$(fgrep "drive speed" /proc/sys/dev/cdrom/info | cut -f3) \
830 -eject -multi "$ISO"
831 }
833 blankcd()
834 {
835 wodim -v -blank=fast
836 }
838 customsector()
839 {
840 local c=$(echo $(get 32848 "$ISO" 4))
841 hascustomconf $(($c+16)) && echo $(($c+16)) || echo $c
842 }
844 hascustomconf()
845 {
846 [ "$(ddq bs=2k skip=${1:-$(customsector)} if="$ISO" | ddq bs=1 count=6)" \
847 == "#!boot" ]
848 }
850 gotcustomconf()
851 {
852 hascustomconf && menuitem "$@"
853 }
855 hasflavor()
856 {
857 [ -x /usr/bin/tazlito ] && [ -s $media/boot/bzImage ] && menuitem "$@"
858 }
860 gotisomd5()
861 {
862 [ "$(which md5sum 2> /dev/null)" ] &&
863 [ $(get 0 "$ISO") -eq 23117 ] &&
864 [ $(get 18 "$ISO") -ne 0 ] && menuitem "$@"
865 }
867 getcustomconf()
868 {
869 ddq bs=2k skip=$(customsector) if="$ISO" | while read line; do
870 case "$line" in
871 \#!boot*) ;;
872 append=*) echo ${line#append=} > cmdline && ls -l $PWD/cmdline ;;
873 initrd:*) cnt=${line#initrd:}
874 { ddq bs=512 count=$(($cnt / 512));
875 ddq bs=1 count=$(($cnt % 512)); } > initrd &&
876 ls -l $PWD/initrd
877 break ;;
878 *) break ;;
879 esac
880 done
881 [ "$1" ] && return 0
882 echo -e "\rPress RETURN to continue."
883 read n
884 }
886 isomd5()
887 {
888 dotwait "Checking iso image"
889 [ "$(ddq if="$ISO" bs=2k skip=16 \
890 count=$(($(get 32848 "$ISO" 4)-16)) | md5sum)" == \
891 "$(ddq if="$ISO" bs=16 count=1 skip=2047 | od -N 16 -t x1 -An | \
892 sed 's/ //g') -" ] && echo "OK" || echo "ERROR"
893 echo -en "\rChecking iso hybrid boot..."
894 n=$(($(get 2 "$ISO")-1+($(get 4 "$ISO")-1)*512))
895 if [ $n -lt 40000 -a $n -gt 32768 ]; then
896 s=$(get 0 "$ISO" 2 $n | awk '{ i+= $0 } END { print i }')
897 [ $(((1+$s+$(get $(($n+1)) "$ISO" 1)) % 65536)) -eq 0 ] &&
898 echo "OK" || echo "ERROR"
899 fi
900 if hascustomconf; then
901 echo -en "\rChecking iso custom config..."
902 TMP=/tmp/$(basename $0)$$md5
903 md5="$(ddq bs=2k skip=$(customsector) if="$ISO" | while read line; do
904 case "$line" in
905 \#!boot*) echo ${line#*boot } > $TMP ;;
906 append=*) echo $line ;;
907 initrd:*) echo $line
908 cnt=${line#initrd:}
909 ddq bs=512 count=$((cnt / 512))
910 ddq bs=1 count=$((cnt % 512))
911 break ;;
912 *) break ;;
913 esac
914 done | md5sum | cut -c1-32)"
915 [ "$md5" == "$(cat $TMP)" ] && echo "OK" || echo "ERROR"
916 rm -f $TMP
917 fi
918 rm -f /tmp/wait
919 [ "$1" ] && return 0
920 echo -e "\rPress RETURN to continue."
921 read n
922 }
924 usbdev()
925 {
926 dotwait "Wait 5 seconds for USB devices"
927 sleep 5
928 rm -f /tmp/wait
929 DEV="$(grep -l 1 /sys/block/*/removable | \
930 sed 's|/sys/block/\(.*\)/removable|\1|')"
931 grep -qs 1 /sys/block/$DEV/ro && return
932 [ "$DEV" ] || return
933 cat > /tmp/dialog$$ <<EOT
934 $DIALOG --clear --title " Select your USB key " \
935 --menu "\nPlease select the USB key according to its known size.\n\n" \
936 0 0 0 \
937 $(for i in $DEV ; do
938 echo -n "/dev/$i \"$(($(cat /sys/block/$i/size)/2048))MB $(cat /sys/block/$i/device/model 2> /dev/null)\" "
939 done) \
941 EOT
942 exec 3>&1
943 device=$(. /tmp/dialog$$ 2>&1 1>&3)
944 rm -f /tmp/dialog$$
945 retval=$?
946 exec 3>&-
947 rm -f /tmp/dialog$$
948 [ $retval -eq 0 ]
949 }
951 tazusbmsg()
952 {
953 [ "$(which tazusb 2> /dev/null)" ] || return
954 echo "You should choose 'USB key read/write installation' to be
955 able to save the package updates or your own configuration and data files.\n\n"
956 }
958 usbbootkey()
959 {
960 if [ -b "$1" ]; then
961 device=$1
962 elif [ "$1" ]; then
963 echo "Invalid USB key device"
964 return 1
965 else
966 $DIALOG --clear --title " Create a USB boot key " \
967 --yes-label "Continue" --yesno \
968 "\nThe USB key will be used like a CD-ROM. You will not be able to write
969 any data on the boot partition.\n\n
970 An extra FAT32 partition will be created with the remaining free space.\n\n
971 $(tazusbmsg)Please plug your USB stick in now.\n" 16 70
972 [ $? -eq 0 ] || return
973 usbdev || return
975 # perform dd in progress bar
976 max=$(($(stat -c %s "$ISO")/2048))
977 i=0; ddq if="$ISO" bs=1024k | (
978 while ddq bs=1024k count=1 ; do
979 i=$(($i + 1))
980 [ $i -gt $max ] && break
981 echo $((($i*100)/$max)) | dialog --gauge \
982 " The ISO image transfer can be long. Please wait..." \
983 6 70 0 > /dev/tty 2>&1
984 done ) > $device
985 fi
987 # partition + fat32 format for the remaining space
988 for p in 0 16; do
989 get $((450+$p)) $device 2 12 | xargs echo | {
990 read dx cx ol oh ll lh
991 [ $dx -eq $((0x3F17)) ] || continue
992 cx=$(($cx & 0xFF00))
993 ofs=$(($ll+($lh<<16)))
994 n=$(($(cat /sys/block/${device#/dev/}/size)-$ofs))
995 m=$(($cx+($n/8)))
996 [ $m -gt $((0x3FF00)) ] && m=$((0x3FF00))
997 m=$((($m & 0xFF00)+(($m>>16)<<6)))
998 words2bin 0 $((0x101+$cx)) 0x3F0B $((32+$m)) \
999 $ll $lh $(($n & 0xFFFF)) $(($n >> 16)) | \
1000 ddq bs=1 seek=$((462-$p)) of=$device
1001 if [ "$(which mkdosfs 2> /dev/null)" ]; then
1002 losetup -o $((512*$ofs)) /dev/loop2 $device
1003 mkdosfs -n "SLITAZ BOOT" /dev/loop2
1004 words2bin $(($ofs & 0xFFFF)) $(($ofs >> 16)) | \
1005 ddq bs=1 seek=28 of=/dev/loop2
1006 sync
1007 losetup -d /dev/loop2
1008 fi
1010 done
1013 usbkey()
1015 $DIALOG --clear --title " Create a SliTaz USB key " \
1016 --yes-label "Continue" --yesno \
1017 "\nUnlike a hard drive install, the filesystem is kept in a compressed
1018 rootfs.gz. The filesystem is loaded entirely into memory upon boot.
1019 This should increase responsiveness, protect the filesystem against
1020 accidental corruption and reduce read/writes to the USB drive.
1021 Once setup, the tazusb utility can rewrite the root filesystem
1022 with any changes you have made since booting up,
1023 giving the effective benefits of a hard drive install.\n\n
1024 /home is mounted on boot using the UUID of your particular flash drive.
1025 Unlike a device name, the UUID has the benefit of never changing from machine
1026 to machine.\n\n
1027 Please plug your USB stick in now.\n" 19 70
1028 [ $? -eq 0 ] || return
1029 usbdev || return
1030 exec 3>&1
1031 format=`$DIALOG --clear \
1032 --title " Select the filesystem " \
1033 --radiolist "\nPlease select the filesystem type to create.\n\n\
1034 The filesystem creation will erase all the data in the USB key." 14 70 4 \
1035 "none" "Do not erase the USB key" on \
1036 "ext3" "Ext3 journaling filesystem" off \
1037 "ext2" "Ext2 filesystem" off \
1038 "fat32" "Windows FAT32 filesystem" off \
1039 2>&1 1>&3`
1040 retval=$?
1041 exec 3>&-
1042 [ $retval -eq 0 ] || return
1043 [ "$format" != "none" ] && tazusb format $device "SliTaz" $format
1044 tazusb gen-iso2usb "$ISO" $device
1047 dokexec()
1049 kexec -l $file || return
1050 quit "kexec -e"
1053 runmemtest()
1055 gotcdfile 'memtest*' && dokexec
1058 runpxe()
1060 gotcdfile '?pxe*' && dokexec
1063 flavdata()
1065 [ $(get 1024 "$ISO") -eq 35615 ] && n=2 || n=$((1+$(get 417 "$ISO" 1)))
1066 [ $n -eq 4 ] && n=20
1067 [ $(get $(($n*512)) "$ISO") -eq 35615 ] || n=13
1068 ddq if="$ISO" bs=512 skip=$n count=20 | zcat 2>/dev/null
1071 hasflavinfo()
1073 [ "$(flavdata | ddq bs=1 count=7 | strings)" == \
1074 "0707010" ] && menuitem "$@"
1077 showfavinfo()
1079 mkdir -p /tmp/data
1080 flavdata | ( cd /tmp/data ; cpio -i )
1081 file=/tmp/data/info
1082 cat /tmp/data/*desc > $file
1083 if [ -s /tmp/data/*receipt ]; then
1084 echo "=== receipt ==="
1085 cat /tmp/data/*receipt
1086 fi >> $file
1087 for i in /tmp/data/*list* ; do
1088 echo "=== extra ${i#*list} files"
1089 cat $i
1090 done >> $file
1091 if [ "$1" ]; then
1092 cat $file
1093 else
1094 $DIALOG --clear --title " Flavor info " \
1095 --textbox $file 0 0
1096 fi
1097 rm -rf /tmp/data
1100 flavor()
1102 name="$(flavdata | cpio -t 2> /dev/null | sed 's/.[a-z]*$//;q')"
1103 echo "Create ${name:=flavor}.flavor..."
1104 tazlito iso2flavor "$ISO" $name
1105 ls -l $name.flavor 2> /dev/null && return
1106 sleep 5
1107 [ "$1" ] && return
1108 echo -e "\rPress RETURN to continue."
1109 read n
1112 if [ "$1" == "--build" ]; then #install-begin
1113 uuencode -m - < ifmem.bin | sed -e '/^ifmemcode$/r/dev/stdin' \
1114 -e '/^ifmemcode$/d' -i $0
1115 uuencode -m - < bootloader.bin | sed -e '/^bootloader$/r/dev/stdin' \
1116 -e '/^bootloader$/d' -e '/install-begin$/,/install-end$/d' -i $0
1117 exit
1118 fi #install-end
1119 parse_isolinux()
1121 awk 'BEGIN { IGNORECASE=1 }
1122 function multi(n)
1124 auto=$n
1125 for (--n; n < NF; n+=2) {
1126 s=$n
1127 if (s ~ /M$/) s = substr(s,0,length(s)-1)
1128 else s /= 1024
1129 sizes=int(s) " " sizes
1131 next
1134 if ($1 == "LABEL") {
1135 label=$2
1136 if (auto == "") auto=label
1138 if ($1 == "KERNEL" || $1 == "COM32") kernel[label]=$2
1139 if ($1 == "INITRD") initrd[label]=$2
1140 if ($1 == "APPEND") {
1141 i=2
1142 if (kernel[label] ~ "ifmem.c32") multi(3)
1143 if (kernel[label] ~ "c32box.c32") {
1144 if ($2 == "linux") { kernel[label]=$3; i=4 }
1145 if ($2 == "ifmem") multi(4)
1147 if (kernel[label] ~ "ifcpu64.c32") { auto=$4; next }
1148 while (i <= NF) {
1149 if ($i ~ "^initrd=") initrd[label]=substr($i,8)
1150 else cmdline[label]=cmdline[label] " " $i
1151 i++
1155 END {
1156 print "KERNEL=\"" kernel[auto] "\""
1157 print "INITRD=\"" initrd[auto] "\""
1158 print "CMDLINE=\"" substr(cmdline[auto],2) "\""
1159 print "SIZES=\"" sizes "\""
1160 }'
1163 locase()
1165 echo "$1" | tr [A-Z] [a-z]
1168 ifmemcode()
1170 uudecode <<EOT
1171 ifmemcode
1172 EOT
1175 floppyset()
1177 gotcdfile 'isolinux.cfg'
1178 $0 include $file | parse_isolinux > /tmp/var$$
1179 . /tmp/var$$
1180 [ -z "$KERNEL" ] && echo "Can't parse isolinux.cfg" && return
1181 for i in $media/$KERNEL $(dirname $file)/$KERNEL $media/$(locase $KERNEL) \
1182 $(dirname $file)/$(locase $KERNEL); do
1183 i="$(ls $i* | sed q)"
1184 [ -n "$i" ] && KERNEL=$i && break
1185 done
1186 rm -f /tmp/var$$
1187 [ $(get 514 $KERNEL 4) -eq 1400005704 ] || return
1188 n=$(($(get 497 $KERNEL 1)+1))
1189 ddq bs=512 count=$n if=$KERNEL of=/tmp/fd$$
1190 uudecode <<EOT | ddq of=/tmp/fd$$ conv=notrunc
1191 bootloader
1192 EOT
1193 pos=$(($n*512))
1194 if [ -n "$CMDLINE" ]; then
1195 echo -n "$CMDLINE" | ddq bs=512 count=1 conv=sync >> /tmp/fd$$
1196 bytes2bin $n | ddq conv=notrunc \
1197 bs=1 seek=497 count=1 of=/tmp/fd$$
1198 words2bin $pos | ddq conv=notrunc \
1199 bs=1 seek=34 count=2 of=/tmp/fd$$
1200 [ $(get 518 $KERNEL 4) -ge 514 ] &&
1201 words2bin 32768 9 | ddq conv=notrunc \
1202 bs=1 seek=552 count=4 of=/tmp/fd$$
1203 fi
1204 syssize=$(echo $(get 500 /tmp/fd$$ 4))
1205 ddq bs=512 skip=$n if=$KERNEL | cat - /dev/zero | \
1206 ddq bs=512 count=$((($syssize+31)/32)) conv=sync >> /tmp/fd$$
1207 base=$(stat -c %s /tmp/fd$$)
1208 len=
1209 if [ "$INITRD" ]; then
1210 l=0
1211 for i in ${INITRD//,/ }; do
1212 for j in $media/$i $(dirname $KERNEL)/$i $media/$(locase $i) \
1213 $(dirname $KERNEL)/$(locase $i); do
1214 j="$(ls $j* | sed q)"
1215 [ -n "$j" ] && i=$j && break
1216 done
1217 ddq if=$i >> /tmp/fd$$
1218 l=$(($l+$(stat -c %s $i)))
1219 r=$((4 - ($l % 4)))
1220 if [ $r -ne 4 ]; then
1221 ddq if=/dev/zero bs=1 count=$r >> /tmp/fd$$
1222 l=$(($l + $r))
1223 fi
1224 case "$i:$INITRD" in
1225 *rootfs.gz:*rootfs.gz,*) continue # loram
1226 esac
1227 len="$len $l"; l=0
1228 done
1229 rdadrs=${RDADRS:-$(((($syssize*16)+0x1F0000) & -4096))}
1230 words2bin $(($rdadrs & 0xFFFF)) $(($rdadrs >> 16)) | ddq \
1231 conv=notrunc bs=1 seek=536 count=4 of=/tmp/fd$$
1232 fi
1233 n=$(echo $len | wc -w)
1234 if [ $((494 - $(get 494 /tmp/fd$$))) -ge $(($n * 4)) ]; then
1235 i=$(($(get 494 /tmp/fd$$)))
1236 bytes2bin $(($i + ($n*4) - 256)) | ddq bs=1 conv=notrunc \
1237 seek=496 count=1 of=/tmp/fd$$
1238 else
1239 i=$(($pos + 0x1FC - ($n*4)))
1240 bytes2bin $(($i % 256)) $((i / 256)) 252 | ddq bs=1 \
1241 conv=notrunc seek=494 count=3 of=/tmp/fd$$
1242 s=$(($i - 2*$(echo "$SIZES" | wc -w)))
1243 p=$(($s - $(ifmemcode | wc -c)))
1244 ifmemcode | ddq bs=1 conv=notrunc seek=$p of=/tmp/fd$$
1245 words2bin $SIZES | ddq bs=1 conv=notrunc seek=$s of=/tmp/fd$$
1246 bytes2bin 154 $(($p%256)) $(($p/256)) 0 144 | \
1247 ddq bs=1 conv=notrunc seek=60 of=/tmp/fd$$
1248 fi
1249 for r in $len ; do
1250 words2bin $(($r & 0xFFFF)) $(($r >> 16)) | ddq conv=notrunc \
1251 bs=1 seek=$i count=4 of=/tmp/fd$$
1252 i=$(($i + 4))
1253 done
1254 split -b 1440k /tmp/fd$$ fd$$
1255 rm -f /tmp/fd$$
1256 n=1; i=0; r=0
1257 set -- $len
1258 ls fd$$* | while read file ; do
1259 if [ $i -gt $(($1+$base)) ]; then
1260 shift
1261 r=$(($r+100)); n=0; i=0; base=0
1262 fi
1263 ddq of=$file bs=18k seek=80 count=0
1264 i=$(($i+1474560))
1265 printf "mv %s fd%03d.img\n" $file $(($r+$n))
1266 n=$(($n+1))
1267 done | sh
1268 du -ch $PWD/fd???.img
1271 quit()
1273 umount -d $media
1274 rmdir $media
1275 ${1:-exit}
1278 infoiso()
1280 isoinfo -d -i "$ISO" > /tmp/isoinfo$$
1281 if [ -x "$(which iso2exe)" ]; then
1282 echo "----"
1283 blkid "$ISO" | while read args; do
1284 set -- $args
1285 while [ -n "$2" ]; do
1286 case "$2" in
1287 *UUID*|PT*) echo $2;;
1288 esac
1289 shift
1290 done
1291 done
1292 if ! fdisk -l "$ISO" | grep -q 'valid partition'; then
1293 fdisk -l "$ISO" | grep heads
1294 fdisk -l "$ISO" | sed 's/^ *[^ ]* *//;s/ */ /g;$!d'
1295 fi
1296 echo "----"
1297 iso2exe -l "$ISO"
1298 fi >> /tmp/isoinfo$$
1299 if [ "$1" ]; then
1300 cat /tmp/isoinfo$$
1301 else
1302 $DIALOG --clear --title " Info ISO " \
1303 --textbox /tmp/isoinfo$$ 0 0
1304 fi
1305 rm -f /tmp/isoinfo$$
1308 isotitle()
1310 echo "$(blkid "$ISO" | sed 's/.*LABEL="\([^"]*\).*/\1/') $(stat \
1311 -c %y $media/.|sed 's/ .*//') $(basename "$ISO")"
1314 if [ "$1" == "include" ]; then
1315 [ -s "$2" ] && cd $(dirname "$2") && awk -v exe=$0 \
1316 '{ if ($1 == "include") system(exe " include " $2); else print }' <"$2"
1317 exit
1318 fi
1319 ISO="${1:-/dev/null}"
1320 [ ${ISO:0:1} != "/" ] && ISO=$(cd $(dirname $ISO); echo $PWD/$(basename $ISO))
1321 [ -z "$(isiso 2> /dev/null)" ] && echo "Usage : $0 file.iso" && exit 1
1322 media=/tmp/media$$
1323 mkdir -p $media
1324 mount -o loop,ro "$ISO" $media
1326 if [ "$2" == "list" ]; then
1327 sed '/^\$(.*") \\/!d;s/^\$(\(.*\)").*/\1"/' $0 | while read line; do
1328 eval $line
1329 echo
1330 done | sed '/^$/d;/"usbkey"/d'
1331 quit
1332 fi
1333 if grep -q "^$2()" $0; then
1334 exe=$2
1335 shift 2
1336 if [ -n "$(eval $(grep "\"$exe\"" $0 | sed \
1337 '/^\$/!d;s/.(\(.*\)[\t ]*".*"[\t ]*".*/\1/'))" ]; then
1338 isotitle
1339 grep "\"$exe\"" $0 | sed '/^\$/!d;s/.*"[\t ]*"\(.*\)".*/\1/'
1340 echo ----
1341 $exe "$@"
1342 fi
1343 quit
1344 fi
1346 while true; do
1347 cat > /tmp/dialog$$ <<EOT
1348 $DIALOG --clear --title " $(isotitle) " --menu "" -2 70 0 \
1349 $(cdfile 'README*' "readme" "Show the README file") \
1350 $(gotcustomconf "getcustomconf" "Get custom config") \
1351 $(gotisomd5 "isomd5" "Check the ISO image") \
1352 $(cdfile 'md5sum*' "md5" "Check the ISO files") \
1353 $(cdfile 'sha*sum*' "sha" "Check the ISO files") \
1354 $(xfile isoinfo "infoiso" "ISO image info") \
1355 $(cdfilex boot/bzImage "bootiso" "Boot the ISO image") \
1356 $(burnable "burniso" "Burn the ISO image") \
1357 $(blankable "blankcd" "Blank the CD/DVD") \
1358 $(gotposixovl "install" "Hard disk installation (UMSDOS way)") \
1359 $(gotposixovl "installtaz" "Hard disk installation (TAZUSB way)") \
1360 $(gotposixovlzip "inst2zip" "ZIP installation archive (UMSDOS way)") \
1361 $(gotposixovlzip "insttaz2zip" "ZIP installation archive (TAZUSB way)") \
1362 $(gottazusb "usbkey" "USB key read/write installation") \
1363 $(ishybrid "usbbootkey" "USB boot key (read only)") \
1364 $(hasflavinfo "showfavinfo" "Show flavor extra info") \
1365 $(hasflavor "flavor" "Get flavor file") \
1366 $(cdfile isolinux.cfg "floppyset" "Boot floppy set") \
1367 $(hastazboot "tazboot" "Get tazboot.exe Linux loader") \
1368 $(cdexe boot/bzImage "bzimage" "Get linux DOS/EXE file") \
1369 $(cdexe 'memtest*' "memtest" "Get Memtest86 DOS/EXE file") \
1370 $(cdfilef 'memtest*' "fdmemtest" "Create a Memtest86 boot floppy") \
1371 $(cdfilex 'memtest*' "runmemtest" "Start Memtest86") \
1372 $(cdexe '?pxe*' "pxe" "Get SliTaz Web boot DOS/EXE utility") \
1373 $(cdfilef '?pxe*' "fdpxe" "Create a SliTaz Web boot floppy") \
1374 $(cdfilex '?pxe*' "runpxe" "Start the SliTaz Web boot utility") \
1375 $(misspkg "missing" "Install packages to get more options") \
1376 $(menuitem "quit" "Quit this utility")
1377 EOT
1378 exec 3>&1
1379 value=$(. /tmp/dialog$$ 2>&1 1>&3)
1380 retval=$?
1381 exec 3>&-
1382 rm -f /tmp/dialog$$
1383 [ $retval -eq 0 ] || quit
1384 $value
1385 done