37 lines
854 B
Bash
37 lines
854 B
Bash
#!/usr/bin/env bash
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
# Uses ansible-pull from a Python venv to create a LXD container
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
usage ()
|
|
{
|
|
echo "Uses ansible-pull from a Python venv to create a LXD container"
|
|
echo " Usage: $1 <new-container-name>"
|
|
}
|
|
|
|
is_in () {
|
|
[[ $2 =~ (^|[[:space:]])$1($|[[:space:]]) ]] && return 1 || return 0
|
|
}
|
|
|
|
CONTAINER="$1"
|
|
|
|
# Need a container name:
|
|
if [ -z "$CONTAINER" ]; then
|
|
usage "$0"
|
|
exit 1
|
|
fi
|
|
|
|
# Container cannot exist already:
|
|
ALLCONTAINERS=$(lxc ls -c n --format csv)
|
|
|
|
is_in "$CONTAINER" "${ALLCONTAINERS}"
|
|
container_exists=$?
|
|
|
|
if [[ ${container_exists} -eq 0 ]]; then
|
|
printf 'ERROR: %s\n' "A container with that name exists already" >&2
|
|
exit 2
|
|
fi
|
|
|
|
echo "Would have launched container"
|
|
|