From 815a3f3c6637e617a0b121510cf43267c9586f4c Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 14 Oct 2024 16:40:15 +0200 Subject: [PATCH] feat: Support multiple shared folders (#810) --- src/samba.sh | 92 ++++++++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 43 deletions(-) diff --git a/src/samba.sh b/src/samba.sh index 6a65095..498194f 100644 --- a/src/samba.sh +++ b/src/samba.sh @@ -14,47 +14,52 @@ if [[ "$DHCP" == [Yy1]* ]]; then interface="$VM_NET_DEV" fi -share="/data" +addShare() { + local dir="$1" + local name="$2" + local comment="$3" -if [ ! -d "$share" ] && [ -d "$STORAGE/data" ]; then - share="$STORAGE/data" -fi + mkdir -p "$dir" || return 1 -if [ ! -d "$share" ] && [ -d "/shared" ]; then - share="/shared" -fi + if [ -z "$(ls -A "$dir")" ]; then -if [ ! -d "$share" ] && [ -d "$STORAGE/shared" ]; then - share="$STORAGE/shared" -fi + chmod 777 "$dir" -mkdir -p "$share" + { echo "--------------------------------------------------------" + echo " $APP for Docker v$( "$dir/readme.txt" -if [ -z "$(ls -A "$share")" ]; then + fi - chmod 777 "$share" + { echo "" + echo "[$name]" + echo " path = $dir" + echo " comment = $comment" + echo " writable = yes" + echo " guest ok = yes" + echo " guest only = yes" + echo " force user = root" + echo " force group = root" + } >> "/etc/samba/smb.conf" - { echo "--------------------------------------------------------" - echo " $APP for Docker v$( "$share/readme.txt" - -fi + return 0 +} { echo "[global]" echo " server string = Dockur" @@ -72,17 +77,18 @@ fi echo " printing = bsd" echo " printcap name = /dev/null" echo " disable spoolss = yes" - echo "" - echo "[Data]" - echo " path = $share" - echo " comment = Shared" - echo " writable = yes" - echo " guest ok = yes" - echo " guest only = yes" - echo " force user = root" - echo " force group = root" } > "/etc/samba/smb.conf" +share="/data" +[ ! -d "$share" ] && [ -d "$STORAGE/data" ] && share="$STORAGE/data" +[ ! -d "$share" ] && [ -d "/shared" ] && share="/shared" +[ ! -d "$share" ] && [ -d "$STORAGE/shared" ] && share="$STORAGE/shared" + +addShare "$share" "Data" "Shared" || error "Failed to create shared folder!" + +[ -d "/data2" ] && addShare "/data2" "Data2" "Shared" +[ -d "/data3" ] && addShare "/data3" "Data3" "Shared" + if ! smbd; then error "Samba daemon failed to start!" smbd -i --debug-stdout || true