selfupdate

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChannelStable     = "stable"
	ChannelPrerelease = "prerelease"
)

Variables

This section is empty.

Functions

func CheckWritePermission

func CheckWritePermission(dir string) error

CheckWritePermission checks if the directory is writable by attempting to create a temporary file.

func DetectPackageManager

func DetectPackageManager(binaryPath string) (string, bool)

DetectPackageManager checks if the binary path is inside a known package-managed prefix. Returns the manager name and whether it was detected.

func DownloadArchive

func DownloadArchive(httpClient *http.Client, url, dir string, isTTY bool) (string, error)

DownloadArchive downloads a file from url to a temp file in dir. Returns the path to the downloaded file. If isTTY is true, displays a progress bar; otherwise uses line-based progress. Checks Content-Length header and caps streaming at maxArchiveSizeLimit.

func ExtractBinary

func ExtractBinary(archivePath, outDir, binaryName string) (string, error)

ExtractBinary extracts the named binary from a .tar.gz archive to a temp file in outDir. Validates that the extracted path contains no separators or traversal components.

func IsDevBuild

func IsDevBuild(version string) bool

IsDevBuild returns true if the version is not a valid semver string, or is a non-canonical short version like "0.0", or has a git describe suffix like "0.1.0-alpha.7-3-gabcdef".

func IsPrerelease

func IsPrerelease(version string) bool

IsPrerelease returns true if the version is a valid semver string with a prerelease suffix (e.g., "0.1.0-alpha.7").

func ReplaceBinary

func ReplaceBinary(targetPath, newPath string) error

ReplaceBinary atomically replaces the binary at targetPath with the new binary at newPath using os.Rename (atomic on POSIX). Preserves the original file permissions.

func ResolveBinaryPath

func ResolveBinaryPath() (string, string, error)

ResolveBinaryPath returns the absolute path to the currently running binary, resolving any symlinks. It also returns the original (unresolved) path, which is useful for package manager detection where symlinks (e.g. /snap/bin/foo -> /usr/bin/snap) would cause incorrect prefix matching.

func ShouldUpdate

func ShouldUpdate(current, latest string, crossChannel bool) bool

ShouldUpdate returns true if the binary should be updated from current to latest. If crossChannel is true, the update is always offered (the user explicitly chose to switch channels). Dev builds always get offered updates.

func VerifyCosignBundle

func VerifyCosignBundle(httpClient *http.Client, archivePath, bundleURL string) error

VerifyCosignBundle verifies the cosign bundle for the archive at archivePath. Downloads the bundle from bundleURL and verifies against Sigstore's public good instance.

Verification checks: - Certificate issuer: https://token.actions.githubusercontent.com - Certificate SAN (prefix): https://github.com/bernd/vibepit/.github/workflows/build.yml

func VerifySHA256

func VerifySHA256(path, expected string) error

VerifySHA256 checks that the SHA256 hash of the file at path matches the expected hex-encoded checksum.

Types

type Asset

type Asset struct {
	OS              string `json:"os"`
	Arch            string `json:"arch"`
	URL             string `json:"url"`
	SHA256          string `json:"sha256"`
	CosignBundleURL string `json:"cosign_bundle_url"`
}

Asset represents a platform-specific release asset.

type ChannelIndex

type ChannelIndex struct {
	Latest   string         `json:"latest"`
	Releases []ReleaseEntry `json:"releases"`
}

ChannelIndex represents a channel index file (e.g., stable.json).

type Client

type Client struct {
	HTTPClient *http.Client
	BaseURL    string
}

Client fetches release metadata from vibepit.dev.

func NewClient

func NewClient() *Client

NewClient creates a new release metadata client.

func (*Client) FetchChannelIndex

func (c *Client) FetchChannelIndex(channel string) (*ChannelIndex, bool, error)

FetchChannelIndex fetches and parses a channel index file. Returns the index and a boolean indicating whether the file was found.

func (*Client) FetchVersionMetadata

func (c *Client) FetchVersionMetadata(version string) (*VersionMetadata, error)

FetchVersionMetadata fetches and parses a version metadata file.

func (*Client) ResolveChannel

func (c *Client) ResolveChannel(preferPre bool) (*ChannelIndex, string, error)

ResolveChannel determines which channel to use and fetches the index. Implements fallback logic: if stable is not found and --pre was not explicitly set, falls back to prerelease.

type ReleaseEntry

type ReleaseEntry struct {
	Version   string `json:"version"`
	Timestamp string `json:"timestamp"`
}

ReleaseEntry is a single entry in the channel index releases array.

type VersionMetadata

type VersionMetadata struct {
	Version   string  `json:"version"`
	Timestamp string  `json:"timestamp"`
	Changelog string  `json:"changelog"`
	Assets    []Asset `json:"assets"`
}

VersionMetadata represents a per-version metadata file (e.g., 0.2.0.json).

func (*VersionMetadata) FindAsset

func (m *VersionMetadata) FindAsset(os, arch string) (*Asset, error)

FindAsset returns the asset matching the given OS and architecture.

Jump to

Keyboard shortcuts

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