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

Up libqcow (20240308)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Mar 24 18:25:46 2024 +0000 (5 weeks ago)
parents 2ac466d9d0a7
children
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" $(busybox 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 fixup_gpt()
1151 quads2bin 1 0 $2 0 | ddq bs=1 seek=$((512+24)) of=$1 # my gpt, alt gpt
1152 quads2bin 0 | ddq bs=1 seek=$((512+88)) of=$device
1153 quads2bin $(isohybrid --crc32 $1 1024 $(($(get 596 $1 4)*$(get 592 $1 4)))) | \
1154 ddq bs=1 seek=$((512+88)) of=$1 # CRC32 partitions
1155 ddn of=$1 if=$1 bs=512 skip=1 seek=$2 count=1
1156 ddn of=$1 if=$1 bs=512 skip=2 seek=$(($2-1)) count=1
1157 quads2bin $2 0 1 0 | ddq bs=1 seek=$(($2*512+24)) of=$1 # my gpt, alt gpt
1158 quads2bin $(($2-1)) 0 | ddq bs=1 seek=$(($2*512+72)) of=$1
1159 i=$(get 524 $1 4)
1160 quads2bin 0 | ddq bs=1 seek=$(($2*512+16)) of=$device
1161 quads2bin $(isohybrid --crc32 $1 $(($2*512)) $i) | \
1162 ddq bs=1 seek=$(($2*512+16)) of=$1 # CRC32 header
1163 quads2bin 0 | ddq bs=1 seek=$((512+16)) of=$device
1164 quads2bin $(isohybrid --crc32 $1 512 $i) | ddq bs=1 seek=$((512+16)) of=$1 # CRC32 header
1165 partprobe $1
1168 usbbootkey()
1170 if [ -b "$1" ]; then
1171 device=$1
1172 elif [ "$1" ]; then
1173 echo "Invalid USB key device"
1174 return 1
1175 else
1176 $DIALOG --clear --title " Create a USB boot key " \
1177 --yes-label "Continue" --yesno \
1178 "\nThe USB key will be used like a CD-ROM. You will not be able to write
1179 any data on the boot partition.\n\n
1180 An extra FAT32 partition will be created with the remaining free space.\n\n
1181 $(tazusbmsg)Please plug your USB stick in now.\n" 16 70
1182 [ $? -eq 0 ] || return
1183 usbdev || return
1184 fi
1186 # perform dd in progress bar
1187 max=$(($(sectcnt "$ISO")/2048))
1188 i=0; while [ $i -le $max ]; do
1189 ddq if="$ISO" bs=1024k count=1 skip=$i seek=$i of=$device
1190 echo $(((i*100)/max))
1191 i=$((i+1))
1192 done | { [ "$1" ] || dialog --gauge \
1193 " The ISO image transfer can be long. Please wait..." \
1194 6 70 0 > /dev/tty 2>&1; }
1196 # GPT partition + fat32 format for the remaining space
1197 sectors=$(($(sectcnt $device)-1))
1198 quads2bin $sectors | ddq bs=1 seek=458 of=$device # pmbr
1199 quads2bin $((sectors-2)) 0 | ddq bs=1 seek=$((512+48)) of=$device
1200 uudecode - <<EOT | gunzip | ddn bs=128 seek=9 of=$device # basic data partiton
1201 begin-base64 644 -
1202 H4sIAAAAAAACA1u04MLrpzuNXdoPZGzbrjbzOAORwIkhkaGYIZMhmUGBIQXI
1203 LgFiBYYCIFkEZGeCcT5DHkFzAAqvwhqAAAAA
1204 ====
1205 EOT
1206 ddq if=/dev/urandom bs=16 count=1 seek=73 of=$device # partition uuid
1207 last=$(sectcnt "$ISO")
1208 custom=$((4*$(get 32848 $device 4)))
1209 [ $custom -gt $((last-4)) ] && last=$((custom+4)) # room for cmdline
1210 quads2bin $last 0 | ddq bs=1 seek=$((1024+128+32)) of=$device # partition first address
1211 quads2bin $((sectors-2)) 0 | ddq bs=1 seek=$((1024+128+40)) of=$device # partition last address
1212 fixup_gpt $device $sectors
1213 [ -b ${device}p2 ] && pdev=${device}p2 || pdev=${device}2
1214 value=$(cat /sys/block/${device#/dev/}/${pdev#/dev/}/size)
1215 [ ${#value} -gt 7 -a "$(which mkfs.exfat)" ] && value="exfat" || value="fat32"
1216 if [ -z "$1" ]; then
1217 echo -n "$DIALOG --clear --title \" Select the filesystem \" \
1218 --radiolist \"\\nPlease select the filesystem type to create.\" 14 70 4" > /tmp/dialog$$
1219 while read type rem; do
1220 which mkfs.${type/fat32/vfat} > /dev/null || continue
1221 echo -n " $type \"$rem" >> /tmp/dialog$$
1222 done <<EOT
1223 fat32 for a small key" $([ "$value" = "fat32" ] && echo "on" || echo "off")
1224 exfat for a large key" $([ "$value" = "exfat" ] && echo "on" || echo "off")
1225 ntfs " off
1226 ext3 for most linux" off
1227 ext4 " off
1228 btrfs for recent linux" off
1229 xfs
1230 EOT
1231 exec 3>&1
1232 value=$(. /tmp/dialog$$ 2>&1 1>&3)
1233 retval=$?
1234 exec 3>&-
1235 rm -f /tmp/dialog$$
1236 fi
1237 homedev=/dev/$(basename /sys/block/${device#/dev/}/${pdev#/dev/})
1238 case "$value" in
1239 *fat*) mkfs.${value/fat32/vfat} -n 'SLITAZ HOME' $homedev;;
1240 *) mkfs.$value -L 'SLITAZ HOME' $homedev;;
1241 esac > /dev/null 2>&1
1243 # update boot/exe crc16
1244 words2bin 0 | ddq bs=1 seek=18 of=$device
1245 i=$(($(get 2 $device) - 1 + ($(get 4 $device) - 1)*512))
1246 i=$(($(od -v -N $i -t u2 -w2 -An $device | \
1247 awk '{ i+= $0 } END { print (i % 65536) }') \
1248 + $(get $((i+1)) $device 1)))
1249 words2bin $(( (-i -1) & 65535 )) | ddq bs=1 seek=18 of=$device
1251 [ "$1" ] || $DIALOG --clear --title " Set /home persistent " \
1252 --yes-label "Continue" --yesno \
1253 "\nThe USB key will run fully in ram. The datas will be lost after each reboot.\n\n
1254 This option will mount /home on the USB key vfat during the boot process.\n\n
1255 Your own data will be saved, but the system stay not upgradable.\n" 16 70
1256 if [ $? -eq 0 ]; then
1257 echo -en "$(echo "SliTaz persistent /home" | sed 's|.|&\\0|g')" | ddn bs=8 seek=151 of=$device
1258 fixup_gpt $device $sectors
1259 [ "$(ddn bs=512 skip=$custom if=$device | ddn bs=1 count=6)" = "#!boot" ] && return
1260 mkdir /tmp/mnt$$
1261 mount $pdev /tmp/mnt$$
1262 echo -e "keyboard\nlocale\ntimezone" > /tmp/dialog.out$$
1263 touch /tmp/dialog$$
1264 if [ -z "$1" ]; then
1265 cat > /tmp/dialog$$ <<EOT
1266 $DIALOG --clear --title " Select configuration " \
1267 --separate-output \
1268 --cancel-label "Skip" \
1269 --checklist "Please select the configuration to store." \
1270 0 0 0 \
1271 keyboard "kmap=$(cat /etc/keymap.conf)" on \
1272 locale "lang=${LANG%.UTF*}" on \
1273 timezone "tz=$(cat /etc/TZ)" on \
1274 $([ -s /tmp/mnt$$/boot/rootfs.gz ] || cat <<EOM
1275 network "/etc/network.conf" off \
1276 ssh "/etc/dropbear" off \
1277 password "/etc/passwd /etc/*shadow /etc/group" off \
1278 custom "Your own list of files" off
1279 EOM
1281 EOT
1282 sh /tmp/dialog$$ 2> /tmp/dialog.out$$
1283 [ $? -eq 0 ] || echo -n "" > /tmp/dialog.out$$
1284 fi
1285 data=""; files=""
1286 while read i ; do
1287 case "$i" in
1288 keyboard) data="${data}kmap=$(cat /etc/keymap.conf) ";;
1289 locale) data="${data}lang=${LANG%.UTF*} " ;;
1290 timezone) data="${data}tz=$(cat /etc/TZ) " ;;
1291 network) files="${files} /etc/network.conf" ;;
1292 ssh) files="${files} /etc/dropbear" ;;
1293 password) files="${files} /etc/passwd /etc/*shadow /etc/group" ;;
1294 custom) exec 3>&1
1295 custom="$($DIALOG --clear --title " Custom files " \
1296 --inputbox "\nEnter the list of files to save:\n" 10 70 2>&1 1>&3)"
1297 retval=$?
1298 exec 3>&-
1299 [ $retval -eq 0 ] && files="${files} $custom" ;;
1300 esac
1301 done < /tmp/dialog.out$$
1302 rm -f /tmp/dialog$$ /tmp/dialog.out$$
1303 [ "$data" ] && cat <<EOT | ddn bs=512 seek=$custom of=$device
1304 #!boot $(echo "append=$data" | md5sum | sed 's/ .*//')
1305 append=$data
1306 --
1307 EOT
1308 if [ "$files" ]; then
1309 mkdir /tmp/mnt$$/boot 2> /dev/null
1310 find $files | cpio -o -H newc | gzip -9 > /tmp/mnt$$/boot/rootfs.gz
1311 fi
1312 umount /tmp/mnt$$
1313 rm -rf /tmp/mnt$$
1314 fi
1317 usbkey()
1319 $DIALOG --clear --title " Create a SliTaz USB key " \
1320 --yes-label "Continue" --yesno \
1321 "\nUnlike a hard drive install, the filesystem is kept in a compressed
1322 rootfs.gz. The filesystem is loaded entirely into memory upon boot.
1323 This should increase responsiveness, protect the filesystem against
1324 accidental corruption and reduce read/writes to the USB drive.
1325 Once setup, the tazusb utility can rewrite the root filesystem
1326 with any changes you have made since booting up,
1327 giving the effective benefits of a hard drive install.\n\n
1328 /home is mounted on boot using the UUID of your particular flash drive.
1329 Unlike a device name, the UUID has the benefit of never changing from machine
1330 to machine.\n\n
1331 Please plug your USB stick in now.\n" 19 70
1332 [ $? -eq 0 ] || return
1333 usbdev || return
1334 exec 3>&1
1335 format=`$DIALOG --clear \
1336 --title " Select the filesystem " \
1337 --radiolist "\nPlease select the filesystem type to create.\n\n\
1338 The filesystem creation will erase all the data in the USB key." 14 70 4 \
1339 "none" "Do not erase the USB key" on \
1340 "ext3" "Ext3 journaling filesystem" off \
1341 "ext2" "Ext2 filesystem" off \
1342 "fat32" "Windows FAT32 filesystem" off \
1343 2>&1 1>&3`
1344 retval=$?
1345 exec 3>&-
1346 [ $retval -eq 0 ] || return
1347 [ "$format" != "none" ] && tazusb format $device "SliTaz" $format
1348 tazusb gen-iso2usb "$ISO" $device
1351 flavdata()
1353 [ $(get 1024 "$ISO") -eq 35615 ] && n=2 || n=$((1+$(get 417 "$ISO" 1)))
1354 [ $n -eq 4 ] && n=20
1355 [ $(get $((n*512)) "$ISO") -eq 35615 ] || n=13
1356 ddq if="$ISO" bs=512 skip=$n count=20 | zcat 2>/dev/null
1359 hasflavinfo()
1361 [ "$(flavdata | ddq bs=1 count=7)" = "0707010" ] && menuitem "$@"
1364 showfavinfo()
1366 mkdir -p /tmp/data
1367 flavdata | ( cd /tmp/data ; cpio -i )
1368 file=/tmp/data/info
1369 cat /tmp/data/*desc > $file
1370 if [ -s /tmp/data/*receipt ]; then
1371 echo "=== receipt ==="
1372 cat /tmp/data/*receipt
1373 fi >> $file
1374 for i in /tmp/data/*list* ; do
1375 echo "=== extra ${i#*list} files"
1376 cat $i
1377 done >> $file
1378 if [ "$1" ]; then
1379 cat $file
1380 else
1381 $DIALOG --clear --title " Flavor info " \
1382 --textbox $file 0 0
1383 fi
1384 rm -rf /tmp/data
1387 flavor()
1389 name="$(flavdata | cpio -t 2> /dev/null | sed 's/.[a-z]*$//;q')"
1390 echo "Create ${name:=flavor}.flavor..."
1391 tazlito iso2flavor "$ISO" $name
1392 ls -l $name.flavor 2> /dev/null && return
1393 sleep 5
1394 [ "$1" ] || read_return
1397 if [ "$1" = "--build" ]; then #install-begin
1398 uuencode -m - < ifmem.bin | sed -e '/^ifmemcode$/r/dev/stdin' \
1399 -e '/^ifmemcode$/d' -i $0
1400 uuencode -m - < bootloader.bin | sed -e '/^bootloader$/r/dev/stdin' \
1401 -e '/^bootloader$/d' -e '/install-begin$/,/install-end$/d' -i $0
1402 exit
1403 fi #install-end
1404 parse_isolinux()
1406 awk 'BEGIN { IGNORECASE=1 }
1407 function multi(n)
1409 auto=$n
1410 for (--n; n < NF; n+=2) {
1411 s=$n
1412 if (s ~ /M$/) s = substr(s,0,length(s)-1)
1413 else s /= 1024
1414 sizes=int(s) " " sizes
1416 next
1419 if ($1 == "LABEL") {
1420 label=$2
1421 if (auto == "") auto=label
1423 if ($1 == "KERNEL" || $1 == "COM32") kernel[label]=$2
1424 if ($1 == "INITRD") initrd[label]=$2
1425 if ($1 == "APPEND") {
1426 i=2
1427 if (kernel[label] ~ "ifmem.c32") multi(3)
1428 if (kernel[label] ~ "c32box.c32") {
1429 if ($2 == "linux") { kernel[label]=$3; i=4 }
1430 if ($2 == "ifmem") multi(4)
1432 if (kernel[label] ~ "ifcpu64.c32") { auto=$4; next }
1433 while (i <= NF) {
1434 if ($i ~ "^initrd=") initrd[label]=substr($i,8)
1435 else cmdline[label]=cmdline[label] " " $i
1436 i++
1440 END {
1441 print "KERNEL=\"" kernel[auto] "\""
1442 print "INITRD=\"" initrd[auto] "\""
1443 print "CMDLINE=\"" substr(cmdline[auto],2) "\""
1444 print "SIZES=\"" sizes "\""
1445 }'
1448 locase()
1450 echo "$1" | tr [A-Z] [a-z]
1453 ifmemcode()
1455 uudecode <<EOT
1456 ifmemcode
1457 EOT
1460 floppyset()
1462 gotcdfile 'isolinux.cfg'
1463 $0 include $file | parse_isolinux > /tmp/var$$
1464 . /tmp/var$$
1465 [ -z "$KERNEL" ] && echo "Can't parse isolinux.cfg" && return
1466 for i in $media/$KERNEL $(dirname $file)/$KERNEL $media/$(locase $KERNEL) \
1467 $(dirname $file)/$(locase $KERNEL); do
1468 i="$(ls $i* | sed q)"
1469 [ -n "$i" ] && KERNEL=$i && break
1470 done
1471 rm -f /tmp/var$$
1472 [ $(get 514 $KERNEL 4) -eq 1400005704 ] || return
1473 n=$(($(get 497 $KERNEL 1)+1))
1474 ddq bs=512 count=$n if=$KERNEL of=/tmp/fd$$
1475 uudecode <<EOT | ddn of=/tmp/fd$$
1476 bootloader
1477 EOT
1478 pos=$((n*512))
1479 if [ -n "$CMDLINE" ]; then
1480 echo -n "$CMDLINE" | ddq bs=512 count=1 conv=sync >> /tmp/fd$$
1481 bytes2bin $n | ddn bs=1 seek=497 of=/tmp/fd$$
1482 words2bin $pos | ddn bs=1 seek=34 of=/tmp/fd$$
1483 [ $(get 518 $KERNEL 4) -ge 514 ] &&
1484 words2bin 32768 9 | ddn bs=1 seek=552 of=/tmp/fd$$
1485 fi
1486 syssize=$(echo $(get 500 /tmp/fd$$ 4))
1487 ddq bs=512 skip=$n if=$KERNEL | cat - /dev/zero | \
1488 ddq bs=512 count=$(((syssize+31)/32)) conv=sync >> /tmp/fd$$
1489 base=$(size /tmp/fd$$)
1490 len=
1491 if [ "$INITRD" ]; then
1492 l=0
1493 for i in ${INITRD//,/ }; do
1494 for j in $media/$i $(dirname $KERNEL)/$i $media/$(locase $i) \
1495 $(dirname $KERNEL)/$(locase $i); do
1496 j="$(ls $j* | sed q)"
1497 [ -n "$j" ] && i=$j && break
1498 done
1499 ddq if=$i >> /tmp/fd$$
1500 l=$((l+$(size $i)))
1501 r=$((4 - (l % 4)))
1502 if [ $r -ne 4 ]; then
1503 ddq if=/dev/zero bs=1 count=$r >> /tmp/fd$$
1504 l=$((l + r))
1505 fi
1506 case "$i:$INITRD" in
1507 *rootfs.gz:*rootfs.gz,*) continue # loram
1508 esac
1509 len="$len $l"; l=0
1510 done
1511 rdadrs=${RDADRS:-$((((syssize*16)+0x1F0000) & -4096))}
1512 quads2bin $rdadrs | ddn bs=1 seek=536 of=/tmp/fd$$
1513 fi
1514 n=$(echo $len | wc -w)
1515 if [ $((494 - $(get 494 /tmp/fd$$))) -ge $((n * 4)) ]; then
1516 i=$(($(get 494 /tmp/fd$$)))
1517 bytes2bin $((i + (n*4) - 256)) | ddn bs=1 \
1518 seek=496 of=/tmp/fd$$
1519 else
1520 i=$((pos + 0x1FC - (n*4)))
1521 bytes2bin $((i % 256)) $((i / 256)) 252 | ddn bs=1 \
1522 seek=494 of=/tmp/fd$$
1523 s=$((i - 2*$(echo "$SIZES" | wc -w)))
1524 p=$((s - $(ifmemcode | wc -c)))
1525 ifmemcode | ddn bs=1 seek=$p of=/tmp/fd$$
1526 words2bin $SIZES | ddn bs=1 seek=$s of=/tmp/fd$$
1527 bytes2bin 154 $((p%256)) $((p/256)) 0 144 | \
1528 ddn bs=1 seek=60 of=/tmp/fd$$
1529 fi
1530 for r in $len ; do
1531 quads2bin $r | ddn bs=1 seek=$i of=/tmp/fd$$
1532 i=$((i + 4))
1533 done
1534 split -b 1440k /tmp/fd$$ fd$$
1535 rm -f /tmp/fd$$
1536 n=1; i=0; r=0
1537 set -- $len
1538 ls fd$$* | while read file ; do
1539 if [ $i -ge $(($1+base)) ]; then
1540 base=$(($1+base-i))
1541 shift
1542 r=$((r+100)); n=0; i=0
1543 fi
1544 ddq of=$file bs=18k seek=80 count=0
1545 i=$((i+1474560))
1546 printf "mv %s fd%03d.img\n" $file $((r+n))
1547 n=$((n+1))
1548 done | sh
1549 du -ch $PWD/fd???.img
1552 quit()
1554 umount -d $media
1555 rmdir $media
1556 ${1:-exit}
1559 infoiso()
1561 isoinfo -d -i "$ISO" > /tmp/isoinfo$$ 2> /dev/null
1562 if [ "$(which iso2exe)" ]; then
1563 echo "----"
1564 blkid "$ISO" | while read args; do
1565 set -- $args
1566 while [ -n "$2" ]; do
1567 case "$2" in
1568 *UUID*|PT*) echo $2;;
1569 esac
1570 shift
1571 done
1572 done
1573 if ! fdisk -l "$ISO" | grep -q 'valid partition'; then
1574 fdisk -l "$ISO" | grep heads
1575 fdisk -l "$ISO" | sed 's/^ *[^ ]* *//;s/ */ /g;$!d'
1576 fi
1577 echo "----"
1578 iso2exe -l "$ISO"
1579 fi >> /tmp/isoinfo$$
1580 if [ "$1" ]; then
1581 cat /tmp/isoinfo$$
1582 else
1583 $DIALOG --clear --title " Info ISO " \
1584 --textbox /tmp/isoinfo$$ 0 0
1585 files=$(sed '/^custom.*d/!d;s| .*||' /tmp/isoinfo$$)
1586 if [ "$files" ]; then
1587 $DIALOG --clear --title " Extract custom files " \
1588 --defaultno --yesno \
1589 "Do you want to extract the custom boot files ?\n$files" 7 70
1590 [ $? -eq 0 ] && for i in $files ; do
1591 echo "Extract $i ..."
1592 iso2exe -l "$ISO" $i
1593 done
1594 fi
1595 fi
1596 rm -f /tmp/isoinfo$$
1599 isotitle()
1601 echo "$(blkid "$ISO" | sed 's/.*LABEL="\([^"]*\).*/\1/') $(stat \
1602 -c %y $media/.|sed 's/ .*//') $(basename "$ISO")"
1605 if [ $0 = /init.exe ]; then
1607 case "${ISO##*/}$(getarg mode)" in
1608 *install*|*INSTALL*) install;;
1609 *live*|*LIVE*) live;;
1610 *text*|*TEXT*) text;;
1611 esac
1612 dmesg > /tmp/dmesg
1614 else
1616 if [ "$1" = "include" ]; then
1617 [ -s "$2" ] && cd $(dirname "$2") && awk -v exe=$0 \
1618 '{ if ($1 == "include") system(exe " include " $2); else print }' <"$2"
1619 exit
1620 fi
1621 ISO="${1:-/dev/null}"
1622 while [ -L "$ISO" ]; do
1623 media="$(readlink "$ISO")"
1624 case "$media" in
1625 /*) ISO="$media" ;;
1626 *) ISO="$(dirname "$ISO")/$media" ;;
1627 esac
1628 done
1629 [ "${ISO:0:1}" != "/" ] && ISO="$(cd $(dirname "$ISO"); echo $PWD/$(basename "$ISO"))"
1630 [ -z "$(isiso 2> /dev/null)" ] && echo "Usage : $0 file.iso" && exit 1
1631 media=/tmp/media$$
1632 mkdir -p $media
1633 mount -o loop,ro "$ISO" $media
1635 if [ "$2" = "list" ]; then
1636 sed '/^\$(.*") \\/!d;s/^\$(\(.*\)").*/\1"/' $0 | while read line; do
1637 eval $line
1638 echo
1639 done | sed '/^$/d;/"usbkey"/d'
1640 quit
1641 fi
1642 if grep -q "^$2()" $0; then
1643 exe=$2
1644 shift 2
1645 if [ -n "$(eval $(grep "\"$exe\"" $0 | sed \
1646 '/^\$/!d;s/.(\(.*\)[\t ]*".*"[\t ]*".*/\1/'))" ]; then
1647 isotitle
1648 grep "\"$exe\"" $0 | sed '/^\$/!d;s/.*"[\t ]*"\(.*\)".*/\1/'
1649 echo ----
1650 $exe "$@"
1651 fi
1652 quit
1653 fi
1654 fi
1656 while true; do
1657 keymap="$(cat /etc/keymap.conf 2>/dev/null)"
1658 locale="$(sed '/^LANG=/!d;s/.*=//' /etc/locale.conf 2>/dev/null)"
1659 cat > /tmp/dialog$$ <<EOT
1660 $DIALOG --clear --title " $(isotitle) " --menu "" 0 0 0 \
1661 $(initxfile tazkeymap "tazkeymap" "Select keyboard (${keymap:-none})") \
1662 $(initxfile tazlocale "tazlocale" "Select locale (${locale:-none})") \
1663 $(initx "live" "Linux RAM boot (full desktop)") \
1664 $(initx "text" "Linux RAM boot") \
1665 $(cdfile 'README*' "readme" "Show the README file") \
1666 $(gotcustomconf "getcustomconf" "Get custom config") \
1667 $(noinit "setcustomconf" "Set custom config") \
1668 $(gotisomd5 "isomd5" "Check the ISO image") \
1669 $(cdfile 'md5sum*' "md5" "Check the ISO files") \
1670 $(cdfile 'sha*sum*' "sha" "Check the ISO files") \
1671 $(menuitem "filepos" "File start sector") \
1672 $(xfile 'isoinfo iso2exe' "infoiso" "ISO image info") \
1673 $(cdfilex 'bzImage*' "bootiso" "Boot the ISO image") \
1674 $(burnable "burniso" "Burn the ISO image") \
1675 $(blankable "blankcd" "Blank the CD/DVD") \
1676 $(gotposixovl "install" "Hard disk installation (UMSDOS way)") \
1677 $(gotposixovl "installtaz" "Hard disk installation (TAZUSB way)") \
1678 $(gotposixovlzip "inst2zip" "ZIP installation archive (UMSDOS way)") \
1679 $(gotposixovlzip "insttaz2zip" "ZIP installation archive (TAZUSB way)") \
1680 $(gottazusb "usbkey" "USB key read/write installation") \
1681 $(ishybrid "usbbootkey" "USB boot key (kernel not upgradable)") \
1682 $(hasflavinfo "showfavinfo" "Show flavor extra info") \
1683 $(hasflavor "flavor" "Get flavor file") \
1684 $(cdfile isolinux.cfg "floppyset" "Boot floppy set") \
1685 $(cdfile linld.com "tazboot" "Get tazboot.exe Linux loader for DOS") \
1686 $(cdexe 'bzImage*' "bzimage" "Get linux DOS/EXE file") \
1687 $(cdexe 'memtest*' "memtest" "Get Memtest86 DOS/EXE file") \
1688 $(cdfilef 'memtest*' "fdmemtest" "Create a Memtest86 boot floppy") \
1689 $(cdexe '?pxe*' "pxe" "Get SliTaz Web boot DOS/EXE utility") \
1690 $(cdfilef '?pxe*' "fdpxe" "Create a SliTaz Web boot floppy") \
1691 $(cdexe 'plop*' "plop" "Get USB boot DOS/EXE utility") \
1692 $(cdfilef 'plop*' "fdplop" "Create a USB boot floppy") \
1693 $(initxfile reboot "restart" "Restart the computer") \
1694 $(initxfile poweroff "stop" "Power off") \
1695 $(initx "bootlog" "Linux boot messages") \
1696 $(initx "shell" "Shell prompt") \
1697 $(noinitmisspkg "missing" "Install packages to get more options") \
1698 $(noinit "quit" "Quit this utility")
1699 EOT
1700 exec 3>&1
1701 value=$(. /tmp/dialog$$ 2>&1 1>&3)
1702 retval=$?
1703 exec 3>&-
1704 rm -f /tmp/dialog$$
1705 [ $retval -ne 0 ] && [ $0 != /init.exe ] && quit
1706 $value
1707 done