-
Notifications
You must be signed in to change notification settings - Fork 27
/
run.sh
106 lines (96 loc) · 2.87 KB
/
run.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
#!/bin/bash
CONFIG_FILE="/etc/samba/smb.conf"
initialized=`getent passwd |grep -c '^smbuser:'`
set -e
if [ $initialized = "0" ]; then
useradd smbuser -M
cat >"$CONFIG_FILE" <<EOT
[global]
workgroup = WORKGROUP
security = user
create mask = 0664
directory mask = 0775
force create mode = 0664
force directory mode = 0775
force user = smbuser
force group = smbuser
load printers = no
printing = bsd
printcap name = /dev/null
disable spoolss = yes
EOT
while getopts ":u:s:h" opt; do
case $opt in
h)
cat <<EOH
Samba server container
Container will be configured as samba sharing server and it just needs:
* host directories to be mounted,
* users (one or more username:password tuples) provided,
* shares defined (name, path, users).
-u username:password add user account (named 'username'), which is
protected by 'password'
-s name:path:rw:user1[,user2[,userN]]
add share, that is visible as 'name', exposing
contents of 'path' directory for read+write (rw)
or read-only (ro) access for specified logins
user1, user2, .., userN
Example:
docker run -d -p 445:445 \\
-v /mnt/data:/share/data \\
-v /mnt/backups:/share/backups \\
trnape/rpi-samba \\
-u "alice:abc123" \\
-u "bob:secret" \\
-u "guest:guest" \\
-s "Backup directory:/share/backups:rw:alice,bob" \\
-s "Alice (private):/share/data/alice:rw:alice" \\
-s "Bob (private):/share/data/bob:rw:bob" \\
-s "Documents (readonly):/share/data/documents:ro:guest,alice,bob"
EOH
exit 1
;;
u)
echo -n "Add user "
IFS=: read username password <<<"$OPTARG"
echo -n "'$username' "
useradd "$username" -M
echo -n "with password '$password' "
echo "$password" |tee - |smbpasswd -s -a "$username"
echo "DONE"
;;
s)
echo -n "Add share "
IFS=: read sharename sharepath readwrite users <<<"$OPTARG"
echo -n "'$sharename' "
echo "[$sharename]" >>"$CONFIG_FILE"
chown smbuser "$sharepath"
echo -n "path '$sharepath' "
echo "path = \"$sharepath\"" >>"$CONFIG_FILE"
echo -n "read"
if [[ "rw" = "$readwrite" ]] ; then
echo -n "+write "
echo "read only = no" >>"$CONFIG_FILE"
else
echo -n "-only "
echo "read only = yes" >>"$CONFIG_FILE"
fi
echo -n "for users: "
users=$(echo "$users" |tr "," " ")
echo -n "$users "
echo "valid users = $users" >>"$CONFIG_FILE"
echo "DONE"
;;
\?)
echo "Invalid option: -$OPTARG"
exit 1
;;
:)
echo "Option -$OPTARG requires an argument."
exit 1
;;
esac
done
fi
nmbd -D
exec ionice -c 3 smbd -FS --configfile="$CONFIG_FILE"