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

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