mirror of
https://github.com/dockur/windows.git
synced 2026-08-03 12:37:20 +01:00
feat: Handle read-only Samba share mounts (#2022)
This commit is contained in:
@@ -106,6 +106,7 @@ An empty default means the variable is unset and its value is determined automat
|
|||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `SAMBA` | `Y` | Enables the Samba shared folder. |
|
| `SAMBA` | `Y` | Enables the Samba shared folder. |
|
||||||
| `SAMBA_DEBUG` | `N` | Enables Samba debug output. |
|
| `SAMBA_DEBUG` | `N` | Enables Samba debug output. |
|
||||||
|
| `SAMBA_READONLY` | `N` | Enables read-only mode for the shared folder. |
|
||||||
| `SHORTCUT` | `Y` | Creates desktop and drive shortcuts to the shared folder. |
|
| `SHORTCUT` | `Y` | Creates desktop and drive shortcuts to the shared folder. |
|
||||||
|
|
||||||
## ⚙️ System
|
## ⚙️ System
|
||||||
|
|||||||
+51
-6
@@ -3,6 +3,7 @@ set -Eeuo pipefail
|
|||||||
|
|
||||||
: "${SAMBA:="Y"}" # Enable Samba
|
: "${SAMBA:="Y"}" # Enable Samba
|
||||||
: "${SAMBA_DEBUG:="N"}" # Disable debug
|
: "${SAMBA_DEBUG:="N"}" # Disable debug
|
||||||
|
: "${SAMBA_READONLY:="N"}" # Disable writes
|
||||||
: "${SAMBA_CONFIG:="/etc/samba/smb.conf"}"
|
: "${SAMBA_CONFIG:="/etc/samba/smb.conf"}"
|
||||||
|
|
||||||
DDN_PID="/var/run/wsdd.pid"
|
DDN_PID="/var/run/wsdd.pid"
|
||||||
@@ -87,7 +88,10 @@ addShare() {
|
|||||||
local name="$3"
|
local name="$3"
|
||||||
local comment="$4"
|
local comment="$4"
|
||||||
local cfg="$5"
|
local cfg="$5"
|
||||||
local owner
|
local owner probe
|
||||||
|
local empty="N"
|
||||||
|
local writable="N"
|
||||||
|
local readonly="N"
|
||||||
local tmp="/tmp/smb"
|
local tmp="/tmp/smb"
|
||||||
|
|
||||||
if [ ! -d "$dir" ]; then
|
if [ ! -d "$dir" ]; then
|
||||||
@@ -102,12 +106,43 @@ addShare() {
|
|||||||
error "$msg" && return 1
|
error "$msg" && return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -w "$dir" ]; then
|
if [ -z "$(ls -A "$dir")" ]; then
|
||||||
local msg="shared folder ($dir) is not writeable!"
|
empty="Y"
|
||||||
warn "$msg"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$(ls -A "$dir")" ]; then
|
if [[ "$dir" == "$tmp" ]]; then
|
||||||
|
|
||||||
|
readonly="Y"
|
||||||
|
|
||||||
|
elif enabled "$SAMBA_READONLY"; then
|
||||||
|
|
||||||
|
readonly="Y"
|
||||||
|
|
||||||
|
elif probe=$(mktemp "$dir/.samba-write-test.XXXXXX" 2>/dev/null); then
|
||||||
|
|
||||||
|
writable="Y"
|
||||||
|
|
||||||
|
if ! rm -f "$probe"; then
|
||||||
|
error "Failed to remove write test file ($probe)."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
elif [[ "$empty" == "Y" ]] && chmod 2777 "$dir" 2>/dev/null; then
|
||||||
|
|
||||||
|
if probe=$(mktemp "$dir/.samba-write-test.XXXXXX" 2>/dev/null); then
|
||||||
|
|
||||||
|
writable="Y"
|
||||||
|
|
||||||
|
if ! rm -f "$probe"; then
|
||||||
|
error "Failed to remove write test file ($probe)."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$writable" == "Y" ]] && [[ "$empty" == "Y" ]]; then
|
||||||
|
|
||||||
if ! chmod 2777 "$dir"; then
|
if ! chmod 2777 "$dir"; then
|
||||||
error "Failed to set permissions for directory $dir" && return 1
|
error "Failed to set permissions for directory $dir" && return 1
|
||||||
@@ -124,6 +159,10 @@ addShare() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
elif [[ "$readonly" != "Y" ]]; then
|
||||||
|
|
||||||
|
readonly="Y"
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$dir" == "$tmp" ]]; then
|
if [[ "$dir" == "$tmp" ]]; then
|
||||||
@@ -135,7 +174,13 @@ addShare() {
|
|||||||
echo "[$name]"
|
echo "[$name]"
|
||||||
echo " path = $dir"
|
echo " path = $dir"
|
||||||
echo " comment = $comment"
|
echo " comment = $comment"
|
||||||
echo " writable = yes"
|
|
||||||
|
if [[ "$readonly" == "Y" ]]; then
|
||||||
|
echo " read only = yes"
|
||||||
|
else
|
||||||
|
echo " read only = no"
|
||||||
|
fi
|
||||||
|
|
||||||
echo " guest ok = yes"
|
echo " guest ok = yes"
|
||||||
echo " guest only = yes"
|
echo " guest only = yes"
|
||||||
} >> "$cfg"; then
|
} >> "$cfg"; then
|
||||||
|
|||||||
Reference in New Issue
Block a user