-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMEMInstall.sh
463 lines (398 loc) · 14 KB
/
MEMInstall.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
#!/bin/bash
#MEMinstall.sh
#This installer will install a member server to a pre-existing domain
clear
dnf -y install net-tools dmidecode
TEXTRESET=$(tput sgr0)
RED=$(tput setaf 1)
YELLOW=$(tput setaf 3)
GREEN=$(tput setaf 2)
INTERFACE=$(nmcli | grep "connected to" | cut -d " " -f4)
FQDN=$(hostname)
IP=$(hostname -I)
FQDN=$(hostname)
DOMAIN=$(hostname | sed 's/^[^.:]*[.:]//' | sed -e 's/\(.*\)/\U\1/')
ADDOMAIN=$(hostname | sed 's/^[^.:]*[.:]//' | cut -d. -f1 | sed -e 's/\(.*\)/\U\1/')
USER=$(whoami)
MAJOROS=$(cat /etc/redhat-release | grep -Eo "[0-9]" | sed '$d')
DETECTIP=$(nmcli -f ipv4.method con show $INTERFACE)
NMCLIIP=$(nmcli | grep inet4 | sed '$d' | cut -c7- | cut -d / -f1)
HWKVM=$(dmidecode | grep -i -e manufacturer -e product -e vendor | grep KVM | cut -c16-)
HWVMWARE=$(dmidecode | grep -i -e manufacturer -e product -e vendor | grep Manufacturer | grep "VMware, Inc." | cut -c16- | cut -d , -f1)
n='([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
m='([0-9]|[12][0-9]|3[012])'
#Bracketed pasting...yuck!
sed -i '8i set enable-bracketed-paste off' /etc/inputrc
#Checking for user permissions
if [ "$USER" = "root" ]; then
echo " "
else
echo ${RED}"This program must be run as root ${TEXTRESET}"
echo "Exiting"
fi
#Checking for version Information
if [ "$MAJOROS" = "9" ]; then
echo " "
else
echo ${RED}"Sorry, but this installer only works on Rocky 9.X ${TEXTRESET}"
echo "Please upgrade to ${GREEN}Rocky 9.x${TEXTRESET}"
echo "Exiting the installer..."
exit
fi
clear
cat <<EOF
Checking for static IP Address
EOF
sleep 1s
#Detect Static or DHCP (IF not Static, change it)
if [ -z "$INTERFACE" ]; then
"Usage: $0 <interface>"
exit 1
fi
if [ "$DETECTIP" = "ipv4.method: auto" ]; then
echo ${RED}"Interface $INTERFACE is using DHCP${TEXTRESET}"
read -p "Please provide a static IP address in CIDR format (i.e 192.168.24.2/24): " IPADDR
while [ -z "$IPADDR" ]; do
echo ${RED}"The response cannot be blank. Please Try again${TEXTRESET}"
read -p "Please provide a static IP address in CIDR format (i.e 192.168.24.2/24): " IPADDR
done
while [[ ! $IPADDR =~ ^$n(\.$n){3}/$m$ ]]; do
read -p ${RED}"The entry is not in valid CIDR notation. Please Try again:${TEXTRESET} " IPADDR
done
read -p "Please Provide a Default Gateway Address: " GW
while [ -z "$GW" ]; do
echo ${RED}"The response cannot be blank. Please Try again${TEXTRESET}"
read -p "Please Provide a Default Gateway Address: " GW
done
read -p "Please provide the FQDN of this machine: " HOSTNAME
while [ -z "$HOSTNAME" ]; do
echo ${RED}"The response cannot be blank. Please Try again${TEXTRESET}"
read -p "Please provide the FQDN of this machine: " HOSTNAME
done
read -p "Please provide the IP address of the Active Directory server: " DNSSERVER
while [ -z "$DNSSERVER" ]; do
echo ${RED}"The response cannot be blank. Please Try again${TEXTRESET}"
read -p "Please provide the IP address of the Active Directory server: " DNSSERVER
done
read -p "Please provide the domain search name: " DNSSEARCH
while [ -z "$DNSSEARCH" ]; do
echo ${RED}"The response cannot be blank. Please Try again${TEXTRESET}"
read -p "Please provide the domain search name: " DNSSEARCH
done
clear
cat <<EOF
The following changes to the system will be configured:
IP address: ${GREEN}$IPADDR${TEXTRESET}
Gateway: ${GREEN}$GW${TEXTRESET}
DNS Search: ${GREEN}$DNSSEARCH${TEXTRESET}
DNS Server: ${GREEN}$DNSSERVER${TEXTRESET}
HOSTNAME: ${GREEN}$HOSTNAME${TEXTRESET}
EOF
read -p "Press any Key to Continue"
nmcli con mod $INTERFACE ipv4.address $IPADDR
nmcli con mod $INTERFACE ipv4.gateway $GW
nmcli con mod $INTERFACE ipv4.method manual
nmcli con mod $INTERFACE ipv4.dns-search $DNSSEARCH
nmcli con mod $INTERFACE ipv4.dns $DNSSERVER
hostnamectl set-hostname $HOSTNAME
cat <<EOF
The System must reboot for the changes to take effect. ${RED}Please log back in as root.${TEXTRESET}
The installer will continue when you log back in.
If using SSH, please use the IP Address: $IPADDR
EOF
read -p "Press Any Key to Continue"
clear
echo "/root/ADDCInstaller/MEMInstall.sh" >>/root/.bash_profile
reboot
exit
else
echo ${GREEN}"Interface $INTERFACE is using a static IP address ${TEXTRESET}"
fi
clear
if [ "$FQDN" = "localhost.localdomain" ]; then
cat <<EOF
${RED}This system is still using the default hostname (localhost.localdomain)${TEXTRESET}
EOF
read -p "Please provide a valid FQDN for this machine: " HOSTNAME
while [ -z "$HOSTNAME" ]; do
echo ${RED}"The response cannot be blank. Please Try again${TEXTRESET}"
read -p "Please provide a valid FQDN for this machine: " HOSTNAME
done
hostnamectl set-hostname $HOSTNAME
cat <<EOF
The System must reboot for the changes to take effect.
${RED}Please log back in as root.${TEXTRESET}
The installer will continue when you log back in.
If using SSH, please use the IP Address: ${NMCLIIP}
EOF
read -p "Press Any Key to Continue"
clear
echo "/root/ADDCInstaller/MEMInstall.sh" >>/root/.bash_profile
reboot
exit
fi
clear
cat <<EOF
*********************************************
This script was created for ${GREEN}Rocky 9.x${TEXTRESET}
This script will quickly configure a Samba File/Print Server
What this script does:
1. Update and install all dependencies the Base OS.
2. Add samba allowances to the Firewall
3. Sets the SELinux to Passive mode (you should change this after install)
4. Joins this server to the domain
5. Creates an example share for AD integration
*********************************************
This will take around 10-15 minutes depending on your Internet connection
and processor speed/memory
EOF
read -p "Press any Key to continue or Ctrl-C to Exit"
clear
cat <<EOF
*********************************************
Checklist:
Before the Installer starts, please make sure you have the following information
1. ${YELLOW}An Active Admin account${TEXTRESET} that you can use to join this server to the Windows domain
2. ${YELLOW}An Active User account${TEXTRESET} that you can use to test login to the Windows domain
2. Verify that this server is ${YELLOW}configured to use the DNS services of AD.${TEXTRESET}
3. Verify that the FQDN contains the ${YELLOW}REALM of the AD environment${TEXTRESET} you wish to join
*********************************************
EOF
read -p "Press any Key to continue or Ctrl-C to Exit"
clear
#Checking for VM platform-Install client
echo ${GREEN}"Installing VMGuest${TEXTRESET}"
if [ "$HWKVM" = "KVM" ]; then
echo ${GREEN}"KVM Platform detected ${TEXTRESET}"
echo "Installing qemu-guest-agent"
sleep 1
dnf -y install qemu-guest-agent
else
echo "Not KVM Platform"
fi
#Checking for VM platform-Install client
if [ "$HWVMWARE" = "VMware" ]; then
echo ${GREEN}"VMWARE Platform detected ${TEXTRESET}"
echo "Installing open-vm-tools"
sleep 1
dnf -y install open-vm-tools
else
echo "Not VMware Platform"
fi
clear
#SELinux Change
#We need to set SELinux to permissive if this is a file server.
#It must be declared what directories to use. RW
sed -i "s/SELINUX=enforcing/SELINUX=permissive/" /etc/selinux/config
#Allow SAMBA Ports on firewall-cmd
echo "Updating Firewall Rules"
echo "${GREEN} "
firewall-cmd --add-service=samba --permanent
firewall-cmd --add-service=samba-client --permanent
firewall-cmd --reload
clear
echo ${GREEN}"These are the services/ports now open on the server${TEXTRESET}"
echo
firewall-cmd --list-services --zone=public
echo "${TEXTRESET}"
echo "The Installer will continue in a moment or Press Ctrl-C to Exit"
sleep 8s
clear
cat <<EOF
${GREEN}Downloading and installing updates${TEXTRESET}
EOF
sleep 3s
dnf -y install epel-release
dnf -y install dnf-plugins-core
dnf config-manager --set-enabled crb
dnf -y update
dnf -y install ntsysv wget oddjob oddjob-mkhomedir samba-winbind samba-winbind-clients samba-common-tools realmd bind-utils samba
systemctl enable winbind
systemctl start winbind
clear
cat <<EOF
The Installer will now ask some questions from the checklist provided earlier.
Please make sure you have this information
EOF
read -p "Press any Key to continue or Ctrl-C to Exit"
clear
read -p "Please provide a valid AD username for testing: " ADUSER
while [ -z "$ADUSER" ]; do
echo ${RED}"The response cannot be blank. Please Try again${TEXTRESET}"
read -p "Please provide a valid AD username for testing: " ADUSER
done
read -p "Please provides this user's password: " ADPASS
while [ -z "$ADPASS" ]; do
echo ${RED}"The response cannot be blank. Please Try again${TEXTRESET}"
read -p "Please provides this user's password: " ADPASS
done
read -p "Please provide the IP/FQDN Address of your NTP/AD Server: " NTP
while [ -z "$NTP" ]; do
echo ${RED}"The response cannot be blank. Please Try again${TEXTRESET}"
read -p "Please provide the IP/FQDN Address of your NTP/AD Server: " NTP
done
read -p "Please provide the Administrator Account to join this system to AD (Just username, not UPN): " DOMAINADMIN
while [ -z "$DOMAINADMIN" ]; do
echo ${RED}"The response cannot be blank. Please Try again${TEXTRESET}"
read -p "Please provide the Administrator Account to join this system to AD (Just username, not UPN): " DOMAINADMIN
done
clear
cat <<EOF
Validating your Entries:
AD Testing Username: ${GREEN}$ADUSER${TEXTRESET}
AD Testing Password: ${GREEN}$ADPASS${TEXTRESET}
Domain: ${GREEN}$ADDOMAIN${TEXTRESET}
NTP Server: ${GREEN}$NTP${TEXTRESET}
AD Administrator Account: ${GREEN}$DOMAINADMIN${TEXTRESET}
EOF
read -p "Press any Key to continue or Ctrl-C to Exit"
clear
cat <<EOF
Joining server to Domain $ADDOMAIN
${RED}The screen may look frozen for up to a minute after the password is entered... Please wait${TEXTRESET}
EOF
realm join -U $DOMAINADMIN --client-software=winbind $DOMAIN
clear
sed -i "/pool /c\server $NTP iburst" /etc/chrony.conf
sed -i "/server /c\server $NTP iburst" /etc/chrony.conf
sed -e '2d' /etc/chrony.conf
systemctl restart chronyd
clear
echo ${RED}"Syncronizing time, Please wait${TEXTRESET}"
sleep 10s
clear
chronyc tracking
cat <<EOF
${GREEN}We should be syncing time${TEXTRESET}
The Installer will continue in a moment, otherwise Ctrl-C to stop processing
EOF
sleep 8
clear
#Validate winbind is working
cat <<EOF
${GREEN}Testing RPC to Active Directory${TEXTRESET}
EOF
echo ${GREEN}
wbinfo -t
echo ${TEXTRESET}
echo " "
echo "The Installer will continue in a moment, otherwise Ctrl-C to stop processing"
sleep 8
clear
#Validate winbind sees users
cat <<EOF
${GREEN}AD Users${TEXTRESET}
Please make sure you see your AD users.
If you do not, then please resolve this issue first before proceeding.
EOF
echo ${GREEN}
wbinfo -u
echo ${TEXTRESET}
echo " "
echo "The Installer will continue in a moment, otherwise Ctrl-C to stop processing"
sleep 8
clear
#Validate winbind groups are seen
cat <<EOF
${GREEN}AD Groups${TEXTRESET}
Please make sure you see your AD groups.
If you do not, then please resolve this issue first before proceeding.
EOF
echo ${GREEN}
wbinfo -g
echo ${TEXTRESET}
echo " "
echo "The Installer will continue in a moment, otherwise Ctrl-C to stop processing"
sleep 10
clear
#Basic test against AD
cat <<EOF
${GREEN}Test a winbind login${TEXTRESET}
We are going to login with the test account ${GREEN}($ADUSER)${TEXTRESET}. Please make sure you see a valid response of:
${GREEN}challenge/response password authentication succeeded${TEXTRESET}
If you do not, then please resolve this issue first before proceeding.
EOF
echo ${GREEN}
wbinfo -a $ADUSER%$ADPASS
echo ${TEXTRESET}
echo " "
echo "The Installer will continue in a moment, otherwise Ctrl-C to stop processing"
sleep 10
clear
#Update /etc/issue so we can see the hostname and IP address Before logging in
rm -r -f /etc/issue
touch /etc/issue
cat <<EOF >/etc/issue
\S
Kernel \r on an \m
Hostname: \n
IP Address: \4
EOF
clear
#Add option for cockpit install
cat <<EOF
${GREEN}Install Cockpit${TEXTRESET}
Cockpit is a server administration tool, focused on providing a modern-looking
and user-friendly interface to manage and administer servers.
EOF
read -r -p "Would you like to install Cockpit for web based administration? [y/N]" -n 1
echo # (optional) move to a new line
if [[ "$REPLY" =~ ^[Yy]$ ]]; then
echo ${YELLOW}"Your cockpit instance can be accessed at ${FQDN}:9090"${TEXTRESET}
sleep 5
dnf -y install cockpit-navigator cockpit cockpit-storaged
systemctl enable cockpit.socket
systemctl start cockpit.socket
fi
#Add Example file share for Samba
cat <<EOF >/etc/samba/smb.tmp
#Create a writable share to be used by an AD group
#Make sure that before you enable the share, you chown, recursively
#(i.e.) chown -R root."${ADDOMAIN}\domain users" /path/to/share
#Also change your permissions for the files/directories. Default is RWX(770) for Users and Groups
# chmod -R 770 /path/to/share
#SELinux also comes into play:
#(top directory-root of share)
#chcon -t samba_share_t /path/to/share/ -R
#Remember to uncomment and modify the lines below
#[SHARE_NAME]
#writeable = yes
#write list = @"${ADDOMAIN}\domain users"
#path = /path/to/share
#force group = "${ADDOMAIN}\domain users"
#force create mode = 2770
#comment = Data Share
#valid users = @"${ADDOMAIN}\domain users"
#create mode = 2770
#directory mode = 2770
#directory mask = 2770
EOF
cat /etc/samba/smb.tmp >> /etc/samba/smb.conf
#Enable and start samba services
systemctl enable smb
systemctl start smb
#Clean up Install files
sed -i '/MEMInstall.sh/d' /root/.bash_profile
rm -r -f /root/FR-Installer
rm -r -f /root/DC-Installer.sh
rm -r -f /root/ADDCInstaller
rm -r -f /root/FR-Installer.sh
clear
cat <<EOF
${GREEN}********************************
Server Installation Complete
********************************${TEXTRESET}
${YELLOW}An example share has been included in the smb.conf file${TEXTRESET}
${RED}SELinux has been set to PERMISSIVE MODE.${TEXTRESET}
Please make sure that you apply the correct
Please adjust, and set SELinux to enabled
Something as easy as:
${YELLOW} chcon -t samba_share_t /path/to/top directory/ -R${TEXTRESET}
Should be good
(Cockpit can help you do this if you are unfamiliar)
The Server will reboot now
EOF
read -p "Press Any Key to reboot"
echo ${RED}"Rebooting${TEXTRESET}"
sleep 1
reboot