feat(nfs): support multiple configurable NFS shares with folder/network/read_only options
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "NFS Server",
|
"name": "NFS Server",
|
||||||
"version": "1.0.1",
|
"version": "1.0.3",
|
||||||
"slug": "nfs_server",
|
"slug": "nfs_server",
|
||||||
"description": "Expose Home Assistant media folder via NFS.",
|
"description": "Expose Home Assistant media folder via NFS.",
|
||||||
"arch": [
|
"arch": [
|
||||||
@@ -16,15 +16,31 @@
|
|||||||
"SYS_ADMIN"
|
"SYS_ADMIN"
|
||||||
],
|
],
|
||||||
"apparmor": false,
|
"apparmor": false,
|
||||||
|
"hassio_api": true,
|
||||||
"kernel_modules": true,
|
"kernel_modules": true,
|
||||||
"map": [
|
"map": [
|
||||||
"media:rw"
|
"media:rw",
|
||||||
|
"share:rw",
|
||||||
|
"config:ro",
|
||||||
|
"backup:ro"
|
||||||
],
|
],
|
||||||
"options": {
|
"options": {
|
||||||
"allowed_network": "192.168.1.0/24"
|
"shares": [
|
||||||
|
{
|
||||||
|
"folder": "media",
|
||||||
|
"allowed_network": "192.168.1.0/24",
|
||||||
|
"read_only": false
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"schema": {
|
"schema": {
|
||||||
"allowed_network": "str"
|
"shares": [
|
||||||
|
{
|
||||||
|
"folder": "str",
|
||||||
|
"allowed_network": "str",
|
||||||
|
"read_only": "bool"
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"build_from": {
|
"build_from": {
|
||||||
"amd64": "ghcr.io/home-assistant/amd64-base:latest",
|
"amd64": "ghcr.io/home-assistant/amd64-base:latest",
|
||||||
|
|||||||
32
nfs/run.sh
32
nfs/run.sh
@@ -1,17 +1,37 @@
|
|||||||
#!/usr/bin/env bashio
|
#!/usr/bin/env bashio
|
||||||
|
|
||||||
# Read config
|
# Build /etc/exports from configured shares
|
||||||
NETWORK=$(bashio::config 'allowed_network')
|
bashio::log.info "Configuring NFS exports..."
|
||||||
|
> /etc/exports
|
||||||
|
|
||||||
|
for index in $(bashio::config 'shares|keys[]'); do
|
||||||
|
FOLDER=$(bashio::config "shares[${index}].folder")
|
||||||
|
NETWORK=$(bashio::config "shares[${index}].allowed_network")
|
||||||
|
READ_ONLY=$(bashio::config "shares[${index}].read_only")
|
||||||
|
MOUNT_PATH="/${FOLDER}"
|
||||||
|
|
||||||
|
if bashio::var.true "${READ_ONLY}"; then
|
||||||
|
OPTIONS="ro,sync,no_subtree_check,no_root_squash"
|
||||||
|
else
|
||||||
|
OPTIONS="rw,sync,no_subtree_check,no_root_squash"
|
||||||
|
fi
|
||||||
|
|
||||||
|
bashio::log.info "Exporting ${MOUNT_PATH} to ${NETWORK} (${OPTIONS})..."
|
||||||
|
echo "${MOUNT_PATH} ${NETWORK}(${OPTIONS})" >> /etc/exports
|
||||||
|
done
|
||||||
|
|
||||||
# Setup exports
|
|
||||||
bashio::log.info "Exporting /media folder to ${NETWORK}..."
|
|
||||||
echo "/media ${NETWORK}(rw,sync,no_subtree_check,no_root_squash)" > /etc/exports
|
|
||||||
cat /etc/exports
|
cat /etc/exports
|
||||||
|
|
||||||
# Load NFS kernel module
|
# Load NFS kernel module
|
||||||
bashio::log.info "Loading nfsd kernel module..."
|
bashio::log.info "Loading nfsd kernel module..."
|
||||||
modprobe nfsd 2>/dev/null || bashio::log.warning "nfsd module not available, assuming built-in..."
|
modprobe nfsd 2>/dev/null || bashio::log.warning "nfsd module not available, assuming built-in..."
|
||||||
|
|
||||||
|
# Mount nfsd filesystem if not already mounted
|
||||||
|
if ! mountpoint -q /proc/fs/nfsd 2>/dev/null; then
|
||||||
|
bashio::log.info "Mounting nfsd filesystem..."
|
||||||
|
mount -t nfsd nfsd /proc/fs/nfsd || bashio::log.warning "Could not mount nfsd filesystem, it may be built-in..."
|
||||||
|
fi
|
||||||
|
|
||||||
# Start NFS services
|
# Start NFS services
|
||||||
bashio::log.info "Starting NFS services..."
|
bashio::log.info "Starting NFS services..."
|
||||||
rpcbind
|
rpcbind
|
||||||
@@ -24,4 +44,4 @@ rpc.statd &
|
|||||||
rpc.nfsd
|
rpc.nfsd
|
||||||
|
|
||||||
# Start rpc.mountd in the foreground to keep the container running
|
# Start rpc.mountd in the foreground to keep the container running
|
||||||
exec rpc.mountd --no-udp -F
|
exec rpc.mountd --no-udp -F
|
||||||
|
|||||||
Reference in New Issue
Block a user