-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sh
executable file
·122 lines (106 loc) · 3.2 KB
/
init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/sh
set -eo pipefail
AVAHI_CONF="/etc/avahi/avahi-daemon.conf"
SMB_CONF="/etc/samba/smb.conf"
: "${SMB_GROUP:=samba}"
: "${SMB_GID:=1234}"
: "${SMB_USER:=samba}"
: "${SMB_UID:=1234}"
: "${SMB_PATH:=/storage}"
: "${WORKGROUP:=123}"
: "${NETBIOS_NAME:=docker}"
: "${SHARE_NAME:=share}"
trap 'echo "==> Exit signal received - goodbye!"; exit 0' INT TERM
echo "==> Creating '${SMB_USER}:${SMB_GROUP}' (${SMB_UID}:${SMB_GID})"
addgroup -g "${SMB_GID}" "${SMB_GROUP}" || true
adduser -D -h "${SMB_PATH}" -G "${SMB_GROUP}" -u "${SMB_UID}" -s /sbin/nologin "${SMB_USER}" || true
chmod -v 775 "${SMB_PATH}"
cat << EOF > "${SMB_CONF}"
[global]
workgroup = ${WORKGROUP}
netbios name = ${NETBIOS_NAME}
server string = Samba server on Docker
server role = standalone server
use sendfile = yes
domain master = no
security = user
map to guest = Bad User
guest account = ${SMB_USER}
# mdns & nmbd
multicast dns register = no
wins support = yes
wins proxy = no
dns proxy = no
local master = no
preferred master = no
# disable printing
load printers = no
disable spoolss = yes
show add printer wizard = no
# enable symlinks
follow symlinks = yes
wide links = yes
allow insecure wide links = yes
# protocol hacks
lanman auth = yes
ntlm auth = yes
server min protocol = ${MIN_PROTOCOL:-NT1}
client min protocol = ${MIN_PROTOCOL:-NT1}
client lanman auth = yes
client ntlmv2 auth = no
client use spnego = no
# fix permissions
force user = ${SMB_USER}
force group = ${SMB_GROUP}
force create mode = 0664
force directory mode = 0775
[${SHARE_NAME}]
path = ${SMB_PATH}
dos filemode = yes
hide dot files = no
writable = yes
browseable = yes
guest ok = yes
guest only = yes
EOF
echo -e "==> Starting Samba with configuration:\n$(cat ${SMB_CONF})"
smbd --configfile="${SMB_CONF}" --foreground --debug-stdout --debuglevel="${DEBUG:-1}" --no-process-group &
while ! nc -z 127.0.0.1 445; do sleep 1; done
echo "==> SMBD started"
nmbd --configfile="${SMB_CONF}" --foreground --debug-stdout --debuglevel="${DEBUG:-1}" --no-process-group &
while ! nc -zu 127.0.0.1 137; do sleep 1; done
echo "==> NMBD started"
if [ "${ENABLE_AVAHI}" = "true" ]; then
cat << EOF > /etc/avahi/services/samba.service
<?xml version="1.0" standalone="no"?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h samba</name>
<service>
<type>_smb._tcp</type>
<port>445</port>
</service>
</service-group>
EOF
cat << EOF > "${AVAHI_CONF}"
[server]
host-name=${NETBIOS_NAME}
enable-dbus=no
EOF
echo -e "==> Starting Avahi with configuration:\n$(cat ${AVAHI_CONF})"
avahi-daemon --file="${AVAHI_CONF}" --no-rlimits --no-drop-root --no-chroot &
while ! nc -zu 127.0.0.1 5353; do sleep 1; done
echo "==> Avahi started"
fi
while true; do
smbclient "//${NETBIOS_NAME}/${SHARE_NAME}" \
--command="recurse;ls" \
--timeout="${HEALTHCHECK_TIMEOUT:-3}" \
--configfile="${SMB_CONF}" \
--name-resolve="wins" \
--workgroup="${WORKGROUP}" \
--user="%" --no-pass \
2>/dev/null | grep -q "blocks available"
sleep ${HEALTHCHECK_INTERVAL:-60} &
wait $!
done