feat: add experimental standalone SMB service for Finder

This commit is contained in:
Meghdad committed 2026-10-16 15:09:41 +03:30
1 parent c9006c11dd
commit b9cb187f0d
55 files changed
+7961 -10

No files matched your search

+4
View File
@@ -5,3 +5,7 @@ The supervisor loads the private `/etc/storage/routershelf.env` file. Use the un
Copy `.env.example` to `.env` in the repository root. Run `--check-config` with `ROUTERSHELF_ENV_FILE` pointing to that file before installation. See [environment configuration](../../docs/configuration.md), [installation](../../docs/getting-started.md), and [operations](../../docs/operations.md).
The script targets the observed firmware hooks and firewall commands. No project edit automatically changes a running router.
## Optional independent SMB service
`smb-supervisor.example.sh` supervises only `routershelf-smb`, using `RS_SMB_BINARY` and `RS_SMB_CONFIG`. It does not load the web env, configure NTP/firewall, or touch public-share paths. See [SMB installation, lifecycle and rollback](../../docs/smb.md). Validate/approve target deployment separately; existing web hooks remain compatible.
+52
View File
@@ -0,0 +1,52 @@
#!/bin/sh
# Independent USB-aware SMB supervisor. No web environment, firewall or NTP.
# Administrator supplies absolute paths. Run foreground from the USB hook.
set -eu
: "${RS_SMB_BINARY:?set RS_SMB_BINARY to the installed SMB executable}"
: "${RS_SMB_CONFIG:?set RS_SMB_CONFIG to private JSON on protected storage}"
case "$RS_SMB_BINARY:$RS_SMB_CONFIG" in *'
'*|*' '*|*'..'*) echo 'Use absolute paths without spaces or ..' >&2; exit 1;; esac
case "$RS_SMB_BINARY" in /*) ;; *) exit 1;; esac
case "$RS_SMB_CONFIG" in /*) ;; *) exit 1;; esac
if [ "${1:-}" = --check-config ]; then
exec "$RS_SMB_BINARY" -config "$RS_SMB_CONFIG" -check-config
fi
if [ "$#" -ne 0 ]; then echo 'Only --check-config is supported' >&2; exit 1; fi
# mkdir is atomic: fail on an existing instance rather than trust reused PIDs.
# This directory is distinct from all public-share compatibility paths.
runtime=/tmp/routershelf-smb
umask 077
if ! mkdir "$runtime" 2>/dev/null; then
echo 'SMB supervisor lock exists; inspect its PID command line before recovery' >&2
exit 1
fi
child=
cleanup() {
trap '' INT TERM
if [ -n "$child" ]; then
# Only the direct child launched by this shell; never read a PID to kill.
kill -TERM "$child" 2>/dev/null || :
wait "$child" 2>/dev/null || :
fi
rm -f "$runtime/child.pid" "$runtime/supervisor.pid"
rmdir "$runtime" 2>/dev/null || :
}
trap 'exit 0' INT TERM
trap cleanup 0
printf '%s\n' "$$" > "$runtime/supervisor.pid"
while :; do
if [ -x "$RS_SMB_BINARY" ] && [ -f "$RS_SMB_CONFIG" ]; then
"$RS_SMB_BINARY" -config "$RS_SMB_CONFIG" &
child=$!
printf '%s\n' "$child" > "$runtime/child.pid"
wait "$child" || :
child=
rm -f "$runtime/child.pid"
fi
# The binary verifies exact mount presence before binding, never mkdirs a
# missing share, and exits on mount/root replacement. Retry is independent.
sleep 10 &
child=$!
wait "$child" || :
child=
done