NFS: several fixes to improve handling

This commit is contained in:
Igor Pecovnik
2025-01-28 13:49:17 +01:00
committed by Igor
parent 5c7743a9d3
commit 596afe06b7
3 changed files with 33 additions and 9 deletions

View File

@@ -209,6 +209,16 @@
"status": "Stable",
"author": "@igorpecovnik",
"condition": "pkg_installed nfs-common"
},
{
"id": "NFS22",
"description": "Show and manage NFS mounts",
"command": [
"module_nfs mounts"
],
"status": "Stable",
"author": "@igorpecovnik",
"condition": "[[ -n $(mount --type=nfs4) ]]"
}
]
}

View File

@@ -2,7 +2,7 @@ module_options+=(
["module_nfs,author"]="@igorpecovnik"
["module_nfs,feature"]="module_nfs"
["module_nfs,desc"]="Install nfs client"
["module_nfs,example"]="install remove servers help"
["module_nfs,example"]="install remove servers mounts help"
["module_nfs,port"]=""
["module_nfs,status"]="Active"
["module_nfs,arch"]=""
@@ -28,11 +28,11 @@ function module_nfs () {
;;
"${commands[2]}")
if ! pkg_installed nmap; then
pkg_install nmap
fi
if ! pkg_installed nmap; then pkg_install nmap; fi
if ! pkg_installed nfs-common; then pkg_install nfs-common; fi
LIST=($(nmap -oG - -p2049 ${LOCALSUBNET} | grep '/open/' | cut -d' ' -f2 | grep -v "${LOCALIPADD}"))
local subnet=$($DIALOG --title "Choose subnet to search for NFS server" --inputbox "\nValid format: <IP Address>/<Subnet Mask Length>" 9 60 "${LOCALSUBNET}" 3>&1 1>&2 2>&3)
LIST=($(nmap -oG - -p2049 ${subnet} | grep '/open/' | cut -d' ' -f2 | grep -v "${LOCALIPADD}"))
LIST_LENGTH=$((${#LIST[@]}))
if nfs_server=$(dialog --no-items \
--title "Network filesystem (NFS) servers in subnet" \
@@ -41,8 +41,8 @@ function module_nfs () {
80 \
$((${LIST_LENGTH})) \
${LIST[@]} 3>&1 1>&2 2>&3); then
# verify if we can connect there
LIST=($(showmount -e "${nfs_server}" | tail -n +2 | cut -d" " -f1 | sort))
# verify if we can connect there. adding timeout kill as it can hang if server doesn't share to this client
LIST=($(timeout --kill 10s 5s showmount -e "${nfs_server}" 2>/dev/null | tail -n +2 | cut -d" " -f1 | sort))
VERIFIED_LIST=()
local tempfolder=$(mktemp -d)
local alreadymounted=$(df | grep $nfs_server | cut -d" " -f1 | xargs)
@@ -84,6 +84,19 @@ function module_nfs () {
fi
;;
"${commands[3]}")
local list=($(mount --type=nfs4 | cut -d" " -f1))
if shares=$(dialog --no-items \
--title "Mounted NFS shares" \
--menu "" \
$((${#list[@]} + 6)) \
80 \
$((${#list[@]})) \
${list[@]} 3>&1 1>&2 2>&3); then
echo "Chosen $mount"
read
fi
;;
"${commands[4]}")
echo -e "\nUsage: ${module_options["module_nfs,feature"]} <command>"
echo -e "Commands: ${module_options["module_nfs,example"]}"
echo "Available commands:"
@@ -93,7 +106,7 @@ function module_nfs () {
echo
;;
*)
${module_options["module_nfs,feature"]} ${commands[3]}
${module_options["module_nfs,feature"]} ${commands[4]}
;;
esac
}

View File

@@ -81,7 +81,7 @@ function module_nfsd () {
if add_folder=$(dialog --title \
"Which folder do you want to export?" \
--inputbox "" \
6 80 "/armbian" 3>&1 1>&2 2>&3); then
6 80 "${SOFTWARE_FOLDER}" 3>&1 1>&2 2>&3); then
if add_ip=$(dialog --title \
"Which IP or range can access this folder?" \
--inputbox "\nExamples: 192.168.1.1, 192.168.1.0/24" \
@@ -93,6 +93,7 @@ function module_nfsd () {
$((${LIST_LENGTH} + 6)) 80 ${LIST_LENGTH} "${LIST[@]}" 3>&1 1>&2 2>&3); then
echo "$add_folder $add_ip($(echo $add_options | tr ' ' ','))" \
>> /etc/exports.d/armbian.exports
[[ -n "${add_folder}" ]] && mkdir -p "${add_folder}"
fi
fi
fi