#! /bin/bash

# mkwiniso version 0.1
# usage: mkwiniso image.iso /path/to/xpcd
#
# by Sam Morris <sam@robots.org.uk>. mkisofs incantation inspired by 
# <871xwc7yem.fsf_wer_das_quoted_hat_verloren@dabetteros.oche.de>
#
# This script makes a bootable CD image from a directory of Windows XP (and
# 2000?) installation files. Useful for creating a "slipstream" CD image from a
# service pack.

# Drop the desired boot sector, named "boot.bin" into the directory of Windows
# files.

set -eu

# Ensure destination file name ends in .iso
isofile="${1%.iso}.iso"

source="$2"

# Find boot image
pushd "$source" > /dev/null
boot="$(find -name boot.bin | head --lines=1 | cut -c 3-)"
popd            > /dev/null

# Confirm
cat <<- EOF
Source: $source
Boot: $boot
Target: $isofile

EOF
read -p "Proceed? "

mkisofs -o "$isofile"                           \
        -b "$boot" -no-emul-boot                \
        -J -l -D -N -relaxed-filenames          \
        "$source"
