diff --git a/CHANGELOG.md b/CHANGELOG.md index bfcbfbf..27de1ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # 更新日志 +v1.5.1 +--- +- CHANGE: 优化代码结构,提升性能 +- CHANGE: Bump github.com/imroc/req/v3 from 3.48.0 to 3.49.0 by @dependabot in https://github.com/WJQSERVER-STUDIO/ghproxy/pull/7 +- ADD: 新增一键部署脚本,简化二进制文件部署流程 + +24w16a +--- +- PRE-RELEASE: 此版本是v1.5.1的预发布版本,请勿在生产环境中使用 +- CHANGE: 优化代码结构,提升性能 +- CHANGE: Bump github.com/imroc/req/v3 from 3.47.0 to 3.48.0 by @dependabot in https://github.com/WJQSERVER-STUDIO/ghproxy/pull/6 +- ADD: 新增一键部署脚本,简化二进制文件部署流程 + v1.5.0 --- - CHANGE: 优化代码结构,提升性能 diff --git a/README.md b/README.md index f518e8f..667d60c 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,16 @@ docker run -p 7210:80 -v ./ghproxy/log/run:/data/ghproxy/log -v ./ghproxy/log/ca 参看[docker-compose.yml](https://github.com/WJQSERVER-STUDIO/ghproxy/blob/main/docker/compose/docker-compose.yml) +### 二进制文件部署 + +一键部署脚本: + +```bash +wget -O install.sh https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/install.sh && chmod +x install.sh &&./install.sh +``` + +## 配置说明 + ### 外部配置文件 本项目采用`config.toml`作为外部配置,默认配置如下 diff --git a/VERSION b/VERSION index 3e1ad72..8e03717 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.5.0 \ No newline at end of file +1.5.1 \ No newline at end of file diff --git a/config/blacklist.json b/config/blacklist.json index 8062ee0..839d3f6 100644 --- a/config/blacklist.json +++ b/config/blacklist.json @@ -2,6 +2,6 @@ "blacklist": [ "black/list", "test/test1", - "example/repo2" + "example/*" ] } \ No newline at end of file diff --git a/config/config.yaml b/config/config.yaml deleted file mode 100644 index 21bc68b..0000000 --- a/config/config.yaml +++ /dev/null @@ -1,29 +0,0 @@ -# Server Configuration -server: - port: 8080 - host: "127.0.0.1" - sizelimit: 131072000 # 125MB - -# Logging Configuration -logger: - logfilepath: "/data/ghproxy/log/ghproxy.log" - maxlogsize: 5 # MB - -# CORS Configuration -cors: - enabled: true - -# Authentication Configuration -auth: - enabled: false - authtoken: "test" - -# Blacklist Configuration -blacklist: - enabled: false - blacklistfile: "/data/ghproxy/config/blacklist.json" - -# Whitelist Configuration -whitelist: - enabled: false - whitelistfile: "/data/ghproxy/config/whitelist.json" \ No newline at end of file diff --git a/config/whitelist.json b/config/whitelist.json index e39661b..868a3a8 100644 --- a/config/whitelist.json +++ b/config/whitelist.json @@ -2,6 +2,6 @@ "whitelist": [ "white/list", "white/test1", - "example/white" + "example/*" ] } \ No newline at end of file diff --git a/deploy/config.toml b/deploy/config.toml new file mode 100644 index 0000000..2e2fd46 --- /dev/null +++ b/deploy/config.toml @@ -0,0 +1,23 @@ +[server] +host = "127.0.0.1" +port = 8080 +sizelimit = 131072000 # 125MB + +[log] +logfilepath = "/root/data/ghproxy/log/ghproxy.log" +maxlogsize = 5 # MB + +[cors] +enabled = true + +[auth] +authtoken = "test" +enabled = false + +[blacklist] +blacklistfile = "/root/data/ghproxy/config/blacklist.json" +enabled = false + +[whitelist] +enabled = false +whitelistfile = "/root/data/ghproxy/config/whitelist.json" diff --git a/deploy/ghproxy.service b/deploy/ghproxy.service new file mode 100644 index 0000000..b2a24a7 --- /dev/null +++ b/deploy/ghproxy.service @@ -0,0 +1,13 @@ +[Unit] +Description=Github Proxy Service +After=network.target + +[Service] +ExecStart=/bin/bash -c '/root/data/ghproxy/ghproxy -cfg /root/data/ghproxy/config/config.toml > /root/data/ghproxy/log/run.log 2>&1' +WorkingDirectory=/root/data/ghproxy +Restart=always +User=root +Group=root + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/deploy/install.sh b/deploy/install.sh new file mode 100644 index 0000000..b260752 --- /dev/null +++ b/deploy/install.sh @@ -0,0 +1,78 @@ +# /bin/bash + +# install packages +install() { + if [ $# -eq 0 ]; then + echo "ARGS NOT FOUND" + return 1 + fi + + for package in "$@"; do + if ! command -v "$package" &>/dev/null; then + if command -v dnf &>/dev/null; then + dnf -y update && dnf install -y "$package" + elif command -v yum &>/dev/null; then + yum -y update && yum -y install "$package" + elif command -v apt &>/dev/null; then + apt update -y && apt install -y "$package" + elif command -v apk &>/dev/null; then + apk update && apk add "$package" + else + echo "UNKNOWN PACKAGE MANAGER" + return 1 + fi + fi + done + + return 0 +} + +# 安装依赖包 +install curl wget sed + +# 查看当前架构是否为linux/amd64或linux/arm64 +ARCH=$(uname -m) +if [ "$ARCH" != "x86_64" ] && [ "$ARCH" != "aarch64" ]; then + echo " $ARCH 架构不被支持" + exit 1 +fi + +# 重写架构值,改为amd64或arm64 +if [ "$ARCH" == "x86_64" ]; then + ARCH="amd64" +elif [ "$ARCH" == "aarch64" ]; then + ARCH="arm64" +fi + +read -p "请输入程序监听的端口(默认8080): " PORT +if [ -z "$PORT" ]; then + PORT=8080 +fi + +# 创建目录 +mkdir -p /root/data/ghproxy +mkdir -p /root/data/ghproxy/config +mkdir -p /root/data/ghproxy/log + +# 获取最新版本号 +VERSION=$(curl -s https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/VERSION) +wget -O /root/data/ghproxy/VERSION https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/VERSION + +# 下载ghproxy +wget -O /root/data/ghproxy/ghproxy https://github.com/WJQSERVER-STUDIO/ghproxy/releases/download/$VERSION/ghproxy-linux-$ARCH +chmod +x /root/data/ghproxy/ghproxy + +# 下载配置文件 +wget -O /root/data/ghproxy/config/config.toml https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/config.toml +# 替换 port = 8080 +sed -i "s/port = 8080/port = $PORT/g" /root/data/ghproxy/config/config.toml + +# 下载systemd服务文件 +wget -O /etc/systemd/system/ghproxy.service https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/ghproxy.service + +# 启动ghproxy +systemctl daemon-reload +systemctl enable ghproxy +systemctl start ghproxy + +echo "ghproxy 安装成功, 监听端口为 $PORT" diff --git a/deploy/uninstall.sh b/deploy/uninstall.sh new file mode 100644 index 0000000..7d1804e --- /dev/null +++ b/deploy/uninstall.sh @@ -0,0 +1,13 @@ +# /bin/bash + +# 停止 ghproxy 服务 +systemctl stop ghproxy + +# 删除 ghproxy 服务 +systemctl disable ghproxy +rm /etc/systemd/system/ghproxy.service + +# 删除 ghproxy 文件夹 +rm -r /root/data/ghproxy + +echo "ghproxy 已成功卸载" \ No newline at end of file