Improved base boxes scripts UI and implement prepare-vagrant-user.sh
This commit is contained in:
parent
12bc88805a
commit
dce843db12
4 changed files with 57 additions and 13 deletions
|
@ -3,17 +3,16 @@ set -e
|
||||||
|
|
||||||
source common/ui.sh
|
source common/ui.sh
|
||||||
|
|
||||||
container_exists=$(lxc-ls | grep -q ${CONTAINER})
|
|
||||||
# If container exists, check if want to continue
|
# If container exists, check if want to continue
|
||||||
if $container_exists; then
|
if $(lxc-ls | grep -q ${CONTAINER}); then
|
||||||
if ! $(confirm "The '${CONTAINER}' container already exists, do you want to continue building the box?" 'n'); then
|
if ! $(confirm "The '${CONTAINER}' container already exists, do you want to continue building the box?" 'y'); then
|
||||||
log 'Aborting...'
|
log 'Aborting...'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If container exists and wants to continue building the box
|
# If container exists and wants to continue building the box
|
||||||
if $container_exists; then
|
if $(lxc-ls | grep -q ${CONTAINER}); then
|
||||||
if $(confirm "Do you want to rebuild the '${CONTAINER}' container?" 'n'); then
|
if $(confirm "Do you want to rebuild the '${CONTAINER}' container?" 'n'); then
|
||||||
log "Destroying container ${CONTAINER}..."
|
log "Destroying container ${CONTAINER}..."
|
||||||
lxc-stop -n ${CONTAINER} &>/dev/null || true
|
lxc-stop -n ${CONTAINER} &>/dev/null || true
|
||||||
|
@ -30,3 +29,4 @@ lxc-create -n ${CONTAINER} -t download -- \
|
||||||
--dist ${DISTRIBUTION} \
|
--dist ${DISTRIBUTION} \
|
||||||
--release ${RELEASE} \
|
--release ${RELEASE} \
|
||||||
--arch ${ARCH}
|
--arch ${ARCH}
|
||||||
|
log "Container created!"
|
||||||
|
|
|
@ -1,6 +1,39 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
container_name=$1
|
source common/ui.sh
|
||||||
|
|
||||||
echo " Will prepare the vagrant user on '${container_name}'"
|
info "Preparing vagrant user..."
|
||||||
|
|
||||||
|
# Create vagrant user
|
||||||
|
if $(grep -q 'vagrant' ${ROOTFS}/etc/shadow); then
|
||||||
|
log 'Skipping vagrant user creation'
|
||||||
|
else
|
||||||
|
debug 'vagrant user does not exist, renaming ubuntu user...'
|
||||||
|
mv ${ROOTFS}/home/{ubuntu,vagrant}
|
||||||
|
chroot ${ROOTFS} usermod -l vagrant -d /home/vagrant ubuntu
|
||||||
|
chroot ${ROOTFS} groupmod -n vagrant ubuntu
|
||||||
|
echo -n 'vagrant:vagrant' | chroot ${ROOTFS} chpasswd
|
||||||
|
log 'Renamed ubuntu user to vagrant and changed password.'
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Configure SSH access
|
||||||
|
if [ -d ${ROOTFS}/home/vagrant/.ssh ]; then
|
||||||
|
log 'Skipping vagrant SSH credentials configuration'
|
||||||
|
else
|
||||||
|
debug 'SSH key has not been set'
|
||||||
|
mkdir -p ${ROOTFS}/home/vagrant/.ssh
|
||||||
|
echo $VAGRANT_KEY > ${ROOTFS}/home/vagrant/.ssh/authorized_keys
|
||||||
|
chroot ${ROOTFS} chown -R vagrant: /home/vagrant/.ssh
|
||||||
|
log 'SSH credentials configured for the vagrant user.'
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Enable passwordless sudo for the vagrant user
|
||||||
|
if [ -f ${ROOTFS}/etc/sudoers.d/vagrant ]; then
|
||||||
|
log 'Skipping sudoers file creation.'
|
||||||
|
else
|
||||||
|
debug 'Sudoers file was not found'
|
||||||
|
echo "vagrant ALL=(ALL) NOPASSWD:ALL" > ${ROOTFS}/etc/sudoers.d/vagrant
|
||||||
|
chmod 0441 ${ROOTFS}/etc/sudoers.d/vagrant
|
||||||
|
log 'Sudoers file created.'
|
||||||
|
fi
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
log() {
|
log() {
|
||||||
echo " ${1}" >&2
|
echo " [${RELEASE}] ${1}" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
debug() {
|
warn() {
|
||||||
[ ! $DEBUG ] || echo " [DEBUG] ${1}" >&2
|
echo -e "${WARN_COLOR}==> [${RELEASE}] ${1}${NO_COLOR}"
|
||||||
|
}
|
||||||
|
|
||||||
|
info() {
|
||||||
|
echo -e "${OK_COLOR}==> [${RELEASE}] ${1}${NO_COLOR}"
|
||||||
}
|
}
|
||||||
|
|
||||||
confirm() {
|
confirm() {
|
||||||
|
@ -21,7 +25,7 @@ confirm() {
|
||||||
default='Yes'
|
default='Yes'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -n " ${question} [${default_prompt}] " >&2
|
echo -e -n "${WARN_COLOR}==> [${RELEASE}] ${question} [${default_prompt}] ${NO_COLOR}" >&2
|
||||||
read answer
|
read answer
|
||||||
|
|
||||||
if [ -z $answer ]; then
|
if [ -z $answer ]; then
|
||||||
|
@ -35,3 +39,7 @@ confirm() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug() {
|
||||||
|
[ ! $DEBUG ] || echo " [${RELEASE}] [DEBUG] ${1}" >&2
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
source common/ui.sh
|
||||||
|
|
||||||
if [ "$(id -u)" != "0" ]; then
|
if [ "$(id -u)" != "0" ]; then
|
||||||
echo "You should run this script as root (sudo)."
|
echo "You should run this script as root (sudo)."
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -16,14 +18,15 @@ export RELEASE=$1
|
||||||
export ARCH=$2
|
export ARCH=$2
|
||||||
export CONTAINER=$3
|
export CONTAINER=$3
|
||||||
export PACKAGE=$4
|
export PACKAGE=$4
|
||||||
|
export ROOTFS="/var/lib/lxc/${CONTAINER}/rootfs"
|
||||||
|
|
||||||
if [ -f ${PACKAGE} ]; then
|
if [ -f ${PACKAGE} ]; then
|
||||||
echo -e "${WARN_COLOR}==> The box '${PACKAGE}' already exists, skipping...${NO_COLOR}"
|
warn "The box '${PACKAGE}' already exists, skipping..."
|
||||||
echo
|
echo
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "${OK_COLOR}==> Building '${RELEASE} (${ARCH})' to '${PACKAGE}'...${NO_COLOR}"
|
info "Building box to '${PACKAGE}'..."
|
||||||
|
|
||||||
./common/download.sh ubuntu ${RELEASE} ${ARCH} ${CONTAINER}
|
./common/download.sh ubuntu ${RELEASE} ${ARCH} ${CONTAINER}
|
||||||
./common/prepare-vagrant-user.sh ${CONTAINER}
|
./common/prepare-vagrant-user.sh ${CONTAINER}
|
||||||
|
@ -32,5 +35,5 @@ echo -e "${OK_COLOR}==> Building '${RELEASE} (${ARCH})' to '${PACKAGE}'...${NO_C
|
||||||
./common/package.sh ${CONTAINER} ${PACKAGE}
|
./common/package.sh ${CONTAINER} ${PACKAGE}
|
||||||
touch $PACKAGE
|
touch $PACKAGE
|
||||||
|
|
||||||
echo -e "${OK_COLOR}==> Finished building '${RELEASE} (${ARCH})' to '${PACKAGE}'...${NO_COLOR}"
|
info "Finished building '${PACKAGE}'!"
|
||||||
echo
|
echo
|
||||||
|
|
Loading…
Reference in a new issue