2025-08-22 18:05:14 +02:00
#!/bin/bash
# ==========================================================
2026-04-01 23:09:51 +02:00
# ProxMenux - NFS Host Manager for Proxmox Host
2025-08-22 18:05:14 +02:00
# ==========================================================
2026-04-01 23:09:51 +02:00
# Author : MacRimi
# Copyright : (c) 2024 MacRimi
# License : MIT
2025-08-22 18:05:14 +02:00
# ==========================================================
# Description:
2026-04-01 23:09:51 +02:00
# Adds external NFS shares as Proxmox storage (pvesm).
# Proxmox manages the mount natively — no fstab entries needed.
2025-08-22 18:05:14 +02:00
# ==========================================================
2025-11-03 01:36:57 +00:00
LOCAL_SCRIPTS = "/usr/local/share/proxmenux/scripts"
2025-08-22 18:05:14 +02:00
BASE_DIR = "/usr/local/share/proxmenux"
UTILS_FILE = " $BASE_DIR /utils.sh "
VENV_PATH = "/opt/googletrans-env"
if [ [ -f " $UTILS_FILE " ] ] ; then
source " $UTILS_FILE "
fi
load_language
initialize_cache
2026-04-01 23:09:51 +02:00
if ! command -v pveversion >/dev/null 2>& 1; then
dialog --backtitle "ProxMenux" --title " $( translate "Error" ) " \
--msgbox " $( translate "This script must be run on a Proxmox host." ) " 8 60
exit 1
2025-08-30 18:56:49 +02:00
fi
2025-08-22 18:05:14 +02:00
2026-04-01 23:09:51 +02:00
# ==========================================================
# STORAGE CONFIG READER
# ==========================================================
get_storage_config( ) {
local storage_id = " $1 "
awk -v id = " $storage_id " '
/^[ a-z] +: / { found = ( $0 ~ ": " id" $" ) ; next }
found && /^[ ^ \t ] / { exit }
found { print }
' /etc/pve/storage.cfg
}
2025-09-03 23:13:21 +02:00
2026-04-01 23:09:51 +02:00
# ==========================================================
# SERVER DISCOVERY
# ==========================================================
2025-08-22 18:05:14 +02:00
discover_nfs_servers( ) {
show_proxmenux_logo
2026-04-01 23:09:51 +02:00
msg_title " $( translate "Add NFS Share as Proxmox Storage" ) "
2025-08-22 18:05:14 +02:00
msg_info " $( translate "Scanning network for NFS servers..." ) "
HOST_IP = $( hostname -I | awk '{print $1}' )
NETWORK = $( echo " $HOST_IP " | cut -d. -f1-3) .0/24
if ! which nmap >/dev/null 2>& 1; then
apt-get install -y nmap & >/dev/null
fi
SERVERS = $( nmap -p 2049 --open " $NETWORK " 2>/dev/null | grep -B 4 "2049/tcp open" | grep "Nmap scan report" | awk '{print $5}' | sort -u || true )
2026-04-01 23:09:51 +02:00
2025-08-22 18:05:14 +02:00
if [ [ -z " $SERVERS " ] ] ; then
cleanup
2026-04-01 23:09:51 +02:00
dialog --clear --title " $( translate "No Servers Found" ) " \
--msgbox " $( translate "No NFS servers found on the network." ) \n\n $( translate "You can add servers manually." ) " 10 60
2025-08-22 18:05:14 +02:00
return 1
fi
2026-04-01 23:09:51 +02:00
2025-08-22 18:05:14 +02:00
OPTIONS = ( )
while IFS = read -r server; do
if [ [ -n " $server " ] ] ; then
EXPORTS_COUNT = $( showmount -e " $server " 2>/dev/null | tail -n +2 | wc -l || echo "0" )
2026-04-01 23:09:51 +02:00
OPTIONS += ( " $server " " NFS Server ( $EXPORTS_COUNT exports) " )
2025-08-22 18:05:14 +02:00
fi
done <<< " $SERVERS "
2026-04-01 23:09:51 +02:00
2025-08-22 18:05:14 +02:00
if [ [ ${# OPTIONS [@] } -eq 0 ] ] ; then
cleanup
2025-09-06 23:18:11 +02:00
dialog --clear --title " $( translate "No Valid Servers" ) " --msgbox " $( translate "No accessible NFS servers found." ) " 8 50
2025-08-22 18:05:14 +02:00
return 1
fi
2026-04-01 23:09:51 +02:00
2025-09-06 23:18:11 +02:00
cleanup
2026-04-01 23:09:51 +02:00
NFS_SERVER = $( whiptail --backtitle "ProxMenux" --title " $( translate "Select NFS Server" ) " \
--menu " $( translate "Choose an NFS server:" ) " 20 80 10 " ${ OPTIONS [@] } " 3>& 1 1>& 2 2>& 3)
2025-08-22 18:05:14 +02:00
[ [ -n " $NFS_SERVER " ] ] && return 0 || return 1
}
select_nfs_server( ) {
2026-04-01 23:09:51 +02:00
METHOD = $( dialog --backtitle "ProxMenux" --title " $( translate "NFS Server Selection" ) " \
--menu " $( translate "How do you want to select the NFS server?" ) " 15 70 3 \
"auto" " $( translate "Auto-discover servers on network" ) " \
"manual" " $( translate "Enter server IP/hostname manually" ) " \
3>& 1 1>& 2 2>& 3)
2025-08-22 18:05:14 +02:00
case " $METHOD " in
auto)
discover_nfs_servers || return 1
; ;
manual)
clear
2026-04-01 23:09:51 +02:00
NFS_SERVER = $( whiptail --inputbox " $( translate "Enter NFS server IP or hostname:" ) " \
10 60 --title " $( translate "NFS Server" ) " 3>& 1 1>& 2 2>& 3)
2025-08-22 18:05:14 +02:00
[ [ -z " $NFS_SERVER " ] ] && return 1
; ;
*)
return 1
; ;
esac
return 0
}
select_nfs_export( ) {
if ! which showmount >/dev/null 2>& 1; then
whiptail --title " $( translate "NFS Client Error" ) " \
2026-04-01 23:09:51 +02:00
--msgbox " $( translate "showmount command is not working properly." ) \n\n $( translate "Please check the installation." ) " \
10 60
2025-08-22 18:05:14 +02:00
return 1
fi
if ! ping -c 1 -W 3 " $NFS_SERVER " >/dev/null 2>& 1; then
whiptail --title " $( translate "Connection Error" ) " \
2026-04-01 23:09:51 +02:00
--msgbox " $( translate "Cannot reach server" ) $NFS_SERVER \n\n $( translate "Please check:" ) \n• $( translate "Server IP/hostname is correct" ) \n• $( translate "Network connectivity" ) \n• $( translate "Server is online" ) " \
12 70
2025-08-22 18:05:14 +02:00
return 1
fi
if ! nc -z -w 3 " $NFS_SERVER " 2049 2>/dev/null; then
whiptail --title " $( translate "NFS Port Error" ) " \
2026-04-01 23:09:51 +02:00
--msgbox " $( translate "NFS port (2049) is not accessible on" ) $NFS_SERVER \n\n $( translate "Please check:" ) \n• $( translate "NFS server is running" ) \n• $( translate "Firewall settings" ) \n• $( translate "NFS service is enabled" ) " \
12 70
2025-08-22 18:05:14 +02:00
return 1
fi
EXPORTS_OUTPUT = $( showmount -e " $NFS_SERVER " 2>& 1)
EXPORTS_RESULT = $?
2026-04-01 23:09:51 +02:00
2025-08-22 18:05:14 +02:00
if [ [ $EXPORTS_RESULT -ne 0 ] ] ; then
ERROR_MSG = $( echo " $EXPORTS_OUTPUT " | grep -i "error\|failed\|denied" | head -1)
2026-04-01 23:09:51 +02:00
whiptail --title " $( translate "NFS Error" ) " \
--msgbox " $( translate "Failed to connect to" ) $NFS_SERVER \n\n $( translate "Error:" ) : $ERROR_MSG " \
12 80
2025-08-22 18:05:14 +02:00
return 1
fi
2026-04-01 23:09:51 +02:00
2025-08-22 18:05:14 +02:00
EXPORTS = $( echo " $EXPORTS_OUTPUT " | tail -n +2 | awk '{print $1}' | grep -v " ^ $" )
if [ [ -z " $EXPORTS " ] ] ; then
whiptail --title " $( translate "No Exports Found" ) " \
2026-04-01 23:09:51 +02:00
--msgbox " $( translate "No exports found on server" ) $NFS_SERVER \n\n $( translate "You can enter the export path manually." ) " \
12 70
NFS_EXPORT = $( whiptail --inputbox " $( translate "Enter NFS export path (e.g., /mnt/shared):" ) " \
10 60 --title " $( translate "Export Path" ) " 3>& 1 1>& 2 2>& 3)
2025-08-22 18:05:14 +02:00
[ [ -z " $NFS_EXPORT " ] ] && return 1
return 0
fi
OPTIONS = ( )
while IFS = read -r export_line; do
if [ [ -n " $export_line " ] ] ; then
EXPORT_PATH = $( echo " $export_line " | awk '{print $1}' )
2026-04-01 23:09:51 +02:00
CLIENTS = $( echo " $EXPORTS_OUTPUT " | grep " ^ $EXPORT_PATH " | awk '{for(i=2;i<=NF;i++) printf "%s ",$i; print ""}' | sed 's/[[:space:]]*$//' )
2025-08-22 18:05:14 +02:00
if [ [ -n " $CLIENTS " ] ] ; then
OPTIONS += ( " $EXPORT_PATH " " $CLIENTS " )
else
OPTIONS += ( " $EXPORT_PATH " " $( translate "NFS export" ) " )
fi
fi
done <<< " $EXPORTS "
2026-04-01 23:09:51 +02:00
2025-08-22 18:05:14 +02:00
if [ [ ${# OPTIONS [@] } -eq 0 ] ] ; then
2026-04-01 23:09:51 +02:00
NFS_EXPORT = $( whiptail --inputbox " $( translate "Enter NFS export path (e.g., /mnt/shared):" ) " \
10 60 --title " $( translate "Export Path" ) " 3>& 1 1>& 2 2>& 3)
2025-08-22 18:05:14 +02:00
[ [ -n " $NFS_EXPORT " ] ] && return 0 || return 1
fi
2026-04-01 23:09:51 +02:00
NFS_EXPORT = $( whiptail --title " $( translate "Select NFS Export" ) " \
--menu " $( translate "Choose an export to mount:" ) " 20 70 10 " ${ OPTIONS [@] } " 3>& 1 1>& 2 2>& 3)
[ [ -n " $NFS_EXPORT " ] ] && return 0 || return 1
2025-08-22 18:05:14 +02:00
}
validate_host_export_exists( ) {
local server = " $1 "
local export = " $2 "
VALIDATION_OUTPUT = $( showmount -e " $server " 2>/dev/null | grep " ^ $export [[:space:]] " )
if [ [ -n " $VALIDATION_OUTPUT " ] ] ; then
return 0
else
show_proxmenux_logo
echo -e
msg_error " $( translate "Export not found on server:" ) $export "
return 1
fi
}
2026-04-01 23:09:51 +02:00
# ==========================================================
# STORAGE CONFIGURATION
# ==========================================================
configure_nfs_storage( ) {
STORAGE_ID = $( whiptail --inputbox " $( translate "Enter storage ID for Proxmox:" ) " \
10 60 " nfs- $( echo " $NFS_SERVER " | tr '.' '-' ) " \
--title " $( translate "Storage ID" ) " 3>& 1 1>& 2 2>& 3)
[ [ $? -ne 0 ] ] && return 1
[ [ -z " $STORAGE_ID " ] ] && STORAGE_ID = " nfs- $( echo " $NFS_SERVER " | tr '.' '-' ) "
if [ [ ! " $STORAGE_ID " = ~ ^[ a-zA-Z0-9] [ a-zA-Z0-9_-] *$ ] ] ; then
whiptail --msgbox " $( translate "Invalid storage ID. Use only letters, numbers, hyphens and underscores." ) " 8 70
return 1
fi
local raw_content
raw_content = $( dialog --backtitle "ProxMenux" \
--title " $( translate "Content Types" ) " \
--checklist " \n $( translate "Select content types for this storage:" ) \n $( translate "(Import is selected by default — required for disk image imports)" ) " 18 65 7 \
"import" " $( translate "Import — disk image imports" ) " on \
"backup" " $( translate "Backup — VM and CT backups" ) " off \
"iso" " $( translate "ISO image — installation images" ) " off \
"vztmpl" " $( translate "Container template— LXC templates" ) " off \
"images" " $( translate "Disk image — VM disk images" ) " off \
"rootdir" " $( translate "Container — LXC root directories" ) " off \
"snippets" " $( translate "Snippets — hook scripts / config" ) " off \
3>& 1 1>& 2 2>& 3)
[ [ $? -ne 0 ] ] && return 1
# Convert dialog checklist output (quoted space-separated) to comma-separated
MOUNT_CONTENT = $( echo " $raw_content " | tr -d '"' | tr -s ' ' ',' | sed 's/^,//;s/,$//' )
[ [ -z " $MOUNT_CONTENT " ] ] && MOUNT_CONTENT = "import"
return 0
}
2025-08-22 18:05:14 +02:00
add_proxmox_nfs_storage( ) {
local storage_id = " $1 "
local server = " $2 "
local export = " $3 "
2026-04-01 23:09:51 +02:00
local content = " ${ 4 :- import } "
2025-08-22 18:05:14 +02:00
msg_info " $( translate "Starting Proxmox storage integration..." ) "
2026-04-01 23:09:51 +02:00
2025-09-03 23:13:21 +02:00
if ! command -v pvesm >/dev/null 2>& 1; then
2025-08-22 18:05:14 +02:00
msg_error " $( translate "pvesm command not found. This should not happen on Proxmox." ) "
return 1
fi
if pvesm status " $storage_id " >/dev/null 2>& 1; then
msg_warn " $( translate "Storage ID already exists:" ) $storage_id "
2026-04-01 23:09:51 +02:00
if ! whiptail --yesno " $( translate "Storage ID already exists. Do you want to remove and recreate it?" ) " \
8 60 --title " $( translate "Storage Exists" ) " ; then
return 0
2025-08-22 18:05:14 +02:00
fi
pvesm remove " $storage_id " 2>/dev/null || true
fi
2026-04-01 23:09:51 +02:00
2025-08-22 18:05:14 +02:00
msg_ok " $( translate "Storage ID is available" ) "
2026-04-12 20:32:34 +02:00
msg_info " $( translate "NFS storage adding in progress..." ) "
2025-09-03 23:13:21 +02:00
if pvesm_output = $( pvesm add nfs " $storage_id " \
2025-08-22 18:05:14 +02:00
--server " $server " \
--export " $export " \
2025-09-03 23:13:21 +02:00
--content " $content " 2>& 1) ; then
2026-04-01 23:09:51 +02:00
2025-09-03 23:13:21 +02:00
msg_ok " $( translate "NFS storage added successfully!" ) "
2026-04-01 23:09:51 +02:00
2025-09-03 23:13:21 +02:00
local nfs_version = "Auto-negotiated"
2026-04-01 23:09:51 +02:00
if get_storage_config " $storage_id " | grep -q "options.*vers=" ; then
nfs_version = " v $( get_storage_config " $storage_id " | grep "options" | grep -o "vers=[0-9.]*" | cut -d= -f2) "
2025-09-03 23:13:21 +02:00
fi
2026-04-01 23:09:51 +02:00
2025-08-22 18:05:14 +02:00
echo -e ""
2026-04-01 23:09:51 +02:00
echo -e " ${ TAB } ${ BOLD } $( translate "Storage Added:" ) ${ CL } "
2025-08-22 18:05:14 +02:00
echo -e " ${ TAB } ${ BGN } $( translate "Storage ID:" ) ${ CL } ${ BL } $storage_id ${ CL } "
echo -e " ${ TAB } ${ BGN } $( translate "Server:" ) ${ CL } ${ BL } $server ${ CL } "
echo -e " ${ TAB } ${ BGN } $( translate "Export:" ) ${ CL } ${ BL } $export ${ CL } "
2025-09-03 23:13:21 +02:00
echo -e " ${ TAB } ${ BGN } $( translate "Content Types:" ) ${ CL } ${ BL } $content ${ CL } "
echo -e " ${ TAB } ${ BGN } $( translate "NFS Version:" ) ${ CL } ${ BL } $nfs_version ${ CL } "
2026-04-01 23:09:51 +02:00
echo -e " ${ TAB } ${ BGN } $( translate "Mount Path:" ) ${ CL } ${ BL } /mnt/pve/ $storage_id ${ CL } "
2025-08-22 18:05:14 +02:00
echo -e ""
msg_ok " $( translate "Storage is now available in Proxmox web interface under Datacenter > Storage" ) "
return 0
else
msg_error " $( translate "Failed to add NFS storage to Proxmox." ) "
2026-04-01 23:09:51 +02:00
echo -e " ${ TAB } $( translate "Error details:" ) : $pvesm_output "
echo -e ""
2025-08-22 18:05:14 +02:00
msg_info2 " $( translate "You can add it manually through:" ) "
echo -e " ${ TAB } • $( translate "Proxmox web interface: Datacenter > Storage > Add > NFS" ) "
2026-04-01 23:09:51 +02:00
echo -e " ${ TAB } • pvesm add nfs $storage_id --server $server --export $export --content $content "
2025-08-22 18:05:14 +02:00
return 1
fi
}
2026-04-01 23:09:51 +02:00
# ==========================================================
# MAIN OPERATIONS
# ==========================================================
2025-08-22 18:05:14 +02:00
2026-04-01 23:09:51 +02:00
add_nfs_to_proxmox( ) {
2025-08-22 18:05:14 +02:00
if ! which showmount >/dev/null 2>& 1; then
2026-04-01 23:09:51 +02:00
msg_info " $( translate "Installing NFS client tools..." ) "
apt-get update & >/dev/null
apt-get install -y nfs-common & >/dev/null
msg_ok " $( translate "NFS client tools installed" ) "
2025-08-22 18:05:14 +02:00
fi
2026-04-01 23:09:51 +02:00
# Step 1: Select server
2025-08-22 18:05:14 +02:00
select_nfs_server || return
2026-04-01 23:09:51 +02:00
# Step 2: Select export
2025-08-22 18:05:14 +02:00
select_nfs_export || return
2026-04-01 23:09:51 +02:00
# Step 3: Validate export
2025-08-22 18:05:14 +02:00
if ! validate_host_export_exists " $NFS_SERVER " " $NFS_EXPORT " ; then
echo -e ""
msg_error " $( translate "Cannot proceed with invalid export path." ) "
2026-04-01 23:09:51 +02:00
msg_success " $( translate "Press Enter to continue..." ) "
2025-08-22 18:05:14 +02:00
read -r
return
fi
show_proxmenux_logo
2026-04-01 23:09:51 +02:00
msg_title " $( translate "Add NFS Share as Proxmox Storage" ) "
msg_ok " $( translate "NFS server:" ) " " $NFS_SERVER "
msg_ok " $( translate "NFS export:" ) " " $NFS_EXPORT "
2025-08-22 18:05:14 +02:00
2026-04-01 23:09:51 +02:00
# Step 4: Configure storage
configure_nfs_storage || return
2025-08-22 18:05:14 +02:00
2026-04-01 23:09:51 +02:00
# Step 5: Add to Proxmox
show_proxmenux_logo
msg_title " $( translate "Add NFS Share as Proxmox Storage" ) "
msg_ok " $( translate "NFS server:" ) $NFS_SERVER "
msg_ok " $( translate "NFS export:" ) $NFS_EXPORT "
msg_ok " $( translate "Storage ID:" ) $STORAGE_ID "
msg_ok " $( translate "Content:" ) $MOUNT_CONTENT "
echo -e ""
2025-08-22 18:05:14 +02:00
2026-04-01 23:09:51 +02:00
add_proxmox_nfs_storage " $STORAGE_ID " " $NFS_SERVER " " $NFS_EXPORT " " $MOUNT_CONTENT "
2025-08-22 18:05:14 +02:00
echo -e ""
2026-04-01 23:09:51 +02:00
msg_success " $( translate "Press Enter to continue..." ) "
2025-08-22 18:05:14 +02:00
read -r
}
2026-04-01 23:09:51 +02:00
view_nfs_storages( ) {
2025-08-22 18:05:14 +02:00
show_proxmenux_logo
2026-04-01 23:09:51 +02:00
msg_title " $( translate "NFS Storages in Proxmox" ) "
2025-08-22 18:05:14 +02:00
2026-04-01 23:09:51 +02:00
echo "=================================================="
2025-09-03 23:13:21 +02:00
echo ""
2025-08-22 18:05:14 +02:00
2026-04-01 23:09:51 +02:00
if ! command -v pvesm >/dev/null 2>& 1; then
msg_error " $( translate "pvesm not found." ) "
echo ""
msg_success " $( translate "Press Enter to continue..." ) "
read -r
2025-08-22 18:05:14 +02:00
return
fi
2026-04-01 23:09:51 +02:00
NFS_STORAGES = $( pvesm status 2>/dev/null | awk '$2 == "nfs" {print $1, $3}' )
if [ [ -z " $NFS_STORAGES " ] ] ; then
msg_warn " $( translate "No NFS storage configured in Proxmox." ) "
echo ""
msg_info2 " $( translate "Use option 1 to add an NFS share as Proxmox storage." ) "
else
echo -e " ${ BOLD } $( translate "NFS Storages:" ) ${ CL } "
echo ""
while IFS = " " read -r storage_id storage_status; do
[ [ -z " $storage_id " ] ] && continue
local storage_info
storage_info = $( get_storage_config " $storage_id " )
local server export_path content
server = $( echo " $storage_info " | awk '$1 == "server" {print $2}' )
export_path = $( echo " $storage_info " | awk '$1 == "export" {print $2}' )
content = $( echo " $storage_info " | awk '$1 == "content" {print $2}' )
echo -e " ${ TAB } ${ BOLD } $storage_id ${ CL } "
echo -e " ${ TAB } ${ BGN } $( translate "Server:" ) ${ CL } ${ BL } $server ${ CL } "
echo -e " ${ TAB } ${ BGN } $( translate "Export:" ) ${ CL } ${ BL } $export_path ${ CL } "
echo -e " ${ TAB } ${ BGN } $( translate "Content:" ) ${ CL } ${ BL } $content ${ CL } "
echo -e " ${ TAB } ${ BGN } $( translate "Mount Path:" ) ${ CL } ${ BL } /mnt/pve/ $storage_id ${ CL } "
if [ [ " $storage_status " = = "active" ] ] ; then
echo -e " ${ TAB } ${ BGN } $( translate "Status:" ) ${ CL } ${ GN } $( translate "Active" ) ${ CL } "
2025-08-22 18:05:14 +02:00
else
2026-04-01 23:09:51 +02:00
echo -e " ${ TAB } ${ BGN } $( translate "Status:" ) ${ CL } ${ RD } $storage_status ${ CL } "
2025-08-22 18:05:14 +02:00
fi
2026-04-01 23:09:51 +02:00
echo ""
done <<< " $NFS_STORAGES "
2025-08-22 18:05:14 +02:00
fi
2026-04-01 23:09:51 +02:00
echo ""
msg_success " $( translate "Press Enter to continue..." ) "
2025-08-22 18:05:14 +02:00
read -r
}
2026-04-01 23:09:51 +02:00
remove_nfs_storage( ) {
2025-08-22 18:05:14 +02:00
if ! command -v pvesm >/dev/null 2>& 1; then
2026-04-01 23:09:51 +02:00
dialog --backtitle "ProxMenux" --title " $( translate "Error" ) " \
--msgbox " \n $( translate "pvesm not found." ) " 8 60
2025-08-22 18:05:14 +02:00
return
fi
NFS_STORAGES = $( pvesm status 2>/dev/null | awk '$2 == "nfs" {print $1}' )
if [ [ -z " $NFS_STORAGES " ] ] ; then
2026-04-01 23:09:51 +02:00
dialog --backtitle "ProxMenux" --title " $( translate "No NFS Storage" ) " \
--msgbox " \n $( translate "No NFS storage found in Proxmox." ) " 8 60
2025-08-22 18:05:14 +02:00
return
fi
2025-09-03 23:13:21 +02:00
OPTIONS = ( )
2025-08-22 18:05:14 +02:00
while IFS = read -r storage_id; do
2026-04-01 23:09:51 +02:00
[ [ -z " $storage_id " ] ] && continue
local storage_info server export_path
storage_info = $( get_storage_config " $storage_id " )
server = $( echo " $storage_info " | awk '$1 == "server" {print $2}' )
export_path = $( echo " $storage_info " | awk '$1 == "export" {print $2}' )
OPTIONS += ( " $storage_id " " $server : $export_path " )
2025-08-22 18:05:14 +02:00
done <<< " $NFS_STORAGES "
2026-04-01 23:09:51 +02:00
SELECTED = $( dialog --backtitle "ProxMenux" --title " $( translate "Remove NFS Storage" ) " \
--menu " $( translate "Select storage to remove:" ) " 20 80 10 \
" ${ OPTIONS [@] } " 3>& 1 1>& 2 2>& 3)
[ [ -z " $SELECTED " ] ] && return
local storage_info server export_path content
storage_info = $( get_storage_config " $SELECTED " )
server = $( echo " $storage_info " | awk '$1 == "server" {print $2}' )
export_path = $( echo " $storage_info " | awk '$1 == "export" {print $2}' )
content = $( echo " $storage_info " | awk '$1 == "content" {print $2}' )
if whiptail --yesno " $( translate "Remove Proxmox NFS storage:" ) \n\n $SELECTED \n\n $( translate "Server:" ) : $server \n $( translate "Export:" ) : $export_path \n $( translate "Content:" ) : $content \n\n $( translate "WARNING: This removes the storage from Proxmox. The NFS server is not affected." ) " \
16 80 --title " $( translate "Confirm Remove" ) " ; then
2025-08-22 18:05:14 +02:00
show_proxmenux_logo
2026-04-01 23:09:51 +02:00
msg_title " $( translate "Remove NFS Storage" ) "
if pvesm remove " $SELECTED " 2>/dev/null; then
msg_ok " $( translate "Storage" ) $SELECTED $( translate "removed successfully from Proxmox." ) "
2025-08-22 18:05:14 +02:00
else
msg_error " $( translate "Failed to remove storage." ) "
fi
2026-04-01 23:09:51 +02:00
echo -e ""
msg_success " $( translate "Press Enter to continue..." ) "
read -r
2025-08-22 18:05:14 +02:00
fi
}
2026-04-01 23:09:51 +02:00
test_nfs_connectivity( ) {
2025-08-22 18:05:14 +02:00
show_proxmenux_logo
2026-04-01 23:09:51 +02:00
msg_title " $( translate "Test NFS Connectivity" ) "
echo "=================================================="
echo ""
2025-08-22 18:05:14 +02:00
if which showmount >/dev/null 2>& 1; then
2026-04-01 23:09:51 +02:00
msg_ok " $( translate "NFS Client Tools: AVAILABLE" ) "
2025-08-22 18:05:14 +02:00
if systemctl is-active --quiet rpcbind 2>/dev/null; then
2026-04-01 23:09:51 +02:00
msg_ok " $( translate "RPC Bind Service: RUNNING" ) "
2025-08-22 18:05:14 +02:00
else
2026-04-01 23:09:51 +02:00
msg_warn " $( translate "RPC Bind Service: STOPPED - starting..." ) "
2025-08-22 18:05:14 +02:00
systemctl start rpcbind 2>/dev/null || true
fi
2026-04-01 23:09:51 +02:00
else
msg_warn " $( translate "NFS Client Tools: NOT AVAILABLE" ) "
fi
echo ""
if command -v pvesm >/dev/null 2>& 1; then
echo -e " ${ BOLD } $( translate "Proxmox NFS Storage Status:" ) ${ CL } "
NFS_STORAGES = $( pvesm status 2>/dev/null | awk '$2 == "nfs" {print $1, $3}' )
if [ [ -n " $NFS_STORAGES " ] ] ; then
while IFS = " " read -r storage_id storage_status; do
[ [ -z " $storage_id " ] ] && continue
local server
server = $( get_storage_config " $storage_id " | awk '$1 == "server" {print $2}' )
echo -n " $storage_id ( $server ): "
if ping -c 1 -W 2 " $server " >/dev/null 2>& 1; then
echo -ne " ${ GN } $( translate "Reachable" ) ${ CL } "
if nc -z -w 2 " $server " 2049 2>/dev/null; then
echo -e " | NFS port 2049: ${ GN } $( translate "Open" ) ${ CL } "
else
echo -e " | NFS port 2049: ${ RD } $( translate "Closed" ) ${ CL } "
fi
if showmount -e " $server " >/dev/null 2>& 1; then
echo -e " $( translate "Export list:" ) ${ GN } $( translate "Available" ) ${ CL } "
2025-08-22 18:05:14 +02:00
else
2026-04-01 23:09:51 +02:00
echo -e " $( translate "Export list:" ) ${ RD } $( translate "Failed" ) ${ CL } "
2025-08-22 18:05:14 +02:00
fi
2026-04-01 23:09:51 +02:00
else
echo -e " ${ RD } $( translate "Unreachable" ) ${ CL } "
2025-08-22 18:05:14 +02:00
fi
2026-04-01 23:09:51 +02:00
if [ [ " $storage_status " = = "active" ] ] ; then
echo -e " $( translate "Proxmox status:" ) ${ GN } $storage_status ${ CL } "
else
echo -e " $( translate "Proxmox status:" ) ${ RD } $storage_status ${ CL } "
fi
echo ""
done <<< " $NFS_STORAGES "
2025-08-22 18:05:14 +02:00
else
2026-04-01 23:09:51 +02:00
echo " $( translate "No NFS storage configured." ) "
2025-08-22 18:05:14 +02:00
fi
else
2026-04-01 23:09:51 +02:00
msg_warn " $( translate "pvesm not available." ) "
2025-08-22 18:05:14 +02:00
fi
2025-08-30 18:56:49 +02:00
echo ""
2026-04-01 23:09:51 +02:00
msg_success " $( translate "Press Enter to continue..." ) "
2025-08-22 18:05:14 +02:00
read -r
}
2026-04-01 23:09:51 +02:00
# ==========================================================
# MAIN MENU
# ==========================================================
2025-08-22 18:05:14 +02:00
while true; do
2026-04-01 23:09:51 +02:00
CHOICE = $( dialog --backtitle "ProxMenux" \
--title " $( translate "NFS Host Manager - Proxmox Host" ) " \
--menu " $( translate "Choose an option:" ) " 18 70 6 \
"1" " $( translate "Add NFS Share as Proxmox Storage" ) " \
"2" " $( translate "View NFS Storages" ) " \
"3" " $( translate "Remove NFS Storage" ) " \
"4" " $( translate "Test NFS Connectivity" ) " \
"5" " $( translate "Exit" ) " \
3>& 1 1>& 2 2>& 3)
2025-08-22 18:05:14 +02:00
RETVAL = $?
if [ [ $RETVAL -ne 0 ] ] ; then
exit 0
fi
2026-04-01 23:09:51 +02:00
2025-08-22 18:05:14 +02:00
case $CHOICE in
2026-04-01 23:09:51 +02:00
1) add_nfs_to_proxmox ; ;
2) view_nfs_storages ; ;
3) remove_nfs_storage ; ;
4) test_nfs_connectivity ; ;
5) exit 0 ; ;
2025-08-22 18:05:14 +02:00
*) exit 0 ; ;
esac
2025-09-03 23:13:21 +02:00
done