From 91b5c7c9bc6781e0e9a2b287fb126d799a40fe2c Mon Sep 17 00:00:00 2001 From: MacRimi Date: Sat, 30 Aug 2025 17:51:45 +0200 Subject: [PATCH] Update share-common.func --- scripts/global/share-common.func | 106 ++++++++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 2 deletions(-) diff --git a/scripts/global/share-common.func b/scripts/global/share-common.func index 38362f9..75fcf0d 100644 --- a/scripts/global/share-common.func +++ b/scripts/global/share-common.func @@ -215,7 +215,7 @@ pmx_select_host_mount_point_() { -pmx_select_host_mount_point() { +pmx_select_host_mount_point__() { local title="${1:-$(translate "Select Mount Point")}" local default_path="${2:-/mnt/shared}" local choice folder_name result @@ -254,9 +254,59 @@ pmx_select_host_mount_point() { +pmx_select_host_mount_point() { + local title="${1:-$(translate "Select Mount Point")}" + local default_path="${2:-/mnt/shared}" + local context="${3:-local}" + local choice folder_name result existing_dirs mount_point + + while true; do + choice=$(whiptail --title "$title" --menu "$(translate "Where do you want the host folder?")" 16 76 3 \ + "1" "$(translate "Create new folder in /mnt")" \ + "2" "$(translate "Use existing folder")" \ + "3" "$(translate "Enter custom path")" 3>&1 1>&2 2>&3) || { echo ""; return 1; } + + case "$choice" in + 1) + folder_name=$(whiptail --inputbox "$(translate "Enter folder name for /mnt:")" 10 70 "$(basename "$default_path")" --title "$(translate "Folder Name")" 3>&1 1>&2 2>&3) || { echo ""; return 1; } + [[ -z "$folder_name" ]] && continue + mount_point="/mnt/$folder_name" + echo "$mount_point"; return 0 + ;; + + 2) + existing_dirs=($(ls -1d /mnt/*/ 2>/dev/null | sed 's:/$::')) + if [[ ${#existing_dirs[@]} -eq 0 ]]; then + whiptail --msgbox "$(translate "No existing folders found in /mnt")" 8 60 + continue + fi + mount_point=$(whiptail --title "$(translate "Select Existing Folder")" \ + --menu "$(translate "Choose a folder in /mnt:")" 20 70 10 \ + $(for d in "${existing_dirs[@]}"; do echo "$d" "$(basename "$d")"; done) \ + 3>&1 1>&2 2>&3) || continue + + if [[ "$context" =~ ^(nfs|samba)$ ]] && [[ -n "$(ls -A "$mount_point" 2>/dev/null)" ]]; then + whiptail --yesno "$(translate "Warning: The selected folder is not empty. Files may not be accessible once the network share is mounted. Proceed anyway?")" 12 70 || continue + fi + echo "$mount_point"; return 0 + ;; + + 3) + result=$(whiptail --inputbox "$(translate "Enter full path:")" 10 80 "$default_path" --title "$(translate "Custom Path")" 3>&1 1>&2 2>&3) || { echo ""; return 1; } + [[ -z "$result" ]] && continue + echo "$result"; return 0 + ;; + esac + done +} -select_host_directory() { + + + + + +select_host_directory_() { local method choice result method=$(whiptail --title "$(translate "Select Host Directory")" --menu "$(translate "How do you want to select the host folder to mount?")" 15 70 4 \ @@ -308,6 +358,58 @@ select_host_directory() { + +select_host_directory() { + local method choice result + + method=$(whiptail --title "$(translate "Select Host Directory")" --menu "$(translate "How do you want to select the host folder to mount?")" 15 70 4 \ + "mnt" "$(translate "Select from /mnt directories")" \ + "manual" "$(translate "Enter path manually")" 3>&1 1>&2 2>&3) || return 1 + + case "$method" in + mnt|srv|media) + local base_path="/$method" + local host_dirs=("$base_path"/*) + local options=() + + for dir in "${host_dirs[@]}"; do + if [[ -d "$dir" ]]; then + options+=("$dir" "$(basename "$dir")") + fi + done + + if [[ ${#options[@]} -eq 0 ]]; then + msg_error "$(translate "No directories found in") $base_path" + return 1 + fi + + result=$(whiptail --title "$(translate "Select Host Folder")" \ + --menu "$(translate "Select the folder to mount:")" 20 80 10 "${options[@]}" 3>&1 1>&2 2>&3) + ;; + manual) + result=$(whiptail --title "$(translate "Enter Path")" \ + --inputbox "$(translate "Enter the full path to the host folder:")" 10 70 "/mnt/" 3>&1 1>&2 2>&3) + ;; + esac + + if [[ -z "$result" ]]; then + return 1 + fi + + if [[ ! -d "$result" ]]; then + msg_error "$(translate "The selected path is not a valid directory:") $result" + return 1 + fi + + echo "$result" +} + + + + + + + select_lxc_container() { local ct_list ctid ct_status