installer

package
v0.0.0-...-5331e25 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2019 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Copyright 2019 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2019 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2019 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2019 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Index

Constants

View Source
const (
	NoReboot = iota
	RebootRequired
	AutomaticReboot
)

Variables

View Source
var (
	RootPartitionDoesNotMatchMount = errors.New("Can not match active partition and any of mounted devices.")
	ErrorNoMatchBootPartRootPart   = errors.New("No match between boot and root partitions.")
	ErrorPartitionNumberNotSet     = errors.New("RootfsPartA and RootfsPartB settings are not both set.")
	ErrorPartitionNumberSame       = errors.New("RootfsPartA and RootfsPartB cannot be set to the same value.")
	ErrorPartitionNoMatchActive    = errors.New("Active root partition matches neither RootfsPartA nor RootfsPartB.")
)
View Source
var (
	ErrorNothingToCommit = errors.New("There is nothing to commit")
)

Functions

func FetchUpdateFromFile

func FetchUpdateFromFile(file string) (io.ReadCloser, int64, error)

FetchUpdateFromFile returns a byte stream of the given file, size of the file and an error if one occurred.

func MissingFeaturesCheck

func MissingFeaturesCheck(artifactAugmentedHeaders artifact.HeaderInfoer,
	payloadHeaders handlers.ArtifactUpdateHeaders) error

func ReadHeaders

func ReadHeaders(art io.ReadCloser, dt string, key []byte, scrDir string,
	inst *AllModules) (*Installer, []PayloadUpdatePerformer, error)

Types

type AllModules

type AllModules struct {
	// Built-in module.
	DualRootfs handlers.UpdateStorerProducer
	// External modules.
	Modules *ModuleInstallerFactory
}

type ArtifactInfoGetter

type ArtifactInfoGetter interface {
	GetCurrentArtifactName() (string, error)
	GetCurrentArtifactGroup() (string, error)
}

type BlockDevice

type BlockDevice struct {
	Path string // device path, ex. /dev/mmcblk0p1

	ImageSize          int64  // image size
	FlushIntervalBytes uint64 // Force a flush to disk each time this many bytes are written
	// contains filtered or unexported fields
}

BlockDevice is a low-level wrapper for a block device. The wrapper implements io.Writer and io.Closer interfaces.

func (*BlockDevice) Close

func (bd *BlockDevice) Close() error

Close closes underlying block device automatically syncing any unwritten data. Othewise, behaves like io.Closer.

func (*BlockDevice) SectorSize

func (bd *BlockDevice) SectorSize() (int, error)

SectorSize queries the logical sector size of the underlying block device. Automatically opens a new fd in O_RDONLY mode, thus can be used in parallel to other operations.

func (*BlockDevice) Size

func (bd *BlockDevice) Size() (uint64, error)

Size queries the size of the underlying block device. Automatically opens a new fd in O_RDONLY mode, thus can be used in parallel to other operations.

func (*BlockDevice) Write

func (bd *BlockDevice) Write(p []byte) (int, error)

Write writes data `p` to underlying block device. Will automatically open the device in a write mode. Otherwise, behaves like io.Writer.

type BlockDeviceGetSectorSizeFunc

type BlockDeviceGetSectorSizeFunc func(file *os.File) (int, error)

BlockDeviceGetSectorSizeFunc is a helper for obtaining the sector size of a block device.

type BlockDeviceGetSizeFunc

type BlockDeviceGetSizeFunc func(file *os.File) (uint64, error)

BlockDeviceGetSizeFunc is a helper for obtaining the size of a block device.

type BootEnvReadWriter

type BootEnvReadWriter interface {
	ReadEnv(...string) (BootVars, error)
	WriteEnv(BootVars) error
}

type BootVars

type BootVars map[string]string

type DeviceInfoGetter

type DeviceInfoGetter interface {
	GetDeviceType() (string, error)
}

type DualRootfsDevice

type DualRootfsDevice interface {
	PayloadUpdatePerformer
	handlers.UpdateStorerProducer
	GetInactive() (string, error)
	GetActive() (string, error)
}

This interface is only here for tests.

func NewDualRootfsDevice

Returns nil if config doesn't contain partition paths.

type DualRootfsDeviceConfig

type DualRootfsDeviceConfig struct {
	RootfsPartA string
	RootfsPartB string
}

type FlushingWriter

type FlushingWriter struct {
	WF                 WriteSyncer
	FlushIntervalBytes uint64
	// contains filtered or unexported fields
}

FlushingWriter is a wrapper around a WriteSyncer which forces a Sync() to occur every so many bytes. FlushingWriter implements WriteSyncer.

func NewFlushingWriter

func NewFlushingWriter(wf WriteSyncer, flushIntervalBytes uint64) *FlushingWriter

NewFlushingWriter returns a FlushingWriter which wraps the provided WriteSyncer and automatically flushes (calls Sync()) each time the specified number of bytes is written. Setting flushIntervalBytes == 0 causes Sync() to be called after every Write().

func (*FlushingWriter) Sync

func (fw *FlushingWriter) Sync() error

func (*FlushingWriter) Write

func (fw *FlushingWriter) Write(p []byte) (int, error)

type Installer

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

func (*Installer) GetArtifactName

func (i *Installer) GetArtifactName() string

func (*Installer) StorePayloads

func (i *Installer) StorePayloads() error

type ModuleInstaller

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

func (*ModuleInstaller) Cleanup

func (mod *ModuleInstaller) Cleanup() error

func (*ModuleInstaller) CommitUpdate

func (mod *ModuleInstaller) CommitUpdate() error

func (*ModuleInstaller) Failure

func (mod *ModuleInstaller) Failure() error

func (*ModuleInstaller) FinishStoreUpdate

func (mod *ModuleInstaller) FinishStoreUpdate() error

func (*ModuleInstaller) GetType

func (mod *ModuleInstaller) GetType() string

func (*ModuleInstaller) Initialize

func (mod *ModuleInstaller) Initialize(artifactHeaders,
	artifactAugmentedHeaders artifact.HeaderInfoer,
	payloadHeaders handlers.ArtifactUpdateHeaders) error

func (*ModuleInstaller) InstallUpdate

func (mod *ModuleInstaller) InstallUpdate() error

func (*ModuleInstaller) NeedsReboot

func (mod *ModuleInstaller) NeedsReboot() (RebootAction, error)

func (*ModuleInstaller) PrepareStoreUpdate

func (mod *ModuleInstaller) PrepareStoreUpdate() error

func (*ModuleInstaller) Reboot

func (mod *ModuleInstaller) Reboot() error

func (*ModuleInstaller) Rollback

func (mod *ModuleInstaller) Rollback() error

func (*ModuleInstaller) RollbackReboot

func (mod *ModuleInstaller) RollbackReboot() error

func (*ModuleInstaller) StoreUpdate

func (mod *ModuleInstaller) StoreUpdate(r io.Reader, info os.FileInfo) error

func (*ModuleInstaller) SupportsRollback

func (mod *ModuleInstaller) SupportsRollback() (bool, error)

func (*ModuleInstaller) VerifyReboot

func (mod *ModuleInstaller) VerifyReboot() error

func (*ModuleInstaller) VerifyRollbackReboot

func (mod *ModuleInstaller) VerifyRollbackReboot() error

type ModuleInstallerFactory

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

func NewModuleInstallerFactory

func NewModuleInstallerFactory(modulesPath, modulesWorkPath string,
	artifactInfo ArtifactInfoGetter, deviceInfo DeviceInfoGetter,
	moduleTimeoutSecs int) *ModuleInstallerFactory

func (*ModuleInstallerFactory) GetModuleTypes

func (mf *ModuleInstallerFactory) GetModuleTypes() []string

func (*ModuleInstallerFactory) NewUpdateStorer

func (mf *ModuleInstallerFactory) NewUpdateStorer(updateType string, payloadNum int) (handlers.UpdateStorer, error)

type PayloadUpdatePerformer

type PayloadUpdatePerformer interface {
	Rebooter
	handlers.UpdateStorer
	InstallUpdate() error
	NeedsReboot() (RebootAction, error)
	CommitUpdate() error
	SupportsRollback() (bool, error)
	Rollback() error
	// Verify that rebooting into the new update worked.
	VerifyReboot() error
	RollbackReboot() error
	// Verify that rebooting into the old update worked.
	VerifyRollbackReboot() error
	Failure() error
	Cleanup() error

	GetType() string
}

func CreateInstallersFromList

func CreateInstallersFromList(inst *AllModules,
	desiredTypes []string) ([]PayloadUpdatePerformer, error)

func Install

func Install(art io.ReadCloser, dt string, key []byte, scrDir string,
	inst *AllModules) ([]PayloadUpdatePerformer, error)

type ReadLogger

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

func (*ReadLogger) Write

func (rl *ReadLogger) Write(p []byte) (int, error)

type RebootAction

type RebootAction int

type Rebooter

type Rebooter interface {
	Reboot() error
}

type StubInstaller

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

A stub installer that fails nearly every step. For use as a stub when we cannot find the module we're looking for.

func NewStubInstaller

func NewStubInstaller(payloadType string) *StubInstaller

func (*StubInstaller) Cleanup

func (d *StubInstaller) Cleanup() error

func (*StubInstaller) CommitUpdate

func (d *StubInstaller) CommitUpdate() error

func (*StubInstaller) Failure

func (d *StubInstaller) Failure() error

func (*StubInstaller) FinishStoreUpdate

func (d *StubInstaller) FinishStoreUpdate() error

func (*StubInstaller) GetType

func (d *StubInstaller) GetType() string

func (*StubInstaller) Initialize

func (d *StubInstaller) Initialize(artifactHeaders,
	artifactAugmentedHeaders artifact.HeaderInfoer,
	payloadHeaders handlers.ArtifactUpdateHeaders) error

func (*StubInstaller) InstallUpdate

func (d *StubInstaller) InstallUpdate() error

func (*StubInstaller) NeedsReboot

func (d *StubInstaller) NeedsReboot() (RebootAction, error)

func (*StubInstaller) PrepareStoreUpdate

func (d *StubInstaller) PrepareStoreUpdate() error

func (*StubInstaller) Reboot

func (d *StubInstaller) Reboot() error

func (*StubInstaller) Rollback

func (d *StubInstaller) Rollback() error

func (*StubInstaller) RollbackReboot

func (d *StubInstaller) RollbackReboot() error

func (*StubInstaller) StoreUpdate

func (d *StubInstaller) StoreUpdate(r io.Reader, info os.FileInfo) error

func (*StubInstaller) SupportsRollback

func (d *StubInstaller) SupportsRollback() (bool, error)

func (*StubInstaller) VerifyReboot

func (d *StubInstaller) VerifyReboot() error

func (*StubInstaller) VerifyRollbackReboot

func (d *StubInstaller) VerifyRollbackReboot() error

type UBootEnv

type UBootEnv struct {
	system.Commander
}

func NewEnvironment

func NewEnvironment(cmd system.Commander) *UBootEnv

func (*UBootEnv) ReadEnv

func (e *UBootEnv) ReadEnv(names ...string) (BootVars, error)

func (*UBootEnv) WriteEnv

func (e *UBootEnv) WriteEnv(vars BootVars) error

type WriteSyncer

type WriteSyncer interface {
	io.Writer
	Sync() error // Commits previously-written data to stable storage.
}

A WriteSyncer is an io.Writer that also implements a Sync() function which commits written data to stable storage. For instance, an os.File is a WriteSyncer.

Jump to

Keyboard shortcuts

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