You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.3 KiB

#!/usr/bin/env bash
# CONSTANTS
BASEDIR=$(dirname "$0")
CONTAINER=''
# FUNCTIONS
function usage {
echo "$(basename "$0") <CONTAINER_NAME>"
}
function parse_options {
while [[ $# -gt 0 ]]; do
case "$1" in
--help | -h)
usage && exit 0
;;
*)
if [[ -z $CONTAINER ]]; then
CONTAINER=$1
else
echo >&2 "Unknown option: $1" && usage && exit 2
fi
;;
esac
shift 1 # Move to the next argument
done
[[ -n $CONTAINER ]] || (usage && exit 1)
}
function before_start {
# cold changes
if [[ -v MIAOU_BASH_DIR ]]; then
pct set $CONTAINER_ID -mp0 $MIAOU_BASH_DIR,mp=/opt/miaou-bash
else
echo >&2 "Warn: variable MIAOU_BASH_DIR missing!"
fi
}
function after_start {
# hot changes
pct exec "$CONTAINER_ID" -- apt-get purge -y postfix
pct exec "$CONTAINER_ID" -- apt-get update
pct exec "$CONTAINER_ID" -- apt-get install -y file git bc vim jq sudo bash-completion
if [[ -v MIAOU_BASH_DIR ]]; then
pct exec "$CONTAINER_ID" -- /opt/miaou-bash/init.sh
fi
}
function create {
CONTAINER_ID=$(pct-create $CONTAINER --no-start | grep "container: $CONTAINER succesfully created" | cut -d= -f2 | cut -d! -f1)
[[ -z $CONTAINER_ID ]] && echo -e "Unable to create container: $CONTAINER\nMight already exists?" && exit 10
before_start
pct start $CONTAINER_ID
after_start
}
# MAIN
set -Eue
parse_options $*
create
echo Success