Skip to content

Commit

Permalink
nfsd: fix uninstall command
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitry-ishenko authored and igorpecovnik committed Dec 11, 2024
1 parent 3c6081a commit 5e336f0
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 12 deletions.
44 changes: 33 additions & 11 deletions tools/json/config.system.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,31 @@
},
{
"id": "NFS01",
"description": "Network filesystem (NFS) Server",
"description": "Enable Network filesystem (NFS) support",
"command": [
"module_nfs install"
],
"status": "Stable",
"author": "@igorpecovnik",
"condition": "! check_if_installed nfs-common"
},
{
"id": "NFS02",
"description": "Disable Network filesystem (NFS) support",
"command": [
"module_nfs remove"
],
"status": "Stable",
"author": "@igorpecovnik",
"condition": "check_if_installed nfs-common"
},
{
"id": "NFS05",
"description": "Manage NFS Server",
"condition": "check_if_installed nfs-common",
"sub": [
{
"id": "NFS02",
"id": "NFS06",
"description": "Enable network filesystem (NFS) daemon",
"command": [
"module_nfsd install"
Expand All @@ -143,7 +164,7 @@
"condition": "! module_nfsd status"
},
{
"id": "NFS03",
"id": "NFS07",
"description": "Configure network filesystem (NFS) daemon",
"command": [
"module_nfsd manage"
Expand All @@ -153,7 +174,7 @@
"condition": "module_nfsd status"
},
{
"id": "NFS04",
"id": "NFS08",
"description": "Remove network filesystem (NFS) daemon",
"command": [
"module_nfsd remove"
Expand All @@ -163,7 +184,7 @@
"condition": "module_nfsd status"
},
{
"id": "NFS05",
"id": "NFS09",
"description": "Show network filesystem (NFS) daemon clients",
"command": [
"module_nfsd clients"
Expand All @@ -175,18 +196,19 @@
]
},
{
"id": "NFS11",
"description": "Network filesystem (NFS) Client",
"id": "NFS20",
"description": "Manage NFS Client",
"condition": "check_if_installed nfs-common",
"sub": [
{
"id": "NFS06",
"description": "Show network filesystem (NFS) servers in subnet",
"id": "NFS21",
"description": "Find NFS servers in subnet and mount shares",
"command": [
"module_nfsd servers"
"module_nfs servers"
],
"status": "Stable",
"author": "@igorpecovnik",
"condition": ""
"condition": "check_if_installed nfs-common"
}
]
}
Expand Down
1 change: 1 addition & 0 deletions tools/modules/functions/service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ function service()
{
# ignore these commands, if running inside container
[[ "$1" =~ ^(reload|restart|start|status|stop)$ ]] && systemd-detect-virt -qc && return 0
systemctl daemon-reload
systemctl "$@"
}
100 changes: 100 additions & 0 deletions tools/modules/system/module_nfs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
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,port"]=""
["module_nfs,status"]="Active"
["module_nfs,arch"]=""
)
#
# Module nfs client
#
function module_nfs () {
local title="nfs"
local condition=$(which "$title" 2>/dev/null)?

local package_name=nfs-common

local commands
IFS=' ' read -r -a commands <<< "${module_options["module_nfs,example"]}"

nfs_BASE="${SOFTWARE_FOLDER}/nfs"

case "$1" in
"${commands[0]}")
apt_install_wrapper apt-get -y install $package_name
;;
"${commands[1]}")
apt_install_wrapper apt-get -y autopurge $package_name
;;
"${commands[2]}")

if ! check_if_installed nmap; then
apt_install_wrapper apt-get -y install nmap
fi

LIST=($(nmap -oG - -p2049 ${LOCALSUBNET} | grep '/open/' | cut -d' ' -f2 | grep -v "${LOCALIPADD}"))
LIST_LENGTH=$((${#LIST[@]}))
if nfs_server=$(dialog --no-items \
--title "Network filesystem (NFS) servers in subnet" \
--menu "" \
$((${LIST_LENGTH} + 6)) \
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))
VERIFIED_LIST=()
local tempfolder=$(mktemp -d)
local alreadymounted=$(df | grep $nfs_server | cut -d" " -f1 | xargs)
for i in "${LIST[@]}"; do
mount -n -t nfs $nfs_server:$i ${tempfolder} 2>/dev/null
if [[ $? -eq 0 ]]; then
if echo "${alreadymounted}" | grep -vq $i; then
VERIFIED_LIST+=($i)
fi
umount ${tempfolder}
fi
done
VERIFIED_LIST_LENGTH=$((${#VERIFIED_LIST[@]}))
if shares=$(dialog --no-items \
--title "Network filesystem (NFS) shares on ${nfs_server}" \
--menu "" \
$((${VERIFIED_LIST_LENGTH} + 6)) \
80 \
$((${VERIFIED_LIST_LENGTH})) \
${VERIFIED_LIST[@]} 3>&1 1>&2 2>&3)
then
if mount_folder=$(dialog --title \
"Where do you want to mount $shares ?" \
--inputbox "" \
6 80 "/armbian" 3>&1 1>&2 2>&3); then
if mount_options=$(dialog --title \
"Which mount options do you want to use?" \
--inputbox "" \
6 80 "auto,noatime 0 0" 3>&1 1>&2 2>&3); then
mkdir -p ${mount_folder}
sed -i '\?^'$nfs_server:$shares'?d' /etc/fstab
echo "${nfs_server}:${shares} ${mount_folder} nfs ${mount_options}" >> /etc/fstab
systemctl daemon-reload
mount ${mount_folder}
fi
fi
fi
fi
;;
"${commands[3]}")
echo -e "\nUsage: ${module_options["module_nfs,feature"]} <command>"
echo -e "Commands: ${module_options["module_nfs,example"]}"
echo "Available commands:"
echo -e "\tinstall\t- Install $title."
echo -e "\tremove\t- Remove $title."
echo -e "\tservers\t- Find and mount shares $title."
echo
;;
*)
${module_options["module_nfs,feature"]} ${commands[3]}
;;
esac
}
7 changes: 6 additions & 1 deletion tools/modules/system/module_nfsd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ function module_nfsd () {
show_message <<< $(printf '%s\n' "${NFS_CLIENTS_CONNECTED[@]}")
;;
"${commands[6]}")
LIST=($(nmap -oG - -p2049 ${LOCALSUBNET} | grep '/open/' | cut -d' ' -f2))

if ! check_if_installed nmap; then
apt_install_wrapper apt-get -y install nmap
fi

LIST=($(nmap -oG - -p2049 ${LOCALSUBNET} | 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 Down

0 comments on commit 5e336f0

Please sign in to comment.