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

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