2014-03-08 02:34:09 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
2014-03-08 04:47:13 +00:00
|
|
|
source common/ui.sh
|
2014-03-09 22:34:59 +00:00
|
|
|
source common/utils.sh
|
2014-03-08 04:47:13 +00:00
|
|
|
|
|
|
|
# If container exists, check if want to continue
|
2014-03-08 05:23:06 +00:00
|
|
|
if $(lxc-ls | grep -q ${CONTAINER}); then
|
|
|
|
if ! $(confirm "The '${CONTAINER}' container already exists, do you want to continue building the box?" 'y'); then
|
2014-03-08 04:47:13 +00:00
|
|
|
log 'Aborting...'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If container exists and wants to continue building the box
|
2014-03-08 05:23:06 +00:00
|
|
|
if $(lxc-ls | grep -q ${CONTAINER}); then
|
2014-03-08 04:47:13 +00:00
|
|
|
if $(confirm "Do you want to rebuild the '${CONTAINER}' container?" 'n'); then
|
|
|
|
log "Destroying container ${CONTAINER}..."
|
2014-03-09 22:34:59 +00:00
|
|
|
utils.lxc.stop
|
|
|
|
utils.lxc.destroy
|
2014-03-08 04:47:13 +00:00
|
|
|
else
|
|
|
|
log "Reusing existing container..."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If we got to this point, we need to create the container
|
|
|
|
log "Creating container..."
|
2014-03-09 20:54:03 +00:00
|
|
|
if [ $RELEASE = 'raring' ]; then
|
2014-03-09 22:34:59 +00:00
|
|
|
utils.lxc.create -t ubuntu -- \
|
|
|
|
--release ${RELEASE} \
|
|
|
|
--arch ${ARCH}
|
2014-03-10 01:54:29 +00:00
|
|
|
elif [ $RELEASE = 'squeeze' ]; then
|
|
|
|
utils.lxc.create -t debian -- \
|
|
|
|
--release ${RELEASE} \
|
|
|
|
--arch ${ARCH}
|
2014-03-09 20:54:03 +00:00
|
|
|
else
|
2014-03-09 22:34:59 +00:00
|
|
|
utils.lxc.create -t download -- \
|
|
|
|
--dist ${DISTRIBUTION} \
|
|
|
|
--release ${RELEASE} \
|
|
|
|
--arch ${ARCH}
|
2014-03-09 20:54:03 +00:00
|
|
|
fi
|
2014-03-08 05:23:06 +00:00
|
|
|
log "Container created!"
|