-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpsinit.sh
171 lines (157 loc) · 4.77 KB
/
vpsinit.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
#!/usr/bin/bash
#############################################################
#
# One Click VPS initializer
#
# Author: Andls
# Version: 0.0.1
# Date: 2017.03.04
# Homepage: https://www.andls.com/
# GitHub: https://github.com/AndlsH/vpsinit
#
#############################################################
Welcome()
{
clear
echo
echo "#####################################"
echo "# One Click VPS initializer #"
echo "# #"
echo "# By Andls #"
echo "# https://www.andls.com/ #"
echo "#####################################"
echo
ChkSys()
{
# Machine: x86_64, i686; Arch: x86_64, i386 ?
osMach=`uname -m`; osArch=`arch`
osId=`cat /etc/*-release | grep "^ID="`; osId=${osId##*=}; osId=${osId#\"}; osId=${osId%\"}
osVer=`cat /etc/*-release | grep "^VERSION_ID="`; osVer=${osVer##*=}; osVer=${osVer#\"}; osVer=${osVer%\"}
}
}
# TODO
# kernel selector
# appen exclutions
ChangeKernel()
{
cp /etc/yum.conf /etc/yum.conf.bak
cat >> /etc/yum.conf <<- EOF
exclude=kernel-2* kernel-3* kernel-4*
EOF
ChkSys
case "${osId}${osVer}" in
centos7)
echo "centos7 detected!"
selectKernelOs="7.1.1503"; selectKernelVer="3.10.0-229.1.2.el7"
;;
centos6)
selectKernelOs="6.6"; selectKernelVer="2.6.32-504.3.3.el6"
;;
*)
#SelectKernel
;;
esac
echo "Please choose kernel version: "
echo "1) ${selectKernelVer} [Default]"
echo "2) Choose another version"
read -p "Please enter your choice: " selectKernel
[[ -z selectKernel ]] && selectKernel=1
[[ 2 == ${selectKernel} ]] && SelectKernel
kernelFile="kernel-${selectKernelVer}.${osMach}.rpm"
getKernel="http://vault.centos.org/${selectKernelOs}/updates/${osArch}/Packages/${kernelFile}"
wget ${getKernel} || { getKernel="http://vault.centos.org/${selectKernelOs}/os/${osArch}/Packages/${kernelFile}" ; wget ${getKernel}; }
rpm -ivh ${kernelFile} --force
}
# TODO
# Add/Delete port
SetFirewall()
{
ChkSys
[[ -z ${firewallPort} ]] && read -p "Please enter port number you want to add: " firewallPort
case "${osId}${osVer}" in
centos7)
sysFirewall="firewalld"
;;
centos6)
sysFirewall="iptables"
;;
*)
;;
esac
#[[ firewalld == ${sysFirewall} ]] && SetFirewalld
#[[ iptables == ${sysFirewall} ]] && SetIptables
}
SetFirewalld()
{
[[ -n ${firewallPort} ]] && systemctl status firewalld > /dev/null 2>&1
if [ $? -eq 0 ]; then
firewall-cmd --permanent --zone=public --add-port=${firewallPort}/tcp
firewall-cmd --permanent --zone=public --add-port=${firewallPort}/udp
firewall-cmd --reload
else
echo "Firewalld is not running, trying to start..."
systemctl start firewalld
if [ $? -eq 0 ]; then
firewall-cmd --permanent --zone=public --add-port=${firewallPort}/tcp
firewall-cmd --permanent --zone=public --add-port=${firewallPort}/udp
firewall-cmd --reload
else
echo "WARNING: Try to start firewalld failed. Please configure port ${firewallPort} manually."
fi
fi
}
{
yum install nodejs npm --enablerepo=epel
git clone git://github.com/c9/core.git --depth=1 /opt/c9sdk
bash /opt/c9sdk/scripts/install-sdk.sh
npm install pm2 -g
pm2 start /opt/c9sdk/server.js -n c9sdk -x -- -w ~ -p 8080 -l 0.0.0.0 -a admin:qweasd
pm2 startup
}
}
# Set root password
SetRootPwd()
{
echo "Please input password for root:"
read -p "(Default password: qwer1234):" rootPwd
[ -z "${rootPwd}" ] && rootPwd="qwer1234"
echo
echo "---------------------------"
echo " root password = ${rootPwd}"
echo "---------------------------"
echo
# set
echo ${rootPwd} | passwd --stdin root
}
SetSshPort()
{
echo "Please input SSH port:"
read -p "(Default port: 2048):" sshPort
[ -z "${sshPort}" ] && sshPort="2048"
echo
echo "---------------------------"
echo " SSH port = ${sshPort}"
echo "---------------------------"
echo
sed -i "/Port 22/aPort ${sshPort}" /etc/ssh/sshd_config
systemctl restart sshd
}
# Disable selinux
DisableSelinux(){
if [ -s /etc/selinux/config ] && grep 'SELINUX=enforcing' /etc/selinux/config; then
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
fi
}
action=$1
[ -z $1 ] && action=Welcome
case "${action}" in
Welcome)
${action}
;;
*)
echo "I cannot understand ${action}!"
echo "Please double check your input!"
echo "Use `usage` argument to see help!"
;;
esac