Documentation
¶
Overview ¶
Package osagnostic holds the machine configurations that behave the same on every operating system allbctl supports: expected directories and environment variables, installable command-line tools, SSH key registration with GitHub, and the tools referenced by shell start-up files.
Index ¶
- Variables
- type EnvVar
- type EnvVarInstall
- type EnvVarUninstall
- type ExpectedDirectory
- type ExpectedEnvVar
- type InstallableCommand
- func (i InstallableCommand) Install(ctx context.Context) (*bytes.Buffer, error)
- func (i InstallableCommand) Name() string
- func (i *InstallableCommand) SetLinuxPackage(packageManager, packageName string) *InstallableCommand
- func (i *InstallableCommand) SetMacOSPackage(packageName string) *InstallableCommand
- func (i *InstallableCommand) SetWindowsPackage(packageManager, packageName string) *InstallableCommand
- func (i InstallableCommand) Uninstall(_ context.Context) (*bytes.Buffer, error)
- func (i InstallableCommand) Validate(_ context.Context) (*bytes.Buffer, error)
- type OperatingSystem
- type SSHKeyGitHubRegistration
- func (s SSHKeyGitHubRegistration) Install(ctx context.Context) (*bytes.Buffer, error)
- func (s SSHKeyGitHubRegistration) Name() string
- func (s SSHKeyGitHubRegistration) Uninstall(_ context.Context) (*bytes.Buffer, error)
- func (s SSHKeyGitHubRegistration) Validate(ctx context.Context) (*bytes.Buffer, error)
- type ShellConfigToolChecker
- type ShellConfigTools
- type ToolStatus
Constants ¶
This section is empty.
Variables ¶
var ErrDirectoryMissing = errors.New("does not exist")
ErrDirectoryMissing is returned by ExpectedDirectory.Validate when the directory does not exist yet. It is read after the step's name, which carries the path: "Expected Directory /home/dev/src: does not exist".
var ErrDirectoryNotEmpty = errors.New("directory is not empty")
ErrDirectoryNotEmpty is returned (wrapped) by Uninstall when the directory still has contents.
var ErrEnvVarMissing = errors.New("is not set")
ErrEnvVarMissing is returned by ExpectedEnvVar.Validate when the variable is not set.
Functions ¶
This section is empty.
Types ¶
type EnvVarInstall ¶
type EnvVarInstall func() error
EnvVarInstall is called to set up a missing environment variable.
type EnvVarUninstall ¶
type EnvVarUninstall func() error
EnvVarUninstall is called to remove an environment variable that is set.
type ExpectedDirectory ¶
ExpectedDirectory is a directory that should exist on the machine.
func NewExpectedDirectory ¶
func NewExpectedDirectory(path string) *ExpectedDirectory
NewExpectedDirectory returns an ExpectedDirectory for path with the default permission.
func (ExpectedDirectory) Install ¶
Install creates the directory (and any missing parents) when it does not already exist.
func (ExpectedDirectory) Name ¶
func (e ExpectedDirectory) Name() string
Name returns a label that includes the directory path.
func (ExpectedDirectory) Uninstall ¶
Uninstall removes the directory only if it is empty. A missing path, or a path that is not a directory, is left alone.
It deliberately never deletes contents: expected directories are places like ~/src and ~/bin, and resetting a machine's bootstrap state must not be able to destroy the user's work. A non-empty directory is reported with ErrDirectoryNotEmpty and left exactly as it was.
type ExpectedEnvVar ¶
type ExpectedEnvVar struct {
Key string
OnInstall EnvVarInstall
OnUninstall EnvVarUninstall
}
ExpectedEnvVar is an environment variable that should be set. allbctl cannot change its parent shell's environment, so installing and uninstalling are delegated to the supplied callbacks.
func (ExpectedEnvVar) Name ¶
func (e ExpectedEnvVar) Name() string
Name returns a label that includes the variable name.
type InstallableCommand ¶ added in v0.0.12
type InstallableCommand struct {
CommandName string
LinuxPackages map[string]string // package manager -> package name
MacOSPackage string // homebrew package name
WindowsPackages map[string]string // package manager -> package name
// contains filtered or unexported fields
}
InstallableCommand is a command-line tool that should be on PATH, along with the package that provides it under each supported package manager.
func NewInstallableCommand ¶ added in v0.0.12
func NewInstallableCommand(commandName string) *InstallableCommand
NewInstallableCommand returns an InstallableCommand with no packages configured; chain the Set*Package methods to add them.
func (InstallableCommand) Install ¶ added in v0.0.12
Install installs the command with the first available package manager that has a package configured. It does nothing when the command is already on PATH.
func (InstallableCommand) Name ¶ added in v0.0.12
func (i InstallableCommand) Name() string
Name returns a label that includes the command name.
func (*InstallableCommand) SetLinuxPackage ¶ added in v0.0.12
func (i *InstallableCommand) SetLinuxPackage(packageManager, packageName string) *InstallableCommand
SetLinuxPackage records the package that provides the command under the given Linux package manager ("apt", "dnf", ..., or "generic").
func (*InstallableCommand) SetMacOSPackage ¶ added in v0.0.12
func (i *InstallableCommand) SetMacOSPackage(packageName string) *InstallableCommand
SetMacOSPackage records the Homebrew package that provides the command.
func (*InstallableCommand) SetWindowsPackage ¶ added in v0.0.12
func (i *InstallableCommand) SetWindowsPackage(packageManager, packageName string) *InstallableCommand
SetWindowsPackage records the package that provides the command under the given Windows package manager ("winget", "choco" or "scoop").
type OperatingSystem ¶
type OperatingSystem struct {
// Name is runtime.GOOS: "linux", "darwin", "windows", ...
Name string
// HomeDirectoryPath is the current user's home directory, or empty when
// it cannot be determined.
HomeDirectoryPath string
CurrentWorkingDirectory string
EnvironmentVariables []*EnvVar
}
OperatingSystem is a snapshot of the facts about the host that the rest of allbctl keys its behaviour on.
func NewOperatingSystem ¶
func NewOperatingSystem() *OperatingSystem
NewOperatingSystem captures the current process's view of the host.
func (*OperatingSystem) UpdateCurrentWorkingDirectory ¶
func (o *OperatingSystem) UpdateCurrentWorkingDirectory(path string)
UpdateCurrentWorkingDirectory records path as the working directory. An empty path means "ask the operating system"; if that fails the previous value is kept.
type SSHKeyGitHubRegistration ¶ added in v0.0.12
type SSHKeyGitHubRegistration struct {
// KeyPath is the public key file, e.g. ~/.ssh/id_rsa.pub.
KeyPath string
// contains filtered or unexported fields
}
SSHKeyGitHubRegistration ensures the user's public SSH key exists and is registered with their GitHub account, using the GitHub CLI.
func NewSSHKeyGitHubRegistration ¶ added in v0.0.12
func NewSSHKeyGitHubRegistration() *SSHKeyGitHubRegistration
NewSSHKeyGitHubRegistration targets the default RSA public key in the current user's ~/.ssh directory.
func (SSHKeyGitHubRegistration) Install ¶ added in v0.0.12
Install generates the key pair if it is missing and registers the public key with GitHub if it is not registered yet.
func (SSHKeyGitHubRegistration) Name ¶ added in v0.0.12
func (s SSHKeyGitHubRegistration) Name() string
Name returns the configuration's label.
type ShellConfigToolChecker ¶ added in v0.0.11
type ShellConfigToolChecker struct {
// contains filtered or unexported fields
}
ShellConfigToolChecker finds the external tools a user's shell start-up files invoke and reports which of them are missing from PATH.
func NewShellConfigToolChecker ¶ added in v0.0.11
func NewShellConfigToolChecker() *ShellConfigToolChecker
NewShellConfigToolChecker returns a checker for the shell start-up files that exist in the current user's home directory.
func (*ShellConfigToolChecker) ExtractTools ¶ added in v0.0.11
func (c *ShellConfigToolChecker) ExtractTools() []ToolStatus
ExtractTools returns every tool referenced by the shell start-up files, sorted by name. A tool referenced from several files is attributed to the first file that mentions it.
type ShellConfigTools ¶ added in v0.0.11
type ShellConfigTools struct {
// contains filtered or unexported fields
}
ShellConfigTools is the configuration that checks every tool referenced by the user's shell start-up files is installed.
func NewShellConfigTools ¶ added in v0.0.11
func NewShellConfigTools() *ShellConfigTools
NewShellConfigTools returns a ShellConfigTools for the current user's shell start-up files.
func (*ShellConfigTools) Install ¶ added in v0.0.11
Install cannot install arbitrary tools: allbctl does not know which package provides them. It lists the missing ones and returns a model.ManualStepError, which callers report without treating the run as failed.
func (*ShellConfigTools) Name ¶ added in v0.0.11
func (s *ShellConfigTools) Name() string
Name returns the configuration's label.
type ToolStatus ¶ added in v0.0.11
type ToolStatus struct {
Tool string
Available bool
Source string // Which config file referenced it
}
ToolStatus is one tool referenced by a shell start-up file.