Update create_lxc.sh
This commit is contained in:
parent
4524378ed7
commit
607ee1c468
@ -78,6 +78,7 @@ msg_ok "Validated Storage (rootdir / vztmpl)."
|
||||
# This function is used to select the storage class and determine the corresponding storage content type and label.
|
||||
function select_storage() {
|
||||
local CLASS=$1 CONTENT CONTENT_LABEL
|
||||
|
||||
case $CLASS in
|
||||
container)
|
||||
CONTENT='rootdir'
|
||||
@ -104,22 +105,13 @@ function select_storage() {
|
||||
CONTENT_LABEL='Snippets'
|
||||
;;
|
||||
*)
|
||||
msg_error "Invalid storage class '$CLASS'."
|
||||
exit 201
|
||||
msg_error "Invalid storage class '$CLASS'"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
command -v whiptail >/dev/null || {
|
||||
msg_error "whiptail missing."
|
||||
exit 220
|
||||
}
|
||||
command -v numfmt >/dev/null || {
|
||||
msg_error "numfmt missing."
|
||||
exit 221
|
||||
}
|
||||
|
||||
local -a MENU
|
||||
local -A STORAGE_MAP=()
|
||||
local -A STORAGE_MAP
|
||||
local COL_WIDTH=0
|
||||
|
||||
while read -r TAG TYPE _ TOTAL USED FREE _; do
|
||||
@ -135,39 +127,30 @@ function select_storage() {
|
||||
|
||||
if [ ${#MENU[@]} -eq 0 ]; then
|
||||
msg_error "No storage found for content type '$CONTENT'."
|
||||
exit 203
|
||||
return 2
|
||||
fi
|
||||
|
||||
if [ $((${#MENU[@]} / 3)) -eq 1 ]; then
|
||||
echo "${STORAGE_MAP[${MENU[0]}]}"
|
||||
return
|
||||
STORAGE_RESULT="${STORAGE_MAP[${MENU[0]}]}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
local WIDTH=$((COL_WIDTH + 42))
|
||||
local DISPLAY_SELECTED=""
|
||||
while true; do
|
||||
DISPLAY_SELECTED=$(whiptail --backtitle "Proxmox VE Helper Scripts" \
|
||||
local DISPLAY_SELECTED=$(whiptail --backtitle "Proxmox VE Helper Scripts" \
|
||||
--title "Storage Pools" \
|
||||
--radiolist "Which storage pool for ${CONTENT_LABEL,,}?\n(Spacebar to select)" \
|
||||
16 "$WIDTH" 6 "${MENU[@]}" 3>&1 1>&2 2>&3)
|
||||
|
||||
local exit_code=$?
|
||||
if [ $exit_code -ne 0 ]; then
|
||||
msg_error "Storage selection cancelled by user."
|
||||
exit 202
|
||||
fi
|
||||
[[ $? -ne 0 ]] && return 3
|
||||
|
||||
if [ -z "$DISPLAY_SELECTED" ]; then
|
||||
whiptail --msgbox "You must select a storage pool to continue." 8 58
|
||||
if [[ -z "$DISPLAY_SELECTED" || -z "${STORAGE_MAP[$DISPLAY_SELECTED]+_}" ]]; then
|
||||
whiptail --msgbox "No valid storage selected. Please try again." 8 58
|
||||
continue
|
||||
fi
|
||||
|
||||
if [[ -n "${STORAGE_MAP[$DISPLAY_SELECTED]:-}" ]]; then
|
||||
echo "${STORAGE_MAP[$DISPLAY_SELECTED]}"
|
||||
return
|
||||
else
|
||||
whiptail --msgbox "Invalid selection. Please try again." 8 58
|
||||
fi
|
||||
STORAGE_RESULT="${STORAGE_MAP[$DISPLAY_SELECTED]}"
|
||||
return 0
|
||||
done
|
||||
}
|
||||
|
||||
@ -195,41 +178,55 @@ if qm status "$CTID" &>/dev/null || pct status "$CTID" &>/dev/null; then
|
||||
exit 206
|
||||
fi
|
||||
|
||||
DEFAULT_FILE="/usr/local/community-scripts/default_storage"
|
||||
if [[ -f "$DEFAULT_FILE" ]]; then
|
||||
source "$DEFAULT_FILE"
|
||||
if [[ -n "$TEMPLATE_STORAGE" && -n "$CONTAINER_STORAGE" ]]; then
|
||||
msg_info "Using default storage configuration from: $DEFAULT_FILE"
|
||||
msg_ok "Template Storage: ${BL}$TEMPLATE_STORAGE${CL} ${GN}|${CL} Container Storage: ${BL}$CONTAINER_STORAGE${CL}"
|
||||
else
|
||||
msg_warn "Default storage file exists but is incomplete – falling back to manual selection"
|
||||
TEMPLATE_STORAGE=$(select_storage template)
|
||||
msg_ok "Using ${BL}$TEMPLATE_STORAGE${CL} ${GN}for Template Storage."
|
||||
CONTAINER_STORAGE=$(select_storage container)
|
||||
msg_ok "Using ${BL}$CONTAINER_STORAGE${CL} ${GN}for Container Storage."
|
||||
fi
|
||||
else
|
||||
# TEMPLATE STORAGE SELECTION
|
||||
# Template Storage
|
||||
while true; do
|
||||
TEMPLATE_STORAGE=$(select_storage template)
|
||||
if [[ -n "$TEMPLATE_STORAGE" ]]; then
|
||||
msg_ok "Using ${BL}$TEMPLATE_STORAGE${CL} ${GN}for Template Storage."
|
||||
# DEFAULT_FILE="/usr/local/community-scripts/default_storage"
|
||||
# if [[ -f "$DEFAULT_FILE" ]]; then
|
||||
# source "$DEFAULT_FILE"
|
||||
# if [[ -n "$TEMPLATE_STORAGE" && -n "$CONTAINER_STORAGE" ]]; then
|
||||
# msg_info "Using default storage configuration from: $DEFAULT_FILE"
|
||||
# msg_ok "Template Storage: ${BL}$TEMPLATE_STORAGE${CL} ${GN}|${CL} Container Storage: ${BL}$CONTAINER_STORAGE${CL}"
|
||||
# else
|
||||
# msg_warn "Default storage file exists but is incomplete – falling back to manual selection"
|
||||
# TEMPLATE_STORAGE=$(select_storage template)
|
||||
# msg_ok "Using ${BL}$TEMPLATE_STORAGE${CL} ${GN}for Template Storage."
|
||||
# CONTAINER_STORAGE=$(select_storage container)
|
||||
# msg_ok "Using ${BL}$CONTAINER_STORAGE${CL} ${GN}for Container Storage."
|
||||
# fi
|
||||
# else
|
||||
# # TEMPLATE STORAGE SELECTION
|
||||
# # Template Storage
|
||||
# while true; do
|
||||
# TEMPLATE_STORAGE=$(select_storage template)
|
||||
# if [[ -n "$TEMPLATE_STORAGE" ]]; then
|
||||
# msg_ok "Using ${BL}$TEMPLATE_STORAGE${CL} ${GN}for Template Storage."
|
||||
# break
|
||||
# fi
|
||||
# msg_warn "No valid template storage selected. Please try again."
|
||||
# done
|
||||
|
||||
# while true; do
|
||||
# CONTAINER_STORAGE=$(select_storage container)
|
||||
# if [[ -n "$CONTAINER_STORAGE" ]]; then
|
||||
# msg_ok "Using ${BL}$CONTAINER_STORAGE${CL} ${GN}for Container Storage."
|
||||
# break
|
||||
# fi
|
||||
# msg_warn "No valid container storage selected. Please try again."
|
||||
# done
|
||||
|
||||
# fi
|
||||
|
||||
while true; do
|
||||
if select_storage template; then
|
||||
TEMPLATE_STORAGE="$STORAGE_RESULT"
|
||||
break
|
||||
fi
|
||||
msg_warn "No valid template storage selected. Please try again."
|
||||
done
|
||||
done
|
||||
|
||||
while true; do
|
||||
CONTAINER_STORAGE=$(select_storage container)
|
||||
if [[ -n "$CONTAINER_STORAGE" ]]; then
|
||||
msg_ok "Using ${BL}$CONTAINER_STORAGE${CL} ${GN}for Container Storage."
|
||||
while true; do
|
||||
if select_storage container; then
|
||||
CONTAINER_STORAGE="$STORAGE_RESULT"
|
||||
break
|
||||
fi
|
||||
msg_warn "No valid container storage selected. Please try again."
|
||||
done
|
||||
|
||||
fi
|
||||
done
|
||||
|
||||
# Check free space on selected container storage
|
||||
STORAGE_FREE=$(pvesm status | awk -v s="$CONTAINER_STORAGE" '$1 == s { print $6 }')
|
||||
|
Loading…
x
Reference in New Issue
Block a user