-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·105 lines (97 loc) · 2.9 KB
/
entrypoint.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
#!/bin/bash
set -e
CONFIG_FILE="/etc/samba/runtime.conf"
HOSTNAME=`hostname`
# Global options.
set -e
cat >"$CONFIG_FILE" <<EOF
[global]
netbios name = $HOSTNAME
server string = $HOSTNAME
EOF
# If the user supplies a custom uid/gid combination, change the default smbuser accordingly.
if [[ -n $USER ]]; then
IFS=: read uid gid <<<"$USER"
if [[ "$uid" == "" ]] || [[ "$gid" == "" ]]; then
echo "invalid UID/GID"
exit 1
fi
groupmod --gid ${uid} smbuser
usermod --uid ${uid} --gid ${gid} smbuser
echo "Using ${uid}:${gid} for smbuser"
fi
# Parse options.
while getopts ":u:p:s:h" opt; do
case $opt in
h)
echo "Options:"
echo " -u user add a user"
echo " -s name@user1:ro[,userN:rw] add a share"
echo " -p user:password set user password"
exit 1
;;
u)
echo -n "Add user "
IFS=: read user <<<"$OPTARG"
echo "'$user' "
addgroup -S "$user"
adduser -s /sbin/nologin -H -D -G "$user" "$user"
;;
p)
echo -n "Setting password for user "
IFS=: read user password <<<"$OPTARG"
echo "'$user'"
echo "$password" |tee - |smbpasswd -s -a "$user"
echo "WARNING: This should not be a runtime parameter!"
;;
s)
echo -n "Add share "
IFS=@ read sharename users <<<"$OPTARG"
sharepath="/data/$sharename"
mkdir -p "$sharepath"
chown smbuser:smbuser "$sharepath"
echo -n "'$sharename' "
echo "[$sharename]" >>"$CONFIG_FILE"
echo -n "path '$sharepath' "
echo "path = \"$sharepath\"" >>"$CONFIG_FILE"
echo "read only = no" >>"$CONFIG_FILE"
echo "writable = yes" >>"$CONFIG_FILE"
if [[ -z "$users" ]] ; then
echo "no user defined"
exit 1
else
echo -n "for users: "
users=$(echo "$users" |tr "," " ")
vusers=""
rusers=""
wusers=""
for user in $users; do
IFS=: read user rw <<<"$user"
vusers="$vusers $user"
rusers="$rusers $user"
if [[ "$rw" == "rw" ]]; then
wusers="$wusers $user"
elif [[ "$rw" != "ro" ]]; then
echo "invalid read/write flag"
exit 1
fi
done
echo -n "$vusers"
echo "valid users = $vusers" >>"$CONFIG_FILE"
echo "read list = $rusers" >>"$CONFIG_FILE"
echo "write list = $wusers" >>"$CONFIG_FILE"
fi
echo
;;
\?)
echo "Invalid option: -$OPTARG"
exit 1
;;
:)
echo "Option -$OPTARG requires an argument."
exit 1
;;
esac
done
# Run samba.
exec ionice -c 3 smbd --foreground --no-process-group --debug-stdout --configfile=/etc/samba/smb.conf