Implement download step
This commit is contained in:
parent
f070e9ec5b
commit
12bc88805a
2 changed files with 66 additions and 2 deletions
|
@ -1,5 +1,32 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo " Will check if the '${CONTAINER}' exists and error if doesnt"
|
||||
echo " Will create '${CONTAINER}'"
|
||||
source common/ui.sh
|
||||
|
||||
container_exists=$(lxc-ls | grep -q ${CONTAINER})
|
||||
# If container exists, check if want to continue
|
||||
if $container_exists; then
|
||||
if ! $(confirm "The '${CONTAINER}' container already exists, do you want to continue building the box?" 'n'); then
|
||||
log 'Aborting...'
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# If container exists and wants to continue building the box
|
||||
if $container_exists; then
|
||||
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}
|
||||
|
|
37
boxes/common/ui.sh
Normal file
37
boxes/common/ui.sh
Normal file
|
@ -0,0 +1,37 @@
|
|||
#!/bin/bash
|
||||
|
||||
log() {
|
||||
echo " ${1}" >&2
|
||||
}
|
||||
|
||||
debug() {
|
||||
[ ! $DEBUG ] || echo " [DEBUG] ${1}" >&2
|
||||
}
|
||||
|
||||
confirm() {
|
||||
question=${1}
|
||||
default=${2}
|
||||
default_prompt=
|
||||
|
||||
if [ $default = 'n' ]; then
|
||||
default_prompt="y/N"
|
||||
default='No'
|
||||
else
|
||||
default_prompt="Y/n"
|
||||
default='Yes'
|
||||
fi
|
||||
|
||||
echo -n " ${question} [${default_prompt}] " >&2
|
||||
read answer
|
||||
|
||||
if [ -z $answer ]; then
|
||||
debug "Answer not provided, assuming '${default}'"
|
||||
answer=${default}
|
||||
fi
|
||||
|
||||
if $(echo ${answer} | grep -q -i '^y'); then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
Loading…
Reference in a new issue