fix: Shared folder location (#1450)

This commit is contained in:
Kroese 2025-10-03 11:41:40 +02:00 committed by GitHub
parent 4cd2a9c70b
commit 434bc11907
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,6 +5,8 @@ set -Eeuo pipefail
: "${SAMBA_DEBUG:="N"}" # Disable debug : "${SAMBA_DEBUG:="N"}" # Disable debug
: "${SAMBA_LEVEL:="1"}" # Debug log level : "${SAMBA_LEVEL:="1"}" # Debug log level
tmp="/tmp/smb"
rm -rf "$tmp"
rm -rf /var/run/wsdd.pid rm -rf /var/run/wsdd.pid
[[ "$SAMBA" == [Nn]* ]] && return 0 [[ "$SAMBA" == [Nn]* ]] && return 0
@ -27,15 +29,18 @@ html "Initializing shared folder..."
addShare() { addShare() {
local dir="$1" local dir="$1"
local name="$2" local ref="$2"
local comment="$3" local name="$3"
local comment="$4"
mkdir -p "$dir" || return 1 mkdir -p "$dir" || return 1
ls -A "$dir" >/dev/null 2>&1 || return 1 ls -A "$dir" >/dev/null 2>&1 || return 1
if [ -z "$(ls -A "$dir")" ]; then if [ -z "$(ls -A "$dir")" ]; then
chmod 777 "$dir" || return 1 chmod 777 "$dir" || return 1
fi
if [[ "$dir" == "$tmp" ]]; then
{ echo "--------------------------------------------------------" { echo "--------------------------------------------------------"
echo " $APP for Docker v$(</run/version)..." echo " $APP for Docker v$(</run/version)..."
@ -44,16 +49,16 @@ addShare() {
echo "" echo ""
echo "Using this folder you can exchange files with the host machine." echo "Using this folder you can exchange files with the host machine."
echo "" echo ""
echo "To select the folder you want to share, include the following bind mount in your compose file:" echo "To select a folder on the host for this purpose, include the following bind mount in your compose file:"
echo "" echo ""
echo " volumes:" echo " volumes:"
echo " - \"./example:/${name,,}\"" echo " - \"./example:${ref}\""
echo "" echo ""
echo "Or in your run command:" echo "Or in your run command:"
echo "" echo ""
echo " -v \"\${PWD:-.}/example:/${name,,}\"" echo " -v \"\${PWD:-.}/example:${ref}\""
echo "" echo ""
echo "Replace the example path ./example with your desired shared folder." echo "Replace the example path ./example with your desired shared folder, which then will become visible here."
echo "" echo ""
} | unix2dos > "$dir/readme.txt" } | unix2dos > "$dir/readme.txt"
@ -94,28 +99,40 @@ addShare() {
echo " disable spoolss = yes" echo " disable spoolss = yes"
} > "/etc/samba/smb.conf" } > "/etc/samba/smb.conf"
share="/data" share="/shared"
[ ! -d "$share" ] && [ -d "$STORAGE/data" ] && share="$STORAGE/data"
[ ! -d "$share" ] && [ -d "/shared" ] && share="/shared"
[ ! -d "$share" ] && [ -d "$STORAGE/shared" ] && share="$STORAGE/shared" [ ! -d "$share" ] && [ -d "$STORAGE/shared" ] && share="$STORAGE/shared"
[ ! -d "$share" ] && [ -d "/data" ] && share="/data"
[ ! -d "$share" ] && [ -d "$STORAGE/data" ] && share="$STORAGE/data"
[ ! -d "$share" ] && share="$tmp"
if ! addShare "$share" "Data" "Shared"; then m1="Failed to add shared folder"
error "Failed to add shared folder '$share'. Please check its permissions." && return 0 m2="Please check its permissions."
if ! addShare "$share" "/shared" "Data" "Shared"; then
error "$m1 '$share'. $m2" && return 0
fi fi
if [ -d "/shared2" ]; then
addShare "/shared2" "/shared2" "Data2" "Shared" || error "$m1 '/shared2'. $m2"
else
if [ -d "/data2" ]; then if [ -d "/data2" ]; then
addShare "/data2" "Data2" "Shared" || error "Failed to add shared folder '/data2'. Please check its permissions." addShare "/data2" "/shared2" "Data2" "Shared" || error "$m1 '/data2'. $m2."
fi
fi fi
if [ -d "/shared3" ]; then
addShare "/shared3" "/shared3" "Data3" "Shared" || error "$m1 '/shared3'. $m2"
else
if [ -d "/data3" ]; then if [ -d "/data3" ]; then
addShare "/data3" "Data3" "Shared" || error "Failed to add shared folder '/data3'. Please check its permissions." addShare "/data3" "/shared3" "Data3" "Shared" || error "$m1 '/data3'. $m2"
fi
fi fi
IFS=',' read -r -a dirs <<< "${SHARES:-}" IFS=',' read -r -a dirs <<< "${SHARES:-}"
for dir in "${dirs[@]}"; do for dir in "${dirs[@]}"; do
[ ! -d "$dir" ] && continue [ ! -d "$dir" ] && continue
dir_name=$(basename "$dir") dir_name=$(basename "$dir")
addShare "$dir" "$dir_name" "Shared $dir_name" || error "Failed to create shared folder for $dir!" addShare "$dir" "/shared" "$dir_name" "Shared $dir_name" || error "Failed to create shared folder for $dir!"
done done
# Try to repair Samba permissions # Try to repair Samba permissions