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

taziso/bootusbkey: up to 2TB
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Sep 21 09:52:25 2020 +0000 (2020-09-21)
parents 1a30965ea03c
children 3a5c9f8a51f4
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 quads2bin()
37 {
38 for i in $@ ; do
39 printf '\\\\x%02X\\\\x%02X\\\\x%02X\\\\x%02X' $(($i&255)) \
40 $((($i>>8)&255)) $((($i>>16)&255)) $((($i>>24)&255))
41 done | xargs echo -en
42 }
44 gettazboot()
45 {
46 echo -e "\nCreating $(basename $1) ..."
47 S=$((32+HEADERSZ))
48 P=$((($S+511)/512))
49 E=$((4096-(32*$P)))
50 words2bin 0x5A4D $(($S%512)) $P 0 2 $E -1 -16 \
51 -2 0 256 -16 28 0x6C53 0x5469 0x7A61 > $1
52 uudecode - >> $1 << EOT
53 HEADERCODE
54 EOT
55 gotcdfile linld.com
56 ddq if=$file >> $1
57 }
59 maybe64()
60 {
61 echo -n $1
62 grep -q ' lm ' /proc/cpuinfo && [ -s ${1}64 ] && echo 64
63 }
65 size()
66 {
67 stat -c %s "$1"
68 }
70 sectcnt()
71 {
72 [ ! -b "$1" ] && echo $(($(size "$1")/512)) ||
73 cat /sys/block/${1#/dev/}/size
74 }
76 uncpio()
77 {
78 i=$1
79 [ $0 = /init.exe ] && i=$(maybe64 $i)
80 [ -s "$i" ] || return
81 echo -en "\n Extracting $(basename $i) ..."
82 case $(get 0 $i) in
83 *35615) ( zcat || gunzip ) ;;
84 *14333) unxz ;;
85 *\ 93) unlzma ;;
86 *) cat ;;
87 esac < $i | ( cd ${2:-/} ; cpio -idmu > /dev/null 2>&1 )
88 }
90 xdotwait=dotwait
91 dotwait()
92 {
93 echo -n "${1:-Install filesystem}.."
94 echo -n > /tmp/wait
95 [ "$REQUEST_URI" ] && return
96 while [ -e /tmp/wait ]; do
97 echo -n "." > /dev/${tty0:-tty}
98 sleep 1
99 done &
100 }
102 getuuid()
103 {
104 dev=$(mount | sed "/ $(echo $mnt | sed 's|/|\\/|g') /!d;s/ .*//;s|/dev/||;q")
105 [ "$dev" ] &&
106 blkid | sed "/$dev:/!d;s/.* UUID=.\\([^ ]*\\)\".*/\\1/" ||
107 echo "/dev/hda1"
108 }
110 tazusbinitfs()
111 {
112 PAD=$(($(size $1) % 4))
113 [ $PAD -ne 0 ] && ddq if=/dev/zero bs=1 count=$((4 - $PAD)) >> $1
114 mkdir -p /tmp/fs$$/etc /tmp/fs$$/lib /tmp/fs$$/home
115 cp -a /etc/locale.conf /etc/locale.conf /tmp/fs$$/etc 2> /dev/null
116 cat > /tmp/fs$$/init1 <<EOT
117 #!/bin/sh
118 sed -i 's|sbin/init|init2|' /init
119 exec /init
120 EOT
121 cat > /tmp/fs$$/init2 <<EOT
122 #!/bin/sh
124 mount -t proc /proc /proc
125 for i in /lib/modules/*.ko* ; do insmod \$i 2> /dev/null ; done; sleep 2
126 v=\$(sed '/\\/home=/!d;s|.*/home=\\([^ ]*\\).*|\\1|' /proc/cmdline /cmdline 2> /dev/null)
127 mount / -o remount,rw
128 mkdir /mnt/dos
129 rm -f /cmdline 2> /dev/null
130 mount / -o remount,ro
131 mnt=/mnt/dos/\${v#*/}
132 dev=\$( (blkid /dev/[sh]d* || blkid) | grep \${v%%/*} | sed 's/:.*//;q')
133 echo "Mount \$dev in /mnt/dos for \$v..." | tee -a /run/boot.log
134 mount \$dev /mnt/dos
135 if [ ! -d /mnt/dos/slitaz ]; then
136 umount /mnt/dos 2> /dev/null
137 (blkid /dev/[sh]d* || blkid) | while read dev line; do
138 case "\$line" in
139 *ntfs*|*vfat*|*msdos*) ;;
140 *) continue ;;
141 esac
142 mount \${dev%:} /mnt/dos
143 [ -d /mnt/dos/slitaz ] && break
144 umount /mnt/dos
145 done
146 fi
147 $([ "$2" ] || echo '# ')mount.posixovl -F \$mnt -- -oallow_other -odefault_permissions -osuid
148 mount --bind \$mnt /home
149 mount -o size=0,ro -t tmpfs tmpfs \$mnt
150 umount /proc
151 exec /sbin/init
152 EOT
153 chmod 755 /tmp/fs$$/init?
154 ln -s /sqfs/bin/gzip /bin 2> /dev/null
155 ( cd /tmp/fs$$ ; find * | cpio -o -H newc ) | gzip -9 >> $1
156 rm -rf /tmp/fs$$
157 }
159 mkinitrd()
160 {
161 echo -en "\nCreating $(basename $1) "
162 fs=/tmp/fs$$
163 for i in bin lib dev proc tmp mnt etc ; do
164 mkdir -p $fs/$i
165 done
166 for i in /dev/null /dev/tty /dev/tty[012] /dev/fuse /dev/[hs]d* \
167 /dev/console ; do
168 cp -a $2$i $fs/dev/
169 done
170 for i in /bin/busybox $(which mount.posixovl) $(which blkid) \
171 $(which ntfs-3g); do
172 cp $(LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $i | \
173 sed 's|.*=> \(.*/lib/l[^ ]*\).*|\1|;/^\//!d') $fs/lib
174 cp $i $fs/bin
175 done
176 cp -a /sqfs/lib/ld-* /tmp/fs/lib 2> /dev/null ||
177 cp -a /lib/ld-* $fs/lib
178 for i in $(busybox | sed '/Current/,$!d'); do
179 [ -e $fs/bin/${i%,} ] || ln -s busybox $fs/bin/${i%,}
180 done
181 ln -s /proc/mounts $fs/etc/mtab
182 sed 's/ .*//' /proc/modules | while read mod ; do
183 find /lib/modules/ | grep $mod.ko | \
184 sed 's|.*|cp & $fs/lib|' | sh
185 done
186 cat > $fs/init <<EOT
187 #!/bin/sh
189 arg()
190 {
191 grep -q \$1 /proc/cmdline &&
192 val="\$(sed "s/.*\$1=\\([^ ]*\\).*/\\1/" < /proc/cmdline)" &&
193 echo "\$2 \$val"
194 }
196 mount -t proc /proc /proc
197 arg debug "shell" && debug=true && set -x
198 for i in /lib/*.ko* ; do insmod \$i 2> /dev/null ; done; sleep 2
199 arg mount "Mount device"
200 dsk=\$( (blkid /dev/[sh]d* || blkid) | grep \$val | sed 's/:.*//;q')
201 mount \$dsk /mnt || mount.ntfs \$dsk /mnt
202 arg subroot "Change root to directory"
203 if [ -d /mnt/\$val ]; then
204 umount /mnt 2> /dev/null
205 (blkid /dev/[sh]d* || blkid) | while read dev line; do
206 case "\$line" in
207 *ntfs*|*vfat*|*msdos*) ;;
208 *) continue ;;
209 esac
210 mount \${dev%:} /mnt
211 [ -d /mnt/\$val ] && break
212 umount /mnt
213 done
214 fi
216 $([ "$3" ] || echo -n '# ')mount.posixovl -F /mnt/\$val -- -oallow_other -odefault_permissions -osuid
217 mount --bind /mnt /mnt/\$val/mnt/dos
218 mount -o size=0,ro -t tmpfs tmpfs /mnt/\$val/mnt/dos/\$val
219 LDSO=\$(ls /mnt/\$val/lib/ld-* | sed q)
220 export LD_LIBRARY_PATH=\$val/lib:\$val/usr/lib:/lib
221 [ "$debug" = "true" ] && sh
222 umount /proc
223 exec /bin/switch_root /mnt \${LDSO#/mnt/} \$val/usr/sbin/chroot \$val /sbin/init
224 EOT
225 chmod +x $fs/init
226 ( cd $fs ; find * | cpio -o -H newc ) | lzma e $1 -si 2> /dev/null
227 rm -rf $fs /tmp/wait
228 }
230 ls_r()
231 {
232 ls -r $@ 2> /dev/null || ls $@
233 }
235 is_loram()
236 {
237 [ -s /lib/modules/squashfs.ko* ]
238 }
240 doinstall()
241 {
242 unset useposixovl
243 blkid | grep $(df $mnt | sed '$!d;s/ .*/:/') | \
244 grep -qiE "(msdos|vfat|ntfs)" && useposixovl=YES
245 case "$mnt" in
246 *mkzip*) useposixovl=YES
247 esac
248 mkdir -p $mnt/slitaz/boot $mnt/slitaz/mnt/dos
249 [ "$useposixovl" ] &&
250 if ! mount.posixovl -F $mnt/slitaz -- \
251 -oallow_other -odefault_permissions -osuid; then
252 echo "Can't install SliTaz. Abort."
253 sleep 5
254 return 1
255 fi
256 dotwait "Install root filesystem in /slitaz.."
257 if [ "$1" ]; then
258 ls_r $media/boot/rootfs*gz | \
259 xargs cat > $mnt/slitaz/boot/rootfs.gz
260 tazusbinitfs $mnt/slitaz/boot/rootfs.gz $useposixovl
261 initrd=rootfs.gz
262 extraargs="/home=$(getuuid)/slitaz rdinit=/init1"
263 else
264 if [ -d $media/fs ]; then
265 cp -a $media/fs/. $mnt/slitaz
266 elif is_loram; then
267 for i in $(ls_r $media/boot/rootfs*); do
268 losetup -o 124 /dev/loop7 $i
269 mount -t squashfs -o ro /dev/loop7 /sqfs/mnt
270 cp -a /sqfs/mnt/. $mnt/slitaz
271 umount /sqfs/mnt
272 losetup -d /dev/loop7
273 done
274 else
275 for i in $(ls_r $media/boot/rootfs*gz); do
276 ${uncpio:-uncpio} $i $mnt/slitaz
277 done
278 fi
279 for i in $packages_list; do
280 tazpkg get-install $i --root=$mnt/slitaz
281 done
282 for i in $packages_dir/*.tazpkg; do
283 [ -s "$i" ] &&
284 tazpkg install $i --root=$mnt/slitaz
285 done
286 cp -a /etc/locale.conf $mnt/slitaz/etc 2> /dev/null
287 cp -a /etc/keymap.conf $mnt/slitaz/etc 2> /dev/null
288 mkinitrd $mnt/slitaz/boot/initrd $mnt/slitaz $useposixovl
289 initrd=initrd
290 extraargs="mount=$(getuuid) subroot=slitaz"
291 fi
292 echo -en "\nInstall boot files..."
293 for i in $media/boot/bzImage* $media/boot/*pxe* \
294 $media/boot/plop.exe \
295 $media/boot/isolinux/he* $media/boot/isolinux/opt* \
296 $media/README $media/boot/memtest* ; do
297 [ -s $i ] && cp $i $mnt/slitaz/boot
298 done
299 for i in $mnt/slitaz/boot/memtest $mnt/slitaz/boot/*pxe ; do
300 [ $(get 0 $i 2> /dev/null || echo 0) -eq 23117 ] &&
301 mv $i $i.exe
302 done
303 bzimage=$(cd $mnt/slitaz/boot ; ls bzimage*)
304 cp /etc/keymap.conf /etc/locale.conf $mnt/slitaz/etc 2> /dev/null
305 gettazboot $mnt/slitaz/boot/tazboot.exe # autoappend 64 suffix
306 unix2dos > $mnt/slitaz/boot/tazboot.cmd <<EOT
307 image=/slitaz/boot/bzimage
308 initrd=/slitaz/boot/$initrd
309 root=/dev/null $extraargs autologin
310 EOT
311 uudecode - <<EOT | gunzip > $mnt/slitaz/boot/slitaz.pif
312 begin-base64 644 -
313 H4sIAAAAAAACA8XPxUHGMBTA8X9ecb/glgFwv+FO23zeI+7ucMFhCjZgEEZh
314 Ctzd4Rf3PFbtQHGLG9BmfmZqdlE/tSmw2LfePzOzWDK0OsQXpPHvFGfZBmL5
315 f3Zns98NuG1BbTrbWj0OFMypSKfT4kYCurKuRleWlBEth2qUTYFBKjg746pI
316 2nZaIT/v9vWwbeuqi9fPznLlSPFLLuK22/0lLT09/BDhXgWKO1f9aLKxOObE
317 EhLuVvO4FksSwaH5qbHpvkle0TyzND82NK+doRVeZgGGbIw0XD2QwV9SnAN/
318 ACxDxwMAAA==
319 ====
320 EOT
321 unix2dos $mnt/slitaz/boot/he* $mnt/slitaz/boot/opt* \
322 $mnt/slitaz/boot/README
323 [ -d $mnt/slitaz/usr/sbin -a ! -x $mnt/slitaz/usr/sbin/mount.posixovl ] &&
324 cp $(which mount.posixovl) $mnt/slitaz/usr/sbin
325 if [ "$useposixovl" ] && grep -qs " $mnt " /proc/mounts &&
326 [ ! -d $mnt/boot/grub ]; then
327 mkdir -p $mnt/boot/grub
328 echo -en "\nInstall grub in /boot/grub..."
329 cp -a /usr/lib/grub/*/* $mnt/boot/grub
330 cat > $mnt/boot/grub/menu.lst <<EOT
331 # /boot/grub/menu.lst: GRUB boot loader configuration.
333 # By default, boot the first entry.
334 default 0
336 # Boot automatically after 8 secs.
337 timeout 8
339 title Microsoft Windows
340 chainloader +1
342 EOT
343 dev=$(grep " $mnt " /proc/mounts | awk '{ print $1 }')
344 base=${dev//[0-9]/}
345 dd if=$base bs=32k count=1 of=$mnt/boot/grub/$(basename $base)
346 cat > $mnt/boot/grub/uninstall-grub.sh <<EOT
347 #!/bin/sh
349 [ -s /boot/grub/$(basename $base) ] &&
350 dd if=/boot/grub/$(basename $base) of=$base
351 EOT
352 grub-install --no-floppy --root-directory=$mnt $base
353 fi
354 if [ -s $mnt/boot/grub/menu.lst ] &&
355 ! grep -q /slitaz/boot/$bzimage $mnt/boot/grub/menu.lst; then
356 echo -en "\nUpdate /boot/grub/menu.lst..."
357 cat >> $mnt/boot/grub/menu.lst <<EOT
358 title SliTaz GNU/Linux $(cat $mnt/slitaz/etc/slitaz-release)
359 kernel /slitaz/boot/$bzimage root=/dev/null $extraargs autologin
360 initrd /slitaz/boot/$initrd
362 EOT
363 fi
364 false &&
365 [ -s $mnt/boot.ini ] && ! grep -qs tazboot $mnt/boot.ini &&
366 echo "Update boot.ini ..." && unix2dos >> $mnt/boot.ini <<EOT
367 C:\\slitaz\\boot\\tazboot.exe="SliTaz"
368 EOT
369 false &&
370 grep -qis menuitem $mnt/config.sys && ! grep -qi tazboot $mnt/config.sys &&
371 echo "Update config.sys ..." &&
372 sed -i 's/menudefault/menuitem SLITAZ, SliTaz\r\n&/' $mnt/config.sys &&
373 unix2dos >> $mnt/config.sys <<EOT
374 [SLITAZ]
375 install=\\slitaz\\boot\\tazboot.exe
376 EOT
377 rm -f $tmp/wait
378 [ "$useposixovl" ] && umount $mnt/slitaz
379 return 0
380 }
382 windev()
383 {
384 if [ -b "$1" ]; then
385 device=$1
386 elif [ "$1" ]; then
387 echo "Invalid Linux/Windows partition"
388 return 1
389 else
390 DEV="$(blkid | grep -iE "(msdos|vfat|ntfs|ext[234]|xfs|btrfs)" | sed 's/:.*//;s|/dev/||')"
391 [ "$DEV" ] || return
392 cat > /tmp/dialog$$ <<EOT
393 $DIALOG --clear --title " Select your Linux/Windows partition " \
394 --menu "\nPlease select the Linux/Windows partition according to its known size.
395 The data will be kept untouched.\n" 17 70 8 \
396 $(for i in $DEV ; do
397 label="$(blkid | sed "/$i:/!d;s/.*://;s/[^ ]*UUID=[^ ]* //g;s/LABEL=//")"
398 echo -n "/dev/$i \"$(($(cat /sys/block/*/$i/size)/2048))MB $label\" "
399 done)
400 EOT
401 exec 3>&1
402 [ $? -eq 0 ] || return
403 device=$(. /tmp/dialog$$ 2>&1 1>&3)
404 exec 3>&-
405 rm -f /tmp/dialog$$
406 fi
407 mnt=/tmp/mnt$$
408 mkdir -p $mnt && mount $device $mnt
409 }
411 extra_packages()
412 {
413 packages_list=
414 packages_dir=
415 [ $0 = /init.exe ] && return
416 $DIALOG --clear --title " Extra packages " \
417 --defaultno --yesno \
418 "Do you want to add extra packages ?" 7 70
419 [ $? -eq 0 ] || return
420 [ -s /var/lib/tazpkg/packages.txt ] || tazpkg recharge
421 if [ -s $media/boot/vmlinuz-$(uname -r) ]; then
422 cat > /tmp/dialog$$ <<EOT
423 $DIALOG --clear --title " Select the packages " \
424 --separate-output \
425 --cancel-label "Skip" \
426 --checklist "Please select the packages you want to install. Try with the first letter." \
427 0 0 0 \\
428 EOT
429 awk -F\| '{ printf "%s \"%s\" off ",$1,$3 }' \
430 /var/lib/tazpkg/packages.desc >> /tmp/dialog$$
431 sh /tmp/dialog$$ 2> /tmp/dialog.out$$
432 [ $? -eq 0 ] && packages_list="$(cat /tmp/dialog.out$$)"
433 fi
434 cat > /tmp/dialog$$ <<EOT
435 $DIALOG --clear \
436 --title "Please select the directory with every custom package to install." \
437 --cancel-label "Skip" --dselect $PWD 13 78
438 EOT
439 sh /tmp/dialog$$ 2> /tmp/dialog.out$$
440 [ $? -eq 0 ] && packages_dir="$(cat /tmp/dialog.out$$)"
441 rm -f /tmp/dialog$$ /tmp/dialog.out$$
442 }
444 _install()
445 {
446 extra_packages
447 $DIALOG --clear --title " SliTaz UMSDOS way installation " \
448 --yes-label "Install" --yesno \
449 "\nSliTaz will be installed in the subdirectory \\slitaz of the current
450 Linux/DOS/Windows partition. You can see your files from /mnt/dos.\n\n
451 You can start SliTaz with \\slitaz\\boot\\tazboot.exe\n\n
452 To uninstall SliTaz, you have only to remove this directory.
453 The file \\boot.ini or \\config.sys may be modified too.\n\n
454 SliTaz may run slowly on the 'UMSDOS way' installation due to the
455 posixovl filesystem. The 'TAZUSB way' installation runs faster.\n\n
456 To do a traditional installation with disk partitioning,
457 start SliTaz Live with the 'SliTaz RAM boot' menu.\n" 19 70
458 [ $? -eq 0 ] || return
459 doinstall
460 [ $0 = /init.exe ] || return
461 [ -x $mnt/slitaz/sbin/init ] || return
462 umount -d $media/cdrom
463 umount_proc
464 exec chroot $mnt/slitaz /sbin/init
465 }
467 readtazbootconf()
468 {
469 kernel="$(sed '/^image=/!d;s/.*=//' $mnt/slitaz/boot/tazboot.cmd)"
470 initrd="$(sed '/^initrd=/!d;s/.*=//' $mnt/slitaz/boot/tazboot.cmd)"
471 cmdline="$(sed '/^image=/d;/^initrd=/d' $mnt/slitaz/boot/tazboot.cmd)"
472 }
474 bootinstalled()
475 {
476 [ "$(which kexec)" ] || return
477 [ -x $mnt/slitaz$1 ] || return
478 [ -s $mnt/slitaz/boot/tazboot.cmd ] || return
479 readtazbootconf
480 kexec -l $kernel --initrd $initrd --command-line "$cmdline" || return
481 umount $mnt
482 rm -rf $mnt
483 quit "kexec -e"
484 }
486 mkzip()
487 {
488 device=
489 packages_list=
490 packages_dir=
491 mnt=/tmp/mkzipmnt$$
492 mkdir -p $mnt
493 $1 $2 || return
494 for i in bootlace.com grubinst.exe grldr ; do
495 wget -O $mnt/slitaz/boot/$i http://mirror.slitaz.org/boot/$i
496 done
497 readtazbootconf
498 cat > $mnt/slitaz/boot/menu.lst <<EOT
499 title SliTaz
500 kernel $kernel $cmdline
501 initrd $initrd
503 EOT
504 while read file title; do
505 file=$(ls $mnt/slitaz/boot/*$file* 2> /dev/null)
506 [ -s "$file" ] && cat >> $mnt/slitaz/boot/menu.lst <<EOT
507 title $title
508 kernel ${file#$mnt}
510 EOT
511 done <<EOT
512 memtest MemTest
513 plop USB boot
514 pxe Web boot
515 EOT
516 unix2dos $mnt/slitaz/boot/menu.lst
517 unix2dos > $mnt/slitaz/boot/install.txt <<EOT
518 For DOS users (real mode only):
520 Start SliTaz with \\slitaz\\boot\\tazboot.exe
523 For NT/2000/XP users:
525 1- Move the files grldr and menu.lst into the root directory
527 C:\\> copy \\slitaz\\boot\\grldr \\
528 C:\\> copy \\slitaz\\boot\\menu.lst \\
530 2- Remove boot.ini attributes
532 C:\\> attrib -r -h -s boot.ini
534 3- Append the following line to boot.init
536 C:\\grldr="slitaz"
538 4- Restore boot.ini attributes
540 C:\\> attrib +r +h +s boot.ini
542 See http://diddy.boot-land.net/grub4dos/files/README_GRUB4DOS.txt
543 and http://xpt.sourceforge.net/techdocs/nix/disk/boot/boot07-GrubForDosInfo/ar01s03.html
544 EOT
545 ( cd $mnt ; echo 'See \slitaz\boot\install.txt to launch SliTaz.' | \
546 zip -zr9 $(basename "$ISO" .iso).zip slitaz )
547 [ "$(which advzip)" ] &&
548 echo "Recompressing $(basename "$ISO" .iso).zip ..." &&
549 advzip -z4 $mnt/*.zip
550 mv $mnt/*.zip .
551 du -h $PWD/$(basename "$ISO" .iso).zip
552 umount $mnt
553 rm -rf $mnt
554 }
556 install()
557 {
558 windev $1 || return
559 packages_list=
560 packages_dir=
561 if [ "$1" ]; then
562 doinstall
563 else
564 _install && bootinstalled /sbin/init
565 fi
566 umount $mnt
567 rm -rf $mnt
568 }
570 inst2zip()
571 {
572 if [ "$1" ]; then
573 mkzip doinstall
574 else
575 mkzip _install
576 fi
577 }
579 _installtaz()
580 {
581 $DIALOG --clear --title " SliTaz TAZUSB way installation " \
582 --yes-label "Install" --yesno \
583 "\nSliTaz will be installed in the subdirectory \\slitaz of the current
584 Linux/DOS/Windows partition. You can see your files from /mnt/dos.\n\n
585 You can start SliTaz with \\slitaz\\boot\\tazboot.exe\n\n
586 To uninstall SliTaz, you have only to remove this directory.
587 The file \\boot.ini or \\config.sys may be modified too.\n\n
588 The filesystem is loaded entirely into memory upon boot to
589 increase responsiveness. Only /home lands on the hard disk.\n\n
590 To do a traditional installation with disk partitioning,
591 start SliTaz Live with the 'SliTaz RAM boot' menu.\n" 19 70
592 [ $? -eq 0 ] || return
593 doinstall tazusblike || return
594 [ $0 = /init.exe ] || return
595 dotwait
596 if [ -d /media/cdrom/fs ]; then
597 cp -a /media/cdrom/fs/. /
598 else
599 for i in $(ls_r /media/cdrom/boot/rootfs*); do
600 ${uncpio:-uncipo} $i
601 done
602 fi
603 cp /tmp/fs/etc/* /etc 2>/dev/null
604 echo "/home=$(getuuid)/slitaz" > /cmdline
605 rm -f /tmp/wait
606 [ -x /init1 ] || return
607 umount -d /media/cdrom
608 umount /mnt/slitaz
609 rm -f /dev/cdrom
610 umount /mnt
611 mkdir /mnt/dos
612 umount_proc
613 exec /init1
614 }
616 installtaz()
617 {
618 windev $1 || return
619 packages_list=
620 packages_dir=
621 if [ "$1" ]; then
622 doinstall tazusblike
623 else
624 _installtaz && bootinstalled /boot/bzimage
625 fi
626 umount $mnt
627 rm -rf $mnt
628 }
630 insttaz2zip()
631 {
632 if [ "$1" ]; then
633 mkzip doinstall tazusblike
634 else
635 mkzip _installtaz
636 fi
637 }
639 bootiso()
640 {
641 cd /tmp
642 for i in $(ls_r $media/boot/rootfs*gz); do
643 i=$(maybe64 $i)
644 cat $i
645 n=$((4 - ($(size $i) % 4)))
646 [ $n -eq 4 ] || dd if=/dev/zero bs=1 count=$n
647 done > initrd$$
648 cmdline="root=/dev/null autologin lang=$LANG"
649 [ -s /etc/keymap.conf ] && cmdline="$cmdline kmap=$(cat /etc/keymap.conf)"
650 [ -s /etc/TZ ] && cmdline="$cmdline tz=$(cat /etc/TZ)"
651 rm -f cmdline initrd 2> /dev/null
652 getcustomconf kexec >/dev/null
653 [ -s cmdline ] && cmdline="$cmdline $(cat cmdline)" && rm cmdline
654 [ -s initrd ] && cat initrd >> initrd$$ && rm initrd
655 kernel=$(maybe64 $media/boot/bzImage)
656 . /etc/locale.conf
657 kexec -l $kernel --initrd initrd$$ --command-line "$cmdline" &&
658 rm -f initrd$$
659 quit "kexec -e"
660 }
662 tazboot()
663 {
664 if [ -z "$1" ]; then
665 $DIALOG --clear --title " SliTaz bootloader for DOS " \
666 --yes-label "Install" --yesno \
667 "\nThe file TAZBOOT.EXE will be created in the top directory. It supports
668 any linux kernel, multiple initramfs and a kernel command line.\n\n
669 Usage: tazboot.exe [[@commands]|[image=<bzimage>]
670 [initrd=<rootfs>[,<rootfs2>...]] cmdline args ...]\n\n
671 Defaults: tazboot @tazboot.cmd or tazboot image=bzImage auto\n\n\
672 Examples for tazboot.cmd:\n\n\
673 image=boot/bzImage\n\
674 initrd=boot/rootfs4.gz,boot/rootfs3.gz,boot/rootfs2.gz,boot/rootfs1.gz\n\
675 root=/dev/null autologin\n\n\
676 image=\\slitaz\\vmlinuz root=/dev/sda5 ro\n" 0 0
677 [ $? -eq 0 ] || return
678 fi
679 gettazboot tazboot.exe
680 du -h $PWD/tazboot.exe
681 }
683 md5()
684 {
685 dotwait "Checking files"
686 ( cd $media ; ${md5sum:-md5sum -c md5sum*} 2>&1 | sort ) > /tmp/data
687 unset md5sum
688 rm -f /tmp/wait
689 if [ "$1" ]; then
690 cat /tmp/data
691 else
692 $DIALOG --clear --title " Checked files " \
693 --textbox /tmp/data 0 0
694 fi
695 rm -f /tmp/data
696 }
698 gotcdfile()
699 {
700 for i in "$media/$1" "$media/*/$1" "$media/*/isolinux/$1" ; do
701 file=$(ls $i 2> /dev/null | sed q)
702 [ -s "$file" ] && break
703 done
704 }
706 sha()
707 {
708 gotcdfile 'sha*sum*'
709 sha=$(basename $file)
710 md5sum="${sha%sum*}sum -c ${file#$media/}"
711 md5 $@
712 }
714 readme()
715 {
716 gotcdfile 'README*'
717 if [ "$1" ]; then
718 cat $file
719 else
720 $DIALOG --clear --title " Readme " --textbox $file 0 0
721 fi
722 }
724 bzimage()
725 {
726 if [ -z "$1" ]; then
727 $DIALOG --clear --title " Create linux.exe ? " \
728 --yes-label "Install" --yesno \
729 "\nLinux.exe launches the linux kernel under DOS (in real mode only).
730 The cmdline arguments are supported except initrd=,
731 vga= (you can try 'rdev -v') and mem= (partially).
732 \nExample:\nC:\\> linux.exe root=/dev/hda2 ro panic=60\n" 12 70
733 [ $? -eq 0 ] || return
734 fi
735 cp $(maybe64 $media/boot/bzImage) linux.exe
736 du -h $PWD/linux.exe
737 }
739 memtest()
740 {
741 if [ -z "$1" ]; then
742 $DIALOG --clear --title " Create memtest.exe ? " \
743 --yes-label "Install" --yesno \
744 "\nMemtest86 is a thorough, stand alone memory test for x86 architecture
745 computers. BIOS based memory tests are a quick, cursory check and often
746 miss many of the failures that are detected by Memtest86.\n" 0 0
747 [ $? -eq 0 ] || return
748 fi
749 gotcdfile 'memtest*' && cp $file memtest.exe
750 du -h $PWD/memtest.exe
751 }
753 mkfat12()
754 {
755 [ $(($(get 0 $1) - 0x5A4D)) -eq 0 ] || return
756 J=$(($(get 3 $1 1) + 0x02))
757 R=$((1 + $(get 497 $1 1) + 1 + ($(get 500 $1)-1)/32))
758 [ $R -lt 2500 ] || return
759 [ $((($(get 500 $1)-1) & 31)) -lt 30 ] &&
760 ddq if=$file bs=32 count=1 seek=$(($R*16 - 1)) of=/dev/fd0
761 G="18 0 2 0 0 0 0 0"
762 [ $J -gt 25 ] || G=""
763 F=0
764 for i in 1 2 3; do
765 F=$((((2880-$R-$F-$F)*3+1023)/1024))
766 done
767 bytes2bin 0xEB $J 0x90 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 \
768 0 2 2 $(($R%256)) $(($R/256)) 2 64 0 64 11 0xF0 $F 0 \
769 $G | ddq bs=1 of=/dev/fd0
770 ddq if=/dev/zero bs=512 count=$((4+$F+$F)) seek=$R of=/dev/fd0
771 for i in $R $(($R+$F)) ; do
772 bytes2bin 0xF0 0xFF 0xFF | ddq bs=512 seek=$i of=/dev/fd0
773 done
774 echo -n $(basename $1) | ddq bs=1 seek=3 count=8 of=/dev/fd0
775 }
777 mkfloppy()
778 {
779 dotwait "Create a $(basename $1 .exe) boot floppy"
780 ddq if=$1 of=/dev/fd0
781 mkfat12 $1
782 rm -f /tmp/wait
783 }
785 fdmemtest()
786 {
787 if [ -z "$1" ]; then
788 $DIALOG --clear --title " Create a Memtest86 boot floppy " \
789 --yes-label "Create floppy" --yesno \
790 "\nMemtest86 is a thorough, stand alone memory test for x86 architecture
791 computers. BIOS based memory tests are a quick, cursory check and often
792 miss many of the failures that are detected by Memtest86.\n\n
793 Please insert a blank disk in floppy drive.\n" 0 0
794 [ $? -eq 0 ] || return
795 fi
796 gotcdfile 'memtest*' && mkfloppy $file
797 }
799 pxe()
800 {
801 gotcdfile '?pxe*'
802 if [ -z "$1" ]; then
803 $DIALOG --clear --title " Create $(basename $file .exe).exe ? " \
804 --yes-label "Install" --yesno \
805 "\nBoot your operating system from the internet and enjoy a full system
806 working entirely in RAM with speed and stability in mind. The Linux Kernel
807 and the complete SliTaz compressed root filesystem will be loaded into RAM
808 from the Web using PXE and HTTP protocols.\n" 0 0
809 [ $? -eq 0 ] || return
810 fi
811 cp $file $(basename $file .exe).exe
812 du -h $PWD/$(basename $file .exe).exe
813 }
815 fdpxe()
816 {
817 if [ -z "$1" ]; then
818 $DIALOG --clear --title " Create a SliTaz Web boot floppy " \
819 --yes-label "Create floppy" --yesno \
820 "\nBoot your operating system from the internet and enjoy a full system
821 working entirely in RAM with speed and stability in mind. The Linux Kernel
822 and the complete SliTaz compressed root filesystem will be loaded into RAM
823 from the Web using PXE and HTTP protocols.\n\n
824 Please insert a blank disk in floppy drive.\n" 0 0
825 [ $? -eq 0 ] || return
826 fi
827 gotcdfile '?pxe*' && mkfloppy $file
828 }
830 plop()
831 {
832 gotcdfile 'plop.exe'
833 if [ -z "$1" ]; then
834 $DIALOG --clear --title " Create $(basename $file .exe).exe ? " \
835 --yes-label "Install" --yesno \
836 "\nBoot your operating system from a USB disk without BIOS support.\n" 0 0
837 [ $? -eq 0 ] || return
838 fi
839 cp $file $(basename $file .exe).exe
840 du -h $PWD/$(basename $file .exe).exe
841 }
843 fdplop()
844 {
845 if [ -z "$1" ]; then
846 $DIALOG --clear --title " Create a Plop boot floppy " \
847 --yes-label "Create floppy" --yesno \
848 "\nBoot your operating system from a USB disk without BIOS support.\n\n
849 Please insert a blank disk in floppy drive.\n" 0 0
850 [ $? -eq 0 ] || return
851 fi
852 gotcdfile 'plop.exe' && mkfloppy $file
853 }
855 menuitem()
856 {
857 [ "$3" ] && shift
858 echo -en "\"$1\" \"$2\""
859 }
861 gotposixovl()
862 {
863 mount.posixovl 2>&1 | grep -qi usage && gotcdfile 'rootfs*.gz' &&
864 menuitem "$@"
865 }
867 gotposixovlzip()
868 {
869 [ "$(which zip)" ] && gotposixovl "$1" "$2"
870 }
872 noinit()
873 {
874 [ $0 = /init.exe ] || menuitem "$@"
875 }
877 initx()
878 {
879 [ $0 = /init.exe ] && menuitem "$@"
880 }
882 xfile()
883 {
884 [ "$(which $1)" ] && menuitem "$@"
885 }
887 initxfile()
888 {
889 [ $0 = /init.exe ] && xfile "$@"
890 }
892 cdfile()
893 {
894 gotcdfile "$1" && menuitem "$@"
895 }
897 gottazusb()
898 {
899 gotcdfile 'rootfs*.gz' && xfile tazusb "$@"
900 }
902 isbzImage()
903 {
904 [ $(get 514 $file 4) -eq 1400005704 ] &&
905 [ $(($(get 529 $file 1) & 1)) -eq 1 ]
906 }
908 cdfilex()
909 {
910 gotcdfile "$1" && [ "$(which kexec)" ] && isbzImage && menuitem "$@"
911 }
913 cdfilef()
914 {
915 [ -e /sys/block/fd0 ] && cdfile "$@"
916 }
918 cdexe()
919 {
920 gotcdfile "$1" &&
921 [ $(get 0 $file 2>/dev/null || echo 0) -eq 23117 ] &&
922 menuitem "$@"
923 }
925 misspkg()
926 {
927 for i in zip kexec-tools posixovl cdrkit cdrkit-isoinfo ; do
928 [ -d /var/lib/tazpkg/installed/$i/ ] && continue
929 [ "$1" != "install" ] && menuitem "$@" && return
930 tazpkg get-install $i
931 done
932 }
934 noinitmisspkg()
935 {
936 [ $0 = /init.exe ] || misspkg "$@"
937 }
939 missing()
940 {
941 misspkg install
942 }
944 ishybrid()
945 {
946 [ $(get 510 "$ISO") -eq 43605 ] || return
947 C=$((2048*$(get $(((17*2048) + 71)) "$ISO" 4)))
948 [ $(get $C "$ISO" 4) -eq 1 ] || return
949 [ $(get $(($C+30)) "$ISO" 4) -eq $((0x88AA55)) ] || return
950 C=$((2048*$(get $(($C+40)) "$ISO" 4)))
951 [ $(get $(($C+64)) "$ISO" 4) -eq 1886961915 ] && menuitem "$@"
952 }
954 isiso()
955 {
956 [ $(get 32769 "$ISO" 4) -eq 808469571 ] && menuitem "$@"
957 }
959 burnable()
960 {
961 [ "$(sed '/Can wr.*1$/!d' /proc/sys/dev/cdrom/info 2> /dev/null)" ] &&
962 menuitem "$@"
963 }
965 blankable()
966 {
967 [ "$(sed '/Can wr.*RW.*1$/!d' /proc/sys/dev/cdrom/info 2> /dev/null)" ] &&
968 menuitem "$@"
969 }
971 burniso()
972 {
973 wodim -v speed=$(fgrep "drive speed" /proc/sys/dev/cdrom/info | cut -f3) \
974 -eject -multi "$ISO"
975 }
977 blankcd()
978 {
979 wodim -v -blank=fast
980 }
982 customsector()
983 {
984 local c=$(echo $(get 32848 "$ISO" 4))
985 hascustomconf $(($c+16)) && echo $(($c+16)) || echo $c
986 }
988 xhascustomconf=hascustomconf
989 hascustomconf()
990 {
991 [ "$(ddq bs=2k skip=${1:-$(customsector)} if="$ISO" | ddq bs=1 count=6)" \
992 = "#!boot" ]
993 }
995 gotcustomconf()
996 {
997 hascustomconf && menuitem "$@"
998 }
1000 hasflavor()
1002 [ -x /usr/bin/tazlito ] && [ -s $(maybe64 $media/boot/bzImage) ] && menuitem "$@"
1005 gotisomd5()
1007 [ "$(which md5sum 2> /dev/null)" ] &&
1008 [ $(get 0 "$ISO") -eq 23117 ] &&
1009 [ $(get 18 "$ISO") -ne 0 ] && menuitem "$@"
1012 getcustomconf()
1014 ddq bs=2k skip=$(customsector) if="$ISO" | while read line; do
1015 case "$line" in
1016 \#!boot*) ;;
1017 append=*) echo ${line#append=} > cmdline && ls -l $PWD/cmdline ;;
1018 initrd:*) cnt=${line#initrd:}
1019 { ddq bs=512 count=$(($cnt / 512));
1020 ddq bs=1 count=$(($cnt % 512)); } > initrd &&
1021 ls -l $PWD/initrd
1022 break ;;
1023 *) break ;;
1024 esac
1025 done
1026 [ "$1" ] && return 0
1027 echo -e "\rPress RETURN to continue."
1028 read n
1031 isomd5()
1033 dotwait "Checking iso image"
1034 [ "$(ddq if="$ISO" bs=2k skip=16 \
1035 count=$(($(get 32848 "$ISO" 4)-16)) | md5sum)" = \
1036 "$(ddq if="$ISO" bs=16 count=1 skip=2047 | od -N 16 -t x1 -An | \
1037 sed 's/ //g') -" ] && echo "OK" || echo "ERROR"
1038 echo -en "\rChecking iso hybrid boot..."
1039 n=$(($(get 2 "$ISO")-1+($(get 4 "$ISO")-1)*512))
1040 if [ $n -lt 40000 -a $n -gt 32768 ]; then
1041 s=$(get 0 "$ISO" 2 $n | awk '{ i+= $0 } END { print i }')
1042 [ $(((1+$s+$(get $(($n+1)) "$ISO" 1)) % 65536)) -eq 0 ] &&
1043 echo "OK" || echo "ERROR"
1044 fi
1045 if hascustomconf; then
1046 echo -en "\rChecking iso custom config..."
1047 TMP=/tmp/$(basename $0)$$md5
1048 md5="$(ddq bs=2k skip=$(customsector) if="$ISO" | while read line; do
1049 case "$line" in
1050 \#!boot*) echo ${line#*boot } > $TMP ;;
1051 append=*) echo $line ;;
1052 initrd:*) echo $line
1053 cnt=${line#initrd:}
1054 ddq bs=512 count=$((cnt / 512))
1055 ddq bs=1 count=$((cnt % 512))
1056 break ;;
1057 *) break ;;
1058 esac
1059 done | md5sum | cut -c1-32)"
1060 [ "$md5" = "$(cat $TMP)" ] && echo "OK" || echo "ERROR"
1061 rm -f $TMP
1062 fi
1063 rm -f /tmp/wait
1064 [ "$1" ] && return 0
1065 echo -e "\rPress RETURN to continue."
1066 read n
1069 usbdev()
1071 dotwait "Wait 5 seconds for USB devices"
1072 sleep 5
1073 rm -f /tmp/wait
1074 DEV="$(grep -l 1 /sys/block/*/removable | \
1075 sed 's|/sys/block/\(.*\)/removable|\1|')"
1076 [ "$DEV" ] || return
1077 cat > /tmp/dialog$$ <<EOT
1078 $DIALOG --clear --title " Select your USB key " \
1079 --menu "\nPlease select the USB key according to its known size.\n\n" \
1080 0 0 0 \
1081 $(for i in $DEV ; do
1082 grep -qs 1 /sys/block/$i/ro ||
1083 echo -n "/dev/$i \"$(($(cat /sys/block/$i/size)/2048))MB $(cat /sys/block/$i/device/model 2> /dev/null)\" "
1084 done) \
1086 EOT
1087 exec 3>&1
1088 device=$(. /tmp/dialog$$ 2>&1 1>&3)
1089 rm -f /tmp/dialog$$
1090 retval=$?
1091 exec 3>&-
1092 rm -f /tmp/dialog$$
1093 [ $retval -eq 0 ]
1096 tazusbmsg()
1098 [ "$(which tazusb 2> /dev/null)" ] || return
1099 echo "You should choose 'USB key read/write installation' to be
1100 able to save the package updates or your own configuration and data files.\n\n"
1103 gpt_crc32()
1105 t0=00000000; t1=77073096; t2=EE0E612C; t3=990951BA;
1106 t4=076DC419; t5=706AF48F; t6=E963A535; t7=9E6495A3;
1107 t8=0EDB8832; t9=79DCB8A4; t10=E0D5E91E; t11=97D2D988;
1108 t12=09B64C2B; t13=7EB17CBD; t14=E7B82D07; t15=90BF1D91;
1109 t16=1DB71064; t17=6AB020F2; t18=F3B97148; t19=84BE41DE;
1110 t20=1ADAD47D; t21=6DDDE4EB; t22=F4D4B551; t23=83D385C7;
1111 t24=136C9856; t25=646BA8C0; t26=FD62F97A; t27=8A65C9EC;
1112 t28=14015C4F; t29=63066CD9; t30=FA0F3D63; t31=8D080DF5;
1113 t32=3B6E20C8; t33=4C69105E; t34=D56041E4; t35=A2677172;
1114 t36=3C03E4D1; t37=4B04D447; t38=D20D85FD; t39=A50AB56B;
1115 t40=35B5A8FA; t41=42B2986C; t42=DBBBC9D6; t43=ACBCF940;
1116 t44=32D86CE3; t45=45DF5C75; t46=DCD60DCF; t47=ABD13D59;
1117 t48=26D930AC; t49=51DE003A; t50=C8D75180; t51=BFD06116;
1118 t52=21B4F4B5; t53=56B3C423; t54=CFBA9599; t55=B8BDA50F;
1119 t56=2802B89E; t57=5F058808; t58=C60CD9B2; t59=B10BE924;
1120 t60=2F6F7C87; t61=58684C11; t62=C1611DAB; t63=B6662D3D;
1121 t64=76DC4190; t65=01DB7106; t66=98D220BC; t67=EFD5102A;
1122 t68=71B18589; t69=06B6B51F; t70=9FBFE4A5; t71=E8B8D433;
1123 t72=7807C9A2; t73=0F00F934; t74=9609A88E; t75=E10E9818;
1124 t76=7F6A0DBB; t77=086D3D2D; t78=91646C97; t79=E6635C01;
1125 t80=6B6B51F4; t81=1C6C6162; t82=856530D8; t83=F262004E;
1126 t84=6C0695ED; t85=1B01A57B; t86=8208F4C1; t87=F50FC457;
1127 t88=65B0D9C6; t89=12B7E950; t90=8BBEB8EA; t91=FCB9887C;
1128 t92=62DD1DDF; t93=15DA2D49; t94=8CD37CF3; t95=FBD44C65;
1129 t96=4DB26158; t97=3AB551CE; t98=A3BC0074; t99=D4BB30E2;
1130 t100=4ADFA541; t101=3DD895D7; t102=A4D1C46D; t103=D3D6F4FB;
1131 t104=4369E96A; t105=346ED9FC; t106=AD678846; t107=DA60B8D0;
1132 t108=44042D73; t109=33031DE5; t110=AA0A4C5F; t111=DD0D7CC9;
1133 t112=5005713C; t113=270241AA; t114=BE0B1010; t115=C90C2086;
1134 t116=5768B525; t117=206F85B3; t118=B966D409; t119=CE61E49F;
1135 t120=5EDEF90E; t121=29D9C998; t122=B0D09822; t123=C7D7A8B4;
1136 t124=59B33D17; t125=2EB40D81; t126=B7BD5C3B; t127=C0BA6CAD;
1137 t128=EDB88320; t129=9ABFB3B6; t130=03B6E20C; t131=74B1D29A;
1138 t132=EAD54739; t133=9DD277AF; t134=04DB2615; t135=73DC1683;
1139 t136=E3630B12; t137=94643B84; t138=0D6D6A3E; t139=7A6A5AA8;
1140 t140=E40ECF0B; t141=9309FF9D; t142=0A00AE27; t143=7D079EB1;
1141 t144=F00F9344; t145=8708A3D2; t146=1E01F268; t147=6906C2FE;
1142 t148=F762575D; t149=806567CB; t150=196C3671; t151=6E6B06E7;
1143 t152=FED41B76; t153=89D32BE0; t154=10DA7A5A; t155=67DD4ACC;
1144 t156=F9B9DF6F; t157=8EBEEFF9; t158=17B7BE43; t159=60B08ED5;
1145 t160=D6D6A3E8; t161=A1D1937E; t162=38D8C2C4; t163=4FDFF252;
1146 t164=D1BB67F1; t165=A6BC5767; t166=3FB506DD; t167=48B2364B;
1147 t168=D80D2BDA; t169=AF0A1B4C; t170=36034AF6; t171=41047A60;
1148 t172=DF60EFC3; t173=A867DF55; t174=316E8EEF; t175=4669BE79;
1149 t176=CB61B38C; t177=BC66831A; t178=256FD2A0; t179=5268E236;
1150 t180=CC0C7795; t181=BB0B4703; t182=220216B9; t183=5505262F;
1151 t184=C5BA3BBE; t185=B2BD0B28; t186=2BB45A92; t187=5CB36A04;
1152 t188=C2D7FFA7; t189=B5D0CF31; t190=2CD99E8B; t191=5BDEAE1D;
1153 t192=9B64C2B0; t193=EC63F226; t194=756AA39C; t195=026D930A;
1154 t196=9C0906A9; t197=EB0E363F; t198=72076785; t199=05005713;
1155 t200=95BF4A82; t201=E2B87A14; t202=7BB12BAE; t203=0CB61B38;
1156 t204=92D28E9B; t205=E5D5BE0D; t206=7CDCEFB7; t207=0BDBDF21;
1157 t208=86D3D2D4; t209=F1D4E242; t210=68DDB3F8; t211=1FDA836E;
1158 t212=81BE16CD; t213=F6B9265B; t214=6FB077E1; t215=18B74777;
1159 t216=88085AE6; t217=FF0F6A70; t218=66063BCA; t219=11010B5C;
1160 t220=8F659EFF; t221=F862AE69; t222=616BFFD3; t223=166CCF45;
1161 t224=A00AE278; t225=D70DD2EE; t226=4E048354; t227=3903B3C2;
1162 t228=A7672661; t229=D06016F7; t230=4969474D; t231=3E6E77DB;
1163 t232=AED16A4A; t233=D9D65ADC; t234=40DF0B66; t235=37D83BF0;
1164 t236=A9BCAE53; t237=DEBB9EC5; t238=47B2CF7F; t239=30B5FFE9;
1165 t240=BDBDF21C; t241=CABAC28A; t242=53B39330; t243=24B4A3A6;
1166 t244=BAD03605; t245=CDD70693; t246=54DE5729; t247=23D967BF;
1167 t248=B3667A2E; t249=C4614AB8; t250=5D681B02; t251=2A6F2B94;
1168 t252=B40BBE37; t253=C30C8EA1; t254=5A05DF1B; t255=2D02EF8D;
1169 crc=$((0xFFFFFFFF))
1170 dd if=$device bs=1 skip=$(($1)) count=$(($2)) 2> /dev/null | \
1171 od -v -w1 -t u1 -An | {
1172 while read n; do
1173 local x=$((($crc ^ $n) & 255))
1174 eval x=0x\$t$x
1175 crc=$(((($crc >> 8) & 0x00FFFFFF) ^ $x))
1176 done
1177 echo $(($crc ^ 0xFFFFFFFF))
1181 usbbootkey()
1183 if [ -b "$1" ]; then
1184 device=$1
1185 elif [ "$1" ]; then
1186 echo "Invalid USB key device"
1187 return 1
1188 else
1189 $DIALOG --clear --title " Create a USB boot key " \
1190 --yes-label "Continue" --yesno \
1191 "\nThe USB key will be used like a CD-ROM. You will not be able to write
1192 any data on the boot partition.\n\n
1193 An extra FAT32 partition will be created with the remaining free space.\n\n
1194 $(tazusbmsg)Please plug your USB stick in now.\n" 16 70
1195 [ $? -eq 0 ] || return
1196 usbdev || return
1197 fi
1199 # perform dd in progress bar
1200 max=$(($(sectcnt "$ISO")/2048))
1201 i=0; while [ $i -le $max ]; do
1202 ddq if="$ISO" bs=1024k count=1 skip=$i seek=$i of=$device
1203 echo $((($i*100)/$max))
1204 i=$(($i+1))
1205 done | dialog --gauge " The ISO image transfer can be long. Please wait..." \
1206 6 70 0 > /dev/tty 2>&1
1208 # GPT partition + fat32 format for the remaining space
1209 sectors=$(($(sectcnt $device)-1))
1210 quads2bin $sectors | ddq bs=1 seek=458 of=$device # pmbr
1211 quads2bin 0 | ddq bs=1 seek=$((512+16)) of=$device
1212 quads2bin $(($sectors-2)) 0 | ddq bs=1 seek=$((512+48)) of=$device
1213 uudecode - <<EOT | gunzip | ddn bs=128 seek=9 of=$device # partiton fat32
1214 begin-base64 644 -
1215 H4sIAAAAAAACA1u04MLrpzuNXdoPZGzbrjbz+C/fHwyfEro9Z7E93Fi5/8sH
1216 BhzAiSGRoZghkyGZQYEhBcguAWIFhgIgWQRkZ4JxPkMeAyEAAOuEo7uAAAAA
1217 ====
1218 EOT
1219 last=$(sectcnt "$ISO")
1220 custom=$((4*$(get 32848 $device 4)))
1221 [ $custom -gt $(($last-4)) ] && last=$(($custom+4)) # room for cmdline
1222 quads2bin $last 0 | ddq bs=1 seek=$((1024+128+32)) of=$device # vfat first address
1223 quads2bin $(($sectors-2)) 0 | ddq bs=1 seek=$((1024+128+40)) of=$device # vfat last address
1224 quads2bin $(gpt_crc32 1024 $(($(get 596 $device 4)*$(get 592 $device 4)))) | \
1225 ddq bs=1 seek=$((512+88)) of=$device # CRC32 partitions
1226 ddn of=$device if=$device bs=512 skip=1 seek=$sectors count=1
1227 ddn of=$device if=$device bs=512 skip=2 seek=$(($sectors-1)) count=1
1228 quads2bin $sectors 0 1 0 | ddq bs=1 seek=$(($sectors*512+24)) of=$device # my gpt, alt gpt
1229 quads2bin 1 0 $sectors 0 | ddq bs=1 seek=$((512+24)) of=$device # my gpt, alt gpt
1230 quads2bin $(($sectors-1)) 0 | ddq bs=1 seek=$(($sectors*512+72)) of=$device
1231 i=$(get 524 $device 4)
1232 quads2bin $(gpt_crc32 $(($sectors*512)) $i) | \
1233 ddq bs=1 seek=$(($sectors*512+16)) of=$device # CRC32 header
1234 quads2bin $(gpt_crc32 512 $i) | ddq bs=1 seek=$((512+16)) of=$device # CRC32 header
1235 partprobe $device
1236 homedev=/dev/$(basename /sys/block/${device#/dev/}/${device#/dev/}*2)
1237 mkdosfs -n 'SLITAZ HOME' $homedev
1239 # update boot/exe crc16
1240 words2bin 0 | ddq bs=1 seek=18 of=$device
1241 i=$(($(get 2 $device) - 1 + ($(get 4 $device) - 1)*512))
1242 i=$(($(od -v -N $i -t u2 -w2 -An $device | \
1243 awk '{ i+= $0 } END { print (i % 65536) }') \
1244 + $(get $(($i+1)) $device 1)))
1245 words2bin $(( (-$i -1) % 65536 )) | ddq bs=1 seek=18 of=$device
1247 $DIALOG --clear --title " Set /home persistent " \
1248 --yes-label "Continue" --yesno \
1249 "\nThe USB key will run fully in ram. The datas will be lost after each reboot.\n\n
1250 This option will mount /home on the USB key vfat during the boot process.\n\n
1251 Your own data will be saved, but the system stay not upgradable.\n" 16 70
1252 if [ $? -eq 0 ]; then
1253 data="append=home=$(blkid $homedev | sed 's|.* UUID="||;s|".*||') kmap=$(cat /etc/keymap.conf) lang=${LANG%.UTF*} tz=$(cat /etc/TZ) loadfs"
1254 cat <<EOT | ddn bs=512 seek=$custom of=$device
1255 #!boot $(echo "$data" | md5sum | sed 's/ .*//')
1256 $data
1257 --
1258 EOT
1259 fi
1262 usbkey()
1264 $DIALOG --clear --title " Create a SliTaz USB key " \
1265 --yes-label "Continue" --yesno \
1266 "\nUnlike a hard drive install, the filesystem is kept in a compressed
1267 rootfs.gz. The filesystem is loaded entirely into memory upon boot.
1268 This should increase responsiveness, protect the filesystem against
1269 accidental corruption and reduce read/writes to the USB drive.
1270 Once setup, the tazusb utility can rewrite the root filesystem
1271 with any changes you have made since booting up,
1272 giving the effective benefits of a hard drive install.\n\n
1273 /home is mounted on boot using the UUID of your particular flash drive.
1274 Unlike a device name, the UUID has the benefit of never changing from machine
1275 to machine.\n\n
1276 Please plug your USB stick in now.\n" 19 70
1277 [ $? -eq 0 ] || return
1278 usbdev || return
1279 exec 3>&1
1280 format=`$DIALOG --clear \
1281 --title " Select the filesystem " \
1282 --radiolist "\nPlease select the filesystem type to create.\n\n\
1283 The filesystem creation will erase all the data in the USB key." 14 70 4 \
1284 "none" "Do not erase the USB key" on \
1285 "ext3" "Ext3 journaling filesystem" off \
1286 "ext2" "Ext2 filesystem" off \
1287 "fat32" "Windows FAT32 filesystem" off \
1288 2>&1 1>&3`
1289 retval=$?
1290 exec 3>&-
1291 [ $retval -eq 0 ] || return
1292 [ "$format" != "none" ] && tazusb format $device "SliTaz" $format
1293 tazusb gen-iso2usb "$ISO" $device
1296 flavdata()
1298 [ $(get 1024 "$ISO") -eq 35615 ] && n=2 || n=$((1+$(get 417 "$ISO" 1)))
1299 [ $n -eq 4 ] && n=20
1300 [ $(get $(($n*512)) "$ISO") -eq 35615 ] || n=13
1301 ddq if="$ISO" bs=512 skip=$n count=20 | zcat 2>/dev/null
1304 hasflavinfo()
1306 [ "$(flavdata | ddq bs=1 count=7)" = "0707010" ] && menuitem "$@"
1309 showfavinfo()
1311 mkdir -p /tmp/data
1312 flavdata | ( cd /tmp/data ; cpio -i )
1313 file=/tmp/data/info
1314 cat /tmp/data/*desc > $file
1315 if [ -s /tmp/data/*receipt ]; then
1316 echo "=== receipt ==="
1317 cat /tmp/data/*receipt
1318 fi >> $file
1319 for i in /tmp/data/*list* ; do
1320 echo "=== extra ${i#*list} files"
1321 cat $i
1322 done >> $file
1323 if [ "$1" ]; then
1324 cat $file
1325 else
1326 $DIALOG --clear --title " Flavor info " \
1327 --textbox $file 0 0
1328 fi
1329 rm -rf /tmp/data
1332 flavor()
1334 name="$(flavdata | cpio -t 2> /dev/null | sed 's/.[a-z]*$//;q')"
1335 echo "Create ${name:=flavor}.flavor..."
1336 tazlito iso2flavor "$ISO" $name
1337 ls -l $name.flavor 2> /dev/null && return
1338 sleep 5
1339 [ "$1" ] && return
1340 echo -e "\rPress RETURN to continue."
1341 read n
1344 if [ "$1" = "--build" ]; then #install-begin
1345 uuencode -m - < header.com | sed -e '/^HEADERCODE$/r/dev/stdin' \
1346 -e "s|HEADERSZ|$(size header.com)|" -e '/^HEADERCODE$/d' -i $0
1347 uuencode -m - < ifmem.bin | sed -e '/^ifmemcode$/r/dev/stdin' \
1348 -e '/^ifmemcode$/d' -i $0
1349 uuencode -m - < bootloader.bin | sed -e '/^bootloader$/r/dev/stdin' \
1350 -e '/^bootloader$/d' -e '/install-begin$/,/install-end$/d' -i $0
1351 exit
1352 fi #install-end
1353 parse_isolinux()
1355 awk 'BEGIN { IGNORECASE=1 }
1356 function multi(n)
1358 auto=$n
1359 for (--n; n < NF; n+=2) {
1360 s=$n
1361 if (s ~ /M$/) s = substr(s,0,length(s)-1)
1362 else s /= 1024
1363 sizes=int(s) " " sizes
1365 next
1368 if ($1 == "LABEL") {
1369 label=$2
1370 if (auto == "") auto=label
1372 if ($1 == "KERNEL" || $1 == "COM32") kernel[label]=$2
1373 if ($1 == "INITRD") initrd[label]=$2
1374 if ($1 == "APPEND") {
1375 i=2
1376 if (kernel[label] ~ "ifmem.c32") multi(3)
1377 if (kernel[label] ~ "c32box.c32") {
1378 if ($2 == "linux") { kernel[label]=$3; i=4 }
1379 if ($2 == "ifmem") multi(4)
1381 if (kernel[label] ~ "ifcpu64.c32") { auto=$4; next }
1382 while (i <= NF) {
1383 if ($i ~ "^initrd=") initrd[label]=substr($i,8)
1384 else cmdline[label]=cmdline[label] " " $i
1385 i++
1389 END {
1390 print "KERNEL=\"" kernel[auto] "\""
1391 print "INITRD=\"" initrd[auto] "\""
1392 print "CMDLINE=\"" substr(cmdline[auto],2) "\""
1393 print "SIZES=\"" sizes "\""
1394 }'
1397 locase()
1399 echo "$1" | tr [A-Z] [a-z]
1402 ifmemcode()
1404 uudecode <<EOT
1405 ifmemcode
1406 EOT
1409 floppyset()
1411 gotcdfile 'isolinux.cfg'
1412 $0 include $file | parse_isolinux > /tmp/var$$
1413 . /tmp/var$$
1414 [ -z "$KERNEL" ] && echo "Can't parse isolinux.cfg" && return
1415 for i in $media/$KERNEL $(dirname $file)/$KERNEL $media/$(locase $KERNEL) \
1416 $(dirname $file)/$(locase $KERNEL); do
1417 i="$(ls $i* | sed q)"
1418 [ -n "$i" ] && KERNEL=$i && break
1419 done
1420 rm -f /tmp/var$$
1421 [ $(get 514 $KERNEL 4) -eq 1400005704 ] || return
1422 n=$(($(get 497 $KERNEL 1)+1))
1423 ddq bs=512 count=$n if=$KERNEL of=/tmp/fd$$
1424 uudecode <<EOT | ddn of=/tmp/fd$$
1425 bootloader
1426 EOT
1427 pos=$(($n*512))
1428 if [ -n "$CMDLINE" ]; then
1429 echo -n "$CMDLINE" | ddq bs=512 count=1 conv=sync >> /tmp/fd$$
1430 bytes2bin $n | ddn bs=1 seek=497 of=/tmp/fd$$
1431 words2bin $pos | ddn bs=1 seek=34 of=/tmp/fd$$
1432 [ $(get 518 $KERNEL 4) -ge 514 ] &&
1433 words2bin 32768 9 | ddn bs=1 seek=552 of=/tmp/fd$$
1434 fi
1435 syssize=$(echo $(get 500 /tmp/fd$$ 4))
1436 ddq bs=512 skip=$n if=$KERNEL | cat - /dev/zero | \
1437 ddq bs=512 count=$((($syssize+31)/32)) conv=sync >> /tmp/fd$$
1438 base=$(size /tmp/fd$$)
1439 len=
1440 if [ "$INITRD" ]; then
1441 l=0
1442 for i in ${INITRD//,/ }; do
1443 for j in $media/$i $(dirname $KERNEL)/$i $media/$(locase $i) \
1444 $(dirname $KERNEL)/$(locase $i); do
1445 j="$(ls $j* | sed q)"
1446 [ -n "$j" ] && i=$j && break
1447 done
1448 ddq if=$i >> /tmp/fd$$
1449 l=$(($l+$(size $i)))
1450 r=$((4 - ($l % 4)))
1451 if [ $r -ne 4 ]; then
1452 ddq if=/dev/zero bs=1 count=$r >> /tmp/fd$$
1453 l=$(($l + $r))
1454 fi
1455 case "$i:$INITRD" in
1456 *rootfs.gz:*rootfs.gz,*) continue # loram
1457 esac
1458 len="$len $l"; l=0
1459 done
1460 rdadrs=${RDADRS:-$(((($syssize*16)+0x1F0000) & -4096))}
1461 quads2bin $rdadrs | ddn bs=1 seek=536 of=/tmp/fd$$
1462 fi
1463 n=$(echo $len | wc -w)
1464 if [ $((494 - $(get 494 /tmp/fd$$))) -ge $(($n * 4)) ]; then
1465 i=$(($(get 494 /tmp/fd$$)))
1466 bytes2bin $(($i + ($n*4) - 256)) | ddn bs=1 \
1467 seek=496 of=/tmp/fd$$
1468 else
1469 i=$(($pos + 0x1FC - ($n*4)))
1470 bytes2bin $(($i % 256)) $((i / 256)) 252 | ddn bs=1 \
1471 seek=494 of=/tmp/fd$$
1472 s=$(($i - 2*$(echo "$SIZES" | wc -w)))
1473 p=$(($s - $(ifmemcode | wc -c)))
1474 ifmemcode | ddn bs=1 seek=$p of=/tmp/fd$$
1475 words2bin $SIZES | ddn bs=1 seek=$s of=/tmp/fd$$
1476 bytes2bin 154 $(($p%256)) $(($p/256)) 0 144 | \
1477 ddn bs=1 seek=60 of=/tmp/fd$$
1478 fi
1479 for r in $len ; do
1480 quads2bin $r | ddn bs=1 seek=$i of=/tmp/fd$$
1481 i=$(($i + 4))
1482 done
1483 split -b 1440k /tmp/fd$$ fd$$
1484 rm -f /tmp/fd$$
1485 n=1; i=0; r=0
1486 set -- $len
1487 ls fd$$* | while read file ; do
1488 if [ $i -gt $(($1+$base)) ]; then
1489 shift
1490 r=$(($r+100)); n=0; i=0; base=0
1491 fi
1492 ddq of=$file bs=18k seek=80 count=0
1493 i=$(($i+1474560))
1494 printf "mv %s fd%03d.img\n" $file $(($r+$n))
1495 n=$(($n+1))
1496 done | sh
1497 du -ch $PWD/fd???.img
1500 quit()
1502 umount -d $media
1503 rmdir $media
1504 ${1:-exit}
1507 infoiso()
1509 isoinfo -d -i "$ISO" > /tmp/isoinfo$$
1510 if [ -x "$(which iso2exe)" ]; then
1511 echo "----"
1512 blkid "$ISO" | while read args; do
1513 set -- $args
1514 while [ -n "$2" ]; do
1515 case "$2" in
1516 *UUID*|PT*) echo $2;;
1517 esac
1518 shift
1519 done
1520 done
1521 if ! fdisk -l "$ISO" | grep -q 'valid partition'; then
1522 fdisk -l "$ISO" | grep heads
1523 fdisk -l "$ISO" | sed 's/^ *[^ ]* *//;s/ */ /g;$!d'
1524 fi
1525 echo "----"
1526 iso2exe -l "$ISO"
1527 fi >> /tmp/isoinfo$$
1528 if [ "$1" ]; then
1529 cat /tmp/isoinfo$$
1530 else
1531 $DIALOG --clear --title " Info ISO " \
1532 --textbox /tmp/isoinfo$$ 0 0
1533 fi
1534 rm -f /tmp/isoinfo$$
1537 isotitle()
1539 echo "$(blkid "$ISO" | sed 's/.*LABEL="\([^"]*\).*/\1/') $(stat \
1540 -c %y $media/.|sed 's/ .*//') $(basename "$ISO")"
1543 if [ $0 = /init.exe ]; then
1545 case "${ISO##*/}$(getarg mode)" in
1546 *install*|*INSTALL*) install;;
1547 *live*|*LIVE*) live;;
1548 *text*|*TEXT*) text;;
1549 esac
1550 dmesg > /tmp/dmesg
1552 else
1554 if [ "$1" = "include" ]; then
1555 [ -s "$2" ] && cd $(dirname "$2") && awk -v exe=$0 \
1556 '{ if ($1 == "include") system(exe " include " $2); else print }' <"$2"
1557 exit
1558 fi
1559 ISO="${1:-/dev/null}"
1560 while [ -L "$ISO" ]; do
1561 media="$(readlink "$ISO")"
1562 case "$media" in
1563 /*) ISO="$media" ;;
1564 *) ISO="$(dirname "$ISO")/$media" ;;
1565 esac
1566 done
1567 [ "${ISO:0:1}" != "/" ] && ISO="$(cd $(dirname "$ISO"); echo $PWD/$(basename "$ISO"))"
1568 [ -z "$(isiso 2> /dev/null)" ] && echo "Usage : $0 file.iso" && exit 1
1569 media=/tmp/media$$
1570 mkdir -p $media
1571 mount -o loop,ro "$ISO" $media
1573 if [ "$2" = "list" ]; then
1574 sed '/^\$(.*") \\/!d;s/^\$(\(.*\)").*/\1"/' $0 | while read line; do
1575 eval $line
1576 echo
1577 done | sed '/^$/d;/"usbkey"/d'
1578 quit
1579 fi
1580 if grep -q "^$2()" $0; then
1581 exe=$2
1582 shift 2
1583 if [ -n "$(eval $(grep "\"$exe\"" $0 | sed \
1584 '/^\$/!d;s/.(\(.*\)[\t ]*".*"[\t ]*".*/\1/'))" ]; then
1585 isotitle
1586 grep "\"$exe\"" $0 | sed '/^\$/!d;s/.*"[\t ]*"\(.*\)".*/\1/'
1587 echo ----
1588 $exe "$@"
1589 fi
1590 quit
1591 fi
1592 fi
1594 while true; do
1595 keymap="$(cat /etc/keymap.conf 2>/dev/null)"
1596 locale="$(sed '/^LANG=/!d;s/.*=//' /etc/locale.conf 2>/dev/null)"
1597 cat > /tmp/dialog$$ <<EOT
1598 $DIALOG --clear --title " $(isotitle) " --menu "" 28 70 30 \
1599 $(initxfile tazkeymap "tazkeymap" "Select keyboard (${keymap:-none})") \
1600 $(initxfile tazlocale "tazlocale" "Select locale (${locale:-none})") \
1601 $(initx "live" "Linux RAM boot (full desktop)") \
1602 $(initx "text" "Linux RAM boot") \
1603 $(cdfile 'README*' "readme" "Show the README file") \
1604 $(gotcustomconf "getcustomconf" "Get custom config") \
1605 $(gotisomd5 "isomd5" "Check the ISO image") \
1606 $(cdfile 'md5sum*' "md5" "Check the ISO files") \
1607 $(cdfile 'sha*sum*' "sha" "Check the ISO files") \
1608 $(xfile isoinfo "infoiso" "ISO image info") \
1609 $(cdfilex 'bzImage*' "bootiso" "Boot the ISO image") \
1610 $(burnable "burniso" "Burn the ISO image") \
1611 $(blankable "blankcd" "Blank the CD/DVD") \
1612 $(gotposixovl "install" "Hard disk installation (UMSDOS way)") \
1613 $(gotposixovl "installtaz" "Hard disk installation (TAZUSB way)") \
1614 $(gotposixovlzip "inst2zip" "ZIP installation archive (UMSDOS way)") \
1615 $(gotposixovlzip "insttaz2zip" "ZIP installation archive (TAZUSB way)") \
1616 $(gottazusb "usbkey" "USB key read/write installation") \
1617 $(ishybrid "usbbootkey" "USB boot key (not upgradable)") \
1618 $(hasflavinfo "showfavinfo" "Show flavor extra info") \
1619 $(hasflavor "flavor" "Get flavor file") \
1620 $(cdfile isolinux.cfg "floppyset" "Boot floppy set") \
1621 $(cdfile linld.com "tazboot" "Get tazboot.exe Linux loader") \
1622 $(cdexe 'bzImage*' "bzimage" "Get linux DOS/EXE file") \
1623 $(cdexe 'memtest*' "memtest" "Get Memtest86 DOS/EXE file") \
1624 $(cdfilef 'memtest*' "fdmemtest" "Create a Memtest86 boot floppy") \
1625 $(cdexe '?pxe*' "pxe" "Get SliTaz Web boot DOS/EXE utility") \
1626 $(cdfilef '?pxe*' "fdpxe" "Create a SliTaz Web boot floppy") \
1627 $(cdexe 'plop.exe' "plop" "Get USB boot DOS/EXE utility") \
1628 $(cdfilef 'plop.exe' "fdplop" "Create a USB boot floppy") \
1629 $(initxfile reboot "restart" "Restart the computer") \
1630 $(initxfile poweroff "stop" "Power off") \
1631 $(initx "bootlog" "Linux boot messages") \
1632 $(initx "shell" "Shell prompt") \
1633 $(noinitmisspkg "missing" "Install packages to get more options") \
1634 $(noinit "quit" "Quit this utility")
1635 EOT
1636 exec 3>&1
1637 value=$(. /tmp/dialog$$ 2>&1 1>&3)
1638 retval=$?
1639 exec 3>&-
1640 rm -f /tmp/dialog$$
1641 [ $retval -ne 0 ] && [ $0 != /init.exe ] && quit
1642 $value
1643 done