diff --git a/tools/json/config.system.json b/tools/json/config.system.json index 1d0a8a51a..54dfe533e 100644 --- a/tools/json/config.system.json +++ b/tools/json/config.system.json @@ -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) ]]" } ] } diff --git a/tools/modules/system/module_nfs.sh b/tools/modules/system/module_nfs.sh index f5cfa13d5..e3eb6b6c5 100644 --- a/tools/modules/system/module_nfs.sh +++ b/tools/modules/system/module_nfs.sh @@ -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: /" 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"]} " 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 } diff --git a/tools/modules/system/module_nfsd.sh b/tools/modules/system/module_nfsd.sh index 9f143b2ae..7280557ad 100644 --- a/tools/modules/system/module_nfsd.sh +++ b/tools/modules/system/module_nfsd.sh @@ -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