2014-03-25 03:26:19 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
|
|
|
source common/ui.sh
|
|
|
|
source common/utils.sh
|
|
|
|
|
|
|
|
# If container exists, check if want to continue
|
|
|
|
if $(lxc-ls | grep -q ${CONTAINER}); then
|
|
|
|
if ! $(confirm "The '${CONTAINER}' container already exists, do you want to continue building the box?" 'y'); then
|
|
|
|
log 'Aborting...'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If container exists and wants to continue building the box
|
|
|
|
if $(lxc-ls | grep -q ${CONTAINER}); then
|
|
|
|
if $(confirm "Do you want to rebuild the '${CONTAINER}' container?" 'n'); then
|
|
|
|
log "Destroying container ${CONTAINER}..."
|
|
|
|
utils.lxc.stop
|
|
|
|
utils.lxc.destroy
|
|
|
|
else
|
|
|
|
log "Reusing existing container..."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If we got to this point, we need to create the container
|
|
|
|
log "Creating container..."
|
2016-03-12 20:01:32 +00:00
|
|
|
if [ $RELEASE = 'raring' ] || [ $RELEASE = 'wily' ] || [ $RELEASE = 'xenial' ]; then
|
2014-03-25 03:26:19 +00:00
|
|
|
utils.lxc.create -t ubuntu -- \
|
|
|
|
--release ${RELEASE} \
|
|
|
|
--arch ${ARCH}
|
2014-09-23 03:31:10 +00:00
|
|
|
elif [ $RELEASE = 'squeeze' ] || [ $RELEASE = 'wheezy' ]; then
|
2014-03-25 03:26:19 +00:00
|
|
|
utils.lxc.create -t debian -- \
|
|
|
|
--release ${RELEASE} \
|
|
|
|
--arch ${ARCH}
|
2015-01-24 18:14:59 +00:00
|
|
|
elif [ ${DISTRIBUTION} = 'fedora' -a "${RELEASE}" = 'rawhide' ]; then
|
|
|
|
ARCH=$(echo ${ARCH} | sed -e "s/38/68/" | sed -e "s/amd64/x86_64/")
|
|
|
|
utils.lxc.create -t fedora --\
|
|
|
|
--release ${RELEASE} \
|
|
|
|
--arch ${ARCH}
|
2015-12-15 17:09:57 +00:00
|
|
|
elif [ ${DISTRIBUTION} = 'fedora' -a ${RELEASE} -ge 21 ]; then
|
2014-12-23 00:12:31 +00:00
|
|
|
ARCH=$(echo ${ARCH} | sed -e "s/38/68/" | sed -e "s/amd64/x86_64/")
|
|
|
|
utils.lxc.create -t fedora --\
|
|
|
|
--release ${RELEASE} \
|
|
|
|
--arch ${ARCH}
|
2014-03-25 03:26:19 +00:00
|
|
|
else
|
|
|
|
utils.lxc.create -t download -- \
|
|
|
|
--dist ${DISTRIBUTION} \
|
|
|
|
--release ${RELEASE} \
|
|
|
|
--arch ${ARCH}
|
|
|
|
fi
|
2015-12-15 16:52:17 +00:00
|
|
|
if [ ${DISTRIBUTION} = 'fedora' ] ||\
|
|
|
|
[ ${DISTRIBUTION} = 'ubuntu' -a ${RELEASE} = 'wily' ] ||\
|
|
|
|
[ ${DISTRIBUTION} = 'debian' -a ${RELEASE} = 'jessie' ]
|
2015-01-05 01:25:23 +00:00
|
|
|
then
|
2014-12-22 17:16:45 +00:00
|
|
|
# Improve systemd support:
|
|
|
|
# - The fedora template does it but the fedora images from the download
|
|
|
|
# template apparently don't.
|
2015-01-05 01:25:23 +00:00
|
|
|
# - The debian template does it but the debian image from the download
|
|
|
|
# template apparently not.
|
2014-12-22 17:16:45 +00:00
|
|
|
utils.lxc.stop
|
|
|
|
echo >> /var/lib/lxc/${CONTAINER}/config
|
|
|
|
echo "# settings for systemd with PID 1:" >> /var/lib/lxc/${CONTAINER}/config
|
|
|
|
echo "lxc.kmsg = 0" >> /var/lib/lxc/${CONTAINER}/config
|
|
|
|
echo "lxc.autodev = 1" >> /var/lib/lxc/${CONTAINER}/config
|
|
|
|
utils.lxc.start
|
2015-01-08 22:43:04 +00:00
|
|
|
utils.lxc.attach rm -f /dev/kmsg
|
|
|
|
utils.lxc.stop
|
2014-12-22 17:16:45 +00:00
|
|
|
fi
|
|
|
|
|
2014-03-25 03:26:19 +00:00
|
|
|
log "Container created!"
|