From 77a3fea2d6dc209fa918935b0ddc25df09f51796 Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 31 Mar 2026 12:07:50 +0200 Subject: [PATCH] fix(nfs): read config from /data/options.json with jq, bypass Supervisor API --- nfs/Dockerfile | 2 +- nfs/config.json | 2 +- nfs/run.sh | 34 +++++++++++++++++++++------------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/nfs/Dockerfile b/nfs/Dockerfile index cd8f6ea..ace40bb 100644 --- a/nfs/Dockerfile +++ b/nfs/Dockerfile @@ -1,6 +1,6 @@ ARG BUILD_FROM FROM $BUILD_FROM -RUN apk add --no-cache unfs3 bash +RUN apk add --no-cache unfs3 bash jq COPY run.sh / RUN chmod +x /run.sh CMD ["/run.sh"] \ No newline at end of file diff --git a/nfs/config.json b/nfs/config.json index fca271b..5c2de36 100644 --- a/nfs/config.json +++ b/nfs/config.json @@ -1,6 +1,6 @@ { "name": "NFS Server", - "version": "1.0.5", + "version": "1.0.6", "slug": "nfs_server", "description": "Expose Home Assistant media folder via NFS.", "arch": [ diff --git a/nfs/run.sh b/nfs/run.sh index c884c0f..8ef8b9a 100644 --- a/nfs/run.sh +++ b/nfs/run.sh @@ -1,24 +1,32 @@ #!/usr/bin/env bashio +CONFIG="/data/options.json" + # Build /etc/exports from configured shares 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}" +count=$(jq '.shares | length' "${CONFIG}") - if bashio::var.true "${READ_ONLY}"; then - OPTIONS="ro,no_root_squash" - else - OPTIONS="rw,no_root_squash" - fi +if [ "${count}" -eq 0 ]; then + bashio::log.warning "No shares configured, nothing to export." +else + for i in $(seq 0 $((count - 1))); do + FOLDER=$(jq -r ".shares[${i}].folder" "${CONFIG}") + NETWORK=$(jq -r ".shares[${i}].allowed_network" "${CONFIG}") + READ_ONLY=$(jq -r ".shares[${i}].read_only" "${CONFIG}") + MOUNT_PATH="/${FOLDER}" - bashio::log.info "Exporting ${MOUNT_PATH} to ${NETWORK} (${OPTIONS})..." - echo "${MOUNT_PATH} ${NETWORK}(${OPTIONS})" >> /etc/exports -done + if [ "${READ_ONLY}" = "true" ]; then + OPTIONS="ro,no_root_squash" + else + OPTIONS="rw,no_root_squash" + fi + + bashio::log.info "Exporting ${MOUNT_PATH} to ${NETWORK} (${OPTIONS})..." + echo "${MOUNT_PATH} ${NETWORK}(${OPTIONS})" >> /etc/exports + done +fi cat /etc/exports