Compare commits

..

4 commits

Author SHA1 Message Date
Kroese
7268cbb14b
feat: File sharing 2025-10-03 11:03:56 +02:00
Kroese
99db4c8e5d
feat: Add share reference 2025-10-03 06:16:54 +02:00
Kroese
ee69662994
fix: Refactor share directory assignment logic 2025-10-03 04:08:46 +02:00
Kroese
f7e023c6b7
feat: Update shared folder instructions 2025-10-03 03:26:11 +02:00

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 "/data2" ]; then if [ -d "/shared2" ]; then
addShare "/data2" "Data2" "Shared" || error "Failed to add shared folder '/data2'. Please check its permissions." 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 fi
if [ -d "/data3" ]; then if [ -d "/shared3" ]; then
addShare "/data3" "Data3" "Shared" || error "Failed to add shared folder '/data3'. Please check its permissions." 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 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