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