From b8bece0239c1f507592c4fb8b33bd21b76809b81 Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 14 Oct 2024 16:22:47 +0200 Subject: [PATCH 1/2] feat: Support multiple shared folders --- src/samba.sh | 100 +++++++++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 47 deletions(-) diff --git a/src/samba.sh b/src/samba.sh index 6a65095ec..f2ef37e5a 100644 --- a/src/samba.sh +++ b/src/samba.sh @@ -14,47 +14,52 @@ if [[ "$DHCP" == [Yy1]* ]]; then interface="$VM_NET_DEV" fi -share="/data" - -if [ ! -d "$share" ] && [ -d "$STORAGE/data" ]; then - share="$STORAGE/data" -fi +addShare() { + local dir="$1" + local name="$2" + local comment="$3" + + mkdir -p "$dir" || return 1 + + if [ -z "$(ls -A "$dir")" ]; then + + chmod 777 "$dir" + + { echo "--------------------------------------------------------" + echo " $APP for Docker v$( "$dir/readme.txt" -if [ ! -d "$share" ] && [ -d "/shared" ]; then - share="/shared" -fi + fi -if [ ! -d "$share" ] && [ -d "$STORAGE/shared" ]; then - share="$STORAGE/shared" -fi + { 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" -mkdir -p "$share" - -if [ -z "$(ls -A "$share")" ]; then - - chmod 777 "$share" - - { 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 From 2d9119fc4657f8edaeb5404985c2cdb047e49c2c Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 14 Oct 2024 16:37:07 +0200 Subject: [PATCH 2/2] Update samba.sh --- src/samba.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/samba.sh b/src/samba.sh index f2ef37e5a..498194f93 100644 --- a/src/samba.sh +++ b/src/samba.sh @@ -35,13 +35,13 @@ addShare() { echo "To change its location, include the following bind mount in your compose file:" echo "" echo " volumes:" - echo " - \"/home/user/example:${name,,}\"" + echo " - \"/home/example:/${name,,}\"" echo "" echo "Or in your run command:" echo "" - echo " -v \"/home/user/example:${name,,}\"" + echo " -v \"/home/example:/${name,,}\"" echo "" - echo "Replace the example path /home/user/example with the desired shared folder." + echo "Replace the example path /home/example with the desired shared folder." echo "" } | unix2dos > "$dir/readme.txt"