forked from dylanbai8/kmspro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kmspro.sh
161 lines (148 loc) · 3.72 KB
/
kmspro.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
#!/bin/bash
#====================================================
# System Request: Debian/Ubuntu/Mint/CentOS/Redhat/Fedora
# Author: dylanbai8
# Dscription: KMS服务一键安装脚本
# Open Source: https://github.com/dylanbai8/kmspro
# Official document: https://v0v.bid
#====================================================
# 定义脚本变量
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
STAT=2
# Debian系列操作系统安装KMS
do_debian(){
apt-get install gcc git make -y
rm -rf /usr/local/kms
mkdir /usr/local/kms
cd /usr/local/kms
git clone https://github.com/Wind4/vlmcsd.git
cd vlmcsd
make
cd bin
mv vlmcsd /usr/local/kms/kms
cd /usr/local/kms/
rm -rf ./vlmcsd/
mv kms vlmcsd
echo "KMS服务安装成功!"
echo "更多教程请访问:https://v0v.bid/kms.html"
}
# Centos系列操作系统安装KMS
do_centos(){
yum install gcc git make -y
rm -rf /usr/local/kms
mkdir /usr/local/kms
cd /usr/local/kms
git clone https://github.com/Wind4/vlmcsd.git
cd vlmcsd
make
cd bin
mv vlmcsd /usr/local/kms/kms
cd /usr/local/kms/
rm -rf ./vlmcsd/
mv kms vlmcsd
echo "KMS服务安装成功!"
echo "更多教程请访问:https://v0v.bid/kms.html"
echo "Centos请自行开放1688端口"
}
# 检测KMS运行状态
check_running(){
PID=`ps -ef | grep -v grep | grep -i "vlmcsd" | awk '{print $2}'`
if [ ! -z $PID ]; then
STAT=0
else
STAT=1
fi
}
# 重启KMS服务
do_restart(){
check_running
if [ $STAT = 0 ]; then
echo "KMS服务已经运行 正在重新启动 ..."
kill $PID
elif [ $STAT = 1 ]; then
echo "KMS服务未运行 正在启动 ..."
fi
/usr/local/kms/vlmcsd
check_running
if [ $STAT = 0 ]; then
local_ip=`curl -4 ip.sb`
echo "KMS服务 启动成功"
echo "[Windows一句命令激活] 命令提示符(管理员):slmgr /skms ${local_ip} && slmgr /ato"
echo "更多教程请访问:https://v0v.bid/kms.html"
elif [ $STAT = 1 ]; then
echo "KMS服务 启动失败"
fi
}
# 停止KMS服务
do_stop(){
check_running
if [ $STAT = 0 ]; then
echo "正在停止 KMS服务 ..."
kill $PID
check_running
if [ $STAT = 0 ]; then
echo "停止 KMS服务 失败"
elif [ $STAT = 1 ]; then
echo "停止 KMS服务 成功"
fi
elif [ $STAT = 1 ]; then
echo "KMS服务 未运行 取消操作"
fi
}
# 检测KMS服务是否运行
do_status(){
check_running
if [ $STAT = 0 ]; then
echo "KMS服务 正在运行"
echo "更多教程请访问:https://v0v.bid/kms.html"
elif [ $STAT = 1 ]; then
echo "KMS服务 未运行"
fi
}
# 启动KMS服务
do_start(){
check_running
if [ $STAT = 0 ]; then
echo "KMS服务 已运行 取消操作"
echo "更多教程请访问:https://v0v.bid/kms.html"
exit 0;
elif [ $STAT = 1 ]; then
echo "正在启动 KMS服务 ..."
/usr/local/kms/vlmcsd
fi
check_running
if [ $STAT = 0 ]; then
local_ip=`curl -4 ip.sb`
echo "KMS服务 启动成功"
echo "[Windows一句命令激活] 命令提示符(管理员):slmgr /skms ${local_ip} && slmgr /ato"
echo "更多教程请访问:https://v0v.bid/kms.html"
elif [ $STAT = 1 ]; then
echo "KMS服务 启动失败"
fi
}
# 添加开机自启动服务
do_auto(){
echo "/usr/local/kms/vlmcsd" >> /etc/rc.local
chmod +x /etc/rc.local
echo "已添加 开机自启动 KMS服务"
echo "更多教程请访问:https://v0v.bid/kms.html"
}
# 卸载KMS服务
do_uninstall(){
do_stop
rm -rf /usr/local/kms
sed -i '/vlmcsd/'d /etc/rc.local
echo "KMS服务 已卸载"
}
# 脚本菜单
case "$1" in
debian|centos|start|stop|auto|restart|status|uninstall)
do_$1
;;
*)
echo "缺少参数: debian | centos | start | stop | auto | restart | status | uninstall "
echo "更多教程请访问:https://github.com/dylanbai8/kmspro"
;;
esac
# 转载请保留版权:https://v0v.bid