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

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