#!/bin/sh

# If this script is interrupted, it may not clean up after itself.
# In particular, it may leave ${TARGET}1 mounted somewhere in tmp.
# Unmount it, then kpartx -d $TARGET to clean up.

export PATH #WTF?

LVNAME="$1"
export HOSTNAME="$2"
export DIST="$3"
export MIRROR="$4"
export IMAGESIZE="$5"  # in megabytes
export IP="$6"

export ARCH=amd64

#LVSIZE=`lvs --noheadings --units M --nosuffix -o Size /dev/xenvg/d_foobar_hda | sed 's/\..*//'`

if [ -z "$IP" ]; then
    IP=`host $HOSTNAME.xvm.mit.edu | sed 's/.* //' | head -n 1`
fi

export TARGET=/dev/mapper/xenvg-$(echo "$LVNAME" | sed -e 's/-/--/g')_hda

/usr/sbin/sipb-xen-create-image

