From 6ae475182dfb8117c01f4d2197fdb58fcbd1ba0b Mon Sep 17 00:00:00 2001 From: strelok Date: Fri, 22 Mar 2019 01:14:47 +0100 Subject: [PATCH 1/2] allow crossmounts and use subnet mask examples for readme --- README.md | 4 +++- exports | 2 +- nfsd.sh | 10 ++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a33a0f0..15acc54 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,9 @@ Adding `-e READ_ONLY=true` will cause the exports file to contain `ro` instead o Adding `-e SYNC=true` will cause the exports file to contain `sync` instead of `async`, enabling synchronous mode. Check the exports man page for more information: https://linux.die.net/man/5/exports. -Adding `-e PERMITTED="10.11.99.*"` will permit only hosts with an IP address starting 10.11.99 to mount the file share. +Adding `-e PERMITTED="10.11.99.0\/24"` will permit only hosts with an IP address starting 10.11.99 to mount the file share. The single backslash is used for escaping the slash dividing net address and netmask during the replacement via sed. + +Adding `-e CROSSMNT=yes` will allow to share mounts which are placed in `/some/where/fileshare`. This is especially needed when allowing more than only one IP. Due to the `fsid=0` parameter set in the **/etc/exports file**, there's no need to specify the folder name when mounting from a client. For example, this works fine even though the folder being mounted and shared is /nfsshare: diff --git a/exports b/exports index 65f29e0..a090fe2 100644 --- a/exports +++ b/exports @@ -1 +1 @@ -{{SHARED_DIRECTORY}} {{PERMITTED}}({{READ_ONLY}},fsid=0,{{SYNC}},no_subtree_check,no_auth_nlm,insecure,no_root_squash) +{{SHARED_DIRECTORY}} {{PERMITTED}}({{READ_ONLY}},fsid=0,{{SYNC}},{{CROSSMNT}},no_subtree_check,no_auth_nlm,insecure,no_root_squash) diff --git a/nfsd.sh b/nfsd.sh index 9faf38f..d0aebc1 100755 --- a/nfsd.sh +++ b/nfsd.sh @@ -74,6 +74,16 @@ else /bin/sed -i "s/{{SYNC}}/sync/g" /etc/exports fi +# Check if the CROSSMNT variable is set (rather than a null string) using parameter expansion +if [ -z "${CROSSMNT+y}" ]; then + echo "The CROSSMNT environment variable is unset or null, so do not allow crossmounts." + echo "Mounts in shares will appear empty" + /bin/sed -i "s/{{CROSSMNT}},//g" /etc/exports +else + echo "The CROSSMNT environment variable is set, allowing crossmounts." + /bin/sed -i "s/{{SYNC}}/crossmnt/g" /etc/exports +fi + # Partially set 'unofficial Bash Strict Mode' as described here: http://redsymbol.net/articles/unofficial-bash-strict-mode/ # We don't set -e because the pidof command returns an exit code of 1 when the specified process is not found # We expect this at times and don't want the script to be terminated when it occurs From ecdd83d3aeff7b3e93c37eef4bf434fab77cac5f Mon Sep 17 00:00:00 2001 From: dev00 Date: Fri, 22 Mar 2019 01:22:04 +0100 Subject: [PATCH 2/2] Update nfsd.sh missed out this little bug --- nfsd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nfsd.sh b/nfsd.sh index d0aebc1..cfe23cb 100755 --- a/nfsd.sh +++ b/nfsd.sh @@ -81,7 +81,7 @@ if [ -z "${CROSSMNT+y}" ]; then /bin/sed -i "s/{{CROSSMNT}},//g" /etc/exports else echo "The CROSSMNT environment variable is set, allowing crossmounts." - /bin/sed -i "s/{{SYNC}}/crossmnt/g" /etc/exports + /bin/sed -i "s/{{CROSSMNT}}/crossmnt/g" /etc/exports fi # Partially set 'unofficial Bash Strict Mode' as described here: http://redsymbol.net/articles/unofficial-bash-strict-mode/