-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstaller.sh
More file actions
413 lines (367 loc) · 18.5 KB
/
installer.sh
File metadata and controls
413 lines (367 loc) · 18.5 KB
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
#!/bin/bash
# A simple script that will install OpenVZ on your server.
# Tested on CentOS 6 64bit, YUM requires minimum of 512MB RAM to work.
# Check for root account
if [[ "$EUID" -ne 0 ]]; then
echo "Sorry, you must to run this script as root!"
exit 1
fi
# Make sure server running is full virtualized (aka not a container)
if [[ -f /proc/user_beancounters ]] && [[ $(cat /proc/1/status | grep envID | cut -f 2) != 0 ]]; then
echo "You need a dedicated server or KVM/XEN/VMware to use this script!"
exit 1
fi
doinstall () {
# If ram is less than ~500MB, quit with error 1
tram=$(($(free -m | awk '/^Mem:/{print $2}')+$(free -m | awk '/^Swap:/{print $2}')))
if [[ "$tram" -lt "480" ]]; then
echo "You probably shouldn't be installing OpenVZ on such little ram system."
exit 1
fi
# Updating system first
yum update -y
# Installing wget
yum install -y wget
# Adding OpenVZ Repo
wget -P /etc/yum.repos.d/ https://download.openvz.org/openvz.repo
rpm --import http://download.openvz.org/RPM-GPG-Key-OpenVZ
# Installing OpenVZ Kernel
yum install -y vzkernel
# Installing OpenVZ tools
yum install -y vzctl vzquota ploop
# Setting kernel parameters
sed -i 's/kernel.sysrq = 0/kernel.sysrq = 1/g' /etc/sysctl.conf
sed -i 's/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/g' /etc/sysctl.conf
echo 'net.ipv4.conf.default.proxy_arp = 0' >> /etc/sysctl.conf
echo 'net.ipv4.conf.all.rp_filter = 1' >> /etc/sysctl.conf
echo 'net.ipv4.conf.default.send_redirects = 1' >> /etc/sysctl.conf
echo 'net.ipv4.conf.all.send_redirects = 0' >> /etc/sysctl.conf
echo 'net.ipv4.icmp_echo_ignore_broadcasts=1' >> /etc/sysctl.conf
echo 'net.ipv4.conf.default.forwarding=1' >> /etc/sysctl.conf
# Apply the changes
sysctl -p
# Making sure the templates directory exists
if ! [[ -e /vz/template/cache ]]; then
mkdir /vz/template/cache
fi
# Download sample VZ config
wget -P /etc/vz/conf/ https://raw.githubusercontent.com/bosscoder/OpenVZ-Basher/master/ve-vswap-ovzbasher.conf-sample
# Changing default VZ settings:
sed -r -i 's/^#*\s*NEIGHBOUR_DEVS\s*=.*/NEIGHBOUR_DEVS=all/g' /etc/vz/vz.conf
sed -r -i 's/^#*\s*VE_LAYOUT\s*=.*/VE_LAYOUT=simfs/g' /etc/vz/vz.conf
sed -i 's/centos-6-x86/debian-7.0-x86_64/g' /etc/vz/vz.conf
sed -i 's/vswap-256m/vswap-ovzbasher/g' /etc/vz/vz.conf
sed -i "s/IPV6=\"yes\"/IPV6=\"no\"/" /etc/vz/vz.conf
sed -r -i 's/^SELINUX=.*\s*/SELINUX=disabled/g' /etc/sysconfig/selinux
# Load tun modules on system boot
echo "modprobe tun" >> /etc/rc.modules
chmod +x /etc/rc.modules
# Allowing everything through iptables
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -t nat -F
iptables -t mangle -F
iptables -F
iptables -X
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
IPoct=11
while [[ $IPoct -lt 255 ]]; do
intIP=192.168.1."$IPoct"
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport "$IPoct"00 -j DNAT --to $intIP:22
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport "$IPoct"01:"$IPoct"99 -j DNAT --to $intIP:"$IPoct"01-"$IPoct"99
iptables -t nat -A PREROUTING -i eth0 -p udp --dport "$IPoct"01:"$IPoct"99 -j DNAT --to $intIP:"$IPoct"01-"$IPoct"99
((IPoct++))
done
iptables-save > /etc/sysconfig/iptables
# Download and install OpenVZ Bash Manager
wget -O /usr/bin/ovzmanager https://git.io/ovzmanager --no-check-certificate && chmod +x /usr/bin/ovzmanager
}
dotempdl () {
while true; do
# START - Defining color codes
ccn=$'\e[0m'
if [[ -f /vz/template/cache/centos-6-x86-minimal.tar.gz ]]; then
cca=$'\e[1;32m'
else
cca=$'\e[1;31m'
fi
if [[ -f /vz/template/cache/centos-6-x86_64-minimal.tar.gz ]]; then
ccb=$'\e[1;32m'
else
ccb=$'\e[1;31m'
fi
if [[ -f /vz/template/cache/centos-7-x86_64-minimal.tar.gz ]]; then
ccc=$'\e[1;32m'
else
ccc=$'\e[1;31m'
fi
if [[ -f /vz/template/cache/centos-7-x86_64.tar.gz ]]; then
ccd=$'\e[1;32m'
else
ccd=$'\e[1;31m'
fi
if [[ -f /vz/template/cache/debian-7.0-x86-minimal.tar.gz ]]; then
cce=$'\e[1;32m'
else
cce=$'\e[1;31m'
fi
if [[ -f /vz/template/cache/debian-7.0-x86_64-minimal.tar.gz ]]; then
ccf=$'\e[1;32m'
else
ccf=$'\e[1;31m'
fi
if [[ -f /vz/template/cache/debian-8.0-x86_64-minimal.tar.gz ]]; then
ccg=$'\e[1;32m'
else
ccg=$'\e[1;31m'
fi
if [[ -f /vz/template/cache/debian-8.0-x86_64.tar.gz ]]; then
cch=$'\e[1;32m'
else
cch=$'\e[1;31m'
fi
if [[ -f /vz/template/cache/ubuntu-14.04-x86-minimal.tar.gz ]]; then
cci=$'\e[1;32m'
else
cci=$'\e[1;31m'
fi
if [[ -f /vz/template/cache/ubuntu-14.04-x86_64-minimal.tar.gz ]]; then
ccj=$'\e[1;32m'
else
ccj=$'\e[1;31m'
fi
if [[ -f /vz/template/cache/ubuntu-15.10-x86_64-minimal.tar.gz ]]; then
cck=$'\e[1;32m'
else
cck=$'\e[1;31m'
fi
if [[ -f /vz/template/cache/ubuntu-16.04-x86_64.tar.gz ]]; then
ccl=$'\e[1;32m'
else
ccl=$'\e[1;31m'
fi
# END - Defining color codes
# Template download selector
clear
printf "Template names in \e[1;32mgreen\e[0m = exist on server.\n"
printf "%s\n" "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
printf "%s\n" "| ${cca}(a) CentOS 6 32bit Minimal${ccn} || ${ccb}(b) CentOS 6 64bit Minimal${ccn} |"
printf "%s\n" "| ${ccd}(c) CentOS 7 64bit Standard${ccn} || ${ccc}(d) CentOS 7 64bit Minimal${ccn} |"
printf "%s\n" "--------------------------------------------------------------------------------"
printf "%s\n" "| ${cce}(e) Debian 7 32bit Minimal${ccn} || ${ccf}(f) Debian 7 64bit Minimal${ccn} |"
printf "%s\n" "| ${cch}(g) Debian 8 64bit Standard${ccn} || ${ccg}(h) Debian 8 64bit Minimal${ccn} |"
printf "%s\n" "--------------------------------------------------------------------------------"
printf "%s\n" "| ${cci}(i) Ubuntu 14.04 32bit Minimal${ccn} || ${ccj}(j) Ubuntu 14.04 64bit Minimal${ccn} |"
printf "%s\n" "| ${cck}(k) Ubuntu 15.10 64bit Minimal${ccn} || ${ccl}(l) Ubuntu 16.04 64bit Standard${ccn} |"
printf "%s\n" "--------------------------------------------------------------------------------"
printf "%s\n" "| (z) ALL Common Templates || (q) Quit & Continue... |"
printf "%s\n" "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
if ! [[ -z $dstatus ]]; then printf "\e[1;33m%s${ccn}\n" "$dstatus"; fi
read -p "Please choose a template to download: " tpdlo
case $tpdlo in
a)
if [[ -f /vz/template/cache/centos-6-x86-minimal.tar.gz ]]; then
dstatus="EXISTS: CentOS 6 32bit minimal template."
else
wget -P /vz/template/cache/ https://download.openvz.org/template/precreated/centos-6-x86-minimal.tar.gz --no-check-certificate
dstatus="DOWNLOADED: CentOS 6 32bit minimal template."
fi
;;
b)
if [[ -f /vz/template/cache/centos-6-x86_64-minimal.tar.gz ]]; then
dstatus="EXISTS: CentOS 6 64bit minimal template."
else
wget -P /vz/template/cache/ https://download.openvz.org/template/precreated/centos-6-x86_64-minimal.tar.gz --no-check-certificate
dstatus="DOWNLOADED: CentOS 6 64bit minimal template."
fi
;;
c)
if [[ -f /vz/template/cache/centos-7-x86_64.tar.gz ]]; then
dstatus="EXISTS: CentOS 7 64bit standard template."
else
wget -P /vz/template/cache/ https://download.openvz.org/template/precreated/centos-7-x86_64.tar.gz --no-check-certificate
dstatus="DOWNLOADED: CentOS 7 64bit standard template."
fi
;;
d)
if [[ -f /vz/template/cache/centos-7-x86_64-minimal.tar.gz ]]; then
dstatus="EXISTS: CentOS 7 64bit minimal template."
else
wget -P /vz/template/cache/ https://download.openvz.org/template/precreated/centos-7-x86_64-minimal.tar.gz --no-check-certificate
dstatus="DOWNLOADED: CentOS 7 64bit minimal template."
fi
;;
e)
if [[ -f /vz/template/cache/debian-7.0-x86-minimal.tar.gz ]]; then
dstatus="EXISTS: Debian 7 32bit minimal template."
else
wget -P /vz/template/cache/ https://download.openvz.org/template/precreated/debian-7.0-x86-minimal.tar.gz --no-check-certificate
dstatus="DOWNLOADED: Debian 7 32bit minimal template."
fi
;;
f)
if [[ -f /vz/template/cache/debian-7.0-x86_64-minimal.tar.gz ]]; then
dstatus="EXISTS: Debian 7 64bit minimal template."
else
wget -P /vz/template/cache/ https://download.openvz.org/template/precreated/debian-7.0-x86_64-minimal.tar.gz --no-check-certificate
dstatus="DOWNLOADED: Debian 7 64bit minimal template."
fi
;;
g)
if [[ -f /vz/template/cache/debian-8.0-x86_64.tar.gz ]]; then
dstatus="EXISTS: Debian 8 64bit standard template."
else
wget -P /vz/template/cache/ https://download.openvz.org/template/precreated/debian-8.0-x86_64.tar.gz --no-check-certificate
dstatus="DOWNLOADED: Debian 8 64bit standard template."
fi
;;
h)
if [[ -f /vz/template/cache/debian-8.0-x86_64-minimal.tar.gz ]]; then
dstatus="EXISTS: Debian 8 64bit minimal template."
else
wget -P /vz/template/cache/ https://download.openvz.org/template/precreated/debian-8.0-x86_64-minimal.tar.gz --no-check-certificate
dstatus="DOWNLOADED: Debian 8 64bit minimal template."
fi
;;
i)
if [[ -f /vz/template/cache/ubuntu-14.04-x86-minimal.tar.gz ]]; then
dstatus="EXISTS: Ubuntu 14.04 32bit minimal template."
else
wget -P /vz/template/cache/ https://download.openvz.org/template/precreated/ubuntu-14.04-x86-minimal.tar.gz --no-check-certificate
dstatus="DOWNLOADED: Ubuntu 14.04 32bit minimal template."
fi
;;
j)
if [[ -f /vz/template/cache/ubuntu-14.04-x86_64-minimal.tar.gz ]]; then
dstatus="EXISTS: Ubuntu 14.04 64bit minimal template."
else
wget -P /vz/template/cache/ https://download.openvz.org/template/precreated/ubuntu-14.04-x86_64-minimal.tar.gz --no-check-certificate
dstatus="DOWNLOADED: Ubuntu 14.04 64bit minimal template."
fi
;;
k)
if [[ -f /vz/template/cache/ubuntu-15.10-x86_64-minimal.tar.gz ]]; then
dstatus="EXISTS: Ubuntu 15.10 64bit minimal template."
else
wget -P /vz/template/cache/ https://download.openvz.org/template/precreated/ubuntu-15.10-x86_64-minimal.tar.gz --no-check-certificate
dstatus="DOWNLOADED: Ubuntu 15.10 64bit minimal template."
fi
;;
l)
if [[ -f /vz/template/cache/ubuntu-16.04-x86_64.tar.gz ]]; then
dstatus="EXISTS: Ubuntu 16.04 64bit standard template."
else
wget -P /vz/template/cache/ https://download.openvz.org/template/precreated/ubuntu-16.04-x86_64.tar.gz --no-check-certificate
dstatus="DOWNLOADED: Ubuntu 16.04 64bit standard template."
fi
;;
z)
if ! [[ -f /vz/template/cache/centos-6-x86-minimal.tar.gz ]]; then
wget -P /vz/template/cache/ https://download.openvz.org/template/precreated/centos-6-x86-minimal.tar.gz --no-check-certificate
fi
if ! [[ -f /vz/template/cache/centos-6-x86_64-minimal.tar.gz ]]; then
wget -P /vz/template/cache/ https://download.openvz.org/template/precreated/centos-6-x86_64-minimal.tar.gz --no-check-certificate
fi
if ! [[ -f /vz/template/cache/centos-7-x86_64.tar.gz ]]; then
wget -P /vz/template/cache/ https://download.openvz.org/template/precreated/centos-7-x86_64.tar.gz --no-check-certificate
fi
if ! [[ -f /vz/template/cache/centos-7-x86_64-minimal.tar.gz ]]; then
wget -P /vz/template/cache/ https://download.openvz.org/template/precreated/centos-7-x86_64-minimal.tar.gz --no-check-certificate
fi
if ! [[ -f /vz/template/cache/debian-7.0-x86-minimal.tar.gz ]]; then
wget -P /vz/template/cache/ https://download.openvz.org/template/precreated/debian-7.0-x86-minimal.tar.gz --no-check-certificate
fi
if ! [[ -f /vz/template/cache/debian-7.0-x86_64-minimal.tar.gz ]]; then
wget -P /vz/template/cache/ https://download.openvz.org/template/precreated/debian-7.0-x86_64-minimal.tar.gz --no-check-certificate
fi
if ! [[ -f /vz/template/cache/debian-8.0-x86_64.tar.gz ]]; then
wget -P /vz/template/cache/ https://download.openvz.org/template/precreated/debian-8.0-x86_64.tar.gz --no-check-certificate
fi
if ! [[ -f /vz/template/cache/debian-8.0-x86_64-minimal.tar.gz ]]; then
wget -P /vz/template/cache/ https://download.openvz.org/template/precreated/debian-8.0-x86_64-minimal.tar.gz --no-check-certificate
fi
if ! [[ -f /vz/template/cache/ubuntu-14.04-x86-minimal.tar.gz ]]; then
wget -P /vz/template/cache/ https://download.openvz.org/template/precreated/ubuntu-14.04-x86-minimal.tar.gz --no-check-certificate
fi
if ! [[ -f /vz/template/cache/ubuntu-14.04-x86_64-minimal.tar.gz ]]; then
wget -P /vz/template/cache/ https://download.openvz.org/template/precreated/ubuntu-14.04-x86_64-minimal.tar.gz --no-check-certificate
fi
if ! [[ -f /vz/template/cache/ubuntu-15.10-x86_64-minimal.tar.gz ]]; then
wget -P /vz/template/cache/ https://download.openvz.org/template/precreated/ubuntu-15.10-x86_64-minimal.tar.gz --no-check-certificate
fi
if ! [[ -f /vz/template/cache/ubuntu-16.04-x86_64.tar.gz ]]; then
wget -P /vz/template/cache/ https://download.openvz.org/template/precreated/ubuntu-16.04-x86_64.tar.gz --no-check-certificate
fi
clear
printf "\e[1;33mDOWNLOADED: All Templates.${ccn}\n\n"
echo "-------------------------------------------------------"
echo "You can find more official OpenVZ templates at"
echo "http://download.openvz.org/template/precreated/"
echo "The templates must be stored in /vz/template/cache"
echo "-------------------------------------------------------"
break
;;
q)
clear
echo "-------------------------------------------------------"
echo "You can find more official OpenVZ templates at"
echo "http://download.openvz.org/template/precreated/"
echo "The templates must be stored in /vz/template/cache"
echo "-------------------------------------------------------"
break
;;
*)
dstatus="Invalid entry, please try again..."
;;
esac
done
}
if [[ $(uname -r) == *"stab"* ]]; then
echo "OpenVZ Kernel detected on this server!"
read -p "Would you like to download some OpenVZ templates instead? [y/N] " ovztpo
case $ovztpo in
y | yes | Y | YES)
dotempdl
;;
*)
echo "-------------------------------------------------------"
echo "You can find the official OpenVZ templates at"
echo "http://download.openvz.org/template/precreated/"
echo "The templates must be stored in /vz/template/cache"
echo "-------------------------------------------------------"
;;
esac
else
doinstall
clear
echo "Congratulations! OpenVZ Basher is now installed on your server!"
read -p "Would you like to download some OpenVZ templates now? [y/N] " ovztpo
case $ovztpo in
y | yes | Y | YES)
dotempdl
;;
*)
echo "-------------------------------------------------------"
echo "You can find the official OpenVZ templates at"
echo "http://download.openvz.org/template/precreated/"
echo "The templates must be stored in /vz/template/cache"
echo "-------------------------------------------------------"
;;
esac
echo "A private NAT IP network has been created for you!"
echo "Available IPs: 192.168.1.11 - 192.168.1.254"
echo "-------------------------------------------------------"
echo "A reboot is required to use the OpenVZ kernel."
read -p "Would you like to reboot now? [y/N] " rbto
if [[ $rbto == "y" ]] || [[ $rbto == "yes" ]] || [[ $rbto == "Y" ]] || [[ $rbto == "YES" ]]; then
clear
echo "Thanks for using the OpenVZ Bash Installer script!"
echo "Rebooting system now!"
reboot
else
clear
echo "Thanks for using the OpenVZ Bash Installer script!"
echo "Please manually reboot the server in order to use the OpenVZ kernel."
fi
fi