wok view syslinux/stuff/iso2exe/iso2exe.sh @ rev 13697

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