wok view syslinux/stuff/iso2exe/iso2exe.sh @ rev 14268
syslinux/iso2exe: do not overload (setup) version in bootlinux.c
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Thu Apr 04 11:19:19 2013 +0200 (2013-04-04) |
parents | ada914860f33 |
children | 589a225cacc7 |
line source
1 #!/bin/sh
3 ddq()
4 {
5 dd $@ 2> /dev/null
6 }
8 store()
9 {
10 n=$2; for i in $(seq 8 8 ${4:-16}); do
11 printf '\\\\x%02X' $(($n & 255))
12 n=$(($n >> 8))
13 done | xargs echo -en | ddq bs=1 conv=notrunc of=$3 seek=$(($1))
14 }
16 get()
17 {
18 echo $(od -j $(($1)) -N ${3:-2} -t u${3:-2} -An $2)
19 }
21 add_rootfs()
22 {
23 TMP=/tmp/iso2exe$$
24 mkdir -p $TMP/bin $TMP/dev
25 cp -a /dev/?d?* $TMP/dev
26 $0 --get init > $TMP/init.exe
27 grep -q mount.posixovl.iso2exe $TMP/init.exe &&
28 cp /usr/sbin/mount.posixovl $TMP/bin/mount.posixovl.iso2exe \
29 2> /dev/null && echo "Store mount.posixovl..."
30 find $TMP -type f | xargs chmod +x
31 ( cd $TMP ; find * | cpio -o -H newc ) | \
32 lzma e $TMP/rootfs.gz -si 2> /dev/null
33 SIZE=$(wc -c < $TMP/rootfs.gz)
34 store 24 $SIZE $1
35 OFS=$(( $OFS - $SIZE ))
36 printf "Adding rootfs.gz file at %04X...\n" $OFS
37 cat $TMP/rootfs.gz | ddq of=$1 bs=1 seek=$OFS conv=notrunc
38 rm -rf $TMP
39 }
41 add_dosexe()
42 {
43 OFS=$((0x7EE0))
44 printf "Adding DOS/EXE at %04X...\n" $OFS
45 $0 --get bootiso.bin 2> /dev/null | \
46 ddq bs=1 skip=$OFS of=$1 seek=$OFS conv=notrunc
47 }
49 add_doscom()
50 {
51 SIZE=$($0 --get boot.com | wc -c)
52 OFS=$(( $OFS - $SIZE ))
53 printf "Adding DOS boot file at %04X...\n" $OFS
54 $0 --get boot.com | ddq of=$1 bs=1 seek=$OFS conv=notrunc
55 store 66 $(($OFS+0xC0)) $1
56 }
58 add_win32exe()
59 {
60 printf "Adding WIN32 file at %04X...\n" 0
61 ddq if=/tmp/exe$$ of=$1 conv=notrunc
62 SIZE=$($0 --get win32.exe 2> /dev/null | tee /tmp/exe$$ | wc -c)
63 ddq if=/tmp/exe$$ of=$1 conv=notrunc
64 printf "Adding bootiso head at %04X...\n" 0
65 $0 --get bootiso.bin 2> /dev/null > /tmp/exe$$
66 ddq if=/tmp/exe$$ of=$1 bs=128 count=1 conv=notrunc
67 store $((0x94)) $((0xE0 - 12*8)) $1
68 store $((0xF4)) $((16 - 12)) $1
69 ddq if=$1 of=/tmp/coff$$ bs=1 skip=$((0x178)) count=$((0x88))
70 ddq if=/tmp/coff$$ of=$1 conv=notrunc bs=1 seek=$((0x178 - 12*8))
71 ddq if=/tmp/exe$$ of=$1 bs=1 count=30 seek=$((0x1A0)) skip=$((0x1A0)) conv=notrunc
72 ddq if=$2 bs=1 skip=$((0x1BE)) seek=$((0x1BE)) count=66 of=$1 conv=notrunc
73 store 69 $(($SIZE/512)) $1 8
74 store 510 $((0xAA55)) $1
75 rm -f /tmp/exe$$ /tmp/coff$$
76 printf "Moving syslinux hybrid boot record at %04X ...\n" $SIZE
77 ddq if=$2 bs=1 count=512 of=$1 seek=$SIZE conv=notrunc
78 OFS=$(($SIZE+512))
79 }
81 add_fdbootstrap()
82 {
83 SIZE=$($0 --get bootfd.bin 2> /dev/null | wc -c)
84 if [ $SIZE -ne 0 ]; then
85 OFS=$(( $OFS - $SIZE + 512 ))
86 printf "Adding floppy bootstrap file at %04X...\n" $OFS
87 $0 --get bootfd.bin | \
88 ddq of=$1 bs=1 count=512 seek=$OFS conv=notrunc
89 $0 --get bootfd.bin | \
90 ddq of=$1 bs=1 skip=1024 seek=$((512 + $OFS)) conv=notrunc
91 store 28 $(($SIZE/512 - 1)) $1 8
92 fi
93 }
94 case "$1" in
95 --build)
96 shift
97 ls -l $@
98 cat >> $0 <<EOM
99 $(tar cf - $@ | lzma e -si -so | uuencode -m -)
100 EOT
101 EOM
102 sed -i '/^case/,/^esac/d' $0
103 exit ;;
104 --get)
105 cat $2
106 exit ;;
107 --array)
108 DATA=/tmp/dataiso$$
109 ddq if=/dev/zero bs=32k count=1 of=$DATA
110 add_win32exe $DATA $2 > /dev/null
111 HSZ=$OFS
112 add_dosexe $DATA > /dev/null
113 add_rootfs $DATA > /dev/null
114 add_doscom $DATA > /dev/null
115 add_fdbootstrap $DATA > /dev/null
116 name=${3:-bootiso}
117 cat <<EOT
119 #define $(echo $name | tr '[a-z]' '[A-Z]')SZ $((0x8000 - $OFS + $HSZ))
121 #ifdef WIN32
122 static char $name[] = {
123 $(hexdump -v -n $HSZ -e '" " 16/1 "0x%02X, "' -e '" // %04.4_ax |" 16/1 "%_p" "| \n"' $DATA | sed 's/ 0x ,/ /g')
124 $(hexdump -v -s $OFS -e '" " 16/1 "0x%02X, "' -e '" // %04.4_ax |" 16/1 "%_p" "| \n"' $DATA | sed 's/ 0x ,/ /g')
125 };
126 #endif
127 EOT
128 rm -rf $DATA
129 exit ;;
130 --exe)
131 # --exe mvcom.bin x.com y.exe > xy.exe
132 cat $4 $3 > /tmp/exe$$
133 S=$(stat -c %s /tmp/exe$$)
134 store 2 $(($S%512)) /tmp/exe$$
135 store 4 $((($S+511)/512)) /tmp/exe$$
136 store 14 -16 /tmp/exe$$
137 store 16 -2 /tmp/exe$$
138 store 20 256 /tmp/exe$$
139 store 22 -16 /tmp/exe$$
140 ddq if=$2 bs=1 seek=64 of=/tmp/exe$$ conv=notrunc
141 store 65 $(stat -c %s $3) /tmp/exe$$
142 store 68 $((0x100-0x40+$(stat -c %s $4))) /tmp/exe$$
143 cat /tmp/exe$$
144 rm -f /tmp/exe$$
145 exit ;;
146 esac
148 main()
149 {
150 [ $(id -u) -ne 0 ] && exec su -c "$0 $@" < /dev/tty
151 case "$1" in
152 --get) shift
153 uudecode | unlzma | tar xOf - $@
154 exit ;;
155 *) cat > /dev/null
156 esac
158 [ ! -s "$1" ] && echo "usage: $0 image.iso" 1>&2 && exit 1
159 case "$(get 0 $1)" in
160 23117) echo "The file $1 is already an EXE file." 1>&2 && exit 1;;
161 0) [ -x /usr/bin/isohybrid ] && isohybrid $1 && echo "Do isohybrid"
162 esac
164 echo "Read hybrid & tazlito data..."
165 ddq if=$1 bs=512 count=1 of=/tmp/hybrid$$
166 ddq if=$1 bs=512 skip=2 count=20 of=/tmp/tazlito$$
167 add_win32exe $1 /tmp/hybrid$$
168 printf "Moving tazlito data record at %04X ...\n" $OFS
169 ddq if=/tmp/tazlito$$ bs=1 count=512 of=$1 seek=$OFS conv=notrunc
170 rm -f /tmp/tazlito$$ /tmp/hybrid$$
172 # keep the largest room for the tazlito info file
173 add_dosexe $1
174 add_rootfs $1
175 add_doscom $1
176 add_fdbootstrap $1
177 store 26 ${RANDOM:-0} $1
178 i=66
179 n=0
180 echo -n "Adding checksum..."
181 while [ $i -lt 32768 ]; do
182 n=$(($n + $(get $i $1) ))
183 i=$(($i + 2))
184 done
185 store 64 -$n $1
186 echo " done."
187 }
189 main $@ <<EOT