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

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