#!/usr/bin/env bash set -Eeuo pipefail : "${SAMBA:="Y"}" [[ "$SAMBA" == [Nn]* ]] && return 0 [[ "$NETWORK" == [Nn]* ]] && return 0 hostname="host.lan" interface="dockerbridge" if [[ "$DHCP" == [Yy1]* ]]; then hostname="$IP" interface="$VM_NET_DEV" fi if [[ "${NETWORK,,}" == "user"* ]]; then interface="127.0.0.1" 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" 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" return 0 } { echo "[global]" echo " server string = Dockur" echo " netbios name = $hostname" echo " workgroup = WORKGROUP" echo " interfaces = $interface" echo " bind interfaces only = yes" echo " security = user" echo " guest account = nobody" echo " map to guest = Bad User" echo " server min protocol = NT1" echo " follow symlinks = yes" echo " wide links = yes" echo " unix extensions = no" echo "" echo " # disable printing services" echo " load printers = no" echo " printing = bsd" echo " printcap name = /dev/null" echo " disable spoolss = yes" } > "/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" 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!" done # Fix Samba permissions [ -d /run/samba/msg.lock ] && chmod -R 0755 /run/samba/msg.lock [ -d /var/log/samba/cores ] && chmod -R 0700 /var/log/samba/cores [ -d /var/cache/samba/msg.lock ] && chmod -R 0755 /var/cache/samba/msg.lock if ! smbd; then error "Samba daemon failed to start!" smbd -i --debug-stdout || true else if [[ "${NETWORK,,}" == "user"* ]]; then NET_OPTS="${NET_OPTS/,hostfwd/,guestfwd=tcp:${VM_NET_IP%.*}.1:445-tcp:127.0.0.1:445,hostfwd}" fi fi [[ "${NETWORK,,}" == "user"* ]] && return 0 if [[ "${BOOT_MODE:-}" == "windows_legacy" ]]; then # Enable NetBIOS on Windows 7 and lower if ! nmbd; then error "NetBIOS daemon failed to start!" nmbd -i --debug-stdout || true fi else # Enable Web Service Discovery on Vista and up wsdd -i "$interface" -p -n "$hostname" & echo "$!" > /var/run/wsdd.pid fi return 0