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

syslinux/iso2exe: add loram support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Dec 18 16:09:07 2012 +0100 (2012-12-18)
parents d47403fdd900
children b5ea41033c21
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/bin $TMP/dev
54 cp /usr/sbin/mount.posixovl $TMP/bin/mount.posixovl.iso2exe
55 cp -a /dev/?d?* $TMP/dev
56 $0 --get init > $TMP/init.exe
57 chmod +x $TMP/init.exe $TMP/bin/mount.posixov*
58 ( cd $TMP ; find * | cpio -o -H newc ) | \
59 lzma e $TMP/rootfs.gz -si 2> /dev/null
60 SIZE=$(wc -c < $TMP/rootfs.gz)
61 store 28 $SIZE $1
62 OFS=$(( 0x8000 - $SIZE ))
63 printf "Adding rootfs.gz file at %04X...\n" $OFS
64 cat $TMP/rootfs.gz | ddq of=$1 bs=1 seek=$OFS conv=notrunc
65 rm -rf $TMP
66 SIZE=$($0 --get lzcom.bin boot.com.lzma | wc -c)
67 OFS=$(( $OFS - $SIZE ))
68 printf "Adding DOS boot file at %04X...\n" $OFS
69 $0 --get lzcom.bin boot.com.lzma | ddq of=$1 bs=1 seek=$OFS conv=notrunc
70 store 34 $(($OFS+0xE0)) $1
71 store 30 ${RANDOM:-0} $1
72 i=34
73 n=0
74 echo -n "Adding checksum..."
75 while [ $i -lt 32768 ]; do
76 n=$(($n + $(od -j $i -N 2 -t u2 -An $1) ))
77 i=$(($i + 2))
78 done
79 store 32 -$n $1
80 echo " done."
81 }
83 main $@ <<EOT