-
Notifications
You must be signed in to change notification settings - Fork 0
/
unas.sh
executable file
·155 lines (127 loc) · 3.01 KB
/
unas.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env bash
#
# 0. Start
#
echo
echo "Starting..."
#
# 1. Protect
#
echo
echo "Step 1. Protect"
# Stop it
echo "-- Stopping..."
systemctl stop unifi-protect >/dev/null 2>/dev/null
echo "---- OK!"
echo "-- Disabling..."
systemctl disable unifi-protect >/dev/null 2>/dev/null
systemctl mask unifi-protect >/dev/null 2>/dev/null
echo "---- OK!"
echo "-- Removing..."
apt-get remove unifi-protect -y
echo "---- OK!"
#
# 2. Install
#
echo
echo "Step 2. Samba"
# Install Samba (to serve up the NAS).
echo "-- Installing..."
apt-get install samba -y >/dev/null 2>/dev/null
echo "---- OK!"
# Start the samba service
echo "-- Starting..."
service smbd start
echo "---- OK!"
# Set the service to start on boot/reboot
echo "-- Autoloading..."
systemctl -q enable smbd.service >/dev/null 2>/dev/null
echo "---- OK!"
#
# 3. Config
#
echo
echo "Step 3. Config"
# Make a backup copy of the smb.conf file
echo "-- Creating backup of Samba config..."
cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
echo "---- OK!"
# Add this to smb.conf
echo "-- Creating new Samba config..."
cat > /etc/samba/smb.conf <<EOF
#============================ Global definition ================================
[global]
workgroup = WORKGROUP
server string = Samba Server %v
log file = /var/log/samba/%m.log
max log size = 50
security = user
map to guest = never
dns proxy = no
#============================ Share Definitions ==============================
[Public]
path = /volume1/Samba/Public
public = yes
guest only = yes
browseable = yes
writable = yes
force create mode = 0666
force directory mode = 0777
[Protected]
path = /volume1/Samba/Protected
valid users = @unasmbgrp
browsable = yes
writable = yes
read only = no
EOF
echo "---- OK!"
#
# 4. Add User & Usergroup
#
echo
echo "Step 4. Auth"
# Create a linux user
echo "-- Adding user..."
adduser -q unasamba >/dev/null 2>/dev/null
echo "---- OK!"
# Create a linux user group
echo "-- Adding usergroup..."
addgroup -q unasmbgrp >/dev/null 2>/dev/null
echo "---- OK!"
# Add user to group
echo "-- Adding user to usergroup..."
adduser -q unasamba unasmbgrp >/dev/null 2>/dev/null
echo "---- OK!"
# Create a password
echo "-- Adding user password..."
echo -e "unasamba\nunasamba" | smbpasswd -a -s unasamba
echo "---- OK!"
#
# 5. Add Directories
#
echo
echo "Step 5. Directories"
# Make directories for Public and Protected
echo "-- Creating directories..."
[ -d /volume1/Samba ] || mkdir /volume1/Samba
[ -d /volume1/Samba/Public ] || mkdir /volume1/Samba/Public
[ -d /volume1/Samba/Protected ] || mkdir /volume1/Samba/Protected
echo "---- OK!"
# Set the permissions on the directories
echo "-- Setting permissions..."
chmod -R ugo+w /volume1/Samba/Public
chmod -R 0770 /volume1/Samba/Protected
chown root:unasmbgrp /volume1/Samba/Protected
echo "---- OK!"
# Restart the smb service
echo "-- Restarting samba..."
service smbd restart
systemctl daemon-reload
echo "---- OK!"
echo
echo "-- Access a Protected directory:"
echo "---- U: unasamba"
echo "---- P: unasamba"
echo
echo "All done!"
echo