Skip to content

Commit

Permalink
NFS: several fixes to improve handling
Browse files Browse the repository at this point in the history
  • Loading branch information
igorpecovnik committed Jan 30, 2025
1 parent 5c7743a commit 596afe0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
10 changes: 10 additions & 0 deletions tools/json/config.system.json
Original file line number Diff line number Diff line change
Expand Up @@ -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) ]]"
}
]
}
Expand Down
29 changes: 21 additions & 8 deletions tools/modules/system/module_nfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"]=""
Expand All @@ -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" \
Expand All @@ -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)
Expand Down Expand Up @@ -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:"
Expand All @@ -93,7 +106,7 @@ function module_nfs () {
echo
;;
*)
${module_options["module_nfs,feature"]} ${commands[3]}
${module_options["module_nfs,feature"]} ${commands[4]}
;;
esac
}
3 changes: 2 additions & 1 deletion tools/modules/system/module_nfsd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand All @@ -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
Expand Down

0 comments on commit 596afe0

Please sign in to comment.