Update create_lxc.sh
This commit is contained in:
parent
7a65e836cd
commit
7384b1f1a2
@ -50,18 +50,54 @@ function on_terminate() {
|
|||||||
exit 143
|
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 </etc/pve/storage.cfg
|
||||||
|
|
||||||
|
if [[ -n "$CURRENT_NAME" ]]; then
|
||||||
|
if [[ " ${CURRENT_CONTENTS[*]} " =~ " $CONTENT " ]]; then
|
||||||
|
VALID_STORAGES+=("$CURRENT_NAME")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ${#VALID_STORAGES[@]} -eq 0 ]]; then
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# This checks for the presence of valid Container Storage and Template Storage locations
|
# This checks for the presence of valid Container Storage and Template Storage locations
|
||||||
msg_info "Validating Storage"
|
msg_info "Validating Storage"
|
||||||
VALIDCT=$(pvesm status -content rootdir | awk 'NR>1')
|
if ! check_storage_support "rootdir"; then
|
||||||
if [ -z "$VALIDCT" ]; then
|
msg_error "No valid storage found for 'rootdir' (Container)."
|
||||||
msg_error "Unable to detect a valid Container Storage location."
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
VALIDTMP=$(pvesm status -content vztmpl | awk 'NR>1')
|
if ! check_storage_support "vztmpl"; then
|
||||||
if [ -z "$VALIDTMP" ]; then
|
msg_error "No valid storage found for 'vztmpl' (Template)."
|
||||||
msg_error "Unable to detect a valid Template Storage location."
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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.
|
# This function is used to select the storage class and determine the corresponding storage content type and label.
|
||||||
function select_storage() {
|
function select_storage() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user