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

syslinux: merge init.exe & taziso
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu May 28 08:35:55 2020 +0000 (2020-05-28)
parents 3f40a3c71c48
children c2a80ff9499e
line source
1 #!/bin/sh
3 [ $(id -u) -eq 0 ] || exec su -c "$0 $@"
5 DIALOG=dialog
7 ddq()
8 {
9 dd $@ 2> /dev/null
10 }
12 get()
13 {
14 od -v -j $1 -N ${4:-${3:-2}} -t u${3:-2} -w${3:-2} -An "$2" 2>/dev/null ||
15 hexdump -v -s $1 -n ${4:-${3:-2}} -e "\"\" 1/${3:-2} \" %u\n\"" "$2"
16 }
18 bytes2bin()
19 {
20 for i in $@ ; do
21 printf '\\\\x%02X' $(($i&255))
22 done | xargs echo -en
23 }
25 words2bin()
26 {
27 for i in $@ ; do
28 printf '\\\\x%02X\\\\x%02X' $(($i&255)) $((($i>>8)&255))
29 done | xargs echo -en
30 }
32 gettazboot()
33 {
34 echo -e "\nCreating $(basename $1) ..."
35 S=$((32+HEADERSZ))
36 P=$((($S+511)/512))
37 E=$((4096-(32*$P)))
38 words2bin 0x5A4D $(($S%512)) $P 0 2 $E -1 -16 \
39 -2 0 256 -16 28 0x6C53 0x5469 0x7A61 > $1
40 uudecode - >> $1 << EOT
41 HEADERCODE
42 EOT
43 gotcdfile linld.com
44 ddq if=$file >> $1
45 }
47 uncpio()
48 {
49 i=$1
50 [ $0 = /init.exe ] && sed 's|$| |' /proc/cpuinfo | grep ' lm ' && [ -s ${i}64 ] && i=${i}64
51 [ -s "$i" ] || return
52 echo -en "\n Extracting $(basename $i) ..."
53 case $(get 0 $i) in
54 *35615) ( zcat || gunzip ) ;;
55 *14333) unxz ;;
56 *\ 93) unlzma ;;
57 *) cat ;;
58 esac < $i | ( cd ${2:-/} ; cpio -idmu > /dev/null 2>&1 )
59 }
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 hascustomconf()
933 {
934 [ "$(ddq bs=2k skip=${1:-$(customsector)} if="$ISO" | ddq bs=1 count=6)" \
935 = "#!boot" ]
936 }
938 gotcustomconf()
939 {
940 hascustomconf && menuitem "$@"
941 }
943 hasflavor()
944 {
945 [ -x /usr/bin/tazlito ] && [ -s $media/boot/bzImage ] && menuitem "$@"
946 }
948 gotisomd5()
949 {
950 [ "$(which md5sum 2> /dev/null)" ] &&
951 [ $(get 0 "$ISO") -eq 23117 ] &&
952 [ $(get 18 "$ISO") -ne 0 ] && menuitem "$@"
953 }
955 getcustomconf()
956 {
957 ddq bs=2k skip=$(customsector) if="$ISO" | while read line; do
958 case "$line" in
959 \#!boot*) ;;
960 append=*) echo ${line#append=} > cmdline && ls -l $PWD/cmdline ;;
961 initrd:*) cnt=${line#initrd:}
962 { ddq bs=512 count=$(($cnt / 512));
963 ddq bs=1 count=$(($cnt % 512)); } > initrd &&
964 ls -l $PWD/initrd
965 break ;;
966 *) break ;;
967 esac
968 done
969 [ "$1" ] && return 0
970 echo -e "\rPress RETURN to continue."
971 read n
972 }
974 isomd5()
975 {
976 dotwait "Checking iso image"
977 [ "$(ddq if="$ISO" bs=2k skip=16 \
978 count=$(($(get 32848 "$ISO" 4)-16)) | md5sum)" = \
979 "$(ddq if="$ISO" bs=16 count=1 skip=2047 | od -N 16 -t x1 -An | \
980 sed 's/ //g') -" ] && echo "OK" || echo "ERROR"
981 echo -en "\rChecking iso hybrid boot..."
982 n=$(($(get 2 "$ISO")-1+($(get 4 "$ISO")-1)*512))
983 if [ $n -lt 40000 -a $n -gt 32768 ]; then
984 s=$(get 0 "$ISO" 2 $n | awk '{ i+= $0 } END { print i }')
985 [ $(((1+$s+$(get $(($n+1)) "$ISO" 1)) % 65536)) -eq 0 ] &&
986 echo "OK" || echo "ERROR"
987 fi
988 if hascustomconf; then
989 echo -en "\rChecking iso custom config..."
990 TMP=/tmp/$(basename $0)$$md5
991 md5="$(ddq bs=2k skip=$(customsector) if="$ISO" | while read line; do
992 case "$line" in
993 \#!boot*) echo ${line#*boot } > $TMP ;;
994 append=*) echo $line ;;
995 initrd:*) echo $line
996 cnt=${line#initrd:}
997 ddq bs=512 count=$((cnt / 512))
998 ddq bs=1 count=$((cnt % 512))
999 break ;;
1000 *) break ;;
1001 esac
1002 done | md5sum | cut -c1-32)"
1003 [ "$md5" = "$(cat $TMP)" ] && echo "OK" || echo "ERROR"
1004 rm -f $TMP
1005 fi
1006 rm -f /tmp/wait
1007 [ "$1" ] && return 0
1008 echo -e "\rPress RETURN to continue."
1009 read n
1012 usbdev()
1014 dotwait "Wait 5 seconds for USB devices"
1015 sleep 5
1016 rm -f /tmp/wait
1017 DEV="$(grep -l 1 /sys/block/*/removable | \
1018 sed 's|/sys/block/\(.*\)/removable|\1|')"
1019 grep -qs 1 /sys/block/$DEV/ro && return
1020 [ "$DEV" ] || return
1021 cat > /tmp/dialog$$ <<EOT
1022 $DIALOG --clear --title " Select your USB key " \
1023 --menu "\nPlease select the USB key according to its known size.\n\n" \
1024 0 0 0 \
1025 $(for i in $DEV ; do
1026 echo -n "/dev/$i \"$(($(cat /sys/block/$i/size)/2048))MB $(cat /sys/block/$i/device/model 2> /dev/null)\" "
1027 done) \
1029 EOT
1030 exec 3>&1
1031 device=$(. /tmp/dialog$$ 2>&1 1>&3)
1032 rm -f /tmp/dialog$$
1033 retval=$?
1034 exec 3>&-
1035 rm -f /tmp/dialog$$
1036 [ $retval -eq 0 ]
1039 tazusbmsg()
1041 [ "$(which tazusb 2> /dev/null)" ] || return
1042 echo "You should choose 'USB key read/write installation' to be
1043 able to save the package updates or your own configuration and data files.\n\n"
1046 usbbootkey()
1048 if [ -b "$1" ]; then
1049 device=$1
1050 elif [ "$1" ]; then
1051 echo "Invalid USB key device"
1052 return 1
1053 else
1054 $DIALOG --clear --title " Create a USB boot key " \
1055 --yes-label "Continue" --yesno \
1056 "\nThe USB key will be used like a CD-ROM. You will not be able to write
1057 any data on the boot partition.\n\n
1058 An extra FAT32 partition will be created with the remaining free space.\n\n
1059 $(tazusbmsg)Please plug your USB stick in now.\n" 16 70
1060 [ $? -eq 0 ] || return
1061 usbdev || return
1063 # perform dd in progress bar
1064 max=$(($(stat -c %s "$ISO")/2048))
1065 i=0; ddq if="$ISO" bs=1024k | (
1066 while ddq bs=1024k count=1 ; do
1067 i=$(($i + 1))
1068 [ $i -gt $max ] && break
1069 echo $((($i*100)/$max)) | dialog --gauge \
1070 " The ISO image transfer can be long. Please wait..." \
1071 6 70 0 > /dev/tty 2>&1
1072 done ) > $device
1073 fi
1075 # partition + fat32 format for the remaining space
1076 for p in 0 16; do
1077 get $((450+$p)) $device 2 12 | xargs echo | {
1078 read dx cx ol oh ll lh
1079 [ $dx -eq $((0x3F17)) ] || continue
1080 cx=$(($cx & 0xFF00))
1081 ofs=$(($ll+($lh<<16)))
1082 n=$(($(cat /sys/block/${device#/dev/}/size)-$ofs))
1083 m=$(($cx+($n/8)))
1084 [ $m -gt $((0x3FF00)) ] && m=$((0x3FF00))
1085 m=$((($m & 0xFF00)+(($m>>16)<<6)))
1086 words2bin 0 $((0x101+$cx)) 0x3F0B $((32+$m)) \
1087 $ll $lh $(($n & 0xFFFF)) $(($n >> 16)) | \
1088 ddq bs=1 seek=$((462-$p)) of=$device
1089 if [ "$(which mkdosfs 2> /dev/null)" ]; then
1090 losetup -o $((512*$ofs)) /dev/loop2 $device
1091 mkdosfs -n "SLITAZ BOOT" /dev/loop2
1092 words2bin $(($ofs & 0xFFFF)) $(($ofs >> 16)) | \
1093 ddq bs=1 seek=28 of=/dev/loop2
1094 sync
1095 losetup -d /dev/loop2
1096 fi
1098 done
1101 usbkey()
1103 $DIALOG --clear --title " Create a SliTaz USB key " \
1104 --yes-label "Continue" --yesno \
1105 "\nUnlike a hard drive install, the filesystem is kept in a compressed
1106 rootfs.gz. The filesystem is loaded entirely into memory upon boot.
1107 This should increase responsiveness, protect the filesystem against
1108 accidental corruption and reduce read/writes to the USB drive.
1109 Once setup, the tazusb utility can rewrite the root filesystem
1110 with any changes you have made since booting up,
1111 giving the effective benefits of a hard drive install.\n\n
1112 /home is mounted on boot using the UUID of your particular flash drive.
1113 Unlike a device name, the UUID has the benefit of never changing from machine
1114 to machine.\n\n
1115 Please plug your USB stick in now.\n" 19 70
1116 [ $? -eq 0 ] || return
1117 usbdev || return
1118 exec 3>&1
1119 format=`$DIALOG --clear \
1120 --title " Select the filesystem " \
1121 --radiolist "\nPlease select the filesystem type to create.\n\n\
1122 The filesystem creation will erase all the data in the USB key." 14 70 4 \
1123 "none" "Do not erase the USB key" on \
1124 "ext3" "Ext3 journaling filesystem" off \
1125 "ext2" "Ext2 filesystem" off \
1126 "fat32" "Windows FAT32 filesystem" off \
1127 2>&1 1>&3`
1128 retval=$?
1129 exec 3>&-
1130 [ $retval -eq 0 ] || return
1131 [ "$format" != "none" ] && tazusb format $device "SliTaz" $format
1132 tazusb gen-iso2usb "$ISO" $device
1135 dokexec()
1137 kexec -l $file || return
1138 quit "kexec -e"
1141 runmemtest()
1143 gotcdfile 'memtest*' && dokexec
1146 runpxe()
1148 gotcdfile '?pxe*' && dokexec
1151 flavdata()
1153 [ $(get 1024 "$ISO") -eq 35615 ] && n=2 || n=$((1+$(get 417 "$ISO" 1)))
1154 [ $n -eq 4 ] && n=20
1155 [ $(get $(($n*512)) "$ISO") -eq 35615 ] || n=13
1156 ddq if="$ISO" bs=512 skip=$n count=20 | zcat 2>/dev/null
1159 hasflavinfo()
1161 [ "$(flavdata | ddq bs=1 count=7 | strings)" = \
1162 "0707010" ] && menuitem "$@"
1165 showfavinfo()
1167 mkdir -p /tmp/data
1168 flavdata | ( cd /tmp/data ; cpio -i )
1169 file=/tmp/data/info
1170 cat /tmp/data/*desc > $file
1171 if [ -s /tmp/data/*receipt ]; then
1172 echo "=== receipt ==="
1173 cat /tmp/data/*receipt
1174 fi >> $file
1175 for i in /tmp/data/*list* ; do
1176 echo "=== extra ${i#*list} files"
1177 cat $i
1178 done >> $file
1179 if [ "$1" ]; then
1180 cat $file
1181 else
1182 $DIALOG --clear --title " Flavor info " \
1183 --textbox $file 0 0
1184 fi
1185 rm -rf /tmp/data
1188 flavor()
1190 name="$(flavdata | cpio -t 2> /dev/null | sed 's/.[a-z]*$//;q')"
1191 echo "Create ${name:=flavor}.flavor..."
1192 tazlito iso2flavor "$ISO" $name
1193 ls -l $name.flavor 2> /dev/null && return
1194 sleep 5
1195 [ "$1" ] && return
1196 echo -e "\rPress RETURN to continue."
1197 read n
1200 if [ "$1" = "--build" ]; then #install-begin
1201 uuencode -m - < header.com | sed -e '/^HEADERCODE$/r/dev/stdin' \
1202 -e "s|HEADERSZ|$(stat -c %s header.com)|" -e '/^HEADERCODE$/d' -i $0
1203 uuencode -m - < ifmem.bin | sed -e '/^ifmemcode$/r/dev/stdin' \
1204 -e '/^ifmemcode$/d' -i $0
1205 uuencode -m - < bootloader.bin | sed -e '/^bootloader$/r/dev/stdin' \
1206 -e '/^bootloader$/d' -e '/install-begin$/,/install-end$/d' -i $0
1207 exit
1208 fi #install-end
1209 parse_isolinux()
1211 awk 'BEGIN { IGNORECASE=1 }
1212 function multi(n)
1214 auto=$n
1215 for (--n; n < NF; n+=2) {
1216 s=$n
1217 if (s ~ /M$/) s = substr(s,0,length(s)-1)
1218 else s /= 1024
1219 sizes=int(s) " " sizes
1221 next
1224 if ($1 == "LABEL") {
1225 label=$2
1226 if (auto == "") auto=label
1228 if ($1 == "KERNEL" || $1 == "COM32") kernel[label]=$2
1229 if ($1 == "INITRD") initrd[label]=$2
1230 if ($1 == "APPEND") {
1231 i=2
1232 if (kernel[label] ~ "ifmem.c32") multi(3)
1233 if (kernel[label] ~ "c32box.c32") {
1234 if ($2 == "linux") { kernel[label]=$3; i=4 }
1235 if ($2 == "ifmem") multi(4)
1237 if (kernel[label] ~ "ifcpu64.c32") { auto=$4; next }
1238 while (i <= NF) {
1239 if ($i ~ "^initrd=") initrd[label]=substr($i,8)
1240 else cmdline[label]=cmdline[label] " " $i
1241 i++
1245 END {
1246 print "KERNEL=\"" kernel[auto] "\""
1247 print "INITRD=\"" initrd[auto] "\""
1248 print "CMDLINE=\"" substr(cmdline[auto],2) "\""
1249 print "SIZES=\"" sizes "\""
1250 }'
1253 locase()
1255 echo "$1" | tr [A-Z] [a-z]
1258 ifmemcode()
1260 uudecode <<EOT
1261 ifmemcode
1262 EOT
1265 floppyset()
1267 gotcdfile 'isolinux.cfg'
1268 $0 include $file | parse_isolinux > /tmp/var$$
1269 . /tmp/var$$
1270 [ -z "$KERNEL" ] && echo "Can't parse isolinux.cfg" && return
1271 for i in $media/$KERNEL $(dirname $file)/$KERNEL $media/$(locase $KERNEL) \
1272 $(dirname $file)/$(locase $KERNEL); do
1273 i="$(ls $i* | sed q)"
1274 [ -n "$i" ] && KERNEL=$i && break
1275 done
1276 rm -f /tmp/var$$
1277 [ $(get 514 $KERNEL 4) -eq 1400005704 ] || return
1278 n=$(($(get 497 $KERNEL 1)+1))
1279 ddq bs=512 count=$n if=$KERNEL of=/tmp/fd$$
1280 uudecode <<EOT | ddq of=/tmp/fd$$ conv=notrunc
1281 bootloader
1282 EOT
1283 pos=$(($n*512))
1284 if [ -n "$CMDLINE" ]; then
1285 echo -n "$CMDLINE" | ddq bs=512 count=1 conv=sync >> /tmp/fd$$
1286 bytes2bin $n | ddq conv=notrunc \
1287 bs=1 seek=497 count=1 of=/tmp/fd$$
1288 words2bin $pos | ddq conv=notrunc \
1289 bs=1 seek=34 count=2 of=/tmp/fd$$
1290 [ $(get 518 $KERNEL 4) -ge 514 ] &&
1291 words2bin 32768 9 | ddq conv=notrunc \
1292 bs=1 seek=552 count=4 of=/tmp/fd$$
1293 fi
1294 syssize=$(echo $(get 500 /tmp/fd$$ 4))
1295 ddq bs=512 skip=$n if=$KERNEL | cat - /dev/zero | \
1296 ddq bs=512 count=$((($syssize+31)/32)) conv=sync >> /tmp/fd$$
1297 base=$(stat -c %s /tmp/fd$$)
1298 len=
1299 if [ "$INITRD" ]; then
1300 l=0
1301 for i in ${INITRD//,/ }; do
1302 for j in $media/$i $(dirname $KERNEL)/$i $media/$(locase $i) \
1303 $(dirname $KERNEL)/$(locase $i); do
1304 j="$(ls $j* | sed q)"
1305 [ -n "$j" ] && i=$j && break
1306 done
1307 ddq if=$i >> /tmp/fd$$
1308 l=$(($l+$(stat -c %s $i)))
1309 r=$((4 - ($l % 4)))
1310 if [ $r -ne 4 ]; then
1311 ddq if=/dev/zero bs=1 count=$r >> /tmp/fd$$
1312 l=$(($l + $r))
1313 fi
1314 case "$i:$INITRD" in
1315 *rootfs.gz:*rootfs.gz,*) continue # loram
1316 esac
1317 len="$len $l"; l=0
1318 done
1319 rdadrs=${RDADRS:-$(((($syssize*16)+0x1F0000) & -4096))}
1320 words2bin $(($rdadrs & 0xFFFF)) $(($rdadrs >> 16)) | ddq \
1321 conv=notrunc bs=1 seek=536 count=4 of=/tmp/fd$$
1322 fi
1323 n=$(echo $len | wc -w)
1324 if [ $((494 - $(get 494 /tmp/fd$$))) -ge $(($n * 4)) ]; then
1325 i=$(($(get 494 /tmp/fd$$)))
1326 bytes2bin $(($i + ($n*4) - 256)) | ddq bs=1 conv=notrunc \
1327 seek=496 count=1 of=/tmp/fd$$
1328 else
1329 i=$(($pos + 0x1FC - ($n*4)))
1330 bytes2bin $(($i % 256)) $((i / 256)) 252 | ddq bs=1 \
1331 conv=notrunc seek=494 count=3 of=/tmp/fd$$
1332 s=$(($i - 2*$(echo "$SIZES" | wc -w)))
1333 p=$(($s - $(ifmemcode | wc -c)))
1334 ifmemcode | ddq bs=1 conv=notrunc seek=$p of=/tmp/fd$$
1335 words2bin $SIZES | ddq bs=1 conv=notrunc seek=$s of=/tmp/fd$$
1336 bytes2bin 154 $(($p%256)) $(($p/256)) 0 144 | \
1337 ddq bs=1 conv=notrunc seek=60 of=/tmp/fd$$
1338 fi
1339 for r in $len ; do
1340 words2bin $(($r & 0xFFFF)) $(($r >> 16)) | ddq conv=notrunc \
1341 bs=1 seek=$i count=4 of=/tmp/fd$$
1342 i=$(($i + 4))
1343 done
1344 split -b 1440k /tmp/fd$$ fd$$
1345 rm -f /tmp/fd$$
1346 n=1; i=0; r=0
1347 set -- $len
1348 ls fd$$* | while read file ; do
1349 if [ $i -gt $(($1+$base)) ]; then
1350 shift
1351 r=$(($r+100)); n=0; i=0; base=0
1352 fi
1353 ddq of=$file bs=18k seek=80 count=0
1354 i=$(($i+1474560))
1355 printf "mv %s fd%03d.img\n" $file $(($r+$n))
1356 n=$(($n+1))
1357 done | sh
1358 du -ch $PWD/fd???.img
1361 quit()
1363 umount -d $media
1364 rmdir $media
1365 ${1:-exit}
1368 infoiso()
1370 isoinfo -d -i "$ISO" > /tmp/isoinfo$$
1371 if [ -x "$(which iso2exe)" ]; then
1372 echo "----"
1373 blkid "$ISO" | while read args; do
1374 set -- $args
1375 while [ -n "$2" ]; do
1376 case "$2" in
1377 *UUID*|PT*) echo $2;;
1378 esac
1379 shift
1380 done
1381 done
1382 if ! fdisk -l "$ISO" | grep -q 'valid partition'; then
1383 fdisk -l "$ISO" | grep heads
1384 fdisk -l "$ISO" | sed 's/^ *[^ ]* *//;s/ */ /g;$!d'
1385 fi
1386 echo "----"
1387 iso2exe -l "$ISO"
1388 fi >> /tmp/isoinfo$$
1389 if [ "$1" ]; then
1390 cat /tmp/isoinfo$$
1391 else
1392 $DIALOG --clear --title " Info ISO " \
1393 --textbox /tmp/isoinfo$$ 0 0
1394 fi
1395 rm -f /tmp/isoinfo$$
1398 isotitle()
1400 echo "$(blkid "$ISO" | sed 's/.*LABEL="\([^"]*\).*/\1/') $(stat \
1401 -c %y $media/.|sed 's/ .*//') $(basename "$ISO")"
1404 if [ $0 = /init.exe ]; then
1406 case "${ISO##*/}$(getarg mode)" in
1407 *install*|*INSTALL*) install;;
1408 *live*|*LIVE*) live;;
1409 *text*|*TEXT*) text;;
1410 esac
1411 dmesg > /tmp/dmesg
1413 else
1415 if [ "$1" = "include" ]; then
1416 [ -s "$2" ] && cd $(dirname "$2") && awk -v exe=$0 \
1417 '{ if ($1 == "include") system(exe " include " $2); else print }' <"$2"
1418 exit
1419 fi
1420 ISO="${1:-/dev/null}"
1421 [ ${ISO:0:1} != "/" ] && ISO=$(cd $(dirname $ISO); echo $PWD/$(basename $ISO))
1422 [ -z "$(isiso 2> /dev/null)" ] && echo "Usage : $0 file.iso" && exit 1
1423 media=/tmp/media$$
1424 mkdir -p $media
1425 mount -o loop,ro "$ISO" $media
1427 if [ "$2" = "list" ]; then
1428 sed '/^\$(.*") \\/!d;s/^\$(\(.*\)").*/\1"/' $0 | while read line; do
1429 eval $line
1430 echo
1431 done | sed '/^$/d;/"usbkey"/d'
1432 quit
1433 fi
1434 if grep -q "^$2()" $0; then
1435 exe=$2
1436 shift 2
1437 if [ -n "$(eval $(grep "\"$exe\"" $0 | sed \
1438 '/^\$/!d;s/.(\(.*\)[\t ]*".*"[\t ]*".*/\1/'))" ]; then
1439 isotitle
1440 grep "\"$exe\"" $0 | sed '/^\$/!d;s/.*"[\t ]*"\(.*\)".*/\1/'
1441 echo ----
1442 $exe "$@"
1443 fi
1444 quit
1445 fi
1446 fi
1448 while true; do
1449 keymap="$(cat /etc/keymap.conf 2>/dev/null)"
1450 locale="$(sed '/^LANG=/!d;s/.*=//' /etc/locale.conf 2>/dev/null)"
1451 cat > /tmp/dialog$$ <<EOT
1452 $DIALOG --clear --title " $(isotitle) " --menu "" 28 70 30 \
1453 $(initxfile tazkeymap "tazkeymap" "Select keyboard (${keymap:-none})") \
1454 $(initxfile tazlocale "tazlocale" "Select locale (${locale:-none})") \
1455 $(initx "live" "Linux RAM boot (full desktop)") \
1456 $(initx "text" "Linux RAM boot") \
1457 $(cdfile 'README*' "readme" "Show the README file") \
1458 $(gotcustomconf "getcustomconf" "Get custom config") \
1459 $(gotisomd5 "isomd5" "Check the ISO image") \
1460 $(cdfile 'md5sum*' "md5" "Check the ISO files") \
1461 $(cdfile 'sha*sum*' "sha" "Check the ISO files") \
1462 $(xfile isoinfo "infoiso" "ISO image info") \
1463 $(cdfilex boot/bzImage "bootiso" "Boot the ISO image") \
1464 $(burnable "burniso" "Burn the ISO image") \
1465 $(blankable "blankcd" "Blank the CD/DVD") \
1466 $(gotposixovl "install" "Hard disk installation (UMSDOS way)") \
1467 $(gotposixovl "installtaz" "Hard disk installation (TAZUSB way)") \
1468 $(gotposixovlzip "inst2zip" "ZIP installation archive (UMSDOS way)") \
1469 $(gotposixovlzip "insttaz2zip" "ZIP installation archive (TAZUSB way)") \
1470 $(gottazusb "usbkey" "USB key read/write installation") \
1471 $(ishybrid "usbbootkey" "USB boot key (read only)") \
1472 $(hasflavinfo "showfavinfo" "Show flavor extra info") \
1473 $(hasflavor "flavor" "Get flavor file") \
1474 $(cdfile isolinux.cfg "floppyset" "Boot floppy set") \
1475 $(cdfile linld.com "tazboot" "Get tazboot.exe Linux loader") \
1476 $(cdexe boot/bzImage "bzimage" "Get linux DOS/EXE file") \
1477 $(cdexe 'memtest*' "memtest" "Get Memtest86 DOS/EXE file") \
1478 $(cdfilef 'memtest*' "fdmemtest" "Create a Memtest86 boot floppy") \
1479 $(cdfilex 'memtest*' "runmemtest" "Start Memtest86") \
1480 $(cdexe '?pxe*' "pxe" "Get SliTaz Web boot DOS/EXE utility") \
1481 $(cdfilef '?pxe*' "fdpxe" "Create a SliTaz Web boot floppy") \
1482 $(cdfilex '?pxe*' "runpxe" "Start the SliTaz Web boot utility") \
1483 $(initxfile reboot "restart" "Restart the computer") \
1484 $(initxfile poweroff "stop" "Power off") \
1485 $(initx "bootlog" "Linux boot messages") \
1486 $(initx "shell" "Shell prompt") \
1487 $(noinitmisspkg "missing" "Install packages to get more options") \
1488 $(noinit "quit" "Quit this utility")
1489 EOT
1490 exec 3>&1
1491 value=$(. /tmp/dialog$$ 2>&1 1>&3)
1492 retval=$?
1493 exec 3>&-
1494 rm -f /tmp/dialog$$
1495 [ $retval -ne 0 ] && [ $0 != /init.exe ] && quit
1496 $value
1497 done