#!/bin/bash
for x in $(cat /proc/cmdline); do
    case $x in
	ip=*)
	/usr/lib/klibc/bin/ipconfig -d ${x#ip=}
	;;
	mirror=*)
	MIRROR=${x#mirror=}
	;;
	dist=*)
	DIST=${x#dist=}
	;;
	arch=*)
	ARCH=${x#arch=}
	;;
	imagesize=*)
	IMAGESIZE=${x#imagesize=}
	;;
	noinstall)
	exit 0
	;;
    esac
done
mount -t tmpfs none /var/log
mount -t tmpfs none /tmp


TARGET=/dev/hda
ARCH=${ARCH-amd64}
IP=$(ifconfig eth0 | sed -n 's/.*inet addr:\([0-9\.]*\).*/\1/p')
HOSTNAME=$(hostname)

echo ,${IMAGESIZE}$',L,*\n,,S\n;\n;' | sfdisk -uM -H 255 -S 63 $TARGET

xen-create-image --image-dev ${TARGET}1 --swap-dev ${TARGET}2 --fs ext3 --ide --arch $ARCH --dist $DIST --hostname $HOSTNAME --mirror $MIRROR --ip=$IP --netmask=255.255.0.0 --gateway=18.181.0.1 --cache=yes

busybox poweroff
exit 0
