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_LEVEL:="1"}" # Debug log level
tmp="/tmp/smb"
rm -rf "$tmp"
rm -rf /var/run/wsdd.pid
[[ "$SAMBA" == [Nn]* ]] && return 0
@ -27,15 +29,18 @@ html "Initializing shared folder..."
addShare() {
local dir="$1"
local name="$2"
local comment="$3"
local ref="$2"
local name="$3"
local comment="$4"
mkdir -p "$dir" || return 1
ls -A "$dir" >/dev/null 2>&1 || return 1
if [ -z "$(ls -A "$dir")" ]; then
chmod 777 "$dir" || return 1
fi
if [[ "$dir" == "$tmp" ]]; then
{ echo "--------------------------------------------------------"
echo " $APP for Docker v$(</run/version)..."
@ -44,16 +49,16 @@ addShare() {
echo ""
echo "Using this folder you can exchange files with the host machine."
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 " volumes:"
echo " - \"./example:/${name,,}\""
echo " - \"./example:${ref}\""
echo ""
echo "Or in your run command:"
echo ""
echo " -v \"\${PWD:-.}/example:/${name,,}\""
echo " -v \"\${PWD:-.}/example:${ref}\""
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 ""
} | unix2dos > "$dir/readme.txt"
@ -94,28 +99,40 @@ addShare() {
echo " disable spoolss = yes"
} > "/etc/samba/smb.conf"
share="/data"
[ ! -d "$share" ] && [ -d "$STORAGE/data" ] && share="$STORAGE/data"
[ ! -d "$share" ] && [ -d "/shared" ] && share="/shared"
share="/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
error "Failed to add shared folder '$share'. Please check its permissions." && return 0
m1="Failed to add shared folder"
m2="Please check its permissions."
if ! addShare "$share" "/shared" "Data" "Shared"; then
error "$m1 '$share'. $m2" && return 0
fi
if [ -d "/data2" ]; then
addShare "/data2" "Data2" "Shared" || error "Failed to add shared folder '/data2'. Please check its permissions."
if [ -d "/shared2" ]; then
addShare "/shared2" "/shared2" "Data2" "Shared" || error "$m1 '/shared2'. $m2"
else
if [ -d "/data2" ]; then
addShare "/data2" "/shared2" "Data2" "Shared" || error "$m1 '/data2'. $m2."
fi
fi
if [ -d "/data3" ]; then
addShare "/data3" "Data3" "Shared" || error "Failed to add shared folder '/data3'. Please check its permissions."
if [ -d "/shared3" ]; then
addShare "/shared3" "/shared3" "Data3" "Shared" || error "$m1 '/shared3'. $m2"
else
if [ -d "/data3" ]; then
addShare "/data3" "/shared3" "Data3" "Shared" || error "$m1 '/data3'. $m2"
fi
fi
IFS=',' read -r -a dirs <<< "${SHARES:-}"
for dir in "${dirs[@]}"; do
[ ! -d "$dir" ] && continue
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
# Try to repair Samba permissions