2014-03-08 02:34:09 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
2014-03-08 05:34:51 +00:00
|
|
|
source common/ui.sh
|
2014-03-08 02:34:09 +00:00
|
|
|
|
2014-03-09 06:55:10 +00:00
|
|
|
# TODO: Create file with build date / time on container
|
|
|
|
|
2014-03-08 05:34:51 +00:00
|
|
|
info "Packaging '${CONTAINER}' to '${PACKAGE}'..."
|
2014-03-08 13:42:28 +00:00
|
|
|
|
|
|
|
debug 'Stopping container'
|
|
|
|
lxc-stop -n ${CONTAINER} &>/dev/null || true
|
|
|
|
|
2014-03-09 06:55:10 +00:00
|
|
|
if [ -f ${WORKING_DIR}/rootfs.tar.gz ]; then
|
2014-03-09 07:18:10 +00:00
|
|
|
log "Removing previous rootfs tarball"
|
2014-03-09 06:55:10 +00:00
|
|
|
rm -f ${WORKING_DIR}/rootfs.tar.gz
|
|
|
|
fi
|
2014-03-08 13:42:28 +00:00
|
|
|
|
|
|
|
log "Compressing container's rootfs"
|
2014-03-09 23:20:37 +00:00
|
|
|
pushd $(dirname ${ROOTFS}) &>>${LOG}
|
2014-03-09 06:55:10 +00:00
|
|
|
tar --numeric-owner --anchored --exclude=./rootfs/dev/log -czf \
|
|
|
|
${WORKING_DIR}/rootfs.tar.gz ./rootfs/*
|
2014-03-09 23:20:37 +00:00
|
|
|
popd &>>${LOG}
|
2014-03-08 13:42:28 +00:00
|
|
|
|
|
|
|
# Prepare package contents
|
2014-03-09 07:18:10 +00:00
|
|
|
log 'Preparing box package contents'
|
|
|
|
cp common/lxc-template ${WORKING_DIR}
|
2014-03-10 01:54:29 +00:00
|
|
|
cp conf/${DISTRIBUTION} ${WORKING_DIR}/lxc-config
|
2014-03-09 07:18:10 +00:00
|
|
|
cp conf/metadata.json ${WORKING_DIR}
|
|
|
|
sed -i "s/<TODAY>/${NOW}/" ${WORKING_DIR}/metadata.json
|
|
|
|
|
|
|
|
# Vagrant box!
|
|
|
|
log 'Packaging box'
|
|
|
|
TARBALL=$(readlink -f ${PACKAGE})
|
|
|
|
(cd ${WORKING_DIR} && tar -czf $TARBALL ./*)
|