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

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