mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-10-02 08:06:17 +00:00
Update share-common.func
This commit is contained in:
@@ -41,104 +41,6 @@ pmx_share_map_set() {
|
||||
|
||||
|
||||
|
||||
pmx_choose_or_create_group__() {
|
||||
|
||||
local default_group="${1:-$PROXMENUX_DEFAULT_SHARE_GROUP}"
|
||||
local choice group_name
|
||||
choice=$(whiptail --title "$(translate "Shared Group")" --menu "$(translate "Choose a group policy for this shared directory:")" 18 78 6 \
|
||||
"1" "$(translate "Use sharefiles group default (recommended)")" \
|
||||
"2" "$(translate "Create a new group for isolation")" \
|
||||
"3" "$(translate "Select an existing group")" \
|
||||
3>&1 1>&2 2>&3) || { echo ""; return 1; }
|
||||
|
||||
case "$choice" in
|
||||
1)
|
||||
|
||||
pmx_ensure_host_group "$default_group" >/dev/null || return 1
|
||||
echo "$default_group"
|
||||
;;
|
||||
2)
|
||||
group_name=$(whiptail --inputbox "$(translate "Enter new group name:")" 10 70 "sharedfiles-project" --title "$(translate "New Group")" 3>&1 1>&2 2>&3) || { echo ""; return 1; }
|
||||
[[ -z "$group_name" ]] && { msg_error "$(translate "Group name cannot be empty.")"; echo ""; return 1; }
|
||||
pmx_ensure_host_group "$group_name" >/dev/null || return 1
|
||||
echo "$group_name"
|
||||
;;
|
||||
3)
|
||||
|
||||
groups=$(getent group | awk -F: '$3 >= 1000 && $1 != "nogroup" && $1 !~ /^pve/ {print $1 ":" $3}')
|
||||
if [[ -z "$groups" ]]; then
|
||||
whiptail --title "$(translate "Groups")" --msgbox "$(translate "No user groups found.")" 8 60
|
||||
echo ""; return 1
|
||||
fi
|
||||
|
||||
|
||||
menu_args=()
|
||||
while IFS=: read -r gname gid; do
|
||||
menu_args+=("$gname" "GID=$gid")
|
||||
done <<< "$groups"
|
||||
|
||||
group_name=$(whiptail --title "$(translate "Existing Groups")" --menu "$(translate "Select an existing group:")" 20 70 12 \
|
||||
"${menu_args[@]}" \
|
||||
3>&1 1>&2 2>&3) || { echo ""; return 1; }
|
||||
|
||||
pmx_ensure_host_group "$group_name" >/dev/null || return 1
|
||||
echo "$group_name"
|
||||
;;
|
||||
|
||||
*) echo ""; return 1;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
pmx_ensure_host_group__() {
|
||||
|
||||
local group_name="$1"
|
||||
local suggested_gid="$2"
|
||||
|
||||
if ! getent group "$group_name" >/dev/null 2>&1; then
|
||||
if [[ -n "$suggested_gid" ]]; then
|
||||
|
||||
if getent group "$suggested_gid" >/dev/null 2>&1; then
|
||||
msg_error "$(translate "GID already in use:") $suggested_gid"
|
||||
return 1
|
||||
fi
|
||||
groupadd -g "$suggested_gid" "$group_name" >/dev/null 2>&1
|
||||
else
|
||||
groupadd "$group_name" >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
if [[ $? -eq 0 ]]; then
|
||||
msg_ok "$(translate "Group created:") $group_name"
|
||||
else
|
||||
msg_error "$(translate "Failed to create group:") $group_name"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
local gid
|
||||
gid="$(getent group "$group_name" | cut -d: -f3)"
|
||||
if [[ -z "$gid" ]]; then
|
||||
msg_error "$(translate "Failed to resolve group GID for") $group_name"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo "$gid"
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -323,48 +225,6 @@ pmx_prepare_host_shared_dir() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
pmx_select_host_mount_point__() {
|
||||
local title="${1:-$(translate "Select Mount Point")}"
|
||||
local default_path="${2:-/mnt/shared}"
|
||||
local choice folder_name result
|
||||
|
||||
while true; do
|
||||
choice=$(whiptail --title "$title" --menu "$(translate "Where do you want the host folder?")" 16 76 4 \
|
||||
"mnt" "$(translate "Create folder in /mnt")" \
|
||||
"srv" "$(translate "Create folder in /srv")" \
|
||||
"media" "$(translate "Create folder in /media")" \
|
||||
"custom" "$(translate "Enter custom path")" 3>&1 1>&2 2>&3) || { echo ""; return 1; }
|
||||
|
||||
case "$choice" in
|
||||
mnt)
|
||||
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
|
||||
echo "/mnt/$folder_name"; return 0;;
|
||||
srv)
|
||||
folder_name=$(whiptail --inputbox "$(translate "Enter folder name for /srv:")" 10 70 "$(basename "$default_path")" --title "$(translate "Folder Name")" 3>&1 1>&2 2>&3) || { echo ""; return 1; }
|
||||
[[ -z "$folder_name" ]] && continue
|
||||
echo "/srv/$folder_name"; return 0;;
|
||||
media)
|
||||
folder_name=$(whiptail --inputbox "$(translate "Enter folder name for /media:")" 10 70 "$(basename "$default_path")" --title "$(translate "Folder Name")" 3>&1 1>&2 2>&3) || { echo ""; return 1; }
|
||||
[[ -z "$folder_name" ]] && continue
|
||||
echo "/media/$folder_name"; return 0;;
|
||||
custom)
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
pmx_select_host_mount_point() {
|
||||
local title="${1:-$(translate "Select Mount Point")}"
|
||||
local default_path="${2:-/mnt/shared}"
|
||||
@@ -417,53 +277,6 @@ pmx_select_host_mount_point() {
|
||||
|
||||
|
||||
|
||||
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")" \
|
||||
"srv" "$(translate "Select from /srv directories")" \
|
||||
"media" "$(translate "Select from /media 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"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -549,3 +362,60 @@ select_lxc_container() {
|
||||
echo "$ctid"
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
select_container_mount_point() {
|
||||
local ctid="$1"
|
||||
local host_dir="$2"
|
||||
local choice mount_point existing_dirs options
|
||||
|
||||
while true; do
|
||||
choice=$(whiptail --title "$(translate "Configure Mount Point inside LXC")" \
|
||||
--menu "$(translate "Where to mount inside container?")" 18 70 5 \
|
||||
"1" "$(translate "Create new directory in /mnt")" \
|
||||
"2" "$(translate "Use existing directory in /mnt")" \
|
||||
"3" "$(translate "Enter path manually")" \
|
||||
"4" "$(translate "Cancel")" 3>&1 1>&2 2>&3) || return 1
|
||||
|
||||
case "$choice" in
|
||||
1)
|
||||
mount_point=$(whiptail --inputbox "$(translate "Enter folder name for /mnt:")" 10 60 "shared" 3>&1 1>&2 2>&3) || continue
|
||||
[[ -z "$mount_point" ]] && continue
|
||||
mount_point="/mnt/$mount_point"
|
||||
pct exec "$ctid" -- mkdir -p "$mount_point" 2>/dev/null
|
||||
;;
|
||||
|
||||
2)
|
||||
existing_dirs=$(pct exec "$ctid" -- ls -1 /mnt 2>/dev/null | awk '{print "/mnt/"$1" "$1}')
|
||||
if [[ -z "$existing_dirs" ]]; then
|
||||
whiptail --msgbox "$(translate "No existing directories found in /mnt")" 8 60
|
||||
continue
|
||||
fi
|
||||
mount_point=$(whiptail --title "$(translate "Select Existing Folder")" \
|
||||
--menu "$(translate "Choose a folder from /mnt:")" 20 70 10 \
|
||||
$existing_dirs 3>&1 1>&2 2>&3) || continue
|
||||
;;
|
||||
|
||||
3)
|
||||
mount_point=$(whiptail --inputbox "$(translate "Enter full path:")" 10 70 "/mnt/shared" 3>&1 1>&2 2>&3) || continue
|
||||
[[ -z "$mount_point" ]] && continue
|
||||
mount_point="/mnt/$mount_point"
|
||||
pct exec "$ctid" -- mkdir -p "$mount_point" 2>/dev/null
|
||||
;;
|
||||
|
||||
4)
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if pct exec "$ctid" -- test -d "$mount_point" 2>/dev/null; then
|
||||
echo "$mount_point"
|
||||
return 0
|
||||
else
|
||||
whiptail --msgbox "$(translate "Could not create or access directory:") $mount_point" 8 70
|
||||
continue
|
||||
fi
|
||||
done
|
||||
}
|
Reference in New Issue
Block a user