2024-02-07 22:48:38 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -Eeuo pipefail
|
|
|
|
|
2024-03-11 12:30:07 +00:00
|
|
|
: "${SAMBA:="Y"}"
|
|
|
|
|
2024-06-10 17:38:32 +00:00
|
|
|
[[ "$SAMBA" == [Nn]* ]] && return 0
|
|
|
|
[[ "$NETWORK" == [Nn]* ]] && return 0
|
2024-02-07 22:48:38 +00:00
|
|
|
|
2024-04-27 16:46:09 +00:00
|
|
|
hostname="host.lan"
|
|
|
|
interface="dockerbridge"
|
2024-02-07 22:48:38 +00:00
|
|
|
|
2024-04-27 16:46:09 +00:00
|
|
|
if [[ "$DHCP" == [Yy1]* ]]; then
|
|
|
|
hostname="$IP"
|
|
|
|
interface="$VM_NET_DEV"
|
|
|
|
fi
|
|
|
|
|
2024-10-13 10:00:31 +00:00
|
|
|
share="/data"
|
|
|
|
|
|
|
|
if [ ! -d "$share" ] && [ -d "$STORAGE/data" ]; then
|
|
|
|
share="$STORAGE/data"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d "$share" ] && [ -d "/shared" ]; then
|
|
|
|
share="/shared"
|
|
|
|
fi
|
2024-05-05 19:24:47 +00:00
|
|
|
|
|
|
|
if [ ! -d "$share" ] && [ -d "$STORAGE/shared" ]; then
|
|
|
|
share="$STORAGE/shared"
|
|
|
|
fi
|
2024-02-07 22:48:38 +00:00
|
|
|
|
2024-04-27 16:46:09 +00:00
|
|
|
mkdir -p "$share"
|
2024-05-31 05:24:46 +00:00
|
|
|
|
|
|
|
if [ -z "$(ls -A "$share")" ]; then
|
|
|
|
|
|
|
|
chmod 777 "$share"
|
|
|
|
|
|
|
|
{ echo "--------------------------------------------------------"
|
|
|
|
echo " $APP for Docker v$(</run/version)..."
|
|
|
|
echo " For support visit $SUPPORT"
|
|
|
|
echo "--------------------------------------------------------"
|
|
|
|
echo ""
|
|
|
|
echo "Using this folder you can share files with the host machine."
|
|
|
|
echo ""
|
|
|
|
echo "To change its location, include the following bind mount in your compose file:"
|
|
|
|
echo ""
|
|
|
|
echo " volumes:"
|
2024-10-13 10:00:31 +00:00
|
|
|
echo " - \"/home/user/example:/data\""
|
2024-05-31 05:24:46 +00:00
|
|
|
echo ""
|
|
|
|
echo "Or in your run command:"
|
|
|
|
echo ""
|
2024-10-13 10:00:31 +00:00
|
|
|
echo " -v \"/home/user/example:/data\""
|
2024-05-31 05:24:46 +00:00
|
|
|
echo ""
|
|
|
|
echo "Replace the example path /home/user/example with the desired shared folder."
|
|
|
|
echo ""
|
|
|
|
} | unix2dos > "$share/readme.txt"
|
|
|
|
|
|
|
|
fi
|
2024-02-07 22:48:38 +00:00
|
|
|
|
|
|
|
{ echo "[global]"
|
|
|
|
echo " server string = Dockur"
|
2024-04-27 16:46:09 +00:00
|
|
|
echo " netbios name = $hostname"
|
2024-02-07 22:48:38 +00:00
|
|
|
echo " workgroup = WORKGROUP"
|
2024-04-27 16:46:09 +00:00
|
|
|
echo " interfaces = $interface"
|
2024-02-07 22:48:38 +00:00
|
|
|
echo " bind interfaces only = yes"
|
|
|
|
echo " security = user"
|
|
|
|
echo " guest account = nobody"
|
|
|
|
echo " map to guest = Bad User"
|
2024-03-26 01:28:13 +00:00
|
|
|
echo " server min protocol = NT1"
|
2024-02-07 22:48:38 +00:00
|
|
|
echo ""
|
|
|
|
echo " # disable printing services"
|
|
|
|
echo " load printers = no"
|
|
|
|
echo " printing = bsd"
|
|
|
|
echo " printcap name = /dev/null"
|
|
|
|
echo " disable spoolss = yes"
|
|
|
|
echo ""
|
|
|
|
echo "[Data]"
|
2024-04-27 16:46:09 +00:00
|
|
|
echo " path = $share"
|
2024-02-07 22:48:38 +00:00
|
|
|
echo " comment = Shared"
|
|
|
|
echo " writable = yes"
|
|
|
|
echo " guest ok = yes"
|
|
|
|
echo " guest only = yes"
|
|
|
|
echo " force user = root"
|
|
|
|
echo " force group = root"
|
2024-04-27 16:46:09 +00:00
|
|
|
} > "/etc/samba/smb.conf"
|
2024-02-07 22:48:38 +00:00
|
|
|
|
2024-06-04 13:55:28 +00:00
|
|
|
if ! smbd; then
|
|
|
|
error "Samba daemon failed to start!"
|
|
|
|
smbd -i --debug-stdout || true
|
|
|
|
fi
|
2024-03-26 01:28:13 +00:00
|
|
|
|
2024-05-28 16:20:27 +00:00
|
|
|
legacy=""
|
2024-03-26 01:28:13 +00:00
|
|
|
|
|
|
|
if [ -f "$STORAGE/windows.old" ]; then
|
|
|
|
MT=$(<"$STORAGE/windows.old")
|
2024-05-28 16:20:27 +00:00
|
|
|
[[ "${MT,,}" == "pc-q35-2"* ]] && legacy="y"
|
|
|
|
[[ "${MT,,}" == "pc-i440fx-2"* ]] && legacy="y"
|
2024-03-26 01:28:13 +00:00
|
|
|
fi
|
|
|
|
|
2024-05-28 16:20:27 +00:00
|
|
|
if [ -n "$legacy" ]; then
|
|
|
|
# Enable NetBIOS on Windows XP and lower
|
2024-06-04 13:55:28 +00:00
|
|
|
if ! nmbd; then
|
|
|
|
error "NetBIOS daemon failed to start!"
|
|
|
|
nmbd -i --debug-stdout || true
|
|
|
|
fi
|
2024-03-26 01:28:13 +00:00
|
|
|
else
|
2024-05-28 16:20:27 +00:00
|
|
|
# Enable Web Service Discovery on Vista and up
|
2024-04-27 16:46:09 +00:00
|
|
|
wsdd -i "$interface" -p -n "$hostname" &
|
2024-05-04 11:28:12 +00:00
|
|
|
echo "$!" > /var/run/wsdd.pid
|
2024-03-26 01:28:13 +00:00
|
|
|
fi
|
2024-02-07 22:48:38 +00:00
|
|
|
|
|
|
|
return 0
|