2014-03-08 02:34:09 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
2014-03-08 04:47:13 +00:00
|
|
|
source common/ui.sh
|
|
|
|
|
|
|
|
# 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}..."
|
|
|
|
lxc-stop -n ${CONTAINER} &>/dev/null || true
|
|
|
|
lxc-destroy -n ${CONTAINER}
|
|
|
|
else
|
|
|
|
log "Reusing existing container..."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If we got to this point, we need to create the container
|
|
|
|
log "Creating container..."
|
|
|
|
lxc-create -n ${CONTAINER} -t download -- \
|
|
|
|
--dist ${DISTRIBUTION} \
|
|
|
|
--release ${RELEASE} \
|
|
|
|
--arch ${ARCH}
|
2014-03-09 06:55:10 +00:00
|
|
|
|
|
|
|
# TODO: Nicely handle boxes that don't have an image associated
|
|
|
|
|
2014-03-08 05:23:06 +00:00
|
|
|
log "Container created!"
|
2014-03-09 20:25:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Fixes some networking issues
|
|
|
|
# See https://github.com/fgrehm/vagrant-lxc/issues/91 for more info
|
|
|
|
if ! $(grep -q 'ip6-allhosts' ${ROOTFS}/etc/hosts); then
|
|
|
|
log "Adding ipv6 allhosts entry to container's /etc/hosts"
|
|
|
|
echo 'ff02::3 ip6-allhosts' >> ${ROOTFS}/etc/hosts
|
|
|
|
fi
|