upgrade

package
v0.1.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package upgrade 提供 agent 自升级:版本查询/比较/下载/校验/替换(CLI 与 WS 推送共用)。

下载源:XPanel-Node 仓库的 GitHub Releases。版本查询走 /releases/latest 的 重定向 Location(不调 REST API,规避匿名速率限制且兼容镜像站);二进制与 checksums.txt 从 /releases/download/<tag>/ 拉取,sha256 必检。

镜像候选链:配置的 update.mirror 置顶,其后自动落回内置候选(与 install-agent.sh 的 DEFAULT_MIRRORS 同源)。逐个尝试,网络/HTTP 级失败切下一个;checksums.txt 拿到了但内容不对(缺条目)视为 release 本身损坏,换镜像无意义,立即报错。 资产与 checksums.txt 始终取自同一镜像,保证校验可信。

Index

Constants

View Source
const DefaultRepo = "acdc-awa/XPanel-Node"

DefaultRepo 默认发布仓库(XPanel-Node on GitHub)。

Variables

View Source
var ErrUpToDate = errors.New("已是最新版本")

ErrUpToDate 已是最新版本。

View Source
var Version = "dev"

Version 当前 agent 版本(构建期 -ldflags -X 注入;"dev" 为默认开发值)。

Functions

func Apply

func Apply(f *Fetcher, exePath string, restart func() error, out io.Writer) error

Apply 完整升级流程:查版本 → 比较 → 下载 → sha256 强制校验 → 原子替换 → 重启。 exePath 为目标二进制路径(通常 os.Executable());restart 由调用方注入(systemd 重启或手动提示)。

func AssetName

func AssetName() string

AssetName 当前平台的发布资产名(agent 运行于 Linux 节点,恒 linux-<arch>)。

func Compare

func Compare(a, b string) int

Compare 语义化比较版本:-1 a<b / 0 相等 / 1 a>b。非法版本归一为 "0"。

func CurrentVersion

func CurrentVersion() string

CurrentVersion 返回当前 agent 版本。

func ReplaceBinary

func ReplaceBinary(exePath string, data []byte) error

ReplaceBinary 原子替换二进制文件:写入同目录 .tmp → chmod 0755 → rename 覆盖。 失败时清理 .tmp。CLI 升级与 WS 触发升级共用。

func Sha256Hex

func Sha256Hex(data []byte) string

Sha256Hex 计算数据 sha256 的 hex 串。

Types

type Fetcher

type Fetcher struct {
	Repo   string // owner/repo,空 = DefaultRepo
	Mirror string // 可选:首选镜像/代理前缀(如 https://ghproxy.net/https://github.com),置顶尝试
	// Mirrors 显式完整候选列表(测试注入用);非空时忽略 Mirror 与内置列表。
	Mirrors []string
	// DownloadTimeout 单镜像单次资产下载超时,0 = defaultDownloadTimeout。
	DownloadTimeout time.Duration
	// Client 测试注入用;非空时两个角色共用(注入方自管重定向策略)。
	Client *http.Client
	// contains filtered or unexported fields
}

Fetcher 从 GitHub Releases 查询版本并下载 agent 发布资产,按镜像候选链逐个尝试。

func (*Fetcher) Download

func (f *Fetcher) Download(tag string) ([]byte, string, error)

Download 按候选链下载指定 tag 的资产与 checksums.txt(同一镜像取齐),返回数据与期望 sha256(hex)。

func (*Fetcher) Latest

func (f *Fetcher) Latest() (string, error)

Latest 按候选链解析最新 release tag:GET /releases/latest 不跟随重定向,从 Location 取 tag。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL