wok-next annotate syslinux/stuff/iso2exe/iso2exe.sh @ rev 18804

Up vanessa_adt (0.0.9), vanessa_logger (0.0.10), vanessa_socket (0.0.12)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Jan 13 22:13:51 2016 +0100 (2016-01-13)
parents 429407501864
children 49be2e5503d0
rev   line source
pascal@13691 1 #!/bin/sh
pascal@13691 2
pascal@13691 3 ddq()
pascal@13691 4 {
pascal@13691 5 dd $@ 2> /dev/null
pascal@13691 6 }
pascal@13691 7
pascal@13691 8 store()
pascal@13691 9 {
pascal@13691 10 n=$2; for i in $(seq 8 8 ${4:-16}); do
pascal@13691 11 printf '\\\\x%02X' $(($n & 255))
pascal@13691 12 n=$(($n >> 8))
pascal@13691 13 done | xargs echo -en | ddq bs=1 conv=notrunc of=$3 seek=$(($1))
pascal@13691 14 }
pascal@13691 15
pascal@13972 16 get()
pascal@13972 17 {
pascal@13972 18 echo $(od -j $(($1)) -N ${3:-2} -t u${3:-2} -An $2)
pascal@13972 19 }
pascal@13972 20
pascal@17476 21 compress()
pascal@17476 22 {
pascal@17489 23 if [ "$1" ]; then
pascal@17489 24 gzip -9 > $1
pascal@17489 25 [ "$(which advdef 2> /dev/null)" ] &&
pascal@17489 26 advdef -z4 $1 > /dev/null
pascal@17489 27 elif [ "$(which xz 2> /dev/null)" ]; then
pascal@17476 28 xz -z -e --format=lzma --lzma1=mode=normal --stdout
pascal@17476 29 else
pascal@17476 30 lzma e -si -so
pascal@17476 31 fi 2> /dev/null
pascal@17476 32 }
pascal@17476 33
pascal@14150 34 add_rootfs()
pascal@13691 35 {
pascal@13691 36 TMP=/tmp/iso2exe$$
pascal@13713 37 mkdir -p $TMP/bin $TMP/dev
pascal@18804 38 cp -a /dev/tty /dev/tty0 $TMP/dev
pascal@13691 39 $0 --get init > $TMP/init.exe
pascal@17489 40 # mount -o loop,ro $1 $TMP
pascal@17489 41 # oldslitaz="$(ls $TMP/boot/isolinux/splash.lss 2> /dev/null)"
pascal@17489 42 # umount -d $TMP
pascal@17489 43 # [ "$oldslitaz" ] && # for SliTaz <= 3.0 only...
pascal@17489 44 # grep -q mount.posixovl.iso2exe $TMP/init.exe &&
pascal@17489 45 # cp /usr/sbin/mount.posixovl $TMP/bin/mount.posixovl.iso2exe \
pascal@17489 46 # 2> /dev/null && echo "Store mount.posixovl ($(wc -c \
pascal@17489 47 # < /usr/sbin/mount.posixovl) bytes) ..."
pascal@17252 48 find $TMP -type f -print0 | xargs -0 chmod +x
pascal@17489 49 ( cd $TMP ; find * | cpio -o -H newc ) | compress $TMP/rootfs.gz
pascal@13691 50 SIZE=$(wc -c < $TMP/rootfs.gz)
pascal@13972 51 store 24 $SIZE $1
pascal@14261 52 OFS=$(( $OFS - $SIZE ))
pascal@17454 53 printf "Adding rootfs.gz file at %04X (%d bytes) ...\n" $OFS $SIZE
pascal@13691 54 cat $TMP/rootfs.gz | ddq of=$1 bs=1 seek=$OFS conv=notrunc
pascal@13691 55 rm -rf $TMP
pascal@14150 56 }
pascal@14150 57
pascal@14261 58 add_dosexe()
pascal@14261 59 {
pascal@17492 60 TMP=/tmp/bootiso$$
pascal@17492 61 $0 --get bootiso.bin > $TMP 2> /dev/null
pascal@17492 62 OFS=$(($(get 20 $TMP) - 0xC0))
pascal@17492 63 printf "Adding DOS/EXE stub at %04X (%d bytes) ...\n" $OFS $((0x8000 - $OFS))
pascal@17492 64 ddq if=$TMP bs=1 skip=$OFS of=$1 seek=$OFS conv=notrunc
pascal@17492 65 rm -f $TMP
pascal@14261 66 }
pascal@14261 67
pascal@14150 68 add_doscom()
pascal@14150 69 {
pascal@13972 70 SIZE=$($0 --get boot.com | wc -c)
pascal@13691 71 OFS=$(( $OFS - $SIZE ))
pascal@17454 72 printf "Adding DOS boot file at %04X (%d bytes) ...\n" $OFS $SIZE
pascal@13972 73 $0 --get boot.com | ddq of=$1 bs=1 seek=$OFS conv=notrunc
pascal@17810 74 store 64 $(($OFS+0xC0)) $1
pascal@14150 75 }
pascal@14150 76
pascal@18062 77 add_tazlito_info()
pascal@18062 78 {
pascal@18062 79 HOLE=$OFS
pascal@18062 80 [ $(get 0 $2) -eq 35615 ] || return
pascal@18062 81 zcat $2 | gzip -9 > /tmp/rezipped$$.gz
pascal@18062 82 [ "$(which advdef 2> /dev/null)" ] &&
pascal@18062 83 advdef -z4 /tmp/rezipped$$.gz > /dev/null
pascal@18062 84 n=$(stat -c %s /tmp/rezipped$$.gz)
pascal@18062 85 printf "Moving tazlito data record at %04X ($n bytes) ...\n" $OFS
pascal@18062 86 ddq if=/tmp/rezipped$$.gz bs=1 of=$1 seek=$OFS conv=notrunc
pascal@18062 87 HOLE=$(($HOLE+$n))
pascal@18062 88 rm -f /tmp/rezipped$$.gz
pascal@18062 89 }
pascal@18062 90
pascal@14150 91 add_win32exe()
pascal@14150 92 {
pascal@13974 93 SIZE=$($0 --get win32.exe 2> /dev/null | tee /tmp/exe$$ | wc -c)
pascal@17454 94 printf "Adding WIN32 file at %04X (%d bytes) ...\n" 0 $SIZE
pascal@14261 95 ddq if=/tmp/exe$$ of=$1 conv=notrunc
pascal@14261 96 printf "Adding bootiso head at %04X...\n" 0
pascal@14261 97 $0 --get bootiso.bin 2> /dev/null > /tmp/exe$$
pascal@14261 98 ddq if=/tmp/exe$$ of=$1 bs=128 count=1 conv=notrunc
pascal@14266 99 store $((0x94)) $((0xE0 - 12*8)) $1
pascal@14266 100 store $((0xF4)) $((16 - 12)) $1
pascal@14267 101 ddq if=$1 of=/tmp/coff$$ bs=1 skip=$((0x178)) count=$((0x88))
pascal@14267 102 ddq if=/tmp/coff$$ of=$1 conv=notrunc bs=1 seek=$((0x178 - 12*8))
pascal@17810 103 ddq if=/tmp/exe$$ of=$1 bs=1 count=24 seek=$((0x1A0)) skip=$((0x1A0)) conv=notrunc
pascal@17810 104 ddq if=$2 bs=1 skip=$((0x1B8)) seek=$((0x1B8)) count=72 of=$1 conv=notrunc
pascal@17810 105 store 417 $(($SIZE/512)) $1 8
pascal@14261 106 store 510 $((0xAA55)) $1
pascal@14267 107 rm -f /tmp/exe$$ /tmp/coff$$
pascal@17454 108 printf "Moving syslinux hybrid boot record at %04X (512 bytes) ...\n" $SIZE
pascal@14261 109 ddq if=$2 bs=1 count=512 of=$1 seek=$SIZE conv=notrunc
pascal@14261 110 OFS=$(($SIZE+512))
pascal@14257 111 }
pascal@14257 112
pascal@14257 113 add_fdbootstrap()
pascal@14257 114 {
pascal@14268 115 SIZE=$($0 --get bootfd.bin 2> /dev/null | wc -c)
pascal@14257 116 if [ $SIZE -ne 0 ]; then
pascal@17454 117 SIZE=$(( $SIZE - 512 )) # sector 2 is data
pascal@17454 118 OFS=$(( $OFS - $SIZE ))
pascal@17454 119 printf "Adding floppy bootstrap file at %04X (%d bytes) ...\n" $OFS $SIZE
pascal@14268 120 $0 --get bootfd.bin | \
pascal@14268 121 ddq of=$1 bs=1 count=512 seek=$OFS conv=notrunc
pascal@14268 122 $0 --get bootfd.bin | \
pascal@14268 123 ddq of=$1 bs=1 skip=1024 seek=$((512 + $OFS)) conv=notrunc
pascal@17810 124 store 26 $(($SIZE/512)) $1 8
pascal@14257 125 fi
pascal@14150 126 }
pascal@18670 127
pascal@18804 128 fileofs()
pascal@18804 129 {
pascal@18804 130 [ $(get 1024 $ISO) -eq 35615 ] && i=1024 || i=$((512*(1+$(get 417 $ISO 1))))
pascal@18804 131 stub=$(($(get 20 $ISO) - 0xC0))
pascal@18804 132 SIZE=0; OFFSET=0
pascal@18804 133 case "$1" in
pascal@18804 134 win32.exe) [ $i -eq 1024 ] || SIZE=$(($i - 512));;
pascal@18804 135 syslinux.mbr) [ $i -eq 1024 ] || OFFSET=$(($i - 512)); SIZE=512;;
pascal@18804 136 flavor.info) OFFSET=$i; SIZE=-1;;
pascal@18804 137 floppy.boot) SIZE=$(($(get 26 $ISO 1)*512))
pascal@18804 138 OFFSET=$(($(get 64 $ISO) - 0xC0 - $SIZE));;
pascal@18804 139 rootfs.gz) SIZE=$(get 24 $ISO); OFFSET=$(($stub - $SIZE));;
pascal@18804 140 tazboot.com) OFFSET=$(($(get 64 $ISO) - 0xC0))
pascal@18804 141 SIZE=$(($stub - $(get 24 $ISO) - $OFFSET));;
pascal@18804 142 dosstub) OFFSET=$stub; SIZE=$((0x8000 - $OFFSET));;
pascal@18804 143 md5) OFFSET=$((0x7FF0)); SIZE=16;;
pascal@18804 144 esac
pascal@18804 145 }
pascal@18804 146
pascal@18804 147 list()
pascal@18804 148 {
pascal@18804 149 for f in win32.exe syslinux.mbr flavor.info floppy.boot \
pascal@18804 150 dosstub rootfs.gz tazboot.com md5 ; do
pascal@18804 151 fileofs $f
pascal@18804 152 [ $SIZE -eq 0 ] && continue
pascal@18804 153 echo -n "$f at $(printf "%X\n" $OFFSET)"
pascal@18804 154 [ $SIZE -eq -1 ] || echo -n " ($SIZE bytes)"
pascal@18804 155 echo .
pascal@18804 156 done
pascal@18804 157 }
pascal@18804 158
pascal@18804 159 extract()
pascal@18804 160 {
pascal@18804 161 for f in $@; do
pascal@18804 162 fileofs $f
pascal@18804 163 case "$SIZE" in
pascal@18804 164 0) ;;
pascal@18804 165 -1) ddq bs=1 count=20480 skip=$OFFSET if="$ISO" | zcat >$f ;;
pascal@18804 166 *) ddq bs=1 count=$SIZE skip=$OFFSET if="$ISO" >$f ;;
pascal@18804 167 esac
pascal@18804 168 done
pascal@18804 169 }
pascal@18804 170
pascal@18670 171 custom_config_sector()
pascal@18670 172 {
pascal@18670 173 echo $(($(get 32848 "$1" 4)+16))
pascal@18670 174 }
pascal@18670 175
pascal@18773 176 clear_custom_config()
pascal@18773 177 {
pascal@18773 178 start=$(custom_config_sector $1)
pascal@18773 179 cnt=$((512 - ($start % 512)))
pascal@18773 180 [ $cnt -ne 512 ] &&
pascal@18773 181 ddq if=/dev/zero of=$1 bs=2k seek=$start count=$cnt
pascal@18773 182 }
pascal@18773 183
pascal@18670 184 extract_custom_config()
pascal@18670 185 {
pascal@18670 186 ISO="$1"
pascal@18670 187 header=
pascal@18670 188 ddq bs=2k skip=$(custom_config_sector "$ISO") if="$ISO" | \
pascal@18670 189 while read line; do
pascal@18670 190 case "$line" in
pascal@18670 191 \#!boot*) header=1 ;;
pascal@18670 192 append=*) [ "$header" ] &&
pascal@18670 193 echo "${line#append=}" > "$ISO.append" &&
pascal@18670 194 ls -l "$ISO.append" ;;
pascal@18670 195 initrd:*) [ "$header" ] &&
pascal@18670 196 ddq bs=1 count=${line#initrd:} > "$ISO.initrd" &&
pascal@18670 197 ls -l "$ISO.initrd" ;;
pascal@18670 198 esac
pascal@18670 199 [ "$header" ] || break
pascal@18670 200 done
pascal@18670 201 }
pascal@14150 202 case "$1" in
pascal@14150 203 --build)
pascal@14150 204 shift
pascal@14261 205 ls -l $@
pascal@14150 206 cat >> $0 <<EOM
pascal@17476 207 $(tar cf - $@ | compress | uuencode -m -)
pascal@14150 208 EOT
pascal@14150 209 EOM
pascal@14150 210 sed -i '/^case/,/^esac/d' $0
pascal@14150 211 exit ;;
pascal@14150 212 --get)
pascal@14150 213 cat $2
pascal@14150 214 exit ;;
pascal@14150 215 --array)
pascal@14150 216 DATA=/tmp/dataiso$$
pascal@14150 217 ddq if=/dev/zero bs=32k count=1 of=$DATA
pascal@14261 218 add_win32exe $DATA $2 > /dev/null
pascal@14261 219 HSZ=$OFS
pascal@14261 220 add_dosexe $DATA > /dev/null
pascal@14150 221 add_rootfs $DATA > /dev/null
pascal@14150 222 add_doscom $DATA > /dev/null
pascal@14257 223 add_fdbootstrap $DATA > /dev/null
pascal@14257 224 name=${3:-bootiso}
pascal@17451 225 BOOTISOSZ=$((0x8000 - $OFS + $HSZ))
pascal@14150 226 cat <<EOT
pascal@14150 227
pascal@17451 228 #define $(echo $name | tr '[a-z]' '[A-Z]')SZ $BOOTISOSZ
pascal@14150 229
pascal@18775 230 #ifndef __MSDOS__
pascal@14257 231 static char $name[] = {
pascal@17591 232 /* head */
pascal@14261 233 $(hexdump -v -n $HSZ -e '" " 16/1 "0x%02X, "' -e '" // %04.4_ax |" 16/1 "%_p" "| \n"' $DATA | sed 's/ 0x ,/ /g')
pascal@17591 234 /* tail */
pascal@14150 235 $(hexdump -v -s $OFS -e '" " 16/1 "0x%02X, "' -e '" // %04.4_ax |" 16/1 "%_p" "| \n"' $DATA | sed 's/ 0x ,/ /g')
pascal@17591 236
pascal@17591 237 /* These strange constants are defined in RFC 1321 as
pascal@17591 238 T[i] = (int)(4294967296.0 * fabs(sin(i))), i=1..64
pascal@17591 239 */
pascal@17591 240 /* static const uint32_t C_array[64] */
pascal@17591 241 EOT
pascal@17591 242 while read a b c d; do
pascal@17591 243 for i in $a $b $c $d; do
pascal@17591 244 echo $i | sed 's/0x\(..\)\(..\)\(..\)\(..\),/0x\4, 0x\3, 0x\2, 0x\1, /'
pascal@17591 245 done
pascal@17591 246 done <<EOT
pascal@17591 247 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
pascal@17591 248 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
pascal@17591 249 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
pascal@17591 250 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
pascal@17591 251 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
pascal@17591 252 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
pascal@17591 253 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
pascal@17591 254 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
pascal@17591 255 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
pascal@17591 256 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
pascal@17591 257 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05,
pascal@17591 258 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
pascal@17591 259 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
pascal@17591 260 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
pascal@17591 261 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
pascal@17591 262 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,
pascal@17591 263 EOT
pascal@17591 264 cat <<EOT
pascal@17591 265 /* static const char P_array[64] */
pascal@17591 266 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 1 */
pascal@17591 267 1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, /* 2 */
pascal@17591 268 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, /* 3 */
pascal@17591 269 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9, /* 4 */
pascal@17591 270 /* static const char S_array[16] */
pascal@17591 271 7, 12, 17, 22,
pascal@17591 272 5, 9, 14, 20,
pascal@17591 273 4, 11, 16, 23,
pascal@17591 274 6, 10, 15, 21,
pascal@17451 275 EOT
pascal@17451 276
pascal@17451 277 for mode in data offset ; do
pascal@17451 278 ofs=0
pascal@17451 279 while read tag str; do
pascal@17451 280 if [ "$mode" == "data" ]; then
pascal@17451 281 echo -en "$str\0" | hexdump -v -e '" " 16/1 "0x%02X, "' \
pascal@17451 282 -e '" // %04.4_ax |" 16/1 "%_p" "| \n"' | \
pascal@17451 283 sed 's/ 0x ,/ /g'
pascal@17451 284 else
pascal@17451 285 if [ $ofs -eq 0 ]; then
pascal@17451 286 cat <<EOT
pascal@14150 287 };
pascal@17451 288 #else
pascal@17451 289 static char *$name;
pascal@14150 290 #endif
pascal@17591 291
pascal@17591 292 #define C_array (uint32_t *) ($name + $(($BOOTISOSZ)))
pascal@17591 293 #define P_array (char *) ($name + $(($BOOTISOSZ+(64*4))))
pascal@17591 294 #define S_array (char *) ($name + $(($BOOTISOSZ+(64*4)+64)))
pascal@17451 295 #define ELTORITOOFS 3
pascal@14150 296 EOT
pascal@17451 297 fi
pascal@17591 298 echo "#define $tag $(($BOOTISOSZ+(64*4)+64+16+$ofs))"
pascal@17451 299 ofs=$(($(echo -en "$str\0" | wc -c)+$ofs))
pascal@17451 300 fi
pascal@17451 301 done <<EOT
pascal@17451 302 READSECTORERR Read sector failure.
pascal@18775 303 USAGE Usage: isohybrid.exe [--append cmdline] [--initrd file] file.iso [--forced|--undo|--quick]
pascal@17451 304 OPENERR Can't open r/w the iso file.
pascal@17451 305 ELTORITOERR No EL TORITO SPECIFICATION signature.
pascal@17451 306 CATALOGERR Invalid boot catalog.
pascal@17451 307 HYBRIDERR No isolinux.bin hybrid signature.
paul@17671 308 SUCCESSMSG Now you can create a USB key with your .iso file.\\\\nSimply rename it to an .exe file and run it.
pascal@17451 309 FORCEMSG You can add --forced to proceed anyway.
pascal@17591 310 MD5MSG Computing md5sum...
pascal@17591 311 UNINSTALLMSG Uninstall done.
pascal@18775 312 OPENINITRDERR Can't open the initrd file.
pascal@18780 313 ALREADYEXEERR Already an EXE file.
pascal@17451 314 EOT
pascal@17451 315 done
pascal@14150 316 rm -rf $DATA
pascal@14150 317 exit ;;
pascal@14150 318 --exe)
pascal@14150 319 # --exe mvcom.bin x.com y.exe > xy.exe
pascal@14150 320 cat $4 $3 > /tmp/exe$$
pascal@14150 321 S=$(stat -c %s /tmp/exe$$)
pascal@14150 322 store 2 $(($S%512)) /tmp/exe$$
pascal@14150 323 store 4 $((($S+511)/512)) /tmp/exe$$
pascal@14150 324 store 14 -16 /tmp/exe$$
pascal@14150 325 store 16 -2 /tmp/exe$$
pascal@14150 326 store 20 256 /tmp/exe$$
pascal@14150 327 store 22 -16 /tmp/exe$$
pascal@14150 328 ddq if=$2 bs=1 seek=64 of=/tmp/exe$$ conv=notrunc
pascal@14150 329 store 65 $(stat -c %s $3) /tmp/exe$$
pascal@14150 330 store 68 $((0x100-0x40+$(stat -c %s $4))) /tmp/exe$$
pascal@14150 331 cat /tmp/exe$$
pascal@14150 332 rm -f /tmp/exe$$
pascal@14150 333 exit ;;
pascal@14150 334 esac
pascal@14150 335
pascal@14150 336 main()
pascal@14150 337 {
pascal@18802 338 [ $(id -u) -ne 0 ] && cmd="$0 $@" && exec su -c "$cmd" < /dev/tty
pascal@18670 339 append=
pascal@18670 340 initrd=
pascal@18670 341 while [ "$1" ]; do
pascal@18670 342 case "${1/--/-}" in
pascal@18670 343 -get) shift
pascal@18670 344 uudecode | unlzma | tar xOf - $@
pascal@18670 345 exit ;;
pascal@18670 346 -a*) append="$2" ; shift 2 ;;
pascal@18670 347 -i*) initrd="$2" ; shift 2 ;;
pascal@18670 348 -e*) extract_custom_config "$2"
pascal@18670 349 exit ;;
pascal@18804 350 -r*) ISO="$2" ; shift 2
pascal@18804 351 [ -z "$1" ] && list || extract $@
pascal@18804 352 exit ;;
pascal@18670 353 *) cat > /dev/null
pascal@18670 354 break
pascal@18670 355 esac
pascal@18670 356 done
pascal@14150 357
pascal@18670 358 [ ! -s "$1" ] && cat 1>&2 <<EOT && exit 1
pascal@18773 359 usage: $0 [--append custom_cmdline ] [ --initrd custom_initramfs ] image.iso [--force|--undo|"DOS help message"]
pascal@18670 360 or: $0 --extract-custom-config image.iso
pascal@18670 361 EOT
pascal@17451 362 case "${2/--/-}" in
pascal@17451 363 -u*|-r*|-w*)
pascal@17451 364 case "$(get 0 $1)" in
pascal@17451 365 23117)
pascal@18063 366 b=$(get 417 $1 1)
pascal@18063 367 n=$(($(get 64 $1) + 0xC0 - ($(get 26 $1 1)*512) - ($b+1)*512))
pascal@18063 368 ddq if=$1 bs=512 count=1 skip=$b of=$1 conv=notrunc
pascal@18063 369 ddq if=/dev/zero bs=512 seek=1 count=1 of=$1 conv=notrunc
pascal@18063 370 ddq if=$1 bs=512 seek=2 count=30 skip=$(($b+1)) of=$1 conv=notrunc
pascal@18063 371 ddq if=/dev/zero bs=1 seek=$n count=$((0x8000 - $n)) of=$1 conv=notrunc ;;
pascal@17451 372 *) ddq if=/dev/zero bs=1k count=32 of=$1 conv=notrunc ;;
pascal@17451 373 esac
pascal@18802 374 clear_custom_config $1
pascal@18776 375 exit 0 ;;
pascal@18773 376 -f*)
pascal@18773 377 ddq if=/dev/zero bs=1k count=32 of=$1 conv=notrunc
pascal@18802 378 [ "$append$initrd" ] && clear_custom_config $1
pascal@17451 379 esac
pascal@14150 380 case "$(get 0 $1)" in
pascal@14150 381 23117) echo "The file $1 is already an EXE file." 1>&2 && exit 1;;
pascal@17812 382 0) [ -x /usr/bin/isohybrid ] && isohybrid $1;;
pascal@14150 383 esac
pascal@14150 384
pascal@14261 385 echo "Read hybrid & tazlito data..."
pascal@14261 386 ddq if=$1 bs=512 count=1 of=/tmp/hybrid$$
pascal@14261 387 ddq if=$1 bs=512 skip=2 count=20 of=/tmp/tazlito$$
pascal@14261 388 add_win32exe $1 /tmp/hybrid$$
pascal@18062 389 add_tazlito_info $1 /tmp/tazlito$$
pascal@14261 390 rm -f /tmp/tazlito$$ /tmp/hybrid$$
pascal@14150 391
pascal@14150 392 # keep the largest room for the tazlito info file
pascal@14261 393 add_dosexe $1
pascal@14150 394 add_rootfs $1
pascal@14150 395 add_doscom $1
pascal@14257 396 add_fdbootstrap $1
pascal@17454 397 printf "%d free bytes in %04X..%04X\n" $(($OFS-$HOLE)) $HOLE $OFS
pascal@17810 398 store 440 $(date +%s) $1 32
pascal@17562 399 [ "$2" ] && echo "$2 " | \
pascal@17562 400 ddq bs=1 seek=$((0x7FDE)) count=15 conv=notrunc of=$1
pascal@17562 401 if [ $(stat -c %s $1) -gt 34816 ]; then
pascal@17562 402 echo "Adding ISO image md5 at 7FF0 (16 bytes) ..."
pascal@17591 403 echo -en "$(ddq if=$1 bs=2k skip=16 count=$(get 32848 $1 4) | \
pascal@17562 404 md5sum | cut -c-32 | sed 's/\(..\)/\\x\1/g')" | \
pascal@17562 405 ddq bs=16 seek=2047 conv=notrunc of=$1
pascal@17496 406 fi
pascal@17496 407 echo -n "Adding boot checksum..."
pascal@17496 408 if [ $(stat -c %s $1) -gt 32768 ]; then
pascal@17496 409 n=$(($(get 2 $1) - 1 + ($(get 4 $1) - 1)*512))
pascal@17496 410 n=$(($(od -v -N $n -t u2 -w2 -An $1 | \
pascal@17496 411 awk '{ i+= $0 } END { print (i % 65536) }') \
pascal@17496 412 + $(get $(($n+1)) $1 1)))
pascal@17496 413 store 18 $(( (-$n -1) % 65536 )) $1
pascal@17496 414 fi
pascal@13697 415 echo " done."
pascal@18670 416 if [ "$append$initrd" ]; then
pascal@18670 417 echo -n "Adding custom config... "
pascal@18676 418 DATA=/tmp/$(basename $0)$$
pascal@18670 419 rm -f $DATA > /dev/null
pascal@18672 420 isosz=$(stat -c %s $1)
pascal@18670 421 [ "$append" ] && echo "append=$append" >> $DATA
pascal@18670 422 [ -s "$initrd" ] && echo "initrd:$(stat -c %s $initrd)" >> $DATA &&
pascal@18670 423 cat $initrd >> $DATA
pascal@18670 424 echo "#!boot $(md5sum $DATA | sed 's/ .*//')" | cat - $DATA | \
pascal@18672 425 ddq bs=2k seek=$(custom_config_sector $1) of=$1 conv=notrunc
pascal@18672 426 if [ $(stat -c %s $1) -gt $isosz ]; then
pascal@18675 427 echo "$(($(stat -c %s $1) - $isosz)) extra bytes."
pascal@18670 428 else
pascal@18672 429 echo "$(($isosz - 32768 - 2048*$(get 32848 $1 4)
pascal@18670 430 - $(stat -c %s $DATA) - 24)) bytes free."
pascal@18670 431 fi
pascal@18670 432 rm -f $DATA > /dev/null
pascal@18670 433 fi
pascal@13691 434 }
pascal@13691 435
pascal@18672 436 main "$@" <<EOT