From 7384b1f1a252ab877256aee62421d2456c59ca0f Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Tue, 1 Jul 2025 13:30:21 +0200 Subject: [PATCH] Update create_lxc.sh --- misc/create_lxc.sh | 48 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/misc/create_lxc.sh b/misc/create_lxc.sh index 5874ac69..fdeb0424 100644 --- a/misc/create_lxc.sh +++ b/misc/create_lxc.sh @@ -50,18 +50,54 @@ function on_terminate() { exit 143 } +function check_storage_support() { + local CONTENT="$1" + local -a VALID_STORAGES=() + local TYPE="" NAME="" CONTENTS=() + local CURRENT_NAME="" CURRENT_TYPE="" CURRENT_CONTENTS=() + + while IFS= read -r line || [[ -n "$line" ]]; do + if [[ "$line" =~ ^([a-z0-9]+):[[:space:]]*([a-zA-Z0-9_-]+) ]]; then + [[ -n "$CURRENT_NAME" ]] && { + if [[ " ${CURRENT_CONTENTS[*]} " =~ " $CONTENT " ]]; then + VALID_STORAGES+=("$CURRENT_NAME") + fi + CURRENT_CONTENTS=() + } + CURRENT_TYPE="${BASH_REMATCH[1]}" + CURRENT_NAME="${BASH_REMATCH[2]}" + elif [[ "$line" =~ ^[[:space:]]*content[[:space:]]*[=]?[[:space:]]*(.+)$ ]]; then + IFS=',' read -ra PARTS <<<"${BASH_REMATCH[1]}" + for c in "${PARTS[@]}"; do + CURRENT_CONTENTS+=("$(echo "$c" | xargs)") + done + fi + done 1') -if [ -z "$VALIDCT" ]; then - msg_error "Unable to detect a valid Container Storage location." +if ! check_storage_support "rootdir"; then + msg_error "No valid storage found for 'rootdir' (Container)." exit 1 fi -VALIDTMP=$(pvesm status -content vztmpl | awk 'NR>1') -if [ -z "$VALIDTMP" ]; then - msg_error "Unable to detect a valid Template Storage location." +if ! check_storage_support "vztmpl"; then + msg_error "No valid storage found for 'vztmpl' (Template)." exit 1 fi +msg_ok "Storage types rootdir and vztmpl are supported." # This function is used to select the storage class and determine the corresponding storage content type and label. function select_storage() {