wok-next diff syslinux/stuff/iso2exe/init @ rev 13691
syslinux: add iso2exe
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Thu Dec 13 14:33:27 2012 +0100 (2012-12-13) |
parents | |
children | 87a217af01ea |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/syslinux/stuff/iso2exe/init Thu Dec 13 14:33:27 2012 +0100 1.3 @@ -0,0 +1,251 @@ 1.4 +#!/bin/sh 1.5 + 1.6 +DIALOG=dialog 1.7 + 1.8 +get() 1.9 +{ 1.10 + od -j $1 -N ${3:-4} -t u${3:-4} -An $2 1.11 +} 1.12 + 1.13 +getarg() 1.14 +{ 1.15 + sed "/$1=/!d;s/.*$1=\\([^ ]*\\).*/\\1/" /proc/cmdline 1.16 +} 1.17 + 1.18 +gettazboot() 1.19 +{ 1.20 + echo "Create $(basename $1) ..." 1.21 + O=$(($(get 36 /mnt/$ISO 2) - 0xE0)) 1.22 + L=$((0x8000 - $(get 28 /mnt/$ISO 2) - $O)) 1.23 + S=$((32+$L)) 1.24 + P=$((($S+511)/512)) 1.25 + E=$((4096-(32*$P))) 1.26 + for i in 0x5A4D $(($S%512)) $P 0 2 $E -1 $((${2:-0}-16)) \ 1.27 + -2 0 256 -16 28 0x6C53 0x5469 0x7A61; do 1.28 + printf '\\\\x%02X\\\\x%02X' $(($i&255)) $((($i>>8)&255)) | \ 1.29 + xargs echo -en 1.30 + done > $1 1.31 + dd bs=1 count=$L skip=$(echo $O) if=/mnt/$ISO >> $1 2> /dev/null 1.32 +} 1.33 + 1.34 +checkmagic() 1.35 +{ 1.36 + [ -s $1 ] && [ $(getarg magic) == $(get 28 $1) ] 1.37 +} 1.38 + 1.39 +getiso() 1.40 +{ 1.41 + blkid | while read dev info ; do 1.42 + case "$info" in 1.43 + *dos*|*fat*|*ntfs*) 1.44 + mount ${dev%:} /mnt 1.45 + if checkmagic /mnt/$ISO; then 1.46 + mount -o loop,ro /mnt/$ISO /media/cdrom 1.47 + echo "Found $ISO on ${dev%:}" 1.48 + break 1.49 + fi 1.50 + umount /mnt ;; 1.51 + esac 1.52 + done 1.53 +} 1.54 + 1.55 +uncpio() 1.56 +{ 1.57 + echo "Extracting $(basename $1) ..." 1.58 + case $(get 0 $1 2) in 1.59 + *35615) zcat $1 ;; 1.60 + *\ 93) unlzma -c $1 ;; 1.61 + *) cat $1 ;; 1.62 + esac | ( cd ${2:-/} ; cpio -idmu > /dev/null 2>&1 ) 1.63 +} 1.64 + 1.65 +getuuid() 1.66 +{ 1.67 + dev=$(mount | sed '/ \/mnt /!d;s/ .*//;s|/dev/||;q') 1.68 + blkid | sed "/$dev:/!d;s/.*UUID=.\\([^ ]*\\)\".*/\\1/" 1.69 +} 1.70 + 1.71 +mkinitrd() 1.72 +{ 1.73 + echo "Create $(basename $1) ..." 1.74 + for i in bin lib dev proc tmp mnt etc ; do 1.75 + mkdir -p /tmp/fs/$i 1.76 + done 1.77 + for i in /dev/console /dev/null /dev/tty /dev/tty1 /dev/fuse \ 1.78 + /dev/hd* /dev/sd* ; do 1.79 + cp -a $i /tmp/fs$i 1.80 + done 1.81 + for i in /bin/busybox /usr/sbin/mount.posixovl $(which blkid); do 1.82 + cp $(LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $i | \ 1.83 + sed 's|.*=> \(.*/lib/l[^ ]*\).*|\1|;/^\//!d') /tmp/fs/lib 1.84 + cp $i /tmp/fs/bin 1.85 + done 1.86 + cp -a /lib/ld-* /tmp/fs/lib 1.87 + for i in $(busybox | sed '/Current/,$!d'); do 1.88 + ln -s busybox /tmp/fs/bin/${i%,} 1.89 + done 1.90 + ln -s /proc/mounts /tmp/fs/etc/mtab 1.91 + cat > /tmp/fs/init <<EOT 1.92 +#!/bin/sh 1.93 + 1.94 +arg() 1.95 +{ 1.96 + grep -q \$1 /proc/cmdline && 1.97 + val="\$(sed "s/.*\$1=\\([^ ]*\\).*/\\1/" < /proc/cmdline)" && 1.98 + echo "\$2 \$val" 1.99 +} 1.100 + 1.101 +mount -t proc /proc /proc 1.102 +arg mount "Mount device" 1.103 +mount \$( (blkid /dev/?d* || blkid) | grep \$val | sed 's/:.*//;q') /mnt 1.104 +arg subroot "Change root to directory" 1.105 +mount.posixovl /mnt/\$val 1.106 +mount --bind /mnt /mnt/\$val/mnt/dos 1.107 +LDSO=\$(ls /mnt/\$val/lib/ld-* | sed q) 1.108 +umount /proc 1.109 +export LD_LIBRARY_PATH=\$val/lib:\$val/usr/lib:/lib 1.110 +exec /bin/switch_root /mnt \${LDSO#/mnt/} \$val/usr/sbin/chroot \$val /sbin/init 1.111 +EOT 1.112 + chmod +x /tmp/fs/init 1.113 + ( cd /tmp/fs ; find * | cpio -o -H newc ) | lzma e $1 -si 2> /dev/null 1.114 + rm -rf /tmp/fs 1.115 +} 1.116 + 1.117 +doinstall() 1.118 +{ 1.119 + mkdir /mnt/slitaz 1.120 + mount.posixovl /mnt/slitaz || return 1.121 + mkdir -p /mnt/slitaz/boot /mnt/slitaz/mnt/dos 1.122 + for i in $(ls -r /media/cdrom/boot/rootfs*); do 1.123 + uncpio $i /mnt/slitaz 1.124 + done 1.125 + for i in /media/cdrom/boot/bzImage /media/cdrom/boot/*pxe* \ 1.126 + /media/cdrom/boot/isolinux/he* /media/cdrom/boot/isolinux/opt* \ 1.127 + /media/cdrom/README /media/cdrom/boot/memtest* ; do 1.128 + [ -s $i ] && cp $i /mnt/slitaz/boot 1.129 + done 1.130 + umount -d /media/cdrom 1.131 + gettazboot /mnt/slitaz/boot/tazboot.exe 1.132 + mkinitrd /mnt/slitaz/boot/initrd 1.133 + cat > /mnt/slitaz/boot/tazboot.cmd <<EOT 1.134 +kernel=\\slitaz\\boot\\bzimage 1.135 +initrd=\\slitaz\\boot\\initrd 1.136 +rw root=/dev/null mount=$(getuuid) subroot=slitaz autologin 1.137 +EOT 1.138 + unix2dos /mnt/slitaz/boot/he* /mnt/slitaz/boot/opt* \ 1.139 + /mnt/slitaz/boot/README /mnt/slitaz/boot/tazboot.cmd 1.140 + [ -x /mnt/slitaz/usr/sbin/mount.posixovl ] || 1.141 + cp /usr/sbin/mount.posixovl /mnt/slitaz/usr/sbin 1.142 + ! grep -qs tazboot /mnt/boot.ini && cat >> /mnt/boot.ini <<EOT 1.143 +C:\\slitaz\\boot\\tazboot.exe="SliTaz" 1.144 +EOT 1.145 + grep -qs menuitem /mnt/config.sys && !grep -q tazboot /mnt/config.sys && 1.146 + sed -i 's/menudefault=/menuitem=slitaz,SliTaz\n&/' /mnt/config.sys && 1.147 + cat >> /mnt/config.sys <<EOT 1.148 +[slitaz] 1.149 +device=\\slitaz\\boot\\tazboot.exe 1.150 +EOT 1.151 +} 1.152 + 1.153 +install() 1.154 +{ 1.155 + $DIALOG --clear \ 1.156 + --title " SliTaz UMSDOS like installation " \ 1.157 + --yes-label "Install" --yesno \ 1.158 +"\nSliTaz will be installed in the subdirectory \\slitaz of the current 1.159 +DOS/Windows partition. You will see your files from /mnt/dos.\n\n 1.160 +You will start SliTaz with \\slitaz\\boot\\tazboot.exe\n\n 1.161 +To uninstall SliTaz, you have only to remove this directory. 1.162 +The file \\boot.ini or \\config.sys may be modified too.\n\n 1.163 +To do a traditionnal installation with disk partitioning 1.164 +start SliTaz Live with 'SliTaz RAM boot' menu.\n 1.165 +" 16 70 1.166 + [ $? -eq 0 -a -x /usr/sbin/mount.posixovl ] || return 1.167 + doinstall 1.168 + umount /proc 1.169 + exec chroot /mnt/slitaz /sbin/init 1.170 +} 1.171 + 1.172 +tazboot() 1.173 +{ 1.174 + $DIALOG --clear \ 1.175 + --title " SliTaz bootloader for DOS " \ 1.176 + --yes-label "Install" --yesno \ 1.177 +"\nThe file TAZBOOT.EXE will be created in top directory. It supports 1.178 +bzImage linux kernel, multiples initramfs, kernel command line and 1.179 +ISO image file loopback (can retrieve files from an ISO file).\n\n 1.180 +Usage: tazboot.exe [[@commands]|[kernel=<bzimage>] 1.181 +[initrd=<rootfs>[,<rootfs2>...]] [iso=<isofile>] cmdline args ...]\n\n 1.182 +Defaults: tazboot @tazboot.cmd or tazboot kernel=bzImage auto\n\n\ 1.183 +Examples for tazboot.cmd:\n\n\ 1.184 + iso=\\isos\\slitaz-4.0.iso\n\ 1.185 + kernel=boot/bzImage\n\ 1.186 + initrd=boot/rootfs4.gz,boot/rootfs3.gz,boot/rootfs2.gz,boot/rootfs1.gz\n\ 1.187 + rw root=/dev/null autologin\n\n\ 1.188 + kernel=\\slitaz\\vmlinuz root=/dev/sda5 ro\n\n 1.189 +Unlike GRUB4DOS, it doesn't require unfragmented ISO image files.\n 1.190 +" 24 78 1.191 + [ $? -eq 0 ] || return 1.192 + gettazboot /mnt/tazboot.exe 1.193 +} 1.194 + 1.195 +text() 1.196 +{ 1.197 + umount -d /media/cdrom 1.198 + umount /mnt 1.199 + umount /proc 1.200 + exec /init 1.201 +} 1.202 + 1.203 +live() 1.204 +{ 1.205 + n=0 1.206 + for i in $(ls -r /media/cdrom/boot/rootfs*); do 1.207 + [ $((n++)) -eq 0 ] || uncpio $i 1.208 + done 1.209 + text 1.210 +} 1.211 + 1.212 +reboot() 1.213 +{ 1.214 + umount -d /media/cdrom 1.215 + umount /mnt 1.216 + /sbin/reboot -f 1.217 +} 1.218 + 1.219 +poweroff() 1.220 +{ 1.221 + umount -d /media/cdrom 1.222 + umount /mnt 1.223 + /sbin/poweroff -f 1.224 +} 1.225 + 1.226 +[ -x /usr/sbin/mount.posixovl ] || 1.227 +mv /usr/sbin/mount.posixovl.iso2exe /usr/sbin/mount.posixovl 1.228 +mount -t proc /proc /proc 1.229 +ISO="$(getarg iso | sed 's/.://;s|\\|/|g')" 1.230 +getiso 1.231 +case "$(basename $ISO | tr [A-Z] [a-z])$(getarg mode)" in 1.232 +*install*) install ;; 1.233 +*live*) live ;; 1.234 +*text*) text ;; 1.235 +esac 1.236 + 1.237 +while true; do 1.238 + exec 3>&1 1.239 + value=`$DIALOG --clear \ 1.240 + --title " Welcome to SliTaz " \ 1.241 + --menu "\nPlease select" 15 70 7 \ 1.242 + "live" "SliTaz RAM boot" \ 1.243 + "text" "SliTaz RAM boot (text mode only)" \ 1.244 + "install" "Hard disk installation" \ 1.245 + "tazboot" "Get tazboot.exe Linux loader" \ 1.246 + "reboot" "Restart the computer" \ 1.247 + "poweroff" "Power off" \ 1.248 + "ash" "Shell prompt" \ 1.249 + 2>&1 1>&3` 1.250 + retval=$? 1.251 + exec 3>&- 1.252 + [ $retval -eq 0 ] || continue 1.253 + $value 1.254 +done