updatecheck

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: AGPL-3.0 Imports: 26 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package updatecheck asks GitHub which release of Mediarium is the newest, so the app can tell an administrator that an update is out.

It only reads. The request goes to the public GitHub Releases API of the official repository and carries no identifying data: no account, no install id, no settings, only a User-Agent of the form "Mediarium/<version>". Nothing is downloaded or installed by this package; installing is up to the person.

Index

Constants

View Source
const (
	SumsName = "sha256sums.txt"
	SigName  = "sha256sums.txt.sig"
)

The files a release carries (see .github/workflows/release.yml and docs/RELEASING.md). sha256sums.txt lists the SHA-256 of every archive and is signed with the maintainer's private key; the signature is the only thing Mediarium trusts, so a changed file on GitHub or a changed download cannot pass for a real release.

View Source
const (
	MaxArchive = 300 << 20 // the archive as downloaded
	// MaxBinary is the biggest program file we unpack from an archive.
	MaxBinary = 200 << 20
)

The sizes we are willing to read. The program is about 45 MB.

View Source
const DefaultBaseURL = "https://api.github.com"

DefaultBaseURL is the GitHub API.

View Source
const DownloadTimeout = 15 * time.Minute

Timeout for a whole release download (a slow line is fine, a hung one is not).

View Source
const (

	// NotesLines is how many lines of the release notes are kept.
	NotesLines = 10
)

Variables

View Source
var (
	ErrNoSignature    = errors.New("the release has no signature file")
	ErrBadSignature   = errors.New("the signature does not match")
	ErrBadChecksum    = errors.New("the downloaded file does not match the signed checksum")
	ErrNoArchive      = errors.New("the release has no program file for this system")
	ErrHostNotAllowed = errors.New("the download was sent to a host that is not allowed")
	ErrNoProgram      = errors.New("the archive does not contain the program")
	ErrKeyMissing     = errors.New("no signing key is built into this version")
)

Problems the caller turns into plain sentences.

View Source
var (
	ErrRateLimited = errors.New("GitHub is limiting requests right now")
	ErrUnavailable = errors.New("GitHub did not give a usable answer")
)

Errors a check can end in. Callers show the same plain "couldn't check just now" for all of them; the difference is only for the log.

View Source
var DefaultRepo = "rdborg/Mediarium"

DefaultRepo is the official repository, as owner/name. A build for another fork can change it with

-ldflags "-X github.com/rdborg/mediarium/internal/updatecheck.DefaultRepo=owner/name"

Functions

func ArchiveName

func ArchiveName(version, goos, goarch string) string

ArchiveName is the file the release pipeline makes for a system: mediarium_1.2.0_linux_amd64.tar.gz (a .zip on Windows).

func Installable

func Installable(rel Release, goos, goarch string) (ok bool, reason string)

Installable says whether a release can be installed by the app on this system: it must have the signature file, the list of checksums and the program file for goos/goarch. reason is a plain sentence when it cannot. Only Linux can install itself, because only the container images know how to start an installed update (see docs/INSTALL.md).

func Newer

func Newer(running string, rel Release) bool

Newer reports whether rel is a newer version than running. A running version that is not a version number (a "dev" build) is never told to update.

func ParsePublicKey

func ParsePublicKey(b64 string) (ed25519.PublicKey, error)

ParsePublicKey reads the base64 text of a raw 32-byte ed25519 public key.

func PlainNotes

func PlainNotes(body string, maxLines int) (notes string, more bool)

PlainNotes turns release notes (Markdown from GitHub) into a few lines of plain text: at most maxLines lines, headings and emphasis marks removed, links reduced to their words, HTML tags and control characters dropped. The result is text only. The page shows it as text, never as HTML. more says whether there was more than was kept.

func SumFor

func SumFor(sums []byte, name string) (string, error)

SumFor finds the SHA-256 of file name in a sha256sum-style list ("<hex> <name>", the name optionally starting with * or ./).

func ValidRepo

func ValidRepo(s string) bool

ValidRepo reports whether s looks like owner/name.

func VerifySignature

func VerifySignature(pub ed25519.PublicKey, data []byte, sigBase64 string) error

VerifySignature checks a base64 ed25519 signature (as written by tools/signsums) over data.

Types

type Asset

type Asset struct {
	Name string `json:"name"`
	Size int64  `json:"size"`
}

Asset is one file attached to a release.

type Checker

type Checker struct {
	Repo    string       // owner/name; DefaultRepo when empty
	Version string       // the running version, for the User-Agent
	BaseURL string       // DefaultBaseURL when empty (tests point it at a fake server)
	Client  *http.Client // netguard client with a timeout when nil
	// contains filtered or unexported fields
}

Checker fetches the release list. It remembers the last answer and its ETag, so asking again costs nothing against GitHub's rate limit while nothing has changed.

func New

func New(runningVersion string) *Checker

New returns a Checker for the official repository.

func (*Checker) Latest

func (c *Checker) Latest(ctx context.Context, running string) (rel Release, ok bool, err error)

Latest returns the newest release that applies to a running version: a stable release when running is a normal release, and the newest of either kind when running is itself a pre-release. It does not say whether that release is newer than the running one (see Newer). ok is false when the repository has no usable release yet.

type Download

type Download struct {
	Path   string // the unpacked program, in the folder that was given
	SHA256 string // hex SHA-256 of that program file
	Bytes  int64
}

Download is what Fetch returns.

func ExtractProgram

func ExtractProgram(archive, dir string) (*Download, error)

ExtractProgram unpacks the "mediarium" program file from a release .tar.gz into dir and returns where it is. Only a regular file named mediarium, at most one folder deep, is taken; every other entry is ignored, so an archive cannot write anywhere else.

type Fetcher

type Fetcher struct {
	Repo    string       // owner/name
	Base    string       // "https://github.com" unless a test says otherwise
	Version string       // running version, for the User-Agent
	Client  *http.Client // built by NewFetcher
	// contains filtered or unexported fields
}

Fetcher downloads a release and checks it. Only the official repository's release files are ever fetched, from GitHub's own hosts.

func NewFetcher

func NewFetcher(runningVersion string) *Fetcher

NewFetcher returns a Fetcher for the official repository.

func NewFetcherForTest

func NewFetcherForTest(base string, hosts ...string) *Fetcher

NewFetcherForTest returns a Fetcher that downloads from base (a local test server, plain HTTP allowed) and accepts redirects only to the given hosts. Real code uses NewFetcher, which is fixed to GitHub.

func (*Fetcher) Fetch

func (f *Fetcher) Fetch(ctx context.Context, rel Release, goos, goarch string, pub ed25519.PublicKey, dir string) (*Download, error)

Fetch downloads the release's checksum list and signature, checks the signature against pub, downloads the archive for goos/goarch, checks its SHA-256 against the signed list, and unpacks the program file into dir. It removes everything it made if it fails. Nothing is installed here.

type Release

type Release struct {
	Version     string    `json:"version"`             // 1.2.0, without a leading v
	Name        string    `json:"name,omitempty"`      // the title of the release
	Notes       string    `json:"notes,omitempty"`     // the first lines of the notes, plain text
	MoreNotes   bool      `json:"moreNotes,omitempty"` // the notes go on past what is shown
	URL         string    `json:"url"`                 // the release page on GitHub
	Prerelease  bool      `json:"prerelease,omitempty"`
	PublishedAt time.Time `json:"publishedAt,omitempty"`
	Tag         string    `json:"tag,omitempty"`    // the git tag, used to build download addresses
	Assets      []Asset   `json:"assets,omitempty"` // the files attached to the release
}

Release is the newest release that applies to this install.

Jump to

Keyboard shortcuts

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