Skip to content

Commit 2035e06

Browse files
dimitry-ishenkoigorpecovnik
authored andcommitted
nfsd: fix uninstall command
1 parent 3c6081a commit 2035e06

3 files changed

Lines changed: 123 additions & 5 deletions

File tree

tools/json/config.system.json

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,24 @@
179179
"description": "Network filesystem (NFS) Client",
180180
"sub": [
181181
{
182-
"id": "NFS06",
183-
"description": "Show network filesystem (NFS) servers in subnet",
182+
"id": "NFS12",
183+
"description": "Enable network filesystem (NFS) client support",
184184
"command": [
185-
"module_nfsd servers"
185+
"module_nfs install"
186186
],
187187
"status": "Stable",
188188
"author": "@igorpecovnik",
189-
"condition": ""
189+
"condition": "check_if_installed nfs-common"
190+
}
191+
{
192+
"id": "NFS13",
193+
"description": "Find and mount network filesystem (NFS) servers from subnet",
194+
"command": [
195+
"module_nfs servers"
196+
],
197+
"status": "Stable",
198+
"author": "@igorpecovnik",
199+
"condition": "check_if_installed nfs-common"
190200
}
191201
]
192202
}

tools/modules/system/module_nfs.sh

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
module_options+=(
2+
["module_nfs,author"]="@igorpecovnik"
3+
["module_nfs,feature"]="module_nfs"
4+
["module_nfs,desc"]="Install nfs client"
5+
["module_nfs,example"]="install remove servers help"
6+
["module_nfs,port"]=""
7+
["module_nfs,status"]="Active"
8+
["module_nfs,arch"]=""
9+
)
10+
#
11+
# Module nfs client
12+
#
13+
function module_nfs () {
14+
local title="nfs"
15+
local condition=$(which "$title" 2>/dev/null)?
16+
17+
local package_name=nfs-common
18+
19+
local commands
20+
IFS=' ' read -r -a commands <<< "${module_options["module_nfs,example"]}"
21+
22+
nfs_BASE="${SOFTWARE_FOLDER}/nfs"
23+
24+
case "$1" in
25+
"${commands[0]}")
26+
apt_install_wrapper apt-get -y install $package_name
27+
;;
28+
"${commands[1]}")
29+
apt_install_wrapper apt-get -y autopurge $package_name
30+
;;
31+
"${commands[3]}")
32+
33+
if ! check_if_installed nmap; then
34+
apt_install_wrapper apt-get -y install nmap
35+
fi
36+
37+
LIST=($(nmap -oG - -p2049 ${LOCALSUBNET} | grep '/open/' | cut -d' ' -f2 | grep -v "${LOCALIPADD}"))
38+
LIST_LENGTH=$((${#LIST[@]}))
39+
if nfs_server=$(dialog --no-items \
40+
--title "Network filesystem (NFS) servers in subnet" \
41+
--menu "" \
42+
$((${LIST_LENGTH} + 6)) \
43+
80 \
44+
$((${LIST_LENGTH})) \
45+
${LIST[@]} 3>&1 1>&2 2>&3); then
46+
# verify if we can connect there
47+
LIST=($(showmount -e "${nfs_server}" | tail -n +2 | cut -d" " -f1 | sort))
48+
VERIFIED_LIST=()
49+
local tempfolder=$(mktemp -d)
50+
local alreadymounted=$(df | grep $nfs_server | cut -d" " -f1 | xargs)
51+
for i in "${LIST[@]}"; do
52+
mount -n -t nfs $nfs_server:$i ${tempfolder} 2>/dev/null
53+
if [[ $? -eq 0 ]]; then
54+
if echo "${alreadymounted}" | grep -vq $i; then
55+
VERIFIED_LIST+=($i)
56+
fi
57+
umount ${tempfolder}
58+
fi
59+
done
60+
VERIFIED_LIST_LENGTH=$((${#VERIFIED_LIST[@]}))
61+
if shares=$(dialog --no-items \
62+
--title "Network filesystem (NFS) shares on ${nfs_server}" \
63+
--menu "" \
64+
$((${VERIFIED_LIST_LENGTH} + 6)) \
65+
80 \
66+
$((${VERIFIED_LIST_LENGTH})) \
67+
${VERIFIED_LIST[@]} 3>&1 1>&2 2>&3)
68+
then
69+
if mount_folder=$(dialog --title \
70+
"Where do you want to mount $shares ?" \
71+
--inputbox "" \
72+
6 80 "/armbian" 3>&1 1>&2 2>&3); then
73+
if mount_options=$(dialog --title \
74+
"Which mount options do you want to use?" \
75+
--inputbox "" \
76+
6 80 "auto,noatime 0 0" 3>&1 1>&2 2>&3); then
77+
mkdir -p ${mount_folder}
78+
read
79+
sed -i '\?^'$nfs_server:$shares'?d' /etc/fstab
80+
echo "${nfs_server}:${shares} ${mount_folder} nfs ${mount_options}" >> /etc/fstab
81+
systemctl daemon-reload
82+
mount ${mount_options}
83+
fi
84+
fi
85+
fi
86+
fi
87+
;;
88+
"${commands[4]}")
89+
echo -e "\nUsage: ${module_options["module_nfs,feature"]} <command>"
90+
echo -e "Commands: ${module_options["module_nfs,example"]}"
91+
echo "Available commands:"
92+
echo -e "\tinstall\t- Install $title."
93+
echo -e "\tmanage\t- Edit exports in $title."
94+
echo -e "\tadd\t- Add exports to $title."
95+
echo -e "\tstatus\t- Installation status $title."
96+
echo -e "\tremove\t- Remove $title."
97+
echo
98+
;;
99+
*)
100+
${module_options["module_nfs,feature"]} ${commands[4]}
101+
;;
102+
esac
103+
}

tools/modules/system/module_nfsd.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,12 @@ function module_nfsd () {
105105
show_message <<< $(printf '%s\n' "${NFS_CLIENTS_CONNECTED[@]}")
106106
;;
107107
"${commands[6]}")
108-
LIST=($(nmap -oG - -p2049 ${LOCALSUBNET} | grep '/open/' | cut -d' ' -f2))
108+
109+
if ! check_if_installed nmap; then
110+
apt_install_wrapper apt-get -y install nmap
111+
fi
112+
113+
LIST=($(nmap -oG - -p2049 ${LOCALSUBNET} | grep '/open/' | cut -d' ' -f2 | grep -v "${LOCALIPADD}"))
109114
LIST_LENGTH=$((${#LIST[@]}))
110115
if nfs_server=$(dialog --no-items \
111116
--title "Network filesystem (NFS) servers in subnet" \

0 commit comments

Comments
 (0)