Compare commits

..

No commits in common. "7268cbb14b5f710a3b0713050a60cee2d1a323a8" and "4cd2a9c70b351f512db5d93ae415411cbc8a3ae0" have entirely different histories.

View file

@ -5,8 +5,6 @@ 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
@ -29,18 +27,15 @@ html "Initializing shared folder..."
addShare() { addShare() {
local dir="$1" local dir="$1"
local ref="$2" local name="$2"
local name="$3" local comment="$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
fi
if [[ "$dir" == "$tmp" ]]; then chmod 777 "$dir" || return 1
{ echo "--------------------------------------------------------" { echo "--------------------------------------------------------"
echo " $APP for Docker v$(</run/version)..." echo " $APP for Docker v$(</run/version)..."
@ -49,16 +44,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 a folder on the host for this purpose, include the following bind mount in your compose file:" echo "To select the folder you want to share, include the following bind mount in your compose file:"
echo "" echo ""
echo " volumes:" echo " volumes:"
echo " - \"./example:${ref}\"" echo " - \"./example:/${name,,}\""
echo "" echo ""
echo "Or in your run command:" echo "Or in your run command:"
echo "" echo ""
echo " -v \"\${PWD:-.}/example:${ref}\"" echo " -v \"\${PWD:-.}/example:/${name,,}\""
echo "" echo ""
echo "Replace the example path ./example with your desired shared folder, which then will become visible here." echo "Replace the example path ./example with your desired shared folder."
echo "" echo ""
} | unix2dos > "$dir/readme.txt" } | unix2dos > "$dir/readme.txt"
@ -99,40 +94,28 @@ addShare() {
echo " disable spoolss = yes" echo " disable spoolss = yes"
} > "/etc/samba/smb.conf" } > "/etc/samba/smb.conf"
share="/shared" share="/data"
[ ! -d "$share" ] && [ -d "$STORAGE/shared" ] && share="$STORAGE/shared"
[ ! -d "$share" ] && [ -d "/data" ] && share="/data"
[ ! -d "$share" ] && [ -d "$STORAGE/data" ] && share="$STORAGE/data" [ ! -d "$share" ] && [ -d "$STORAGE/data" ] && share="$STORAGE/data"
[ ! -d "$share" ] && share="$tmp" [ ! -d "$share" ] && [ -d "/shared" ] && share="/shared"
[ ! -d "$share" ] && [ -d "$STORAGE/shared" ] && share="$STORAGE/shared"
m1="Failed to add shared folder" if ! addShare "$share" "Data" "Shared"; then
m2="Please check its permissions." error "Failed to add shared folder '$share'. Please check its permissions." && return 0
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" "/shared2" "Data2" "Shared" || error "$m1 '/data2'. $m2." addShare "/data2" "Data2" "Shared" || error "Failed to add shared folder '/data2'. Please check its permissions."
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" "/shared3" "Data3" "Shared" || error "$m1 '/data3'. $m2" addShare "/data3" "Data3" "Shared" || error "Failed to add shared folder '/data3'. Please check its permissions."
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" "/shared" "$dir_name" "Shared $dir_name" || error "Failed to create shared folder for $dir!" addShare "$dir" "$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