Skip to content

Commit 9d30f8c

Browse files
committed
feat(install): 优化一键安装脚本
1 parent a9c5dc8 commit 9d30f8c

6 files changed

Lines changed: 58 additions & 44 deletions

File tree

README.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,23 @@
1919
Linux/macOS 推荐使用一键安装脚本,默认安装 [GitHub Releases](https://github.com/https-cert/deploy/releases) 最新版本:
2020

2121
```bash
22-
curl -fsSL https://raw.githubusercontent.com/https-cert/deploy/main/scripts/install.sh | sh
23-
```
24-
25-
国内服务器可使用 GitHub 代理加速下载:
26-
27-
```bash
28-
curl -fsSL https://ghproxy.net/https://raw.githubusercontent.com/https-cert/deploy/main/scripts/install.sh | MIRROR=ghproxy sh
22+
curl -fsSL https://gh-proxy.com/https://raw.githubusercontent.com/https-cert/deploy/main/scripts/install.sh | sh
2923
```
3024

3125
如需固定版本或修改安装目录:
3226

3327
```bash
34-
curl -fsSL https://raw.githubusercontent.com/https-cert/deploy/main/scripts/install.sh | VERSION=v0.6.0 APP_DIR=/opt/anssl sh
28+
curl -fsSL https://gh-proxy.com/https://raw.githubusercontent.com/https-cert/deploy/main/scripts/install.sh | VERSION=v0.6.0 APP_DIR=/opt/anssl sh
3529
```
3630

3731
默认安装到 `/opt/anssl`,并创建 `/usr/local/bin/anssl` 软链接。如需卸载:
3832

3933
```bash
4034
# 卸载程序,保留配置
41-
curl -fsSL https://raw.githubusercontent.com/https-cert/deploy/main/scripts/install.sh | sh -s -- --uninstall
35+
curl -fsSL https://gh-proxy.com/https://raw.githubusercontent.com/https-cert/deploy/main/scripts/install.sh | sh -s -- --uninstall
4236

4337
# 卸载程序并删除配置
44-
curl -fsSL https://raw.githubusercontent.com/https-cert/deploy/main/scripts/install.sh | sh -s -- --uninstall --purge
38+
curl -fsSL https://gh-proxy.com/https://raw.githubusercontent.com/https-cert/deploy/main/scripts/install.sh | sh -s -- --uninstall --purge
4539
```
4640

4741
### 2. 配置
@@ -74,7 +68,7 @@ ssl:
7468
apiKey: ""
7569

7670
update:
77-
# 镜像源类型:github、ghproxy、ghproxy2、custom
71+
# 镜像源类型:github、ghproxy、custom
7872
mirror: "ghproxy"
7973
# 使用 custom 镜像源时填写
8074
customUrl: ""

README_EN.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,23 @@ An automated SSL certificate deployment tool for downloading certificates from [
1919
For Linux/macOS, use the install script. It installs the latest version from [GitHub Releases](https://github.com/https-cert/deploy/releases) by default:
2020

2121
```bash
22-
curl -fsSL https://raw.githubusercontent.com/https-cert/deploy/main/scripts/install.sh | sh
23-
```
24-
25-
For servers with slow GitHub access, use a GitHub proxy:
26-
27-
```bash
28-
curl -fsSL https://ghproxy.net/https://raw.githubusercontent.com/https-cert/deploy/main/scripts/install.sh | MIRROR=ghproxy sh
22+
curl -fsSL https://gh-proxy.com/https://raw.githubusercontent.com/https-cert/deploy/main/scripts/install.sh | sh
2923
```
3024

3125
To pin a version or customize paths:
3226

3327
```bash
34-
curl -fsSL https://raw.githubusercontent.com/https-cert/deploy/main/scripts/install.sh | VERSION=v0.6.0 APP_DIR=/opt/anssl sh
28+
curl -fsSL https://gh-proxy.com/https://raw.githubusercontent.com/https-cert/deploy/main/scripts/install.sh | VERSION=v0.6.0 APP_DIR=/opt/anssl sh
3529
```
3630

3731
By default, anssl is installed into `/opt/anssl` and linked as `/usr/local/bin/anssl`. To uninstall:
3832

3933
```bash
4034
# Remove the binary and keep config
41-
curl -fsSL https://raw.githubusercontent.com/https-cert/deploy/main/scripts/install.sh | sh -s -- --uninstall
35+
curl -fsSL https://gh-proxy.com/https://raw.githubusercontent.com/https-cert/deploy/main/scripts/install.sh | sh -s -- --uninstall
4236

4337
# Remove the binary and config
44-
curl -fsSL https://raw.githubusercontent.com/https-cert/deploy/main/scripts/install.sh | sh -s -- --uninstall --purge
38+
curl -fsSL https://gh-proxy.com/https://raw.githubusercontent.com/https-cert/deploy/main/scripts/install.sh | sh -s -- --uninstall --purge
4539
```
4640

4741
### 2. Configure
@@ -74,7 +68,7 @@ ssl:
7468
apiKey: ""
7569

7670
update:
77-
# Mirror type: github, ghproxy, ghproxy2, custom
71+
# Mirror type: github, ghproxy, custom
7872
mirror: "ghproxy"
7973
# Required when mirror is custom
8074
customUrl: ""

config.example.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ssl:
2020
apiKey: ""
2121

2222
update:
23-
# 镜像源类型:github、ghproxy、ghproxy2、custom
23+
# 镜像源类型:github、ghproxy、custom
2424
mirror: "ghproxy"
2525
# 使用 custom 镜像源时填写
2626
customUrl: ""

internal/config/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type (
5959

6060
// UpdateConfig 自更新下载源和代理配置
6161
UpdateConfig struct {
62-
// 镜像源类型: github, ghproxy, ghproxy2, custom
62+
// 镜像源类型: github, ghproxy, custom
6363
Mirror string `yaml:"mirror"`
6464
// 自定义镜像地址(当 mirror=custom 时使用)
6565
CustomURL string `yaml:"customUrl"`
@@ -157,10 +157,10 @@ func validateConfig() error {
157157
Config.Update = &UpdateConfig{}
158158
}
159159
if Config.Update.Mirror != "" {
160-
validMirrors := []string{"github", "ghproxy", "ghproxy2", "custom"}
160+
validMirrors := []string{"github", "ghproxy", "custom"}
161161
isValid := slices.Contains(validMirrors, Config.Update.Mirror)
162162
if !isValid {
163-
return fmt.Errorf("不支持的镜像源类型: %s (支持: github, ghproxy, ghproxy2, custom)", Config.Update.Mirror)
163+
return fmt.Errorf("不支持的镜像源类型: %s (支持: github, ghproxy, custom)", Config.Update.Mirror)
164164
}
165165

166166
// 如果使用自定义镜像,检查 customUrl 是否设置

internal/updater/updater.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,14 @@ const (
3434

3535
// 常见的 GitHub 镜像加速服务
3636
const (
37-
mirrorGitHub = "github"
38-
mirrorGHProxy = "ghproxy"
39-
mirrorGHProxy2 = "ghproxy2"
40-
mirrorCustom = "custom"
37+
mirrorGitHub = "github"
38+
mirrorGHProxy = "ghproxy"
39+
mirrorCustom = "custom"
4140
)
4241

4342
var mirrorMap = map[string]string{
44-
mirrorGitHub: "https://github.com",
45-
mirrorGHProxy: "https://ghproxy.net/https://github.com",
46-
mirrorGHProxy2: "https://gh-proxy.com/https://github.com",
43+
mirrorGitHub: "https://github.com",
44+
mirrorGHProxy: "https://gh-proxy.com/https://github.com",
4745
}
4846

4947
// GitHubRelease GitHub Release API 响应结构

scripts/install.sh

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set -eu
77
REPO="${REPO:-https-cert/deploy}"
88
BIN_NAME="${BIN_NAME:-anssl}"
99
VERSION="${VERSION:-latest}"
10-
MIRROR="${MIRROR:-}"
10+
MIRROR="${MIRROR:-ghproxy}"
1111
APP_DIR="${APP_DIR:-/opt/anssl}"
1212
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
1313
CONFIG_DIR="${CONFIG_DIR:-$APP_DIR}"
@@ -43,7 +43,7 @@ usage() {
4343
4444
环境变量:
4545
VERSION 安装版本,默认 latest,例如 v0.6.0
46-
MIRROR GitHub 代理,可选 ghproxy、ghproxy2
46+
MIRROR 下载源,可选 ghproxy、github,默认 ghproxy
4747
APP_DIR 程序目录,默认 /opt/anssl
4848
INSTALL_DIR 命令链接目录,默认 /usr/local/bin
4949
CONFIG_DIR 配置目录,默认等于 APP_DIR
@@ -137,18 +137,14 @@ build_release_urls() {
137137
checksum_url="${base_url}/checksums.txt"
138138

139139
case "$MIRROR" in
140-
"")
140+
github)
141141
;;
142142
ghproxy)
143-
asset_url="https://ghproxy.net/${asset_url}"
144-
checksum_url="https://ghproxy.net/${checksum_url}"
145-
;;
146-
ghproxy2 | gh-proxy)
147143
asset_url="https://gh-proxy.com/${asset_url}"
148144
checksum_url="https://gh-proxy.com/${checksum_url}"
149145
;;
150146
*)
151-
log_error "不支持的镜像源: ${MIRROR},可选值: ghproxy, ghproxy2"
147+
log_error "不支持的下载源: ${MIRROR},可选值: ghproxy, github"
152148
;;
153149
esac
154150
}
@@ -244,6 +240,39 @@ uninstall_anssl() {
244240
log_info "卸载完成"
245241
}
246242

243+
# print_success_banner 输出安装完成后的摘要信息。
244+
print_success_banner() {
245+
version_output="$("${INSTALL_DIR}/${BIN_NAME}" version 2>/dev/null || true)"
246+
if [ "$version_output" = "" ]; then
247+
version_output="${BIN_NAME} version unknown"
248+
fi
249+
250+
cat <<EOF
251+
252+
------------------------------------------------------------
253+
___ _ _ ____ ____ _
254+
/ _ \ | \ | / ___/ ___|| |
255+
/ /_\ \ | \| \___ \___ \| |
256+
/ ___ \ | |\ | ___) |__) | |___
257+
/_/ \_\|_| \_||____/____/|_____|
258+
259+
anssl 安装成功
260+
261+
版本: ${version_output}
262+
程序: ${APP_DIR}/${BIN_NAME}
263+
命令: ${INSTALL_DIR}/${BIN_NAME}
264+
配置: ${CONFIG_DIR}/config.yaml
265+
266+
卸载:
267+
curl -fsSL https://gh-proxy.com/https://raw.githubusercontent.com/https-cert/deploy/main/scripts/install.sh | sh -s -- --uninstall
268+
269+
卸载并删除配置:
270+
curl -fsSL https://gh-proxy.com/https://raw.githubusercontent.com/https-cert/deploy/main/scripts/install.sh | sh -s -- --uninstall --purge
271+
------------------------------------------------------------
272+
273+
EOF
274+
}
275+
247276
# main 执行下载、校验、解压和安装流程。
248277
main() {
249278
parse_args "$@"
@@ -287,9 +316,8 @@ main() {
287316
log_info "准备配置目录 ${CONFIG_DIR}"
288317
install_config
289318

290-
log_info "安装完成"
291-
"${INSTALL_DIR}/${BIN_NAME}" version || true
292-
printf '\n%s\n' "下一步:编辑 ${CONFIG_DIR}/config.yaml,填写 server.accessKey 后运行:"
319+
print_success_banner
320+
printf '%s\n' "下一步:编辑 ${CONFIG_DIR}/config.yaml,填写 server.accessKey 后运行:"
293321
printf '%s\n' "${INSTALL_DIR}/${BIN_NAME} daemon -c ${CONFIG_DIR}/config.yaml"
294322
}
295323

0 commit comments

Comments
 (0)