mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-10-02 08:06:17 +00:00
Update nfs_host.sh
This commit is contained in:
@@ -34,10 +34,7 @@ else
|
|||||||
SHARE_COMMON_LOADED=true
|
SHARE_COMMON_LOADED=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
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
|
|
||||||
fi
|
|
||||||
|
|
||||||
discover_nfs_servers() {
|
discover_nfs_servers() {
|
||||||
show_proxmenux_logo
|
show_proxmenux_logo
|
||||||
@@ -195,10 +192,6 @@ select_nfs_export() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
select_host_mount_point() {
|
select_host_mount_point() {
|
||||||
local export_name=$(basename "$NFS_EXPORT")
|
local export_name=$(basename "$NFS_EXPORT")
|
||||||
local default_path="/mnt/shared_nfs_${export_name}"
|
local default_path="/mnt/shared_nfs_${export_name}"
|
||||||
@@ -209,8 +202,6 @@ select_host_mount_point() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
configure_host_mount_options() {
|
configure_host_mount_options() {
|
||||||
MOUNT_TYPE=$(whiptail --title "$(translate "Mount Options")" --menu "$(translate "Select mount configuration:")" 15 70 4 \
|
MOUNT_TYPE=$(whiptail --title "$(translate "Mount Options")" --menu "$(translate "Select mount configuration:")" 15 70 4 \
|
||||||
"default" "$(translate "Default options")" \
|
"default" "$(translate "Default options")" \
|
||||||
@@ -250,11 +241,11 @@ configure_host_mount_options() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Test basic NFS connectivity before offering Proxmox storage
|
|
||||||
show_proxmenux_logo
|
|
||||||
msg_info "$(translate "Testing NFS export accessibility...")"
|
msg_info "$(translate "Testing NFS export accessibility...")"
|
||||||
|
|
||||||
# Try a simple mount test to validate the export
|
|
||||||
TEMP_MOUNT="/tmp/nfs_test_$$"
|
TEMP_MOUNT="/tmp/nfs_test_$$"
|
||||||
mkdir -p "$TEMP_MOUNT" 2>/dev/null
|
mkdir -p "$TEMP_MOUNT" 2>/dev/null
|
||||||
|
|
||||||
@@ -264,7 +255,7 @@ configure_host_mount_options() {
|
|||||||
rmdir "$TEMP_MOUNT" 2>/dev/null || true
|
rmdir "$TEMP_MOUNT" 2>/dev/null || true
|
||||||
msg_ok "$(translate "NFS export is accessible")"
|
msg_ok "$(translate "NFS export is accessible")"
|
||||||
|
|
||||||
# Export is accessible, offer Proxmox storage integration
|
|
||||||
if whiptail --yesno "$(translate "Do you want to add this as Proxmox storage?")\n\n$(translate "This will make the NFS share available as storage in Proxmox web interface.")" 10 70 --title "$(translate "Proxmox Storage")"; then
|
if whiptail --yesno "$(translate "Do you want to add this as Proxmox storage?")\n\n$(translate "This will make the NFS share available as storage in Proxmox web interface.")" 10 70 --title "$(translate "Proxmox Storage")"; then
|
||||||
PROXMOX_STORAGE=true
|
PROXMOX_STORAGE=true
|
||||||
|
|
||||||
@@ -289,7 +280,7 @@ configure_host_mount_options() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# Export is not accessible or has issues
|
|
||||||
rmdir "$TEMP_MOUNT" 2>/dev/null || true
|
rmdir "$TEMP_MOUNT" 2>/dev/null || true
|
||||||
msg_warn "$(translate "NFS export accessibility test failed")"
|
msg_warn "$(translate "NFS export accessibility test failed")"
|
||||||
|
|
||||||
@@ -325,11 +316,12 @@ add_proxmox_nfs_storage() {
|
|||||||
local storage_id="$1"
|
local storage_id="$1"
|
||||||
local server="$2"
|
local server="$2"
|
||||||
local export="$3"
|
local export="$3"
|
||||||
local mount_point="$4"
|
local content="${4:-backup,iso,vztmpl}"
|
||||||
|
|
||||||
msg_info "$(translate "Starting Proxmox storage integration...")"
|
msg_info "$(translate "Starting Proxmox storage integration...")"
|
||||||
|
|
||||||
if ! which pvesm >/dev/null 2>&1; then
|
if ! command -v pvesm >/dev/null 2>&1; then
|
||||||
|
show_proxmenux_logo
|
||||||
msg_error "$(translate "pvesm command not found. This should not happen on Proxmox.")"
|
msg_error "$(translate "pvesm command not found. This should not happen on Proxmox.")"
|
||||||
echo "Press Enter to continue..."
|
echo "Press Enter to continue..."
|
||||||
read -r
|
read -r
|
||||||
@@ -338,6 +330,7 @@ add_proxmox_nfs_storage() {
|
|||||||
|
|
||||||
msg_ok "$(translate "pvesm command found")"
|
msg_ok "$(translate "pvesm command found")"
|
||||||
|
|
||||||
|
# Check if storage ID already exists
|
||||||
if pvesm status "$storage_id" >/dev/null 2>&1; then
|
if pvesm status "$storage_id" >/dev/null 2>&1; then
|
||||||
msg_warn "$(translate "Storage ID already exists:") $storage_id"
|
msg_warn "$(translate "Storage ID already exists:") $storage_id"
|
||||||
if ! whiptail --yesno "$(translate "Storage ID already exists. Do you want to remove and recreate it?")" 8 60 --title "$(translate "Storage Exists")"; then
|
if ! whiptail --yesno "$(translate "Storage ID already exists. Do you want to remove and recreate it?")" 8 60 --title "$(translate "Storage Exists")"; then
|
||||||
@@ -348,33 +341,34 @@ add_proxmox_nfs_storage() {
|
|||||||
|
|
||||||
msg_ok "$(translate "Storage ID is available")"
|
msg_ok "$(translate "Storage ID is available")"
|
||||||
|
|
||||||
msg_info "$(translate "Creating NFS storage...")"
|
msg_info "$(translate "Creating NFS storage (Proxmox will auto-detect optimal NFS version)...")"
|
||||||
CONTENT_LIST="backup,iso,vztmpl"
|
|
||||||
|
|
||||||
# Use NFS version 3 for better compatibility
|
# Let Proxmox handle NFS version negotiation automatically
|
||||||
NFS_VERSION="3"
|
if pvesm_output=$(pvesm add nfs "$storage_id" \
|
||||||
|
|
||||||
PVESM_OUTPUT=$(pvesm add nfs "$storage_id" \
|
|
||||||
--server "$server" \
|
--server "$server" \
|
||||||
--export "$export" \
|
--export "$export" \
|
||||||
--content "$CONTENT_LIST" \
|
--content "$content" 2>&1); then
|
||||||
--options "vers=$NFS_VERSION" 2>&1)
|
|
||||||
PVESM_RESULT=$?
|
msg_ok "$(translate "NFS storage added successfully!")"
|
||||||
|
|
||||||
|
# Get the actual NFS version that Proxmox negotiated
|
||||||
|
local nfs_version="Auto-negotiated"
|
||||||
|
if pvesm config "$storage_id" 2>/dev/null | grep -q "options.*vers="; then
|
||||||
|
nfs_version="v$(pvesm config "$storage_id" | grep "options" | grep -o "vers=[0-9.]*" | cut -d= -f2)"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ $PVESM_RESULT -eq 0 ]]; then
|
|
||||||
msg_ok "$(translate "NFS storage added successfully to Proxmox!")"
|
|
||||||
echo -e ""
|
echo -e ""
|
||||||
echo -e "${TAB}${BGN}$(translate "Storage ID:")${CL} ${BL}$storage_id${CL}"
|
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 "Server:")${CL} ${BL}$server${CL}"
|
||||||
echo -e "${TAB}${BGN}$(translate "Export:")${CL} ${BL}$export${CL}"
|
echo -e "${TAB}${BGN}$(translate "Export:")${CL} ${BL}$export${CL}"
|
||||||
echo -e "${TAB}${BGN}$(translate "Content Types:")${CL} ${BL}$CONTENT_LIST${CL}"
|
echo -e "${TAB}${BGN}$(translate "Content Types:")${CL} ${BL}$content${CL}"
|
||||||
echo -e "${TAB}${BGN}$(translate "NFS Version:")${CL} ${BL}$NFS_VERSION${CL}"
|
echo -e "${TAB}${BGN}$(translate "NFS Version:")${CL} ${BL}$nfs_version${CL}"
|
||||||
echo -e ""
|
echo -e ""
|
||||||
msg_ok "$(translate "Storage is now available in Proxmox web interface under Datacenter > Storage")"
|
msg_ok "$(translate "Storage is now available in Proxmox web interface under Datacenter > Storage")"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
msg_error "$(translate "Failed to add NFS storage to Proxmox.")"
|
msg_error "$(translate "Failed to add NFS storage to Proxmox.")"
|
||||||
echo "Error details: $PVESM_OUTPUT"
|
echo "$(translate "Error details:"): $pvesm_output"
|
||||||
msg_warn "$(translate "The NFS share is still mounted, but not added as Proxmox storage.")"
|
msg_warn "$(translate "The NFS share is still mounted, but not added as Proxmox storage.")"
|
||||||
msg_info2 "$(translate "You can add it manually through:")"
|
msg_info2 "$(translate "You can add it manually through:")"
|
||||||
echo -e "${TAB}• $(translate "Proxmox web interface: Datacenter > Storage > Add > NFS")"
|
echo -e "${TAB}• $(translate "Proxmox web interface: Datacenter > Storage > Add > NFS")"
|
||||||
@@ -480,7 +474,7 @@ mount_host_nfs_share() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$PROXMOX_STORAGE" == "true" ]]; then
|
if [[ "$PROXMOX_STORAGE" == "true" ]]; then
|
||||||
add_proxmox_nfs_storage "$STORAGE_ID" "$NFS_SERVER" "$NFS_EXPORT" "$MOUNT_POINT"
|
add_proxmox_nfs_storage "$STORAGE_ID" "$NFS_SERVER" "$NFS_EXPORT" "$MOUNT_CONTENT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e ""
|
echo -e ""
|
||||||
@@ -559,32 +553,17 @@ view_host_nfs_mounts() {
|
|||||||
echo "$(translate "No permanent NFS mounts configured on host.")"
|
echo "$(translate "No permanent NFS mounts configured on host.")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "${BOLD}$(translate "Proxmox NFS Storage:")${CL}"
|
echo ""
|
||||||
|
echo "$(translate "Proxmox NFS Storage Status:")"
|
||||||
if which pvesm >/dev/null 2>&1; then
|
if which pvesm >/dev/null 2>&1; then
|
||||||
NFS_STORAGES=$(pvesm status 2>/dev/null | grep "nfs" | awk '{print $1}' || true)
|
NFS_STORAGES=$(pvesm status 2>/dev/null | grep "nfs" || true)
|
||||||
if [[ -n "$NFS_STORAGES" ]]; then
|
if [[ -n "$NFS_STORAGES" ]]; then
|
||||||
while IFS= read -r storage_id; do
|
echo "$NFS_STORAGES"
|
||||||
if [[ -n "$storage_id" ]]; then
|
|
||||||
echo -e "${TAB}${BGN}$(translate "Storage ID:")${CL} ${BL}$storage_id${CL}"
|
|
||||||
|
|
||||||
STORAGE_INFO=$(pvesm config "$storage_id" 2>/dev/null || true)
|
|
||||||
if [[ -n "$STORAGE_INFO" ]]; then
|
|
||||||
SERVER=$(echo "$STORAGE_INFO" | grep "server" | awk '{print $2}')
|
|
||||||
EXPORT=$(echo "$STORAGE_INFO" | grep "export" | awk '{print $2}')
|
|
||||||
CONTENT=$(echo "$STORAGE_INFO" | grep "content" | awk '{print $2}')
|
|
||||||
|
|
||||||
[[ -n "$SERVER" ]] && echo -e "${TAB} ${BGN}$(translate "Server:")${CL} ${BL}$SERVER${CL}"
|
|
||||||
[[ -n "$EXPORT" ]] && echo -e "${TAB} ${BGN}$(translate "Export:")${CL} ${BL}$EXPORT${CL}"
|
|
||||||
[[ -n "$CONTENT" ]] && echo -e "${TAB} ${BGN}$(translate "Content:")${CL} ${BL}$CONTENT${CL}"
|
|
||||||
fi
|
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
done <<< "$NFS_STORAGES"
|
|
||||||
else
|
else
|
||||||
echo -e "${TAB}$(translate "No NFS storage configured in Proxmox")"
|
echo "$(translate "No NFS storage configured in Proxmox.")"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo -e "${TAB}$(translate "pvesm command not available")"
|
echo "$(translate "pvesm command not available.")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
@@ -701,7 +680,7 @@ manage_proxmox_storage() {
|
|||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
OPTIONS=()
|
OPTIONS=()
|
||||||
while IFS= read -r storage_id; do
|
while IFS= read -r storage_id; do
|
||||||
if [[ -n "$storage_id" ]]; then
|
if [[ -n "$storage_id" ]]; then
|
||||||
STORAGE_INFO=$(pvesm config "$storage_id" 2>/dev/null || true)
|
STORAGE_INFO=$(pvesm config "$storage_id" 2>/dev/null || true)
|
||||||
|
Reference in New Issue
Block a user