-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjl_installer.sh
333 lines (302 loc) · 12.7 KB
/
jl_installer.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
#! /bin/bash
# clear screen and spacing
clear
echo ''
# Functions:
# ----------
# ask()
# -----
ask() {
local prompt default reply
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
default=Y
elif [ "${2:-}" = "N" ]; then
prompt="y/N"
default=N
else
prompt="y/n"
default=
fi
while true; do
# Ask the question (not using "read -p" as it uses stderr not stdout)
echo -e -n "\e[38;5;15m$1 [$prompt] \e[0m"
# Read the answer (use /dev/tty in case stdin is redirected from somewhere else)
read reply </dev/tty
# Default?
if [ -z "$reply" ]; then
reply=$default
fi
# Check if the reply is valid
case "$reply" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
esac
done
}
# checksshconfig()
# ----------------
checksshconfig() {
echo ''
echo -e '\e[38;5;15m==============| \e[38;5;39mSSH (\e[38;5;15mcontinued\e[38;5;39m) \e[38;5;15m|===============\e[0m'
echo -e '\e[38;5;68m------------------------------------------------\e[0m'
echo -e '\e[38;5;68m| |\e[0m'
echo -e '\e[38;5;68m| | \e[38;5;15mPlease verify \e[38;5;162m/etc/ssh/sshd_config \e[38;5;15mto \e[38;5;68m| |\e[0m'
echo -e '\e[38;5;68m| | \e[38;5;15msee if your choice was properly made. \e[38;5;68m| |\e[0m'
echo -e '\e[38;5;68m| |\e[0m'
echo -e '\e[38;5;68m| ( \e[38;5;214mNOTE:\e[38;5;15m Press \e[38;5;46mQ \e[38;5;15mwhen finished \e[38;5;68m) |\e[0m'
echo -e '\e[38;5;68m------------------------------------------------\e[0m'
echo ''
read -r -s -p $'[ Press ENTER to continue ]'
echo ''
cat /etc/ssh/sshd_config | less
clear
}
# BEGIN SCRIPT:
#--------------
# Introduction
echo -e "\e[38;5;15m==| \e[38;5;39mWelcome to Jacques' Linux Install Script! \e[38;5;15m|==\e[0m"
echo -e '\e[38;5;68m-------------------------------------------------\e[0m'
echo -e '\e[38;5;68m| \e[38;5;15mv 0.3.2 \e[38;5;68m|\e[0m'
echo -e '\e[38;5;68m-------------------------------------------------\e[0m'
echo ''
read -r -s -p '[ Press ENTER to continue ]'
clear
# System Update
echo ''
echo -e '\e[38;5;15m==============| \e[38;5;39mSYSTEM UPDATE \e[38;5;15m|==============\e[0m'
echo -e '\e[38;5;68m---------------------------------------------\e[0m'
echo ''
if ask "Do you want to update the system?: " Y; then
echo -e '\e[38;5;15m-----------------------------------------\e[0m'
echo ''
yum -y update && yum clean all
echo ''
read -r -s -p '[ Press ENTER to continue ]'
clear
else
echo ''
echo -e '\e[38;5;68m ---------------------------------------\e[0m'
echo -e '\e[38;5;68m| \e[38;5;15mSystem Updates: \e[38;5;68m|| \e[38;5;160mSYSTEM NOT UPDATED \e[38;5;68m|\e[0m'
echo -e '\e[38;5;68m ---------------------------------------\e[0m'
echo ''
read -r -s -p '[ Press ENTER to continue ]'
clear
fi
# Useful Packages Installation
echo ''
echo -e '\e[38;5;15m==============| \e[38;5;39mUSEFUL PACKAGES \e[38;5;15m|==============\e[0m'
echo -e '\e[38;5;68m-----------------------------------------------\e[0m'
echo ''
if ask "Do you want to install Useful Packages on the system?: "; then
echo -e '\e[38;5;68m-------------------------------------------------------------\e[0m'
echo ''
clear
echo -e '\e[38;5;162m<< \e[38;5;15mThe following packages will be installed \e[38;5;162m>>\e[0m'
echo -e ' \e[38;5;68m----------------------------------------\e[0m'
echo -e ' \e[38;5;121mepel-release\e[38;5;15m, \e[38;5;121mnano\e[38;5;15m, \e[38;5;121mwget\e[38;5;15m, \e[38;5;121mcurl\e[38;5;15m, \e[38;5;121mnet-tools\e[38;5;15m,\e[0m'
echo -e ' \e[38;5;121mlsof\e[38;5;15m, \e[38;5;121mbash-completion\e[38;5;15m, \e[38;5;121mpsmisc\e[38;5;15m, \e[38;5;121munzip\e[38;5;15m, \e[38;5;121mhtop\e[38;5;15m,\e[0m'
echo -e ' \e[38;5;121mtmux\e[38;5;15m, \e[38;5;121mgit\e[0m'
echo ''
read -r -s -p '[ Press ENTER to continue ]'
clear
yum -y install epel-release
yum -y update
yum -y install nano wget curl net-tools lsof bash-completion psmisc unzip htop tmux git
echo ''
echo -e '\e[38;5;68m -------------------------------\e[0m'
echo -e '\e[38;5;68m| \e[38;5;15mUseful Packages: \e[38;5;68m|| \e[38;5;46mINSTALLED \e[38;5;68m|\e[0m'
echo -e '\e[38;5;68m -------------------------------\e[0m'
echo ''
read -r -s -p '[ Press ENTER to continue ]'
clear
else
echo ''
echo -e '\e[38;5;68m -----------------------------------\e[0m'
echo -e '\e[38;5;68m| \e[38;5;15mUseful Packages: \e[38;5;68m|| \e[38;5;160mNOT INSTALLED \e[38;5;68m|\e[0m'
echo -e '\e[38;5;68m -----------------------------------\e[0m'
echo ''
read -r -s -p '[ Press ENTER to continue ]'
clear
fi
# SELINUX
echo ''
echo -e '\e[38;5;15m==============| \e[38;5;39mSELINUX \e[38;5;15m|==============\e[0m'
echo -e '\e[38;5;68m---------------------------------------\e[0m'
echo ''
PS3=$'\n'"How would you like SELINUX to function?: "
options=("Enabled" "Disabled" "Permissive Mode")
select opt in "${options[@]}"
do
case $opt in
"Enabled")
sed -i -e 's/SELINUX=disabled/SELINUX=enforcing/g' /etc/selinux/config
sed -i -e 's/SELINUX=permissive/SELINUX=enforcing/g' /etc/selinux/config
echo ''
echo -e ' \e[38;5;68m------------------------------\e[0m'
echo -e '\e[38;5;68m| \e[38;5;15mSELINUX: \e[38;5;68m|| \e[38;5;15mSet to \e[38;5;46mENFORCING \e[38;5;68m|\e[0m'
echo -e ' \e[38;5;68m------------------------------\e[0m'
echo ''
read -r -s -p '[ Press ENTER to continue ]'
break
;;
"Disabled")
sed -i -e 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
sed -i -e 's/SELINUX=permissive/SELINUX=disabled/g' /etc/selinux/config
echo ''
echo -e ' \e[38;5;68m-----------------------------\e[0m'
echo -e '\e[38;5;68m| \e[38;5;15mSELINUX: \e[38;5;68m|| \e[38;5;15mSet to \e[38;5;160mDISABLED \e[38;5;68m|\e[0m'
echo -e ' \e[38;5;68m-----------------------------\e[0m'
echo ''
read -r -s -p '[ Press ENTER to continue ]'
break
;;
"Permissive Mode")
sed -i -e 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config
sed -i -e 's/SELINUX=disabled/SELINUX=permissive/g' /etc/selinux/config
echo ''
echo -e ' \e[38;5;68m-------------------------------\e[0m'
echo -e '\e[38;5;68m| \e[38;5;15mSELINUX: \e[38;5;68m|| \e[38;5;15mSet to \e[38;5;208mPERMISSIVE \e[38;5;68m|\e[0m'
echo -e ' \e[38;5;68m-------------------------------\e[0m'
echo ''
read -r -s -p '[ Press ENTER to continue ]'
break
;;
*) echo "invalid option $REPLY";;
esac
done
echo ''
clear
echo -e '\e[38;5;15m==============| \e[38;5;39mSELINUX (\e[38;5;15mcontinued\e[38;5;39m) \e[38;5;15m|===============\e[0m'
echo -e '\e[38;5;68m----------------------------------------------------\e[0m'
echo -e '\e[38;5;68m| |\e[0m'
echo -e '\e[38;5;68m| | \e[38;5;15mPlease verify \e[38;5;162m/etc/selinux/config \e[38;5;15mto \e[38;5;68m| |\e[0m'
echo -e '\e[38;5;68m| | \e[38;5;15msee if your choice was properly made \e[38;5;68m| |\e[0m'
echo -e '\e[38;5;68m| |\e[0m'
echo -e '\e[38;5;68m| ( \e[38;5;214mNOTE\e[38;5;15m: Press \e[38;5;46mQ\e[38;5;15m when finished \e[38;5;68m) |\e[0m'
echo -e '\e[38;5;68m----------------------------------------------------\e[0m'
echo ''
read -r -s -p $'[ Press ENTER to continue ]'
echo ''
cat /etc/selinux/config | less
clear
# firewalld
echo ''
echo -e '\e[38;5;15m==============| \e[38;5;39mFirewall \e[38;5;15m|==============\e[0m'
echo -e '\e[38;5;68m----------------------------------------\e[0m'
echo ''
PS3=$'\n'"Would you like to Enable or Disable the Firewall?: "
options=("Enable" "Disable")
select opt in "${options[@]}"
do
case $opt in
"Enable")
echo ''
systemctl enable firewalld
echo ''
echo -e ' \e[38;5;68m-----------------------------\e[0m'
echo -e '\e[38;5;68m| \e[38;5;15mFirewall: \e[38;5;68m|| \e[38;5;15mSet to \e[38;5;46mENABLED \e[38;5;68m|\e[0m'
echo -e ' \e[38;5;68m-----------------------------\e[0m'
echo ''
read -r -s -p '[ Press ENTER to continue ]'
clear
break
;;
"Disable")
echo ''
systemctl disable firewalld
echo ''
echo -e ' \e[38;5;68m-----------------------------\e[0m'
echo -e '\e[38;5;68m| \e[38;5;15mSELINUX: \e[38;5;68m|| \e[38;5;15mSet to \e[38;5;160mDISABLED \e[38;5;68m|\e[0m'
echo -e ' \e[38;5;68m-----------------------------\e[0m'
echo ''
read -r -s -p '[ Press ENTER to continue ]'
clear
break
;;
*) echo "invalid option $REPLY";;
esac
done
# SSH
echo ''
echo -e '\e[38;5;15m==============| \e[38;5;39mSSH \e[38;5;15m|==============\e[0m'
echo -e '\e[38;5;68m-----------------------------------\e[0m'
echo ''
PS3=$'\n'"Would you like to configure SSH? "
options=("Install, Enable and Configure" "Disable")
select opt in "${options[@]}"
do
case $opt in
"Install, Enable and Configure")
echo ''
yum -y install openssh && yum -y install openssh-server
systemctl enable sshd
echo ''
echo -e ' \e[38;5;68m--------------------------------------\e[0m'
echo -e '\e[38;5;68m| \e[38;5;15mSSH: \e[38;5;68m|| \e[38;5;15mINSTALLED and set to \e[38;5;46mENABLED \e[38;5;68m|\e[0m'
echo -e ' \e[38;5;68m--------------------------------------\e[0m'
echo ''
read -r -s -p '[ Press ENTER to continue ]'
clear
echo -e '\e[38;5;15m==============| \e[38;5;39mSSH (\e[38;5;15mcontinued\e[38;5;39m) \e[38;5;15m|==============\e[0m'
echo -e '\e[38;5;68m-----------------------------------------------\e[0m'
echo ''
PS3=$'\n'"Would you like to use Port 22 or another Port? "
extraoptions=("Use Port 22" "Use Alternate Port")
select xopt in "${extraoptions[@]}"
do
case $xopt in
"Use Port 22")
echo ''
sed -i 's/^Port .*/Port 22/g' /etc/ssh/sshd_config
checksshconfig
break
;;
"Use Alternate Port")
echo ''
while :; do
read -p "Enter port number between 1024 and 65535: " portnum
[[ $portnum =~ ^[0-9]+$ ]] || { echo -e '\e[38;5;68m[ \e[38;5;160mInvalid Port: \e[38;5;15mPlease enter a port number between \e[38;5;87m1024 \e[38;5;15mand \e[38;5;87m65535 \e[38;5;68m]\e[0m\n'; continue; }
if ((portnum >= 1024 && portnum <= 65535)); then
sed -i -r 's/^#?Port .*/'"Port $portnum"'/g' /etc/ssh/sshd_config
checksshconfig
break
else
echo -e '\e[38;5;68m[ \e[38;5;160mInvalid Port: \e[38;5;15mPlease enter a port number between \e[38;5;87m1024 \e[38;5;15mand \e[38;5;87m65535 \e[38;5;68m]\e[0m\n'
fi
done
break
;;
*) echo "invalid option $REPLY";;
esac
done
break
;;
"Disable")
echo ''
systemctl disable sshd
echo ''
echo -e ' \e[38;5;68m-------------------------\e[0m'
echo -e '\e[38;5;68m| \e[38;5;15mSSH: \e[38;5;68m|| \e[38;5;15mSet to \e[38;5;160mDISABLED \e[38;5;68m|\e[0m'
echo -e ' \e[38;5;68m-------------------------\e[0m'
echo ''
read -r -s -p '[ Press ENTER to continue ]'
clear
break
;;
*) echo "invalid option $REPLY";;
esac
done
# Upcoming Section:
#------------------
# SNMP
# END SCRIPT:
#------------
clear
echo -e "\e[38;5;15m==============| \e[38;5;39mScript Execution Complete! \e[38;5;15m|==============\e[0m"
echo -e '\e[38;5;68m----------------------------------------------------------\e[0m'
echo -e "\e[38;5;68m| \e[38;5;15mThank you for using Jacques' Linux Install Script! \e[38;5;68m|\e[0m"
echo -e '\e[38;5;68m----------------------------------------------------------\e[0m'
echo ''
read -r -s -p '[ Press ENTER to continue ]'
clear