wok-next annotate syslinux/stuff/iso2exe/iso2exe.sh @ rev 13692
syslinux: iso2exe (tiny edits)
author | Paul Issott <paul@slitaz.org> |
---|---|
date | Thu Dec 13 18:22:00 2012 +0000 (2012-12-13) |
parents | 7d300004a3b8 |
children | d47403fdd900 |
rev | line source |
---|---|
pascal@13691 | 1 #!/bin/sh |
pascal@13691 | 2 if [ "$1" == "--build" ]; then |
pascal@13691 | 3 shift |
pascal@13691 | 4 [ $(tar cf - $@ | wc -c) -gt $((32 * 1024)) ] && |
pascal@13691 | 5 echo "The file set $@ is too large (31K max) :" && |
pascal@13691 | 6 ls -l $@ && exit 1 |
pascal@13691 | 7 cat >> $0 <<EOM |
pascal@13691 | 8 $(tar cf - $@ | lzma e -si -so | uuencode -m -) |
pascal@13691 | 9 EOT |
pascal@13691 | 10 EOM |
pascal@13691 | 11 sed -i '/--build/,/^fi/d' $0 |
pascal@13691 | 12 exit |
pascal@13691 | 13 fi |
pascal@13691 | 14 |
pascal@13691 | 15 ddq() |
pascal@13691 | 16 { |
pascal@13691 | 17 dd $@ 2> /dev/null |
pascal@13691 | 18 } |
pascal@13691 | 19 |
pascal@13691 | 20 store() |
pascal@13691 | 21 { |
pascal@13691 | 22 n=$2; for i in $(seq 8 8 ${4:-16}); do |
pascal@13691 | 23 printf '\\\\x%02X' $(($n & 255)) |
pascal@13691 | 24 n=$(($n >> 8)) |
pascal@13691 | 25 done | xargs echo -en | ddq bs=1 conv=notrunc of=$3 seek=$(($1)) |
pascal@13691 | 26 } |
pascal@13691 | 27 |
pascal@13691 | 28 main() |
pascal@13691 | 29 { |
pascal@13691 | 30 case "$1" in |
pascal@13691 | 31 --get) shift |
pascal@13691 | 32 uudecode | unlzma | tar xOf - $@ |
pascal@13691 | 33 exit ;; |
pascal@13691 | 34 *) cat > /dev/null |
pascal@13691 | 35 esac |
pascal@13691 | 36 |
pascal@13691 | 37 [ ! -s "$1" ] && echo "usage: $0 image.iso" 1>&2 && exit 1 |
pascal@13691 | 38 case "$(od -N 2 -t x2 -An $1)" in |
pascal@13691 | 39 *5a4d) echo "The file $1 is already an EXE file." 1>&2 && exit 1;; |
pascal@13691 | 40 *0000) [ -x /usr/bin/isohybrid ] && isohybrid $1 |
pascal@13691 | 41 esac |
pascal@13691 | 42 [ ! -x /usr/sbin/mount.posixovl ] && |
paul@13692 | 43 echo "No file mount.posixovl. Aborting." 1>&2 && exit 1 |
pascal@13691 | 44 |
paul@13692 | 45 echo "Moving syslinux hybrid boot record..." |
pascal@13691 | 46 ddq if=$1 bs=512 count=1 | ddq of=$1 bs=512 count=1 seek=1 conv=notrunc |
pascal@13691 | 47 |
paul@13692 | 48 echo "Inserting EXE boot record..." |
pascal@13691 | 49 $0 --get bootiso.bin | ddq of=$1 conv=notrunc |
pascal@13691 | 50 |
pascal@13691 | 51 # keep the largest room for the tazlito info file |
pascal@13691 | 52 TMP=/tmp/iso2exe$$ |
pascal@13691 | 53 mkdir -p $TMP/usr/sbin |
pascal@13691 | 54 cp /usr/sbin/mount.posixovl $TMP/usr/sbin/mount.posixovl.iso2exe |
pascal@13691 | 55 $0 --get init > $TMP/init.exe |
pascal@13691 | 56 chmod +x $TMP/init.exe $TMP/usr/sbin/mount.posixov* |
pascal@13691 | 57 ( cd $TMP ; ls init.exe usr/sbin/mount.posixov* | cpio -o -H newc ) | \ |
pascal@13691 | 58 lzma e $TMP/rootfs.gz -si 2> /dev/null |
pascal@13691 | 59 SIZE=$(wc -c < $TMP/rootfs.gz) |
pascal@13691 | 60 store 28 $SIZE $1 |
pascal@13691 | 61 OFS=$(( 0x8000 - $SIZE )) |
paul@13692 | 62 printf "Adding rootfs.gz file at %04X...\n" $OFS |
pascal@13691 | 63 cat $TMP/rootfs.gz | ddq of=$1 bs=1 seek=$OFS conv=notrunc |
pascal@13691 | 64 rm -rf $TMP |
pascal@13691 | 65 SIZE=$($0 --get lzcom.bin boot.com.lzma | wc -c) |
pascal@13691 | 66 OFS=$(( $OFS - $SIZE )) |
paul@13692 | 67 printf "Adding DOS boot file at %04X...\n" $OFS |
pascal@13691 | 68 $0 --get lzcom.bin boot.com.lzma | ddq of=$1 bs=1 seek=$OFS conv=notrunc |
pascal@13691 | 69 store 36 $(($OFS+0xE0)) $1 |
pascal@13691 | 70 store 30 ${RANDOM:-0} $1 |
pascal@13691 | 71 } |
pascal@13691 | 72 |
pascal@13691 | 73 main $@ <<EOT |