wok-6.x view syslinux/stuff/iso2exe/iso2exe.sh @ rev 13974
syslinux/iso2exe: fix checksum
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Wed Feb 06 12:05:22 2013 +0100 (2013-02-06) |
parents | b5ea41033c21 |
children | a26ba54f3ea7 |
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 get()
29 {
30 echo $(od -j $(($1)) -N ${3:-2} -t u${3:-2} -An $2)
31 }
33 main()
34 {
35 case "$1" in
36 --get) shift
37 uudecode | unlzma | tar xOf - $@
38 exit ;;
39 *) cat > /dev/null
40 esac
42 [ ! -s "$1" ] && echo "usage: $0 image.iso" 1>&2 && exit 1
43 case "$(od -N 2 -t x2 -An $1)" in
44 *5a4d) echo "The file $1 is already an EXE file." 1>&2 && exit 1;;
45 *0000) [ -x /usr/bin/isohybrid ] && isohybrid $1
46 esac
48 echo "Moving syslinux hybrid boot record..."
49 ddq if=$1 bs=512 count=1 | ddq of=$1 bs=512 count=1 seek=1 conv=notrunc
51 echo "Inserting EXE boot record..."
52 $0 --get bootiso.bin | ddq of=$1 conv=notrunc
54 # keep the largest room for the tazlito info file
55 TMP=/tmp/iso2exe$$
56 mkdir -p $TMP/bin $TMP/dev
57 cp -a /dev/?d?* $TMP/dev
58 $0 --get init > $TMP/init.exe
59 grep -q mount.posixovl.iso2exe $TMP/init.exe &&
60 cp /usr/sbin/mount.posixovl $TMP/bin/mount.posixovl.iso2exe
61 find $TMP -type f | xargs chmod +x
62 ( cd $TMP ; find * | cpio -o -H newc ) | \
63 lzma e $TMP/rootfs.gz -si 2> /dev/null
64 SIZE=$(wc -c < $TMP/rootfs.gz)
65 store 24 $SIZE $1
66 OFS=$(( 0x8000 - $SIZE ))
67 printf "Adding rootfs.gz file at %04X...\n" $OFS
68 cat $TMP/rootfs.gz | ddq of=$1 bs=1 seek=$OFS conv=notrunc
69 rm -rf $TMP
70 SIZE=$($0 --get boot.com | wc -c)
71 OFS=$(( $OFS - $SIZE ))
72 printf "Adding DOS boot file at %04X...\n" $OFS
73 $0 --get boot.com | ddq of=$1 bs=1 seek=$OFS conv=notrunc
74 store 66 $(($OFS+0xC0)) $1
75 SIZE=$($0 --get win32.exe 2> /dev/null | tee /tmp/exe$$ | wc -c)
76 if [ $SIZE -ne 0 ]; then
77 OFS=$(( 128 + ( ($OFS - $SIZE + 128) & 0xFE00 ) ))
78 printf "Adding WIN32 file at %04X...\n" $OFS
79 LOC=$((0xAC+$(get 0x94 /tmp/exe$$)))
80 for i in $(seq 1 $(get 0x86 /tmp/exe$$)); do
81 store $LOC $(($(get $LOC /tmp/exe$$)+$OFS-128)) /tmp/exe$$
82 LOC=$(($LOC+40))
83 done
84 ddq if=/tmp/exe$$ of=$1 bs=1 skip=128 seek=$OFS conv=notrunc
85 fi
86 rm -f /tmp/exe$$
87 store 60 $OFS $1
88 store 26 ${RANDOM:-0} $1
89 i=66
90 n=0
91 echo -n "Adding checksum..."
92 while [ $i -lt 32768 ]; do
93 n=$(($n + $(get $i $1) ))
94 i=$(($i + 2))
95 done
96 store 64 -$n $1
97 echo " done."
98 }
100 main $@ <<EOT