updater

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultServerTokenEnv = "MOLTNET_UPDATE_SERVER_TOKEN"

Variables

This section is empty.

Functions

func AssetName

func AssetName(platform Platform) (string, error)

func CompareVersions

func CompareVersions(left string, right string) (int, error)

func ExtractMoltnetBinary

func ExtractMoltnetBinary(archive []byte, destinationDir string) (string, error)

func IsDevelopmentVersion

func IsDevelopmentVersion(version string) bool

func NormalizeVersion

func NormalizeVersion(version string) string

func ReplaceBinary

func ReplaceBinary(installPath string, replacementPath string) (string, error)

func ResolveHome added in v0.1.15

func ResolveHome() string

ResolveHome returns the directory updater reads and writes install/update state in (install.json, update.lock): MOLTNET_HOME when set, otherwise ~/.moltnet. It is exported so `moltnet uninstall` can detect a MOLTNET_HOME override that points outside the ~/.moltnet it already handles, using the exact same resolution this package uses to read/write that state, so the two can never drift apart.

func VerifyChecksum

func VerifyChecksum(assetName string, archive []byte, manifest []byte) error

func WriteResult

func WriteResult(writer io.Writer, result Result, verbose bool) error

WriteResult writes result's report to writer. verbose additionally includes a source update's per-step detail (git pull, make build, binary replace, version verify); every other field already prints unconditionally, matching this CLI family's "core facts always show, extra narration is --verbose-only" convention.

Types

type CommandRunner added in v0.1.15

type CommandRunner interface {
	Run(ctx context.Context, dir string, name string, args ...string) ([]byte, error)
}

CommandRunner executes one external command (git or make) rooted at dir and returns its combined output. Production code uses defaultCommandRunner; tests inject a fake so they never touch a real git binary or a real make against the checkout this package lives in.

type DefaultInstallDetector

type DefaultInstallDetector struct{}

func (DefaultInstallDetector) DetectInstall

func (DefaultInstallDetector) DetectInstall(_ context.Context, currentVersion string) (Install, error)

type HTTPClient

type HTTPClient interface {
	Do(request *http.Request) (*http.Response, error)
}

type HTTPReleaseSource

type HTTPReleaseSource struct {
	APIBase         string
	Client          HTTPClient
	DownloadBaseURL string
	GitHubBase      string
	OwnerRepo       string
}

func NewHTTPReleaseSource

func NewHTTPReleaseSource(client HTTPClient) HTTPReleaseSource

func (HTTPReleaseSource) Archive

func (s HTTPReleaseSource) Archive(ctx context.Context, version string, assetName string) ([]byte, error)

func (HTTPReleaseSource) Checksums

func (s HTTPReleaseSource) Checksums(ctx context.Context, version string) ([]byte, error)

func (HTTPReleaseSource) InstallMetadata

func (s HTTPReleaseSource) InstallMetadata() ReleaseSourceMetadata

func (HTTPReleaseSource) LatestVersion

func (s HTTPReleaseSource) LatestVersion(ctx context.Context) (string, error)

type HTTPServerProbe

type HTTPServerProbe struct {
	Client HTTPClient
}

func (HTTPServerProbe) ProbeServer

func (p HTTPServerProbe) ProbeServer(ctx context.Context, probe ServerProbeRequest) (ServerInfo, error)

type Install

type Install struct {
	Method            InstallMethod
	Path              string
	SelfUpdateAllowed bool
	// SourceCheckout is the source checkout path for a source-method
	// install, populated by Run from Options.SourceCheckout. Empty when the
	// install method is not source, or when the binary carries no stamp.
	SourceCheckout string
}

type InstallDetector

type InstallDetector interface {
	DetectInstall(ctx context.Context, currentVersion string) (Install, error)
}

type InstallMethod

type InstallMethod string
const (
	InstallMethodReleaseTarball InstallMethod = "release-tarball"
	InstallMethodSource         InstallMethod = "source"
	InstallMethodContainer      InstallMethod = "container"
	InstallMethodUnknown        InstallMethod = "unknown"
)

type Options

type Options struct {
	CheckOnly      bool
	CommandRunner  CommandRunner
	CurrentVersion string
	Detector       InstallDetector
	DryRun         bool
	LockPath       string
	LockStaleAfter time.Duration
	Platform       Platform
	ReleaseSource  ReleaseSource
	ServerProbe    ServerProbe
	ServerToken    string
	ServerTokenEnv string
	ServerURL      string
	// SourceCheckout is the ldflags-stamped source checkout path from the
	// running binary (main.sourceCheckout in cmd/moltnet), forwarded here so
	// Run can attempt a source-install update. Empty on a binary built
	// without the stamp, which degrades to the plain source-install refusal.
	SourceCheckout string
	TargetVersion  string
	TempDir        string
	Yes            bool
}

type Platform

type Platform struct {
	Arch string
	OS   string
}

func CurrentPlatform

func CurrentPlatform() Platform

func (Platform) WithDefaults

func (p Platform) WithDefaults() Platform

type ReleaseSource

type ReleaseSource interface {
	LatestVersion(ctx context.Context) (string, error)
	Archive(ctx context.Context, version string, assetName string) ([]byte, error)
	Checksums(ctx context.Context, version string) ([]byte, error)
}

type ReleaseSourceMetadata

type ReleaseSourceMetadata struct {
	DownloadBaseURL string
	OwnerRepo       string
}

type Result

type Result struct {
	AssetName         string
	BackupPath        string
	ChecksumAvailable bool
	CheckOnly         bool
	CurrentVersion    string
	DryRun            bool
	Install           Install
	LatestVersion     string
	MutationRefused   bool
	// RefusalReason is the exact reason a real (mutating) run refused,
	// set whenever MutationRefused is true. It is deliberately kept out of
	// Warnings for a real run: main.go already prints the returned error
	// (this same text) to stderr, so also queuing it as a stdout warning
	// would print the identical sentence twice. --check/--dry-run never set
	// this — a refusal there is informational only and stays in Warnings,
	// since no error is returned to echo it.
	RefusalReason string
	Server        ServerInfo
	// SourceUpdate is set only when the resolved install is a source build
	// with a usable stamped checkout: it carries the git status a source
	// update inspected or acted on. Nil for release-tarball, container, and
	// unknown installs, and for source installs with no usable checkout.
	SourceUpdate    *SourceUpdatePlan
	TargetVersion   string
	Updated         bool
	UpdateAvailable bool
	Warnings        []string
}

func Run

func Run(ctx context.Context, options Options) (Result, error)

func (Result) String

func (r Result) String() string

String renders result's report with no verbose detail. It exists alongside WriteResult for callers (and tests) that only have a Result in hand, with no CLI flag to thread through.

type ServerInfo

type ServerInfo struct {
	URL     string
	Version string
	Warning string
}

type ServerProbe

type ServerProbe interface {
	ProbeServer(ctx context.Context, request ServerProbeRequest) (ServerInfo, error)
}

type ServerProbeRequest

type ServerProbeRequest struct {
	Token string
	URL   string
}

type SourceUpdatePlan added in v0.1.15

type SourceUpdatePlan struct {
	Branch         string
	Checkout       string
	Clean          bool
	Detached       bool
	LocalCommit    string
	PulledCommit   string
	RebuildNeeded  bool
	Steps          []string
	UpstreamCommit string
	UpstreamKnown  bool
}

SourceUpdatePlan reports what a source install's `moltnet update` found or did: the git status it inspected, and — only once a mutation actually ran — the steps it took, in order.

Jump to

Keyboard shortcuts

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