create_lxc: better handling of storage names & exit script
This commit is contained in:
parent
143bdcfd9b
commit
6c0599e30b
@ -415,70 +415,11 @@ msg_custom() {
|
||||
echo -e "${BFR:-} ${symbol} ${color}${msg}${CL:-\e[0m}"
|
||||
}
|
||||
|
||||
# msg_ok() {
|
||||
# local msg="$1"
|
||||
# [[ -z "$msg" ]] && return
|
||||
# stop_spinner
|
||||
# printf "\r\e[2K%s %b\n" "$CM" "${GN}${msg}${CL}" >&2
|
||||
# if declare -p MSG_INFO_SHOWN &>/dev/null && [[ "$(declare -p MSG_INFO_SHOWN 2>/dev/null)" =~ "declare -A" ]]; then
|
||||
# unset MSG_INFO_SHOWN["$msg"]
|
||||
# fi
|
||||
# }
|
||||
|
||||
# msg_error() {
|
||||
# local msg="$1"
|
||||
# [[ -z "$msg" ]] && return
|
||||
# stop_spinner
|
||||
# printf "\r\e[2K%s %b\n" "$CROSS" "${RD}${msg}${CL}" >&2
|
||||
# }
|
||||
|
||||
# msg_warn() {
|
||||
# local msg="$1"
|
||||
# [[ -z "$msg" ]] && return
|
||||
# stop_spinner
|
||||
# printf "\r\e[2K%s %b\n" "$INFO" "${YWB}${msg}${CL}" >&2
|
||||
# if declare -p MSG_INFO_SHOWN &>/dev/null && [[ "$(declare -p MSG_INFO_SHOWN 2>/dev/null)" =~ "declare -A" ]]; then
|
||||
# unset MSG_INFO_SHOWN["$msg"]
|
||||
# fi
|
||||
# }
|
||||
|
||||
# msg_custom() {
|
||||
# local symbol="${1:-"[*]"}"
|
||||
# local color="${2:-"\e[36m"}" # Default: Cyan
|
||||
# local msg="${3:-}"
|
||||
|
||||
# [[ -z "$msg" ]] && return
|
||||
# stop_spinner 2>/dev/null || true
|
||||
# printf "\r\e[2K%s %b\n" "$symbol" "${color}${msg}${CL:-\e[0m}" >&2
|
||||
# }
|
||||
|
||||
# msg_progress() {
|
||||
# local current="$1"
|
||||
# local total="$2"
|
||||
# local label="$3"
|
||||
# local width=40
|
||||
# local filled percent bar empty
|
||||
# local fill_char="#"
|
||||
# local empty_char="-"
|
||||
|
||||
# if ! [[ "$current" =~ ^[0-9]+$ ]] || ! [[ "$total" =~ ^[0-9]+$ ]] || [[ "$total" -eq 0 ]]; then
|
||||
# printf "\r\e[2K%s %b\n" "$CROSS" "${RD}Invalid progress input${CL}" >&2
|
||||
# return
|
||||
# fi
|
||||
|
||||
# percent=$(((current * 100) / total))
|
||||
# filled=$(((current * width) / total))
|
||||
# empty=$((width - filled))
|
||||
|
||||
# bar=$(printf "%${filled}s" | tr ' ' "$fill_char")
|
||||
# bar+=$(printf "%${empty}s" | tr ' ' "$empty_char")
|
||||
|
||||
# printf "\r\e[2K%s [%s] %3d%% %s" "${TAB}" "$bar" "$percent" "$label" >&2
|
||||
|
||||
# if [[ "$current" -eq "$total" ]]; then
|
||||
# printf "\n" >&2
|
||||
# fi
|
||||
# }
|
||||
exit_script() {
|
||||
clear
|
||||
echo -e "\n${CROSS}${RD}User exited script${CL}\n"
|
||||
exit
|
||||
}
|
||||
|
||||
run_container_safe() {
|
||||
local ct="$1"
|
||||
|
@ -75,7 +75,7 @@ if ! check_storage_support "vztmpl"; then
|
||||
fi
|
||||
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 selects a storage pool for a given content type (e.g., rootdir, vztmpl).
|
||||
function select_storage() {
|
||||
local CLASS=$1 CONTENT CONTENT_LABEL
|
||||
|
||||
@ -110,7 +110,7 @@ function select_storage() {
|
||||
;;
|
||||
esac
|
||||
|
||||
# >>> NEW: support STORAGE preset <<<
|
||||
# Check for preset STORAGE variable
|
||||
if [ "$CONTENT" = "rootdir" ] && [ -n "${STORAGE:-}" ]; then
|
||||
if pvesm status -content "$CONTENT" | awk 'NR>1 {print $1}' | grep -qx "$STORAGE"; then
|
||||
STORAGE_RESULT="$STORAGE"
|
||||
@ -121,8 +121,9 @@ function select_storage() {
|
||||
return 2
|
||||
fi
|
||||
fi
|
||||
local -a MENU
|
||||
|
||||
local -A STORAGE_MAP
|
||||
local -a MENU
|
||||
local COL_WIDTH=0
|
||||
|
||||
while read -r TAG TYPE _ TOTAL USED FREE _; do
|
||||
@ -148,12 +149,17 @@ function select_storage() {
|
||||
|
||||
local WIDTH=$((COL_WIDTH + 42))
|
||||
while true; do
|
||||
local DISPLAY_SELECTED=$(whiptail --backtitle "Proxmox VE Helper Scripts" \
|
||||
local DISPLAY_SELECTED
|
||||
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)
|
||||
|
||||
[[ $? -ne 0 ]] && return 3
|
||||
# Cancel or ESC
|
||||
[[ $? -ne 0 ]] && exit_script
|
||||
|
||||
# Strip trailing whitespace or newline (important for storages like "storage (dir)")
|
||||
DISPLAY_SELECTED=$(sed 's/[[:space:]]*$//' <<<"$DISPLAY_SELECTED")
|
||||
|
||||
if [[ -z "$DISPLAY_SELECTED" || -z "${STORAGE_MAP[$DISPLAY_SELECTED]+_}" ]]; then
|
||||
whiptail --msgbox "No valid storage selected. Please try again." 8 58
|
||||
|
Loading…
x
Reference in New Issue
Block a user