wok diff syslinux/stuff/iso2exe/taziso @ rev 17635
syslinux-tools: add taziso
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Feb 14 18:17:26 2015 +0100 (2015-02-14) |
parents | |
children | 77c3484cda94 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/syslinux/stuff/iso2exe/taziso Sat Feb 14 18:17:26 2015 +0100 1.3 @@ -0,0 +1,909 @@ 1.4 +#!/bin/sh 1.5 + 1.6 +[ $(id -u) -eq 0 ] || exec su -c "$0 $@" 1.7 + 1.8 +DIALOG=dialog 1.9 + 1.10 +ddq() 1.11 +{ 1.12 + dd $@ 2> /dev/null 1.13 +} 1.14 + 1.15 +get() 1.16 +{ 1.17 + od -v -j $1 -N ${4:-${3:-2}} -t u${3:-2} -w${3:-2} -An $2 2>/dev/null || 1.18 + hexdump -v -s $1 -n ${4:-${3:-2}} -e "\"\" 1/${3:-2} \" %d\n\"" $2 1.19 +} 1.20 + 1.21 +bytes2bin() 1.22 +{ 1.23 + for i in $@ ; do 1.24 + printf '\\\\x%02X' $(($i&255)) 1.25 + done | xargs echo -en 1.26 +} 1.27 + 1.28 +words2bin() 1.29 +{ 1.30 + for i in $@ ; do 1.31 + printf '\\\\x%02X\\\\x%02X' $(($i&255)) $((($i>>8)&255)) 1.32 + done | xargs echo -en 1.33 +} 1.34 + 1.35 +gettazboot() 1.36 +{ 1.37 + echo "Creating $(basename $1) ..." 1.38 + if [ $(get 0 $ISO) -eq 23117 ]; then 1.39 + O=$(($(get 66 $ISO) - 0xC0)) 1.40 + L=$(($(get 20 $ISO) - 0xC0 - $(get 24 $ISO) - $O)) 1.41 + S=$((32+$L)) 1.42 + P=$((($S+511)/512)) 1.43 + E=$((4096-(32*$P))) 1.44 + words2bin 0x5A4D $(($S%512)) $P 0 2 $E -1 $((${2:-0}-16)) \ 1.45 + -2 0 256 -16 28 0x6C53 0x5469 0x7A61 > $1 1.46 + ddq bs=1 count=$L skip=$(echo $O) if=$ISO >> $1 1.47 + else 1.48 + wget -O $1 http://mirror.slitaz.org/boot/tazboot.exe 1.49 + fi 1.50 +} 1.51 + 1.52 +uncpio() 1.53 +{ 1.54 + [ -s "$1" ] || return 1.55 + echo -en "\n Extracting $(basename $1) ..." 1.56 + case $(get 0 $1) in 1.57 + *35615) ( zcat || gunzip ) ;; 1.58 + *14333) unxz ;; 1.59 + *\ 93) unlzma ;; 1.60 + *) cat ;; 1.61 + esac < $1 | ( cd ${2:-/} ; cpio -idmu > /dev/null 2>&1 ) 1.62 +} 1.63 + 1.64 +dotwait() 1.65 +{ 1.66 + echo -n "${1:-Install filesystem}.." 1.67 + touch /tmp/wait 1.68 + while [ -e /tmp/wait ]; do 1.69 + echo -n "." > /dev/tty 1.70 + sleep 1 1.71 + done & 1.72 +} 1.73 + 1.74 +getuuid() 1.75 +{ 1.76 + dev=$(mount | sed "/ $(echo $mnt | sed 's|/|\\/|g') /!d;s/ .*//;s|/dev/||;q") 1.77 + [ "$dev" ] && 1.78 + blkid | sed "/$dev:/!d;s/.* UUID=.\\([^ ]*\\)\".*/\\1/" || 1.79 + echo "/dev/hda1" 1.80 +} 1.81 + 1.82 +tazusbinitfs() 1.83 +{ 1.84 + PAD=$(($(stat -c %s $1) % 4)) 1.85 + [ $PAD -ne 0 ] && ddq if=/dev/zero bs=1 count=$((4 - $PAD)) >> $1 1.86 + mkdir -p /tmp/fs$$/etc /tmp/fs$$/lib /tmp/fs$$/home 1.87 + cp -a /etc/locale.conf /tmp/fs$$/etc 2> /dev/null 1.88 + cp -a /etc/keymap.conf /tmp/fs$$/etc 2> /dev/null 1.89 + cat > /tmp/fs$$/init1 <<EOT 1.90 +#!/bin/sh 1.91 +sed -i 's|sbin/init|init2|' /init 1.92 +exec /init 1.93 +EOT 1.94 + cat > /tmp/fs$$/init2 <<EOT 1.95 +#!/bin/sh 1.96 + 1.97 +mount -t proc /proc /proc 1.98 +for i in /lib/*.ko* ; do insmod \$i 2> /dev/null ; done; sleep 2 1.99 +v=\$(sed '/\\/home=/!d;s|.*/home=\\([^ ]*\\).*|\\1|' /proc/cmdline /cmdline 2> /dev/null) 1.100 +mount / -o remount,rw 1.101 +mkdir /mnt/dos 1.102 +rm -f /cmdline 2> /dev/null 1.103 +mount / -o remount,ro 1.104 +mnt=/mnt/dos/\${v#*/} 1.105 +dev=\$( (blkid /dev/[sh]d* || blkid) | grep \${v%%/*} | sed 's/:.*//;q') 1.106 +echo "Mount \$dev in /mnt/dos for \$v..." | tee -a /run/boot.log 1.107 +mount \$dev /mnt/dos 1.108 +if [ ! -d /mnt/dos/slitaz ]; then 1.109 + umount /mnt/dos 2> /dev/null 1.110 + (blkid /dev/[sh]d* || blkid) | while read dev line; do 1.111 + case "\$line" in 1.112 + *ntfs*|*vfat*|*msdos*) ;; 1.113 + *) continue ;; 1.114 + esac 1.115 + mount \${dev%:} /mnt/dos 1.116 + [ -d /mnt/dos/slitaz ] && break 1.117 + umount /mnt/dos 1.118 + done 1.119 +fi 1.120 +mount.posixovl -F \$mnt -- -oallow_other -odefault_permissions -osuid 1.121 +mount --bind \$mnt /home 1.122 +umount /proc 1.123 +exec /sbin/init 1.124 +EOT 1.125 + chmod 755 /tmp/fs$$/init? 1.126 + ( cd /tmp/fs$$ ; find * | cpio -o -H newc ) | gzip -9 >> $1 1.127 + rm -rf /tmp/fs$$ 1.128 +} 1.129 + 1.130 +mkinitrd() 1.131 +{ 1.132 + echo -en "\nCreating $(basename $1) " 1.133 + fs=/tmp/fs$$ 1.134 + for i in bin lib dev proc tmp mnt etc ; do 1.135 + mkdir -p $fs/$i 1.136 + done 1.137 + for i in /dev/console /dev/null /dev/tty /dev/tty0 /dev/tty1 /dev/tty2 \ 1.138 + /dev/fuse /dev/hd* /dev/sd* ; do 1.139 + cp -a $2$i $fs/dev/ 1.140 + done 1.141 + for i in /bin/busybox $(which mount.posixovl) $(which blkid); do 1.142 + cp $(LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $i | \ 1.143 + sed 's|.*=> \(.*/lib/l[^ ]*\).*|\1|;/^\//!d') $fs/lib 1.144 + cp $i $fs/bin 1.145 + done 1.146 + cp -a /lib/ld-* $fs/lib 1.147 + for i in $(busybox | sed '/Current/,$!d'); do 1.148 + [ -e $fs/bin/${i%,} ] || ln -s busybox $fs/bin/${i%,} 1.149 + done 1.150 + ln -s /proc/mounts $fs/etc/mtab 1.151 + sed 's/ .*//' /proc/modules | while read mod ; do 1.152 + find /lib/modules/ | grep $mod.ko | \ 1.153 + sed 's|.*|cp & $fs/lib|' | sh 1.154 + done 1.155 + cat > $fs/init <<EOT 1.156 +#!/bin/sh 1.157 + 1.158 +arg() 1.159 +{ 1.160 + grep -q \$1 /proc/cmdline && 1.161 + val="\$(sed "s/.*\$1=\\([^ ]*\\).*/\\1/" < /proc/cmdline)" && 1.162 + echo "\$2 \$val" 1.163 +} 1.164 + 1.165 +mount -t proc /proc /proc 1.166 + arg debug "shell" && debug=true && set -x 1.167 +for i in /lib/*.ko* ; do insmod \$i 2> /dev/null ; done; sleep 2 1.168 +arg mount "Mount device" 1.169 +mount \$( (blkid /dev/[sh]d* || blkid) | grep \$val | sed 's/:.*//;q') /mnt 1.170 +arg subroot "Change root to directory" 1.171 +if [ -d /mnt/\$val ]; then 1.172 + umount /mnt 2> /dev/null 1.173 + (blkid /dev/[sh]d* || blkid) | while read dev line; do 1.174 + case "\$line" in 1.175 + *ntfs*|*vfat*|*msdos*) ;; 1.176 + *) continue ;; 1.177 + esac 1.178 + mount \${dev%:} /mnt 1.179 + [ -d /mnt/\$val ] && break 1.180 + umount /mnt 1.181 + done 1.182 +fi 1.183 +mount.posixovl -F /mnt/\$val -- -oallow_other -odefault_permissions -osuid 1.184 +mount --bind /mnt /mnt/\$val/mnt/dos 1.185 +mount -o size=0 -t tmpfs tmpfs /mnt/\$val/mnt/dos/\$val 1.186 +LDSO=\$(ls /mnt/\$val/lib/ld-* | sed q) 1.187 +export LD_LIBRARY_PATH=\$val/lib:\$val/usr/lib:/lib 1.188 + [ "$debug" = "true" ] && sh 1.189 +umount /proc 1.190 +exec /bin/switch_root /mnt \${LDSO#/mnt/} \$val/usr/sbin/chroot \$val /sbin/init 1.191 +EOT 1.192 + chmod +x $fs/init 1.193 + ( cd $fs ; find * | cpio -o -H newc ) | lzma e $1 -si 2> /dev/null 1.194 + rm -rf $fs /tmp/wait 1.195 +} 1.196 + 1.197 +ls_r() 1.198 +{ 1.199 + ls -r $@ 2> /dev/null || ls $@ 1.200 +} 1.201 + 1.202 +doinstall() 1.203 +{ 1.204 + mkdir -p $mnt/slitaz/boot $mnt/slitaz/mnt/dos 1.205 + if ! mount.posixovl -F $mnt/slitaz -- \ 1.206 + -oallow_other -odefault_permissions -osuid; then 1.207 + echo "Can't install SliTaz. Abort." 1.208 + sleep 5 1.209 + return 1 1.210 + fi 1.211 + dotwait "Install root filesystem in /slitaz.." 1.212 + if [ "$1" ]; then 1.213 + ls_r /media/cdrom/boot/rootfs*gz | \ 1.214 + xargs cat > $mnt/slitaz/boot/rootfs.gz 1.215 + tazusbinitfs $mnt/slitaz/boot/rootfs.gz 1.216 + initrd=rootfs.gz 1.217 + extraargs="/home=$(getuuid)/slitaz rdinit=/init1" 1.218 + else 1.219 + for i in $(ls_r /media/cdrom/boot/rootfs*gz); do 1.220 + uncpio $i $mnt/slitaz 1.221 + done 1.222 + for i in $packages_list; do 1.223 + tazpkg get-install $i --root=$mnt/slitaz 1.224 + done 1.225 + for i in $packages_dir/*.tazpkg; do 1.226 + [ -s "$i" ] && 1.227 + tazpkg install $i --root=$mnt/slitaz 1.228 + done 1.229 + cp -a /etc/locale.conf $mnt/slitaz/etc 2> /dev/null 1.230 + cp -a /etc/keymap.conf $mnt/slitaz/etc 2> /dev/null 1.231 + mkinitrd $mnt/slitaz/boot/initrd $mnt/slitaz 1.232 + initrd=initrd 1.233 + extraargs="mount=$(getuuid) subroot=slitaz" 1.234 + fi 1.235 + echo -en "\nInstall boot files..." 1.236 + for i in /media/cdrom/boot/bzImage /media/cdrom/boot/*pxe* \ 1.237 + /media/cdrom/boot/isolinux/he* /media/cdrom/boot/isolinux/opt* \ 1.238 + /media/cdrom/README /media/cdrom/boot/memtest* ; do 1.239 + [ -s $i ] && cp $i $mnt/slitaz/boot 1.240 + done 1.241 + for i in $mnt/slitaz/boot/memtest $mnt/slitaz/boot/*pxe* ; do 1.242 + [ $(get 0 $i 2> /dev/null || echo 0) -eq 23117 ] && 1.243 + mv $i $i.exe 1.244 + done 1.245 + gettazboot $mnt/slitaz/boot/tazboot.exe 1.246 + unix2dos > $mnt/slitaz/boot/tazboot.cmd <<EOT 1.247 +kernel=/slitaz/boot/bzimage 1.248 +initrd=/slitaz/boot/$initrd 1.249 +rw root=/dev/null $extraargs autologin 1.250 +EOT 1.251 + unix2dos $mnt/slitaz/boot/he* $mnt/slitaz/boot/opt* \ 1.252 + $mnt/slitaz/boot/README 1.253 + [ -d $mnt/slitaz/usr/sbin -a ! -x $mnt/slitaz/usr/sbin/mount.posixovl ] && 1.254 + cp $(which mount.posixovl) $mnt/slitaz/usr/sbin 1.255 + rm -f /tmp/wait 1.256 + umount $mnt/slitaz 1.257 + return 0 1.258 +} 1.259 + 1.260 +windev() 1.261 +{ 1.262 + DEV="$(blkid | grep -iE "(msdos|vfat|ntfs)" | sed 's/:.*//;s|/dev/||')" 1.263 + [ "$DEV" ] || return 1.264 + cat > /tmp/dialog$$ <<EOT 1.265 +$DIALOG --clear \ 1.266 + --title " Select your Windows partition " \ 1.267 + --menu "\nPlease select the Windows partition according to its known size. 1.268 +The datas will be kept untouched.\n" \ 1.269 + 17 70 8 \ 1.270 + $(for i in $DEV ; do 1.271 + label="$(blkid | sed "/$i:/!d;s/.*://;s/[^ ]*UUID=[^ ]* //g;s/LABEL=//")" 1.272 + echo -n "/dev/$i \"$(($(cat /sys/block/*/$i/size)/2048))MB $label\" " 1.273 + done) 1.274 +EOT 1.275 + exec 3>&1 1.276 + [ $? -eq 0 ] || return 1.277 + device=$(. /tmp/dialog$$ 2>&1 1>&3) 1.278 + exec 3>&- 1.279 + rm -f /tmp/dialog$$ 1.280 + mnt=/tmp/mnt$$ 1.281 + mkdir -p $mnt && mount $device $mnt 1.282 +} 1.283 + 1.284 +extra_packages() 1.285 +{ 1.286 + packages_list= 1.287 + packages_dir= 1.288 + $DIALOG --clear \ 1.289 + --title " Extra packages " \ 1.290 + --defaultno --yesno \ 1.291 +" 1.292 +Do you want to add extra packages ? 1.293 +" 7 70 1.294 + [ $? -eq 0 ] || return 1.295 + [ -s /var/lib/tazpkg/packages.txt ] || tazpkg recharge 1.296 + if [ -s /media/cdrom/boot/vmlinuz-$(uname -r) ]; then 1.297 + cat > /tmp/dialog$$ <<EOT 1.298 +$DIALOG --clear \ 1.299 + --title " Select the packages " \ 1.300 + --separate-output \ 1.301 + --cancel-label "Skip" \ 1.302 + --checklist "Please select the packages you want to install. Try with the first letter." \ 1.303 + 23 78 20 \\ 1.304 +EOT 1.305 + awk -F\| '{ printf "%s \"%s\" off ",$1,$3 }' \ 1.306 + /var/lib/tazpkg/packages.desc >> /tmp/dialog$$ 1.307 + sh /tmp/dialog$$ 2> /tmp/dialog.out$$ 1.308 + [ $? -eq 0 ] && packages_list="$(cat /tmp/dialog.out$$)" 1.309 + fi 1.310 + cat > /tmp/dialog$$ <<EOT 1.311 +$DIALOG --clear \ 1.312 + --title "Please select the directory with every custom packages to install." \ 1.313 + --cancel-label "Skip" \ 1.314 + --dselect $PWD 13 78 1.315 +EOT 1.316 + sh /tmp/dialog$$ 2> /tmp/dialog.out$$ 1.317 + [ $? -eq 0 ] && packages_dir="$(cat /tmp/dialog.out$$)" 1.318 + rm -f /tmp/dialog$$ /tmp/dialog.out$$ 1.319 +} 1.320 + 1.321 +_install() 1.322 +{ 1.323 + extra_packages 1.324 + $DIALOG --clear \ 1.325 + --title " SliTaz UMSDOS way installation " \ 1.326 + --yes-label "Install" --yesno \ 1.327 +"\nSliTaz will be installed in the subdirectory \\slitaz of the current 1.328 +DOS/Windows partition. You will see your files from /mnt/dos.\n\n 1.329 +You can start SliTaz with \\slitaz\\boot\\tazboot.exe\n\n 1.330 +To uninstall SliTaz, you have only to remove this directory. 1.331 +The file \\boot.ini or \\config.sys may be modified too.\n\n 1.332 +SliTaz may run slowly on 'UMSDOS way' installation due to the 1.333 +posixovl filesystem. The 'TAZUSB way' installation runs faster.\n\n 1.334 +To do a traditional installation with disk partitioning, 1.335 +start SliTaz Live with 'SliTaz RAM boot' menu.\n 1.336 +" 19 70 1.337 + [ $? -eq 0 ] || return 1.338 + doinstall 1.339 +} 1.340 + 1.341 +readtazbootconf() 1.342 +{ 1.343 + kernel="$(sed '/^kernel=/!d;s/.*=//' $mnt/slitaz/boot/tazboot.cmd)" 1.344 + initrd="$(sed '/^initrd=/!d;s/.*=//' $mnt/slitaz/boot/tazboot.cmd)" 1.345 + cmdline="$(sed '/^kernel=/d;/^initrd=/d' $mnt/slitaz/boot/tazboot.cmd)" 1.346 +} 1.347 + 1.348 +bootinstalled() 1.349 +{ 1.350 + [ "$(which kexec)" ] || return 1.351 + [ -x $mnt/slitaz$1 ] || return 1.352 + [ -s $mnt/slitaz/boot/tazboot.cmd ] || return 1.353 + readtazbootconf 1.354 + kexec -l $kernel --initrd $initrd --command-line "$cmdline" --atags 1.355 + umount $mnt 1.356 + rm -rf $mnt 1.357 + umount -d /media/cdrom 1.358 + kexec -e 1.359 +} 1.360 + 1.361 +mkzip() 1.362 +{ 1.363 + device= 1.364 + packages_list= 1.365 + packages_dir= 1.366 + mnt=/tmp/mnt$$ 1.367 + mkdir -p $mnt 1.368 + $1 || return 1.369 + wget -O $mnt/slitaz/boot/grldr http://mirror.slitaz.org/boot/grldr 1.370 + readtazbootconf 1.371 + cat > $mnt/slitaz/menu.lst <<EOT 1.372 +title SliTaz 1.373 + kernel $kernel $cmdline 1.374 + initrd $initrd 1.375 + 1.376 +EOT 1.377 + while read file title; do 1.378 + file=$(ls $mnt/slitaz/boot/*file* 2> /dev/null) 1.379 + [ -s "$file" ] && cat >> $mnt/slitaz/menu.lst <<EOT 1.380 +title $title 1.381 + kernel $file 1.382 + 1.383 +EOT 1.384 + done <<EOT 1.385 +memtest MemTest 1.386 +pxe Web boot 1.387 +EOT 1.388 + cat > $mnt/slitaz/install.txt <<EOT 1.389 +For NT/2000/XP users: 1.390 + 1.391 +1- Move the files grldr and menu.lst into the root directory 1.392 + 1.393 +C:\\> copy \\slitaz\\boot\\grldr \\ 1.394 +C:\\> copy \\slitaz\\boot\\menu.lst \\ 1.395 + 1.396 +2- Remove boot.ini attributes 1.397 + 1.398 +C:\\> attrib -r -h -s boot.ini 1.399 + 1.400 +3- Append the following line to boot.init 1.401 + 1.402 +C:\\grldr="slitaz" 1.403 + 1.404 +4- Restore boot.ini attributes 1.405 + 1.406 +C:\\> attrib +r +h +s boot.ini 1.407 + 1.408 +See http://diddy.boot-land.net/grub4dos/files/README_GRUB4DOS.txt 1.409 +EOT 1.410 + ( cd $mnt ; zip -r9 $(basename $ISO .iso) slitaz ) 1.411 + mv $mnt/*.zip . 1.412 +} 1.413 + 1.414 +install() 1.415 +{ 1.416 + windev || return 1.417 + packages_list= 1.418 + packages_dir= 1.419 + _install && bootinstalled /sbin/init 1.420 + umount $mnt 1.421 + rm -rf $mnt 1.422 +} 1.423 + 1.424 +inst2zip() 1.425 +{ 1.426 + mkzip _install 1.427 +} 1.428 + 1.429 +_installtaz() 1.430 +{ 1.431 + $DIALOG --clear \ 1.432 + --title " SliTaz TAZUSB way installation " \ 1.433 + --yes-label "Install" --yesno \ 1.434 +"\nSliTaz will be installed in the subdirectory \\slitaz of the current 1.435 +DOS/Windows partition. You will see your files from /mnt/dos.\n\n 1.436 +You can start SliTaz with \\slitaz\\boot\\tazboot.exe\n\n 1.437 +To uninstall SliTaz, you have only to remove this directory. 1.438 +The file \\boot.ini or \\config.sys may be modified too.\n\n 1.439 +The filesystem is loaded entirely into memory upon boot to 1.440 +increase responsiveness. Only /home lands on hard disk.\n\n 1.441 +To do a traditional installation with disk partitioning, 1.442 +start SliTaz Live with 'SliTaz RAM boot' menu.\n 1.443 +" 19 70 1.444 + [ $? -eq 0 ] || return 1.445 + doinstall tazusblike 1.446 +} 1.447 + 1.448 +installtaz() 1.449 +{ 1.450 + windev || return 1.451 + packages_list= 1.452 + packages_dir= 1.453 + _installtaz && bootinstalled /boot/bzimage 1.454 + umount $mnt 1.455 + rm -rf $mnt 1.456 +} 1.457 + 1.458 +insttaz2zip() 1.459 +{ 1.460 + mkzip _installtaz 1.461 +} 1.462 + 1.463 +bootiso() 1.464 +{ 1.465 + for i in $(ls_r /media/cdrom/boot/rootfs*gz); do 1.466 + grep -q ' lm ' /proc/cpuinfo && [ -s ${i}64 ] && i=${i}64 1.467 + cat $i 1.468 + n=$((4 - ($(stat -c %s $i) % 4))) 1.469 + [ $n -eq 4 ] || dd if=/dev/zero bs=1 count=$n 1.470 + done > /tmp/initrd$$ 1.471 + kernel=/media/cdrom/boot/bzImage 1.472 + grep -q ' lm ' /proc/cpuinfo && [ -s ${kernel}64 ] && kernel=${kernel}64 1.473 + . /etc/locale.conf 1.474 + kexec -l $kernel --initrd /tmp/initrd$$ --atags --command-line \ 1.475 + "root=/dev/null autologin lang=$LANG kmap=$(cat /etc/keymap.conf)" 1.476 + umount -d /media/cdrom 1.477 + kexec -e 1.478 +} 1.479 + 1.480 +tazboot() 1.481 +{ 1.482 + $DIALOG --clear \ 1.483 + --title " SliTaz bootloader for DOS " \ 1.484 + --yes-label "Install" --yesno \ 1.485 +"\nThe file TAZBOOT.EXE will be created in the top directory. It supports 1.486 +any linux kernel, multiple initramfs, a kernel command line and 1.487 +an ISO image file loopback (retrieves files from an ISO file).\n\n 1.488 +Usage: tazboot.exe [[@commands]|[kernel=<bzimage>] 1.489 +[initrd=<rootfs>[,<rootfs2>...]] [bootfrom=<isofile>] cmdline args ...]\n\n 1.490 +Defaults: tazboot @tazboot.cmd or tazboot kernel=bzImage auto\n\n\ 1.491 +Examples for tazboot.cmd:\n\n\ 1.492 + bootfrom=\\isos\\slitaz-4.0.iso\n\ 1.493 + kernel=boot/bzImage\n\ 1.494 + initrd=boot/rootfs4.gz,boot/rootfs3.gz,boot/rootfs2.gz,boot/rootfs1.gz\n\ 1.495 + rw root=/dev/null autologin\n\n\ 1.496 + kernel=\\slitaz\\vmlinuz root=/dev/sda5 ro\n\n 1.497 +Unlike GRUB4DOS, it doesn't require unfragmented ISO image files.\n 1.498 +" 24 78 1.499 + [ $? -eq 0 ] || return 1.500 + gettazboot tazboot.exe 1.501 +} 1.502 + 1.503 +md5() 1.504 +{ 1.505 + dotwait "Checking files" 1.506 + ( cd /media/cdrom ; ${1:-md5sum -c md5sum*} ) > /tmp/data 1.507 + rm -f /tmp/wait 1.508 + $DIALOG --clear \ 1.509 + --title " Checked files " \ 1.510 + --textbox /tmp/data 24 78 1.511 + rm -f /tmp/data 1.512 +} 1.513 + 1.514 +gotcdfile() 1.515 +{ 1.516 + for i in "/media/cdrom/$1" "/media/cdrom/*/$1" \ 1.517 + "/media/cdrom/*/isolinux/$1" ; do 1.518 + file=$(ls $i 2> /dev/null | sed q) 1.519 + [ -s "$file" ] && break 1.520 + done 1.521 +} 1.522 + 1.523 +sha() 1.524 +{ 1.525 + gotcdfile 'sha*sum*' 1.526 + sha=$(basename $file) 1.527 + md5 "${sha%sum*}sum -c ${file#/media/cdrom/}" 1.528 +} 1.529 + 1.530 +readme() 1.531 +{ 1.532 + gotcdfile 'README*' 1.533 + $DIALOG --clear \ 1.534 + --title " Readme " \ 1.535 + --textbox $file 24 78 1.536 +} 1.537 + 1.538 +bzimage() 1.539 +{ 1.540 + $DIALOG --clear \ 1.541 + --title " Create linux.exe ? " \ 1.542 + --yes-label "Install" --yesno \ 1.543 +"\nLinux.exe launches the linux kernel under DOS (in real mode only). 1.544 +The cmdline arguments are supported except initrd=, 1.545 +vga= (you can try 'rdev -v') and mem= (partially). 1.546 +\nExample:\nC:\\> linux.exe root=/dev/hda2 ro panic=60\n 1.547 +" 12 70 1.548 + [ $? -eq 0 ] || return 1.549 + cp /media/cdrom/boot/bzImage linux.exe 1.550 +} 1.551 + 1.552 +memtest() 1.553 +{ 1.554 + $DIALOG --clear \ 1.555 + --title " Create memtest.exe ? " \ 1.556 + --yes-label "Install" --yesno \ 1.557 +"\nMemtest86 is a thorough, stand alone memory test for x86 architecture 1.558 +computers. BIOS based memory tests are a quick, cursory check and often 1.559 +miss many of the failures that are detected by Memtest86.\n 1.560 +" 12 70 1.561 + [ $? -eq 0 ] && gotcdfile 'memtest*' && cp $file memtest.exe 1.562 +} 1.563 + 1.564 +mkfat12() 1.565 +{ 1.566 + [ $(($(get 0 $1) - 0x5A4D)) -eq 0 ] || return 1.567 + J=$(($(get 3 $1 1) + 0x02)) 1.568 + R=$((1 + $(get 497 $1 1) + 1 + ($(get 500 $1)-1)/32)) 1.569 + [ $R -lt 2500 ] || return 1.570 + [ $((($(get 500 $1)-1) & 31)) -lt 30 ] && 1.571 + ddq if=$file bs=32 count=1 seek=$(($R*16 - 1)) of=/dev/fd0 1.572 + G="18 0 2 0 0 0 0 0" 1.573 + [ $J -gt 25 ] || G="" 1.574 + F=0 1.575 + for i in 1 2 3; do 1.576 + F=$((((2880-$R-$F-$F)*3+1023)/1024)) 1.577 + done 1.578 + bytes2bin 0xEB $J 0x90 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 \ 1.579 + 0 2 2 $(($R%256)) $(($R/256)) 2 64 0 64 11 0xF0 $F 0 \ 1.580 + $G | ddq bs=1 of=/dev/fd0 1.581 + ddq if=/dev/zero bs=512 count=$((4+$F+$F)) seek=$R of=/dev/fd0 1.582 + for i in $R $(($R+$F)) ; do 1.583 + bytes2bin 0xF0 0xFF 0xFF | ddq bs=512 seek=$i of=/dev/fd0 1.584 + done 1.585 + echo -n $(basename $1) | ddq bs=1 seek=3 count=8 of=/dev/fd0 1.586 +} 1.587 + 1.588 +mkfloppy() 1.589 +{ 1.590 + dotwait "Create a $(basename $1) boot floppy" 1.591 + ddq if=$1 of=/dev/fd0 1.592 + mkfat12 $1 1.593 + rm -f /tmp/wait 1.594 +} 1.595 + 1.596 +fdmemtest() 1.597 +{ 1.598 + $DIALOG --clear \ 1.599 + --title " Create a Memtest86 boot floppy " \ 1.600 + --yes-label "Create floppy" --yesno \ 1.601 +"\nMemtest86 is a thorough, stand alone memory test for x86 architecture 1.602 +computers. BIOS based memory tests are a quick, cursory check and often 1.603 +miss many of the failures that are detected by Memtest86.\n\n 1.604 +Please insert a blank disk in floppy drive.\n 1.605 +" 12 70 1.606 + [ $? -eq 0 ] && gotcdfile 'memtest*' && mkfloppy $file 1.607 +} 1.608 + 1.609 +pxe() 1.610 +{ 1.611 + gotcdfile '?pxe' 1.612 + $DIALOG --clear \ 1.613 + --title " Create $(basename $file).exe ? " \ 1.614 + --yes-label "Install" --yesno \ 1.615 +"\nBoot your operating system from the internet and enjoy a full system 1.616 +working entirely in RAM with speed and stability in mind. The Linux Kernel 1.617 +and the complete SliTaz compressed root filesystem will be loaded into RAM 1.618 +from the Web using PXE and HTTP protocols.\n 1.619 +" 12 70 1.620 + [ $? -eq 0 ] || return 1.621 + cp $file $(basename $file).exe 1.622 +} 1.623 + 1.624 +fdpxe() 1.625 +{ 1.626 + $DIALOG --clear \ 1.627 + --title " Create a SliTaz Web boot floppy " \ 1.628 + --yes-label "Create floppy" --yesno \ 1.629 +"\nBoot your operating system from the internet and enjoy a full system 1.630 +working entirely in RAM with speed and stability in mind. The Linux Kernel 1.631 +and the complete SliTaz compressed root filesystem will be loaded into RAM 1.632 +from the Web using PXE and HTTP protocols.\n\n 1.633 +Please insert a blank disk in floppy drive.\n 1.634 +" 12 70 1.635 + [ $? -eq 0 ] && gotcdfile '?pxe' && mkfloppy $file 1.636 +} 1.637 + 1.638 +gotposixovl() 1.639 +{ 1.640 + mount.posixovl 2>&1 | grep -qi usage && 1.641 + echo -en "\"$1\" \"$2\"" 1.642 +} 1.643 + 1.644 +gotposixovlzip() 1.645 +{ 1.646 + [ "$(which zip)" ] && gotposixovl "$1" "$2" 1.647 +} 1.648 + 1.649 +xfile() 1.650 +{ 1.651 + [ "$(which $1)" ] && echo -en "\"$2\" \"$3\"" 1.652 +} 1.653 + 1.654 +cdfile() 1.655 +{ 1.656 + gotcdfile "$1" && echo -en "\"$2\" \"$3\"" 1.657 +} 1.658 + 1.659 +cdfilex() 1.660 +{ 1.661 + [ "$(which kexec)" ] && cdfile "$@" 1.662 +} 1.663 + 1.664 +cdfilef() 1.665 +{ 1.666 + [ -e /sys/block/fd0 ] && cdfile "$@" 1.667 +} 1.668 + 1.669 +cdexe() 1.670 +{ 1.671 + gotcdfile "$1" && 1.672 + [ $(get 0 $file 2>/dev/null || echo 0) -eq 23117 ] && 1.673 + echo -en "\"$2\" \"$3\"" 1.674 +} 1.675 + 1.676 +misspkg() 1.677 +{ 1.678 + for i in zip kexec-tools posixovl ; do 1.679 + [ -d /var/lib/tazpkg/installed/$i/ ] && continue 1.680 + [ "$1" != "install" ] && 1.681 + echo -en "\"$1\" \"$2\"" && return 1.682 + tazpkg get-install $i 1.683 + done 1.684 +} 1.685 + 1.686 +missing() 1.687 +{ 1.688 + misspkg install 1.689 +} 1.690 + 1.691 +ishybrid() 1.692 +{ 1.693 + C=$((2048*$(get $(((17*2048) + 71)) $ISO 4))) 1.694 + [ $(get $C $ISO 4) -eq 1 ] || return 1.695 + [ $(get $(($C+30)) $ISO 4) -eq $((0x88AA55)) ] || return 1.696 + C=$((2048*$(get $(($C+40)) $ISO 4))) 1.697 + [ $(get $(($C+64)) $ISO 4) -eq 1886961915 ] && 1.698 + echo -en "\"$1\" \"$2\"" 1.699 +} 1.700 + 1.701 +isiso() 1.702 +{ 1.703 + [ $(get 32769 $ISO 4) -eq 808469571 ] && 1.704 + echo -en "\"$1\" \"$2\"" 1.705 +} 1.706 + 1.707 +gotisomd5() 1.708 +{ 1.709 + [ "$(which md5sum 2> /dev/null)" ] && 1.710 + [ $(get 0 $ISO) -eq 23117 ] && 1.711 + [ $(get 18 $ISO) -ne 0 ] && echo -en "\"$1\" \"$2\"" 1.712 +} 1.713 + 1.714 +isomd5() 1.715 +{ 1.716 + dotwait "Checking iso image" 1.717 + [ "$(ddq if=$ISO bs=2k skip=16 \ 1.718 + count=$(echo $(get 32848 $ISO 4)) | md5sum)" == \ 1.719 + "$(ddq if=$ISO bs=16 count=1 skip=2047 | od -N 16 -t x1 -An | \ 1.720 + sed 's/ //g') -" ] && echo "OK" || echo "ERROR" 1.721 + echo -en "\rChecking iso hybrid boot..." 1.722 + n=$(($(get 2 $ISO)-1+($(get 4 $ISO)-1)*512)) 1.723 + if [ $n -lt 40000 -a $n -gt 32768 ]; then 1.724 + s=$(get 0 $ISO 2 $n | awk '{ i+= $0 } END { print i }') 1.725 + [ $(((1+$s+$(get $(($n+1)) $ISO 1)) % 65536)) -eq 0 ] && 1.726 + echo "OK" || echo "ERROR" 1.727 + fi 1.728 + rm -f /tmp/wait 1.729 + echo -e "\rPress RETURN to continue." 1.730 + read n 1.731 +} 1.732 + 1.733 +usbdev() 1.734 +{ 1.735 + dotwait "Wait 5 seconds for USB devices" 1.736 + sleep 5 1.737 + rm -f /tmp/wait 1.738 + DEV="$(grep -l 1 /sys/block/*/removable | \ 1.739 + sed 's|/sys/block/\(.*\)/removable|\1|')" 1.740 + grep -qs 1 /sys/block/$DEV/ro && return 1.741 + [ "$DEV" ] || return 1.742 + cat > /tmp/dialog$$ <<EOT 1.743 +$DIALOG --clear \ 1.744 + --title " Select your USB key " \ 1.745 + --menu "\nPlease select the USB key according to its known size.\n\n" \ 1.746 + 14 70 4 \ 1.747 + $(for i in $DEV ; do 1.748 + echo -n "/dev/$i \"$(($(cat /sys/block/$i/size)/2048))MB $(cat /sys/block/$i/device/model 2> /dev/null)\" " 1.749 + done) \ 1.750 + 1.751 +EOT 1.752 + exec 3>&1 1.753 + device=$(. /tmp/dialog$$ 2>&1 1>&3) 1.754 + rm -f /tmp/dialog$$ 1.755 + retval=$? 1.756 + exec 3>&- 1.757 + rm -f /tmp/dialog$$ 1.758 + [ $retval -eq 0 ] 1.759 +} 1.760 + 1.761 +tazusbmsg() 1.762 +{ 1.763 + [ "$(which tazusb 2> /dev/null)" ] || return 1.764 + echo "You should choose 'USB key read/write installation' to be 1.765 +able to save the package updates or your own configuration and data files.\n\n" 1.766 +} 1.767 + 1.768 +usbbootkey() 1.769 +{ 1.770 + $DIALOG --clear \ 1.771 + --title " Create a USB boot key " \ 1.772 + --yes-label "Continue" --yesno \ 1.773 +"\nThe USB key will be used like a CD-ROM. You will not be able to write 1.774 +any data on the boot partition.\n\n 1.775 +An extra FAT32 partition will be created with the remaining free space.\n\n 1.776 +$(tazusbmsg)Please plug your USB stick in now.\n 1.777 +" 16 70 1.778 + [ $? -eq 0 ] || return 1.779 + usbdev || return 1.780 + 1.781 + # perform dd in progess bar 1.782 + max=$(($(stat -c %s $ISO)/2048)) 1.783 + i=0; ddq if=$ISO bs=1024k | ( 1.784 + while ddq bs=1024k count=1 ; do 1.785 + i=$(($i + 1)) 1.786 + [ $i -gt $max ] && break 1.787 + echo $((($i*100)/$max)) | dialog --gauge \ 1.788 + " The ISO image transfer can be long. Please wait..." \ 1.789 + 6 70 0 > /dev/tty 2>&1 1.790 + done ) > $device 1.791 + 1.792 + # partition + fat32 format for the remining space 1.793 + get 446 $device 2 12 | xargs echo | { read dx cx ol oh ll lh 1.794 + if [ $dx -eq $((0x3F17)) ]; then 1.795 + cx=$(($cx & 0xFF00)) 1.796 + ofs=$(($ll+($lh<<16))) 1.797 + n=$(($(cat /sys/block/${device#/dev/}/size)-$ofs)) 1.798 + m=$(($cx+($n/8))) 1.799 + [ $m -gt $((0x3FF00)) ] && m=$((0x3FF00)) 1.800 + m=$((($m & 0xFF00)+(($m>>16)<<6))) 1.801 + words2bin 0 $((0x101+$cx)) 0x3F0B $((32+$m)) \ 1.802 + $ll $lh $(($n & 0xFFFF)) $(($n >> 16)) | \ 1.803 + ddq bs=1 seek=446 of=$device 1.804 + if [ "$(which mkdosfs 2> /dev/null)" ]; then 1.805 + losetup -o $((512*$ofs)) /dev/loop2 $device 1.806 + mkdosfs -n "SLITAZ BOOT" /dev/loop2 1.807 + words2bin $(($ofs & 0xFFFF)) $(($ofs >> 16)) | \ 1.808 + ddq bs=1 seek=28 of=/dev/loop2 1.809 + losetup -d /dev/loop2 1.810 + fi 1.811 + fi ; } 1.812 +} 1.813 + 1.814 +usbkey() 1.815 +{ 1.816 + $DIALOG --clear \ 1.817 + --title " Create a SliTaz USB key " \ 1.818 + --yes-label "Continue" --yesno \ 1.819 +"\nUnlike a hard drive install, the filesystem is kept in a compressed 1.820 +rootfs.gz. The filesystem is loaded entirely into memory upon boot. 1.821 +This should increase responsiveness, protect the filesystem against 1.822 +accidental corruption and reduce read/writes to the USB drive. 1.823 +Once setup, the tazusb utility can rewrite the root filesystem 1.824 +with any changes you have made since booting up, 1.825 +giving the effective benefits of a hard drive install.\n\n 1.826 +/home is mounted on boot using the UUID of your particular flash drive. 1.827 +Unlike a device name, the UUID has the benefit of never changing from machine 1.828 +to machine.\n\n 1.829 +Please plug your USB stick in now.\n 1.830 +" 19 70 1.831 + [ $? -eq 0 ] || return 1.832 + usbdev || return 1.833 + exec 3>&1 1.834 + format=`$DIALOG --clear \ 1.835 + --title " Select the filesystem " \ 1.836 + --radiolist "\nPlease select the filesystem type to create.\n\n\ 1.837 +The filesystem creation will erase all the data \ 1.838 +in the USB key." 14 70 4 \ 1.839 + "none" "Do not erase the USB key" on \ 1.840 + "ext3" "Ext3 journaling filesystem" off \ 1.841 + "ext2" "Ext2 filesystem" off \ 1.842 + "fat32" "Windows FAT32 filesystem" off \ 1.843 + 2>&1 1>&3` 1.844 + retval=$? 1.845 + exec 3>&- 1.846 + [ $retval -eq 0 ] || return 1.847 + [ "$format" != "none" ] && tazusb format $device "SliTaz" $format 1.848 + tazusb gen-iso2usb $ISO $device 1.849 +} 1.850 + 1.851 +dokexec() 1.852 +{ 1.853 + kexec -l $file 1.854 + umount -d /media/cdrom 1.855 + kexec -e 1.856 +} 1.857 + 1.858 +runmemtest() 1.859 +{ 1.860 + gotcdfile 'memtest*' && dokexec 1.861 +} 1.862 + 1.863 +runpxe() 1.864 +{ 1.865 + gotcdfile '?pxe' && dokexec 1.866 +} 1.867 + 1.868 +quit() 1.869 +{ 1.870 + umount -d /media/cdrom 1.871 + exit 1.872 +} 1.873 + 1.874 +ISO="$1" 1.875 +[ -z "$(isiso 2> /dev/null)" ] && echo "Usage : $0 file.iso" && exit 1 1.876 +mount -o loop,ro $ISO /media/cdrom 1.877 + 1.878 +while true; do 1.879 + cat > /tmp/dialog$$ <<EOT 1.880 +$DIALOG --clear \ 1.881 + --title " SliTaz ISO tool " \ 1.882 + --menu "" 23 70 17 \ 1.883 +$(cdfile 'README*' "readme" "Show the README file") \ 1.884 +$(gotisomd5 "isomd5" "Check the ISO image") \ 1.885 +$(cdfile 'md5sum*' "md5" "Check the ISO files") \ 1.886 +$(cdfile 'sha*sum*' "sha" "Check the ISO files") \ 1.887 +$(cdfilex boot/bzImage "bootiso" "Boot the ISO image") \ 1.888 +$(gotposixovl "install" "Hard disk installation (UMSDOS way)") \ 1.889 +$(gotposixovl "installtaz" "Hard disk installation (TAZUSB way)") \ 1.890 +$(gotposixovlzip "inst2zip" "ZIP installation archive (UMSDOS way)") \ 1.891 +$(gotposixovlzip "insttaz2zip" "ZIP installation archive (TAZUSB way)") \ 1.892 +$(xfile tazusb "usbkey" "USB key read/write installation") \ 1.893 +$(ishybrid "usbbootkey" "USB boot key (read only)") \ 1.894 + "tazboot" "Get tazboot.exe Linux loader" \ 1.895 +$(cdexe boot/bzImage "bzimage" "Get linux DOS/EXE file") \ 1.896 +$(cdexe 'memtest*' "memtest" "Get Memtest86 DOS/EXE file") \ 1.897 +$(cdfilef 'memtest*' "fdmemtest" "Create a Memtest86 boot floppy") \ 1.898 +$(cdfilex 'memtest*' "runmemtest" "Start Memtest86") \ 1.899 +$(cdexe '?pxe' "pxe" "Get SliTaz Web boot DOS/EXE utility") \ 1.900 +$(cdfilef '?pxe' "fdpxe" "Create a SliTaz Web boot floppy") \ 1.901 +$(cdfilex '?pxe' "runpxe" "Start the SliTaz Web boot utility") \ 1.902 +$(misspkg "missing" "Install packages to get more options") \ 1.903 + "quit" "Quit this utility" 1.904 +EOT 1.905 + exec 3>&1 1.906 + value=$(. /tmp/dialog$$ 2>&1 1>&3) 1.907 + retval=$? 1.908 + exec 3>&- 1.909 + rm -f /tmp/dialog$$ 1.910 + [ $retval -eq 0 ] || continue 1.911 + $value 1.912 +done