Skip to content

Commit

Permalink
System: add NFSD manipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
igorpecovnik committed Dec 8, 2024
1 parent 6fc59d1 commit 29a7631
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tools/json/config.network.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,36 @@
"status": "Disabled",
"author": "@armbian",
"condition": ""
},
{
"id": "NE105",
"description": "Install NFS daemon",
"command": [
"module_nfsd install"
],
"status": "Stable",
"author": "@igorpecovnik",
"condition": "! module_nfsd status"
},
{
"id": "NE106",
"description": "Configure NFS daemon",
"command": [
"module_nfsd manage"
],
"status": "Stable",
"author": "@igorpecovnik",
"condition": "module_nfsd status"
},
{
"id": "NE107",
"description": "Remove NFS daemon",
"command": [
"module_nfsd uninstall"
],
"status": "Stable",
"author": "@igorpecovnik",
"condition": "module_nfsd status"
}
]
}
Expand Down
1 change: 1 addition & 0 deletions tools/modules/functions/set_runtime_variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function set_runtime_variables() {
SOFTWARE_FOLDER="/armbian" # where we should keep 3rd party software
DEFAULT_ADAPTER=$(ip -4 route ls | grep default | tail -1 | grep -Po '(?<=dev )(\S+)')
LOCALIPADD=$(ip -4 addr show dev $DEFAULT_ADAPTER | awk '/inet/ {print $2}' | cut -d'/' -f1)
LOCALSUBNET=$(echo ${LOCALIPADD} | cut -d"." -f1-3).0/24
BACKTITLE="Contribute: https://github.com/armbian/configng"
TITLE="Armbian configuration utility"
[[ -z "${DEFAULT_ADAPTER// /}" ]] && DEFAULT_ADAPTER="lo"
Expand Down
120 changes: 120 additions & 0 deletions tools/modules/network/module_nfsd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
module_options+=(
["module_nfsd,author"]="@igorpecovnik"
["module_nfsd,feature"]="module_nfsd"
["module_nfsd,desc"]="Install nfsd server"
["module_nfsd,example"]="install remove manage add status help"
["module_nfsd,port"]=""
["module_nfsd,status"]="Active"
["module_nfsd,arch"]=""
)
#
# Module nfsd
#
function module_nfsd () {
local title="nfsd"
local condition=$(which "$title" 2>/dev/null)?

# we will store our config in subfolder
mkdir -p /etc/exports.d/

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

NFSD_BASE="${SOFTWARE_FOLDER}/nfsd"

case "$1" in
"${commands[0]}")
apt_install_wrapper apt-get -y install nfs-common nfs-kernel-server
# add some exports
${module_options["module_nfsd,feature"]} ${commands[2]}
systemctl restart nfs-server.service
;;
"${commands[1]}")
apt_install_wrapper apt-get -y autopurge nfs-kernel-server
;;
"${commands[2]}")
while true; do
LIST=() IFS=$'\n' LIST=($(grep "^[^#;]" /etc/exports.d/armbian.exports))
LIST_LENGTH=${#LIST[@]}
if [[ "${LIST_LENGTH}" -ge 1 ]]; then
line=$(dialog --no-items \
--title "Select export to edit" \
--ok-label "Add" \
--cancel-label "Apply" \
--extra-button \
--extra-label "Delete" \
--menu "" \
$((${LIST_LENGTH} + 6)) \
80 \
$((${LIST_LENGTH})) \
${LIST[@]} 3>&1 1>&2 2>&3)
exitstatus=$?
case "$exitstatus" in
0)
${module_options["module_nfsd,feature"]} ${commands[3]}
;;
1)
break
;;
3)
sed -i '\?^'$line'?d' /etc/exports.d/armbian.exports
;;
esac
else
${module_options["module_nfsd,feature"]} ${commands[3]}
break
fi
done
systemctl restart nfs-server.service
;;
"${commands[3]}")
# choose between most common options
LIST=()
LIST=("ro" "Allow read only requests" On)
LIST+=("rw" "Allow read and write requests" OFF)
LIST+=("sync" "Immediate sync all writes" On)
LIST+=("fsid=0" "Check man pages" OFF)
LIST+=("no_subtree_check" "Disables subtree checking, improves reliability" On)
LIST_LENGTH=$((${#LIST[@]}/3))
if add_folder=$(dialog --title \
"Which folder do you want to export?" \
--inputbox "" \
6 80 "/armbian" 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" \
8 80 "${LOCALSUBNET}" 3>&1 1>&2 2>&3); then
if add_options=$(dialog --separate-output \
--nocancel \
--title "NFS volume options" \
--checklist "" \
$((${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
fi
fi
fi
;;
"${commands[4]}")
if systemctl is-active --quiet nfs-server.service; then
return 0
else
return 1
fi
;;
"${commands[5]}")
echo -e "\nUsage: ${module_options["module_nfsd,feature"]} <command>"
echo -e "Commands: ${module_options["module_nfsd,example"]}"
echo "Available commands:"
echo -e "\tinstall\t- Install $title."
echo -e "\tmanage\t- Edit exports in $title."
echo -e "\tadd\t- Add exports to $title."
echo -e "\tstatus\t- Installation status $title."
echo -e "\tremove\t- Remove $title."
echo
;;
*)
${module_options["module_nfsd,feature"]} ${commands[5]}
;;
esac
}

0 comments on commit 29a7631

Please sign in to comment.