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

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