This repository was archived by the owner on Dec 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaddyInstall.sh
More file actions
55 lines (47 loc) · 1.33 KB
/
caddyInstall.sh
File metadata and controls
55 lines (47 loc) · 1.33 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
#!/bin/bash
# 设置反向代理
github=https://github.com/
raw=https://raw.githubusercontent.com/
curl() {
# Copy from https://github.com/XTLS/Xray-install
if ! $(type -P curl) -L -q --retry 5 --retry-delay 10 --retry-max-time 60 "$@";then
echo "ERROR:Curl Failed, check your network"
exit 1
fi
}
# 检测微架构
case $(lscpu) in
*avx512*)
microArch=4
;;
*avx2*)
microArch=3
;;
*sse4_2*)
microArch=2
;;
*)
microArch=1
;;
esac
# 安装 caddy
groupadd --system caddy
useradd --system --gid caddy --create-home --home-dir /var/lib/caddy --shell /usr/sbin/nologin --comment "Caddy web server" caddy
curl -o /usr/bin/caddy $github/AsenHu/caddy-builder/releases/download/cfdnstls/caddy-linux-amd64-v$microArch
curl -o /etc/systemd/system/caddy.service $raw/caddyserver/dist/master/init/caddy.service
chmod +x /usr/bin/caddy
# 配置 caddy
mkdir -p /etc/caddy
if [ ! -f /etc/caddy/Caddyfile ]
then
echo -e ':2077\nrespond "Hello, world!"' > /etc/caddy/Caddyfile
fi
if ! /usr/bin/caddy validate --config /etc/caddy/Caddyfile
then
mv -b /etc/caddy/Caddyfile /etc/caddy/Caddyfile.badconfig
echo -e ':2077\nrespond "Hello, world!"' > /etc/caddy/Caddyfile
fi
# 启动 caddy
systemctl daemon-reload
systemctl enable caddy
systemctl restart caddy