|
|
@ -20,19 +20,19 @@ function usage { |
|
|
function parse_options { |
|
|
function parse_options { |
|
|
while [[ $# -gt 0 ]]; do |
|
|
while [[ $# -gt 0 ]]; do |
|
|
case "$1" in |
|
|
case "$1" in |
|
|
--help | -h) |
|
|
|
|
|
usage && exit 0 |
|
|
|
|
|
;; |
|
|
|
|
|
--no-start) |
|
|
|
|
|
START=false |
|
|
|
|
|
;; |
|
|
|
|
|
*) |
|
|
|
|
|
if [[ -z $CONTAINER_NAME ]]; then |
|
|
|
|
|
CONTAINER_NAME=$1 |
|
|
|
|
|
else |
|
|
|
|
|
echo >&2 "Unknown option: $1" && usage && exit 2 |
|
|
|
|
|
fi |
|
|
|
|
|
;; |
|
|
|
|
|
|
|
|
--help | -h) |
|
|
|
|
|
usage && exit 0 |
|
|
|
|
|
;; |
|
|
|
|
|
--no-start) |
|
|
|
|
|
START=false |
|
|
|
|
|
;; |
|
|
|
|
|
*) |
|
|
|
|
|
if [[ -z $CONTAINER_NAME ]]; then |
|
|
|
|
|
CONTAINER_NAME=$1 |
|
|
|
|
|
else |
|
|
|
|
|
echo >&2 "Unknown option: $1" && usage && exit 2 |
|
|
|
|
|
fi |
|
|
|
|
|
;; |
|
|
esac |
|
|
esac |
|
|
|
|
|
|
|
|
shift 1 # Move to the next argument |
|
|
shift 1 # Move to the next argument |
|
|
@ -77,7 +77,7 @@ function create_container { |
|
|
local vol_in_gb=$(convert_human_size_to_gigabyte $STORAGE_SIZE) |
|
|
local vol_in_gb=$(convert_human_size_to_gigabyte $STORAGE_SIZE) |
|
|
local mem_in_mb=$(convert_human_size_to_megabyte $MEMORY) |
|
|
local mem_in_mb=$(convert_human_size_to_megabyte $MEMORY) |
|
|
local swp_in_mb=$(convert_human_size_to_megabyte $SWAP) |
|
|
local swp_in_mb=$(convert_human_size_to_megabyte $SWAP) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pct create \ |
|
|
pct create \ |
|
|
$new_id \ |
|
|
$new_id \ |
|
|
$template_file \ |
|
|
$template_file \ |
|
|
@ -92,15 +92,15 @@ function create_container { |
|
|
--onboot true \ |
|
|
--onboot true \ |
|
|
$(optional_public_keys) \ |
|
|
$(optional_public_keys) \ |
|
|
--unprivileged true \ |
|
|
--unprivileged true \ |
|
|
--features nesting=1 \ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--features nesting=1 |
|
|
|
|
|
|
|
|
[[ -n $TAG_NAME ]] && pct set $new_id --tags $TAG_NAME |
|
|
[[ -n $TAG_NAME ]] && pct set $new_id --tags $TAG_NAME |
|
|
echo "container: $CONTAINER_NAME succesfully created with vmid=$new_id!" |
|
|
echo "container: $CONTAINER_NAME succesfully created with vmid=$new_id!" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function existing_container { |
|
|
function existing_container { |
|
|
local vmid=$($BASEDIR/pct-lookup "$CONTAINER_NAME" 2>/dev/null) |
|
|
local vmid=$($BASEDIR/pct-lookup "$CONTAINER_NAME" 2>/dev/null) |
|
|
if [[ -z $vmid ]]; then |
|
|
|
|
|
|
|
|
if [[ -z $vmid ]]; then |
|
|
false |
|
|
false |
|
|
else |
|
|
else |
|
|
echo "container $CONTAINER_NAME already exists with vmid=$vmid!" |
|
|
echo "container $CONTAINER_NAME already exists with vmid=$vmid!" |
|
|
@ -111,9 +111,6 @@ function existing_container { |
|
|
# MAIN |
|
|
# MAIN |
|
|
|
|
|
|
|
|
set -Eue |
|
|
set -Eue |
|
|
parse_options $* |
|
|
|
|
|
|
|
|
parse_options "$@" |
|
|
source "$CONFIG_FILE" |
|
|
source "$CONFIG_FILE" |
|
|
existing_container && false || create_container |
|
|
existing_container && false || create_container |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|