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

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