This repository was archived by the owner on Jun 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathinstall.sh
More file actions
331 lines (300 loc) · 9.99 KB
/
Copy pathinstall.sh
File metadata and controls
331 lines (300 loc) · 9.99 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
#!/bin/bash
#
PROJECT_DIR=$(cd "$(dirname "$0")" || exit 1; pwd)
cd "${PROJECT_DIR}" || exit 1
VERSION=v1.7.4
if [ ! "$(echo $PATH | grep /usr/local/bin)" ]; then
export PATH=/usr/local/bin:$PATH
fi
while [[ $# > 0 ]]; do
lowerI="$(echo $1 | awk '{print tolower($0)}')"
case $lowerI in
-h|--help)
echo "Usage: $0 [OPTIONS]"
echo
echo "Global Options:"
echo -e " -h, --help \t Show this help message and exit"
echo -e " -v, --version Show the version information"
echo -e " --port \t Configure web access port in the Installation Phase."
echo -e " --user \t Configure 1Panel user in the Installation Phase."
echo -e " --password \t Configure 1Panel password in the Installation Phase."
echo -e " --entrance \t Configure 1Panel web security access in the Installation Phase."
echo -e " --install-dir Configure 1Panel install directory in the Installation Phase."
echo
echo "For more help options on how to use 1Panel, head to https://1panel.cn/docs/"
exit 0
;;
-v|--version)
echo "1Panel-installer version: $VERSION"
exit 0
;;
--port)
PANEL_PORT=$2
shift
;;
--user)
PANEL_USER=$2
shift
;;
--password)
PANEL_PASSWORD=$2
shift
;;
--entrance)
PANEL_ENTRANCE=$2
shift
;;
--install-dir)
INSTALL_DIR=$2
shift
;;
*)
echo "install: Unknown option $1"
echo "eg: $0 --port 8888 --user admin --password ******** --entrance secret"
exit 1
;;
esac
shift
done
PANEL_PORT=${PANEL_PORT:-"8888"}
PANEL_USER=${PANEL_USER:-"admin"}
PANEL_PASSWORD=${PANEL_PASSWORD:-""}
PANEL_ENTRANCE=${PANEL_ENTRANCE:-"secret"}
INSTALL_DIR=${INSTALL_DIR:-"/opt/1panel"}
INSTALL_DIR=${INSTALL_DIR%/1panel}
INSTALL_CHECK=0
if [ -f "/usr/local/bin/1pctl" ] && [ "${INSTALL_CHECK}" == "0" ]; then
VERSION=$(grep "ORIGINAL_VERSION=" /usr/local/bin/1pctl | awk -F "=" '{print $2}')
PANEL_PORT=$(grep "ORIGINAL_PORT=" /usr/local/bin/1pctl | awk -F "=" '{print $2}')
PANEL_USER=$(grep "ORIGINAL_USERNAME=" /usr/local/bin/1pctl | awk -F "=" '{print $2}')
PANEL_PASSWORD=$(grep "ORIGINAL_PASSWORD=" /usr/local/bin/1pctl | awk -F "=" '{print $2}')
PANEL_ENTRANCE=$(grep "ORIGINAL_ENTRANCE=" /usr/local/bin/1pctl | awk -F "=" '{print $2}')
INSTALL_DIR=$(grep "BASE_DIR=" /usr/local/bin/1pctl | awk -F "=" '{print $2}')
INSTALL_CHECK=1
fi
function echo_logo() {
cat << EOF
██╗ ██████╗ █████╗ ███╗ ██╗███████╗██╗
███║ ██╔══██╗██╔══██╗████╗ ██║██╔════╝██║
╚██║ ██████╔╝███████║██╔██╗ ██║█████╗ ██║
██║ ██╔═══╝ ██╔══██║██║╚██╗██║██╔══╝ ██║
██║ ██║ ██║ ██║██║ ╚████║███████╗███████╗
╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝╚══════╝
EOF
echo
echo -e "\t\t\t\t Version: \033[33m $VERSION \033[0m \n"
}
function log_warn() {
echo -e "\033[33m[WARN]: $1 \033[0m"
}
function log_error() {
echo -e "\033[31m[ERROR]: $1 \033[0m"
}
function check_os() {
if [ "$(uname -s)" != "Linux" ]; then
log_error "1Panel only support Linux"
exit 1
fi
}
function check_systemd() {
if ! command -v systemctl >/dev/null 2>&1; then
log_error "systemctl: command not found"
exit 1
fi
}
function check_prepare(){
for app in tar iptables; do
if ! command -v $app >/dev/null 2>&1; then
echo "$app: command not found"
exit 1
fi
done
if [ ! -d "${INSTALL_DIR}" ]; then
mkdir -p "${INSTALL_DIR}"
fi
}
function check_docker() {
if ! command -v docker >/dev/null 2>&1; then
install_docker
fi
if ! docker ps >/dev/null 2>&1; then
systemctl start docker
fi
}
function install_docker() {
if [ ! -f "docker.tgz" ]; then
log_error "docker.tgz not found"
exit 1
fi
if [ ! -f "docker.service" ]; then
log_error "docker.service not found"
exit 1
fi
if [ ! -f "/etc/systemd/system/docker.service" ]; then
cp docker.service /etc/systemd/system
fi
tar -xf docker.tgz
chown -R root:root docker
chmod -R 755 docker
cp -f docker/* /usr/local/bin
systemctl daemon-reload
systemctl enable docker
systemctl start docker
}
function check_compose() {
if ! command -v docker-compose >/dev/null 2>&1; then
install_compose
fi
}
function install_compose() {
if [ ! -f "docker-compose" ]; then
log_error "docker-compose not found"
exit 1
fi
chown root:root docker-compose
chmod 755 docker-compose
cp -f docker-compose /usr/local/bin
}
function check_1panel() {
if ! command -v 1panel >/dev/null 2>&1; then
install_1panel
fi
if command -v firewall-cmd >/dev/null; then
if firewall-cmd --state >/dev/null 2>&1; then
if ! firewall-cmd --list-all | grep "${PANEL_PORT}" >/dev/null 2>&1; then
firewall-cmd --zone=public --add-port="${PANEL_PORT}/tcp" --permanent
firewall-cmd --reload
fi
fi
fi
if which ufw >/dev/null 2>&1; then
if ufw status | grep "Status: active" >/dev/null 2>&1; then
if ! ufw status | grep "${PANEL_PORT}/tcp" | grep "ALLOW" >/dev/null 2>&1; then
ufw allow "${PANEL_PORT}/tcp"
ufw reload
fi
fi
fi
if ! systemctl status 1panel | grep "running" >/dev/null 2>&1; then
systemctl start 1panel
fi
}
function install_1panel() {
if [ ! -f "1panel" ]; then
log_error "1panel not found"
exit 1
fi
if [ ! -f "1panel.service" ]; then
log_error "1panel.service not found"
exit 1
fi
if [ ! -f "/etc/systemd/system/1panel.service" ]; then
cp 1panel.service /etc/systemd/system
fi
if grep -q "/usr/bin/1panel" /etc/systemd/system/1panel.service; then
sed -i 's@/usr/bin/1panel@/usr/local/bin/1panel@g' /etc/systemd/system/1panel.service
fi
cp -rf lang /usr/local/bin
cp -f 1panel /usr/local/bin
chown root:root /usr/local/bin/1panel
chmod 700 /usr/local/bin/1panel
systemctl daemon-reload
systemctl enable 1panel
systemctl start 1panel
}
function check_1pctl() {
if ! command -v 1pctl >/dev/null 2>&1; then
install_1pctl
fi
}
function install_1pctl() {
if [ ! -f "1pctl" ]; then
log_error "1pctl not found"
exit 1
fi
if [ ! -f "/usr/local/bin/1pctl" ]; then
cp -f 1pctl /usr/local/bin
fi
chown root:root /usr/local/bin/1pctl
chmod 700 /usr/local/bin/1pctl
sed -i -e "s#BASE_DIR=.*#BASE_DIR=${INSTALL_DIR}#g" /usr/local/bin/1pctl
sed -i -e "s#ORIGINAL_PORT=.*#ORIGINAL_PORT=${PANEL_PORT}#g" /usr/local/bin/1pctl
sed -i -e "s#ORIGINAL_USERNAME=.*#ORIGINAL_USERNAME=${PANEL_USER}#g" /usr/local/bin/1pctl
if [ -z "${PANEL_PASSWORD}" ]; then
PANEL_PASSWORD=$(random_str 24)
fi
sed -i -e "s#ORIGINAL_PASSWORD=.*#ORIGINAL_PASSWORD=${PANEL_PASSWORD}#g" /usr/local/bin/1pctl
if [ -z "${PANEL_ENTRANCE}" ]; then
sed -i -e "s#ORIGINAL_ENTRANCE=.*#ORIGINAL_ENTRANCE=''#g" /usr/local/bin/1pctl
else
sed -i -e "s#ORIGINAL_ENTRANCE=.*#ORIGINAL_ENTRANCE=${PANEL_ENTRANCE}#g" /usr/local/bin/1pctl
fi
}
function random_str() {
len=$1
if [[ -z ${len} ]]; then
len=24
fi
uuid=None
if command -v dmidecode &>/dev/null; then
if [[ ${len} > 16 ]]; then
uuid=$(dmidecode -t 1 | grep UUID | awk '{print $2}' | sha256sum | awk '{print $1}' | head -c ${len})
fi
fi
if [[ "${#uuid}" == "${len}" ]]; then
echo "${uuid}"
else
head -c100 < /dev/urandom | base64 | tr -dc A-Za-z0-9 | head -c ${len}; echo
fi
}
function get_host_ip() {
local default_ip="127.0.0.1"
host=$(command -v hostname &>/dev/null && hostname -I | cut -d ' ' -f1)
if [ ! "${host}" ]; then
host=$(command -v ip &>/dev/null && ip addr | grep 'inet ' | grep -Ev '(127.0.0.1|inet6|docker)' | awk '{print $2}' | head -n 1 | cut -d / -f1)
fi
if [[ ${host} =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "${host}"
else
echo "${default_ip}"
fi
}
function post_install() {
echo ""
PANEL_HOST=$(get_host_ip)
if [[ -z "${PANEL_HOST}" ]]; then
PANEL_HOST="127.0.0.1"
fi
if [ "${INSTALL_CHECK}" == "1" ]; then
echo "=============== 检测到 1Panel 已经安装, 跳过配置 ==============="
else
echo "================ 感谢您的耐心等待, 安装已经完成 ================="
fi
echo ""
echo -e "面板地址:\033[33m http://${PANEL_HOST}:${PANEL_PORT}/${PANEL_ENTRANCE} \033[0m"
if [ -n "${PANEL_PASSWORD}" ]; then
echo -e "用户名称:\033[31m $PANEL_USER \033[0m"
echo -e "用户密码:\033[31m $PANEL_PASSWORD \033[0m"
fi
echo ""
echo "项目官网: https://1panel.cn"
echo "项目文档: https://1panel.cn/docs"
echo "代码仓库: https://github.com/1Panel-dev/1Panel"
echo "交流社区: https://bbs.fit2cloud.com"
echo ""
echo -e "\033[33m 如果使用的是云服务器, 请至安全组开放 $PANEL_PORT 端口 \033[0m"
echo ""
echo "================================================================="
}
function main() {
echo_logo
check_os
check_systemd
check_prepare
check_docker
check_compose
check_1pctl
check_1panel
post_install
}
main