diff --git a/.goreleaser.yml b/.goreleaser.yml index 6c768659..96aa2457 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -22,9 +22,6 @@ builds: - amd64 - arm64 - arm - goarm: - - "6" - - "7" ignore: - goos: windows goarch: arm64 @@ -42,6 +39,8 @@ builds: main: internal/cmd/agent/agent.go env: - CGO_ENABLED=0 + ldflags: + - -s -w -X github.com/henrygd/beszel/internal/ghupdate.buildGOARM={{ .Arm }} goos: - linux - darwin @@ -108,6 +107,7 @@ archives: {{ .Binary }}_ {{- .Os }}_ {{- .Arch }} + {{- if ne .Arm "6" }}{{ with .Arm }}v{{ . }}{{ end }}{{ end }} format_overrides: - goos: windows formats: [zip] diff --git a/internal/ghupdate/ghupdate.go b/internal/ghupdate/ghupdate.go index f5baf0d6..881e6c6f 100644 --- a/internal/ghupdate/ghupdate.go +++ b/internal/ghupdate/ghupdate.go @@ -30,6 +30,10 @@ const ( colorGray = "\033[90m" ) +// buildGOARM is set by GoReleaser for agent builds. An empty value identifies +// legacy builds, which used GoReleaser's default GOARM value (ARMv6). +var buildGOARM string + func ColorPrint(color, text string) { fmt.Println(color + text + colorReset) } @@ -129,7 +133,7 @@ func (p *updater) update() (updated bool, err error) { return false, nil } - suffix := archiveSuffix(p.config.ArchiveExecutable, runtime.GOOS, runtime.GOARCH) + suffix := archiveSuffix(p.config.ArchiveExecutable, runtime.GOOS, runtime.GOARCH, buildGOARM) asset, err := latest.findAssetBySuffix(suffix) if err != nil { return false, err @@ -346,7 +350,7 @@ func copyFile(src, dst string) error { return destFile.Chmod(sourceInfo.Mode()) } -func archiveSuffix(binaryName, goos, goarch string) string { +func archiveSuffix(binaryName, goos, goarch, goarm string) string { if goos == "windows" { return fmt.Sprintf("%s_%s_%s.zip", binaryName, goos, goarch) } @@ -354,7 +358,11 @@ func archiveSuffix(binaryName, goos, goarch string) string { if binaryName == "beszel-agent" && goos == "linux" && goarch == "amd64" && isGlibc() { return fmt.Sprintf("%s_%s_%s_glibc.tar.gz", binaryName, goos, goarch) } - return fmt.Sprintf("%s_%s_%s.tar.gz", binaryName, goos, goarch) + armSuffix := "" + if binaryName == "beszel-agent" && goarch == "arm" && (goarm == "5" || goarm == "7") { + armSuffix = "v" + goarm + } + return fmt.Sprintf("%s_%s_%s%s.tar.gz", binaryName, goos, goarch, armSuffix) } func isGlibc() bool { diff --git a/internal/ghupdate/ghupdate_test.go b/internal/ghupdate/ghupdate_test.go index f23b5750..5598c93d 100644 --- a/internal/ghupdate/ghupdate_test.go +++ b/internal/ghupdate/ghupdate_test.go @@ -8,6 +8,31 @@ import ( "testing" ) +func TestArchiveSuffix(t *testing.T) { + tests := []struct { + name string + binary, goos, goarch string + goarm, want string + }{ + {"armv5 agent", "beszel-agent", "linux", "arm", "5", "beszel-agent_linux_armv5.tar.gz"}, + {"armv6 keeps legacy name", "beszel-agent", "linux", "arm", "6", "beszel-agent_linux_arm.tar.gz"}, + {"hub keeps legacy arm name", "beszel", "linux", "arm", "6", "beszel_linux_arm.tar.gz"}, + {"armv7 agent", "beszel-agent", "linux", "arm", "7", "beszel-agent_linux_armv7.tar.gz"}, + {"newer arm keeps legacy name", "beszel-agent", "linux", "arm", "8", "beszel-agent_linux_arm.tar.gz"}, + {"unknown arm keeps legacy name", "beszel-agent", "linux", "arm", "", "beszel-agent_linux_arm.tar.gz"}, + {"amd64 hub", "beszel", "linux", "amd64", "", "beszel_linux_amd64.tar.gz"}, + {"windows", "beszel-agent", "windows", "amd64", "", "beszel-agent_windows_amd64.zip"}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := archiveSuffix(tt.binary, tt.goos, tt.goarch, tt.goarm); got != tt.want { + t.Errorf("archiveSuffix() = %q, want %q", got, tt.want) + } + }) + } +} + func TestReleaseFindAssetBySuffix(t *testing.T) { r := release{ Assets: []*releaseAsset{ diff --git a/supplemental/scripts/install-agent.sh b/supplemental/scripts/install-agent.sh index 246f647b..dbbda569 100755 --- a/supplemental/scripts/install-agent.sh +++ b/supplemental/scripts/install-agent.sh @@ -215,9 +215,15 @@ detect_architecture() { x86_64) arch="amd64" ;; - armv6l|armv7l) + armv5*) + arch="armv5" + ;; + armv6l) arch="arm" ;; + armv7l) + arch="armv7" + ;; aarch64) arch="arm64" ;;