ota

package
v0.0.0-...-41ea6b9 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: GPL-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrVersionNotFound is returned when the specified version is not found
	ErrVersionNotFound = errors.New("specified version not found")
)

Functions

This section is empty.

Types

type GPGVerifier

type GPGVerifier struct {
	// contains filtered or unexported fields
}

GPGVerifier handles GPG signature verification for OTA updates

func NewGPGVerifier

func NewGPGVerifier(logger *zerolog.Logger, httpClient func() HttpClient) *GPGVerifier

NewGPGVerifier creates a new GPG verifier instance

func (*GPGVerifier) ClearCache

func (g *GPGVerifier) ClearCache()

ClearCache clears the cached public key (useful for testing)

func (*GPGVerifier) FetchPublicKey

func (g *GPGVerifier) FetchPublicKey(ctx context.Context) ([]byte, error)

FetchPublicKey fetches the public key from keyservers with fallback support. It tries each keyserver in order and returns on first success. The key is cached for 24 hours.

func (*GPGVerifier) GetRootKeyFingerprint

func (g *GPGVerifier) GetRootKeyFingerprint() string

GetRootKeyFingerprint returns the configured root key fingerprint

func (*GPGVerifier) VerifySignature

func (g *GPGVerifier) VerifySignature(ctx context.Context, signature, data []byte) error

VerifySignature verifies a detached GPG signature against the provided data. The signature should be in binary format (not armored).

func (*GPGVerifier) VerifySignatureFromFile

func (g *GPGVerifier) VerifySignatureFromFile(ctx context.Context, signature []byte, filePath string) error

VerifySignatureFromFile verifies a detached GPG signature against a file. This is more memory-efficient for large files.

type GetHTTPClientFunc

type GetHTTPClientFunc func() HttpClient

GetHTTPClientFunc is a function that returns the HTTP client

type GetLocalVersionFunc

type GetLocalVersionFunc func() (systemVersion *semver.Version, appVersion *semver.Version, err error)

GetLocalVersionFunc is a function that returns the local version of the system and app

type HttpClient

type HttpClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HttpClient is the interface for the HTTP client

type HwRebootFunc

type HwRebootFunc func(force bool, postRebootAction *PostRebootAction, delay time.Duration) error

HwRebootFunc is a function that reboots the hardware

type LocalMetadata

type LocalMetadata struct {
	AppVersion    string `json:"appVersion"`
	SystemVersion string `json:"systemVersion"`
}

LocalMetadata represents the local metadata of the system

type OnProgressUpdateFunc

type OnProgressUpdateFunc func(progress float32)

OnProgressUpdateFunc is a function that updates the progress of the OTA

type OnStateUpdateFunc

type OnStateUpdateFunc func(state *RPCState)

OnStateUpdateFunc is a function that updates the state of the OTA

type Options

type Options struct {
	Logger             *zerolog.Logger
	GetHTTPClient      GetHTTPClientFunc
	GetLocalVersion    GetLocalVersionFunc
	OnStateUpdate      OnStateUpdateFunc
	OnProgressUpdate   OnProgressUpdateFunc
	HwReboot           HwRebootFunc
	ReleaseAPIEndpoint string
	ResetConfig        ResetConfigFunc
	SkipConfirmSystem  bool
	SetAutoUpdate      SetAutoUpdateFunc
}

Options represents the options for the OTA state

type PostRebootAction

type PostRebootAction struct {
	HealthCheck string `json:"healthCheck"` // The health check URL to call after the reboot
	RedirectTo  string `json:"redirectTo"`  // The URL to redirect to after the reboot
}

PostRebootAction represents the action to be taken after a reboot It is used to redirect the user to a specific page after a reboot

type RPCState

type RPCState struct {
	Updating                   bool       `json:"updating"`
	Error                      string     `json:"error,omitempty"`
	MetadataFetchedAt          *time.Time `json:"metadataFetchedAt,omitempty"`
	AppUpdatePending           bool       `json:"appUpdatePending"`
	SystemUpdatePending        bool       `json:"systemUpdatePending"`
	AppDownloadProgress        *float32   `json:"appDownloadProgress,omitempty"` //TODO: implement for progress bar
	AppDownloadFinishedAt      *time.Time `json:"appDownloadFinishedAt,omitempty"`
	SystemDownloadProgress     *float32   `json:"systemDownloadProgress,omitempty"` //TODO: implement for progress bar
	SystemDownloadFinishedAt   *time.Time `json:"systemDownloadFinishedAt,omitempty"`
	AppVerificationProgress    *float32   `json:"appVerificationProgress,omitempty"`
	AppVerifiedAt              *time.Time `json:"appVerifiedAt,omitempty"`
	SystemVerificationProgress *float32   `json:"systemVerificationProgress,omitempty"`
	SystemVerifiedAt           *time.Time `json:"systemVerifiedAt,omitempty"`
	AppUpdateProgress          *float32   `json:"appUpdateProgress,omitempty"` //TODO: implement for progress bar
	AppUpdatedAt               *time.Time `json:"appUpdatedAt,omitempty"`
	SystemUpdateProgress       *float32   `json:"systemUpdateProgress,omitempty"` //TODO: port rk_ota, then implement
	SystemUpdatedAt            *time.Time `json:"systemUpdatedAt,omitempty"`
}

RPCState represents the current OTA state for the RPC API

type ResetConfigFunc

type ResetConfigFunc func() error

ResetConfigFunc is a function that resets the config

type SetAutoUpdateFunc

type SetAutoUpdateFunc func(enabled bool) (bool, error)

SetAutoUpdateFunc is a function that sets the auto-update state

type State

type State struct {
	// contains filtered or unexported fields
}

State represents the current OTA state for the UI

func NewState

func NewState(opts Options) *State

NewState creates a new OTA state

func (*State) GetReleaseAPIEndpoint

func (s *State) GetReleaseAPIEndpoint() string

GetReleaseAPIEndpoint returns the release API endpoint

func (*State) GetUpdateStatus

func (s *State) GetUpdateStatus(ctx context.Context, params UpdateParams) (*UpdateStatus, error)

GetUpdateStatus returns the current update status (for backwards compatibility)

func (*State) IsUpdatePending

func (s *State) IsUpdatePending() bool

IsUpdatePending returns true if an update is pending

func (*State) ToRPCState

func (s *State) ToRPCState() *RPCState

ToRPCState converts the State to the RPCState

func (*State) ToUpdateStatus

func (s *State) ToUpdateStatus() *UpdateStatus

ToUpdateStatus converts the State to the UpdateStatus

func (*State) TryUpdate

func (s *State) TryUpdate(ctx context.Context, params UpdateParams) error

TryUpdate tries to update the given components if the update is already in progress, it returns an error

func (*State) UpdateReleaseAPIEndpoint

func (s *State) UpdateReleaseAPIEndpoint(endpoint string)

UpdateReleaseAPIEndpoint updates the release API endpoint

type UpdateMetadata

type UpdateMetadata struct {
	AppVersion    string `json:"appVersion"`
	AppURL        string `json:"appUrl"`
	AppHash       string `json:"appHash"`
	AppSigURL     string `json:"appSigUrl,omitempty"`
	SystemVersion string `json:"systemVersion"`
	SystemURL     string `json:"systemUrl"`
	SystemHash    string `json:"systemHash"`
	SystemSigURL  string `json:"systemSigUrl,omitempty"`
}

UpdateMetadata represents the metadata of an update

type UpdateParams

type UpdateParams struct {
	DeviceID          string            `json:"deviceID"`
	Components        map[string]string `json:"components"`
	IncludePreRelease bool              `json:"includePreRelease"`
	ResetConfig       bool              `json:"resetConfig"`
	// RequestID is a unique identifier for the update request
	// When it's set, detailed trace logs will be enabled (if the log level is Trace)
	RequestID string
}

UpdateParams represents the parameters for the update

type UpdateStatus

type UpdateStatus struct {
	Local                 *LocalMetadata  `json:"local"`
	Remote                *UpdateMetadata `json:"remote"`
	SystemUpdateAvailable bool            `json:"systemUpdateAvailable"`
	AppUpdateAvailable    bool            `json:"appUpdateAvailable"`
	WillDisableAutoUpdate bool            `json:"willDisableAutoUpdate"`

	// only available for debugging and won't be exported
	SystemUpdateAvailableReason string `json:"-"`
	AppUpdateAvailableReason    string `json:"-"`

	// for backwards compatibility
	Error string `json:"error,omitempty"`
}

UpdateStatus represents the current update status

Jump to

Keyboard shortcuts

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