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

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