osagnostic

package
v0.0.43 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 17 Imported by: ? 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 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

Constants

This section is empty.

Variables

View Source
var ErrDirectoryMissing = errors.New("directory does not exist")

ErrDirectoryMissing is returned (wrapped) by ExpectedDirectory.Validate when the directory does not exist yet.

View Source
var ErrDirectoryNotEmpty = errors.New("directory is not empty")

ErrDirectoryNotEmpty is returned (wrapped) by Uninstall when the directory still has contents.

View Source
var ErrEnvVarMissing = errors.New("envvar does not exist")

ErrEnvVarMissing is returned by ExpectedEnvVar.Validate when the variable is not set.

Functions

This section is empty.

Types

type EnvVar

type EnvVar struct {
	Key   string
	Value string
}

EnvVar is one KEY=VALUE pair from the process environment.

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

type ExpectedDirectory struct {
	Path       string
	Permission os.FileMode
}

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

func (e ExpectedDirectory) Install(ctx context.Context) (*bytes.Buffer, error)

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

func (e ExpectedDirectory) Uninstall(_ context.Context) (*bytes.Buffer, error)

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.

func (ExpectedDirectory) Validate

func (e ExpectedDirectory) Validate(_ context.Context) (*bytes.Buffer, error)

Validate reports whether the directory exists. It returns an error when the directory is missing, cannot be inspected, or is not a directory.

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) Install

func (e ExpectedEnvVar) Install(_ context.Context) (*bytes.Buffer, error)

Install runs OnInstall when the variable is not set.

func (ExpectedEnvVar) Name

func (e ExpectedEnvVar) Name() string

Name returns a label that includes the variable name.

func (ExpectedEnvVar) Uninstall

func (e ExpectedEnvVar) Uninstall(_ context.Context) (*bytes.Buffer, error)

Uninstall runs OnUninstall when the variable is set. There is nothing to do when it is already absent.

func (ExpectedEnvVar) Validate

func (e ExpectedEnvVar) Validate(_ context.Context) (*bytes.Buffer, error)

Validate reports whether the variable is set (an empty value counts).

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

func (i InstallableCommand) Install(ctx context.Context) (*bytes.Buffer, error)

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").

func (InstallableCommand) Uninstall added in v0.0.12

func (i InstallableCommand) Uninstall(_ context.Context) (*bytes.Buffer, error)

Uninstall only explains that tools are not removed automatically.

func (InstallableCommand) Validate added in v0.0.12

func (i InstallableCommand) Validate(_ context.Context) (*bytes.Buffer, error)

Validate reports whether the command is on PATH.

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

Name returns the configuration's label.

func (SSHKeyGitHubRegistration) Uninstall added in v0.0.12

Uninstall only explains that the registration is not removed automatically.

func (SSHKeyGitHubRegistration) Validate added in v0.0.12

Validate reports whether the public key exists and is listed among the authenticated GitHub user's SSH keys.

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

func (s *ShellConfigTools) Install(_ context.Context) (*bytes.Buffer, error)

Install cannot install arbitrary tools; it lists the missing ones and returns an error so the user knows manual action is needed.

func (*ShellConfigTools) Name added in v0.0.11

func (s *ShellConfigTools) Name() string

Name returns the configuration's label.

func (*ShellConfigTools) Uninstall added in v0.0.11

func (s *ShellConfigTools) Uninstall(_ context.Context) (*bytes.Buffer, error)

Uninstall only explains that there is nothing to uninstall.

func (*ShellConfigTools) Validate added in v0.0.11

func (s *ShellConfigTools) Validate(_ context.Context) (*bytes.Buffer, error)

Validate lists the referenced tools grouped by the file that references them, and returns an error when any is missing from PATH.

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.

Jump to

Keyboard shortcuts

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