forked from 1Panel-dev/installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1pctl
222 lines (216 loc) · 5.03 KB
/
1pctl
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
#!/bin/bash
action=$1
target=$2
args=$@
BASE_DIR=/opt
ORIGINAL_PORT=9999
ORIGINAL_VERSION=v1.0.0
ORIGINAL_ENTRANCE=entrance
ORIGINAL_USERNAME=username
ORIGINAL_PASSWORD=password
function usage() {
echo "1Panel 控制脚本"
echo
echo "Usage: "
echo " ./1pctl [COMMAND] [ARGS...]"
echo " ./1pctl --help"
echo
echo "Commands: "
echo " status 查看 1Panel 服务运行状态"
echo " start 启动 1Panel 服务"
echo " stop 停止 1Panel 服务"
echo " restart 重启 1Panel 服务"
echo " uninstall 卸载 1Panel 服务"
echo " user-info 获取 1Panel 用户信息"
echo " listen-ip 切换 1Panel 监听 IP"
echo " version 查看 1Panel 版本信息"
echo " update 修改 1Panel 系统信息"
echo " reset 重置 1Panel 系统信息"
echo " restore 恢复 1Panel 服务及数据"
}
function status() {
systemctl status 1panel.service
}
function start() {
systemctl start 1panel.service
status
}
function stop() {
systemctl stop 1panel.service
status
}
function restart() {
systemctl restart 1panel.service
status
}
function uninstall() {
read -p "卸载将会完全清除 1Panel 服务和数据目录,是否继续 [y/n] : " yn
if [ "$yn" == "Y" ] || [ "$yn" == "y" ]; then
echo -e "================== 开始卸载 1Panel Linux 服务器运维管理面板 =================="
echo -e ""
echo -e "1) 停止 1Panel 服务进程..."
systemctl stop 1panel.service
systemctl disable 1panel.service >/dev/null 2>&1
else
exit 0
fi
echo -e "2) 删除 1Panel 服务和数据目录..."
rm -rf $BASE_DIR/1panel /usr/local/bin/{1pctl,1panel} /etc/systemd/system/1panel.service
echo -e "3) 重新加载服务配置文件..."
systemctl daemon-reload
systemctl reset-failed
echo -e ""
echo -e "================================== 卸载完成 =================================="
}
function user-info() {
1panel user-info
}
function listen-ip() {
1panel listen-ip
}
function listen_ipv4() {
1panel listen-ip ipv4
restart
}
function listen_ipv6() {
1panel listen-ip ipv6
restart
}
function restore() {
read -p "1Panel 将会恢复至上一个稳定版本,是否继续 [y/n] : " yn
if [ "$yn" == "Y" ] || [ "$yn" == "y" ]; then
echo -e ""
1panel restore
systemctl daemon-reload
restart
echo -e ""
1panel version
else
exit 0
fi
}
function version() {
1panel version
}
function reset() {
1panel reset
}
function reset_domain() {
1panel reset domain
}
function reset_entrance() {
1panel reset entrance
}
function reset_https() {
1panel reset https
restart
}
function reset_ips() {
1panel reset ips
}
function reset_mfa() {
1panel reset mfa
}
function update() {
1panel update
}
function update_username() {
1panel update username
}
function update_password() {
1panel update password
}
function update_port() {
1panel update port
}
function main() {
case "${action}" in
status)
status
;;
start)
start
;;
stop)
stop
;;
restart)
restart
;;
restore)
restore
;;
uninstall)
uninstall
;;
user-info)
user-info
;;
listen-ip)
case "${target}" in
ipv4)
listen_ipv4
;;
ipv6)
listen_ipv6
;;
*)
listen-ip
;;
esac
;;
version)
version
;;
reset)
case "${target}" in
domain)
reset_domain
;;
entrance)
reset_entrance
;;
https)
reset_https
;;
ips)
reset_ips
;;
mfa)
reset_mfa
;;
*)
reset
;;
esac
;;
update)
case "${target}" in
username)
update_username
;;
password)
update_password
;;
port)
update_port
;;
*)
update
;;
esac
;;
help)
usage
;;
--help)
usage
;;
"")
usage
;;
*)
echo "不支持的参数,请使用 help 或 --help 参数获取帮助"
esac
}
main