preppi

package
v0.0.0-...-8a15e0a Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2017 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Version of PrepPi. Usually overridden at build time.
	Version = "0.1.dev"

	// BuildID of PrepPi. Usually overridden at build time.
	BuildID = "dev"
)
View Source
var RebootCommand = "/sbin/reboot"

RebootCommand is the path to the command to execute to reboot the machine.

Functions

func Fingerprint

func Fingerprint(mode os.FileMode, f io.ReadSeeker) ([]byte, error)

fingerprint checksums the file and its relavent metadata for PrepPi. TODO(cfunkhouser): UID/GID

func MapperToFile

func MapperToFile(path string, m *Mapper) error

MapperToFile marshals m to path as JSON.

func RebootSystem

func RebootSystem() error

RebootSystem reboots the system.

func VersionString

func VersionString() string

VersionString returnds a human-readable PrepPi version ID.

Types

type BasePathFs

type BasePathFs struct {
	*afero.BasePathFs
	// contains filtered or unexported fields
}

BasePathFs extends afero.BasePathFs with some things needed by PrepPi.

func (*BasePathFs) Chown

func (b *BasePathFs) Chown(name string, uid, gid int) error

Chown changes the numeric uid and gid of the named file.

type Fs

type Fs interface {
	afero.Fs
	// Chown changes the numeric uid and gid of the named file.
	Chown(name string, uid, gid int) error
}

Fs represents a file system with which PrepPi will interact. It extends afero.Fs with a few functions we need but which are not supplied there.

func NewBasePathFs

func NewBasePathFs(source Fs, path string) Fs

NewBasePathFs creates and return a BasePathFs instance.

func NewMemMapFs

func NewMemMapFs() Fs

NewMemMapFs creates and return a MemMapFs instance.

func NewOsFs

func NewOsFs() Fs

NewOsFs creates and return a OsFs instance.

type Ingredient

type Ingredient struct {
	Source      string      `json:"source"`
	Destination string      `json:"destination"`
	Mode        os.FileMode `json:"mode"`
	DirMode     os.FileMode `json:"dirmode"`
	UID         int         `json:"uid"`
	GID         int         `json:"gid"`
	Clobber     bool        `json:"clobber,omitempty"`
	Vars        []string    `json:"vars"`
}

func (*Ingredient) Mapping

func (i *Ingredient) Mapping() *Mapping

func (*Ingredient) Prepare

func (i *Ingredient) Prepare(srcRoot, destRoot string, d *RecipeData) error

type Mapper

type Mapper struct {
	Mappings []*Mapping `json:"map"`
}

Mapper represents a set of file mappings.

func MapperFromConfig

func MapperFromConfig(config string) (*Mapper, error)

MapperFromConfig reads a config and returns a Mapper

func (*Mapper) Apply

func (m *Mapper) Apply() (int, error)

Apply the set of mappings to the preppiFS. Returns a count of files modified, and the first error encountered. If an error is encoutered, modified count reflects number of files modified beforehand.

type Mapping

type Mapping struct {
	Source      string      `json:"source"`
	Destination string      `json:"destination"`
	Mode        os.FileMode `json:"mode"`
	DirMode     os.FileMode `json:"dirmode"`
	UID         int         `json:"uid"`
	GID         int         `json:"gid"`

	// Clobber is true when it's okay to overrwite Destination if it exists.
	Clobber bool `json:"clobber,omitempty"`
}

Mapping represents a file mapped from the Source to Destination. Mode, UID and GID apply to the written Destination file. DirMode is applied to any directories created.

func (*Mapping) Apply

func (m *Mapping) Apply() (bool, error)

Apply the mapping, copying Source to Destination and set the metadata.

type MemMapFs

type MemMapFs struct {
	*afero.MemMapFs
}

MemMapFs extends afero.MemMapFs with some things needed by PrepPi.

func (*MemMapFs) Chown

func (m *MemMapFs) Chown(name string, uid, gid int) error

Chown for MemMapFs does nothing. The underlying afero.MemMapFs doesn't support UID/GID at this time, and so there's no point. It would be good for testing in the future. TODO(cfunkhouser): Implement this for better testing.

type OsFs

type OsFs struct {
	*afero.OsFs
}

OsFs extends afero.OsFs with some things needed by PrepPi.

func (*OsFs) Chown

func (o *OsFs) Chown(name string, uid, gid int) error

Chown changes the numeric uid and gid of the named file.

type Recipe

type Recipe struct {
	Name        string        `json:"name"`
	Ingredients []*Ingredient `json:"ingredients"`
	// contains filtered or unexported fields
}

func RecipeFromFile

func RecipeFromFile(name string) (*Recipe, error)

RecipeFromFile reads a config and returns a Mapper

func (*Recipe) Bake

func (r *Recipe) Bake(dest string, d *RecipeData) error

type RecipeData

type RecipeData struct {
	Vars map[string]string
}

RecipeData is a data structure used to execute templates when generating files for the recipe.

func (*RecipeData) GeneratedByPrepPi

func (r *RecipeData) GeneratedByPrepPi() string

GeneratedByPrepPi returns a string of the format: "Generated by PrepPi $VERSION ($BUILD_ID)"

Jump to

Keyboard shortcuts

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