diff --git a/tools/json/config.system.json b/tools/json/config.system.json index b5dd941d..13428890 100644 --- a/tools/json/config.system.json +++ b/tools/json/config.system.json @@ -74,7 +74,7 @@ }, { "id": "Storage", - "description": "Install to internal media, ZFS, read-only rootfs", + "description": "Install to internal media, ZFS, NFS, read-only rootfs", "sub": [ { "id": "SY001", @@ -127,6 +127,36 @@ "status": "Stable", "author": "@igorpecovnik", "condition": "command -v overlayroot-chroot > /dev/null 2>&1 && findmnt -k /media/root-ro | tail -1 | grep -w /media/root-ro > /dev/null 2>&1" + }, + { + "id": "NFS01", + "description": "Install network filesystem (NFS) daemon", + "command": [ + "module_nfsd install" + ], + "status": "Stable", + "author": "@igorpecovnik", + "condition": "! module_nfsd status" + }, + { + "id": "NFS02", + "description": "Configure network filesystem (NFS) daemon", + "command": [ + "module_nfsd manage" + ], + "status": "Stable", + "author": "@igorpecovnik", + "condition": "module_nfsd status" + }, + { + "id": "NFS03", + "description": "Remove network filesystem (NFS) daemon", + "command": [ + "module_nfsd uninstall" + ], + "status": "Stable", + "author": "@igorpecovnik", + "condition": "module_nfsd status" } ] }, diff --git a/tools/modules/functions/set_runtime_variables.sh b/tools/modules/functions/set_runtime_variables.sh index 477e36f3..87ca3d26 100644 --- a/tools/modules/functions/set_runtime_variables.sh +++ b/tools/modules/functions/set_runtime_variables.sh @@ -60,6 +60,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" diff --git a/tools/modules/network/module_nfsd.sh b/tools/modules/network/module_nfsd.sh new file mode 100644 index 00000000..e18d80b9 --- /dev/null +++ b/tools/modules/network/module_nfsd.sh @@ -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"]} " + 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 +}