-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
kms.sh
228 lines (209 loc) · 6.63 KB
/
kms.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
#!/usr/bin/env bash
#
# Auto install KMS Server
# System Required: CentOS 6+, Debian7+, Ubuntu12+
# Copyright (C) 2017-2018 Teddysun <[email protected]>
# URL: https://teddysun.com/530.html
#
# Thanks: https://github.com/Wind4/vlmcsd
#
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
plain='\033[0m'
cur_dir=$(pwd)
[[ $EUID -ne 0 ]] && echo -e "${red}Error:${plain} This script must be run as root!" && exit 1
if [ -f /etc/redhat-release ]; then
release="centos"
elif grep -Eqi "debian" /etc/issue; then
release="debian"
elif grep -Eqi "ubuntu" /etc/issue; then
release="ubuntu"
elif grep -Eqi "centos|red hat|redhat" /etc/issue; then
release="centos"
elif grep -Eqi "debian" /proc/version; then
release="debian"
elif grep -Eqi "ubuntu" /proc/version; then
release="ubuntu"
elif grep -Eqi "centos|red hat|redhat" /proc/version; then
release="centos"
else
release=""
fi
boot_start(){
if [[ x"${release}" == x"debian" || x"${release}" == x"ubuntu" ]]; then
update-rc.d -f "${1}" defaults
elif [[ x"${release}" == x"centos" ]]; then
chkconfig --add "${1}"
chkconfig "${1}" on
fi
}
boot_stop(){
if [[ x"${release}" == x"debian" || x"${release}" == x"ubuntu" ]]; then
update-rc.d -f "${1}" remove
elif [[ x"${release}" == x"centos" ]]; then
chkconfig "${1}" off
chkconfig --del "${1}"
fi
}
# Get version
getversion(){
if [[ -s /etc/redhat-release ]]; then
grep -oE "[0-9.]+" /etc/redhat-release
else
grep -oE "[0-9.]+" /etc/issue
fi
}
# CentOS version
centosversion(){
if [[ x"${release}" == x"centos" ]]; then
local code=$1
local version="$(getversion)"
local main_ver=${version%%.*}
if [ "$main_ver" == "$code" ]; then
return 0
else
return 1
fi
else
return 1
fi
}
get_opsy() {
[ -f /etc/redhat-release ] && awk '{print ($1,$3~/^[0-9]/?$3:$4)}' /etc/redhat-release && return
[ -f /etc/os-release ] && awk -F'[= "]' '/PRETTY_NAME/{print $3,$4,$5}' /etc/os-release && return
[ -f /etc/lsb-release ] && awk -F'[="]+' '/DESCRIPTION/{print $2}' /etc/lsb-release && return
}
get_char() {
SAVEDSTTY=$(stty -g)
stty -echo
stty cbreak
dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -raw
stty echo
stty "$SAVEDSTTY"
}
set_firewall() {
if centosversion 6; then
/etc/init.d/iptables status > /dev/null 2>&1
if [ $? -eq 0 ]; then
iptables -L -n | grep -i 1688 > /dev/null 2>&1
if [ $? -ne 0 ]; then
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 1688 -j ACCEPT
/etc/init.d/iptables save
/etc/init.d/iptables restart
fi
else
echo -e "${yellow}Warning:${plain} iptables looks like shutdown or not installed, please enable port 1688 manually set if necessary."
fi
elif centosversion 7; then
systemctl status firewalld > /dev/null 2>&1
if [ $? -eq 0 ]; then
firewall-cmd --permanent --zone=public --add-port=1688/tcp
firewall-cmd --reload
else
echo -e "${yellow}Warning:${plain} firewalld looks like shutdown or not installed, please enable port 1688 manually set if necessary."
fi
fi
}
install_main() {
[ -f /usr/bin/vlmcsd ] && echo -e "${yellow}Warning:${plain} KMS Server is already installed. nothing to do..." && exit 1
clear
opsy=$( get_opsy )
arch=$( uname -m )
lbit=$( getconf LONG_BIT )
kern=$( uname -r )
echo "---------- System Information ----------"
echo " OS : $opsy"
echo " Arch : $arch ($lbit Bit)"
echo " Kernel : $kern"
echo "----------------------------------------"
echo " Auto install KMS Server"
echo
echo " URL: https://teddysun.com/530.html"
echo "----------------------------------------"
echo
echo "Press any key to start...or Press Ctrl+C to cancel"
char=$(get_char)
if [[ x"${release}" == x"centos" ]]; then
yum -y install gcc git make nss curl libcurl
if ! wget --no-check-certificate -O /etc/init.d/kms https://raw.githubusercontent.com/teddysun/across/master/kms; then
echo -e "[${red}Error:${plain}] Failed to download KMS Server script."
exit 1
fi
elif [[ x"${release}" == x"debian" || x"${release}" == x"ubuntu" ]]; then
apt-get -y update
apt-get install -y gcc git make libnss3 curl libcurl3-nss
if ! wget --no-check-certificate -O /etc/init.d/kms https://raw.githubusercontent.com/teddysun/across/master/kms-debian; then
echo -e "[${red}Error:${plain}] Failed to download KMS Server script."
exit 1
fi
else
echo -e "${red}Error:${plain} OS is not be supported, please change to CentOS/Debian/Ubuntu and try again."
exit 1
fi
cd "${cur_dir}" || exit
git clone https://github.com/Wind4/vlmcsd.git > /dev/null 2>&1
[ -d vlmcsd ] && cd vlmcsd || echo -e "[${red}Error:${plain}] Failed to git clone vlmcsd."
make
if [ $? -ne 0 ]; then
echo -e "${red}Error:${plain} Install KMS Server failed, please check it and try again."
exit 1
fi
cp -p bin/vlmcsd /usr/bin/
chmod 755 /usr/bin/vlmcsd
chmod 755 /etc/init.d/kms
boot_start kms
/etc/init.d/kms start
if [ $? -ne 0 ]; then
echo -e "${red}Error:${plain} KMS server start failed."
fi
if [[ x"${release}" == x"centos" ]]; then
set_firewall
fi
cd "${cur_dir}" || exit
rm -rf vlmcsd
echo
echo "Install KMS Server success"
echo "Welcome to visit:https://teddysun.com/530.html"
echo "Enjoy it!"
echo
}
install_kms() {
install_main 2>&1 | tee "${cur_dir}"/install_kms.log
}
# Uninstall KMS Server
uninstall_kms() {
printf "Are you sure uninstall KMS Server? (y/n) "
printf "\n"
read -p "(Default: n):" answer
[ -z "${answer}" ] && answer="n"
if [ "${answer}" == "y" ] || [ "${answer}" == "Y" ]; then
/etc/init.d/kms status > /dev/null 2>&1
if [ $? -eq 0 ]; then
/etc/init.d/kms stop
fi
boot_stop kms
# delete kms server
rm -f /usr/bin/vlmcsd
rm -f /etc/init.d/kms
rm -f /var/log/vlmcsd.log
echo "KMS Server uninstall success"
else
echo
echo "Uninstall cancelled, nothing to do..."
echo
fi
}
# Initialization step
action=$1
[ -z "$1" ] && action=install
case "$action" in
install|uninstall)
${action}_kms
;;
*)
echo "Arguments error! [${action}]"
echo "Usage: $(basename $0) [install|uninstall]"
;;
esac