bc8b070565
I've been hacking my way through building vagrant boxes in unprivileged containers. It works. Barely but it works. I can end up with a functional vagrant box with `make stretch`. The only place where I need `sudo` is when we tar up the root fs because it doesn't belong to the same UID.
45 lines
1.3 KiB
Bash
Executable file
45 lines
1.3 KiB
Bash
Executable file
#!/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..."
|
|
utils.lxc.create -t download -- \
|
|
--dist ${DISTRIBUTION} \
|
|
--release ${RELEASE} \
|
|
--arch ${ARCH}
|
|
|
|
# Improve systemd support:
|
|
# - The fedora template does it but the fedora images from the download
|
|
# template apparently don't.
|
|
# - The debian template does it but the debian image from the download
|
|
# template apparently not.
|
|
utils.lxc.stop
|
|
cfgpath="${HOME}/.local/share/lxc/${CONTAINER}/config"
|
|
echo >> ${cfgpath}
|
|
echo "# settings for systemd with PID 1:" >> ${cfgpath}
|
|
echo "lxc.autodev = 1" >> ${cfgpath}
|
|
|
|
log "Container created!"
|