// Package install is `quarry-runner install`, `doctor` and `uninstall`
// (RFC 0030, A CI runner by one command): a CI runner as a systemd
// service with its own users, from one command. Every effect on the
// machine goes through System, so the logic runs on any host against a
// fake; the real System shells out to the shadow-utils and systemctl.
package install
import (
"context"
"io/fs"
)
// User is a system user to create: its primary group is a group of the
// same name, which must exist.
type User struct {
Name string
Group string
Home string
Shell string
}
// Info is what Stat says about a path.
type Info struct {
Owner string
Group string
Mode fs.FileMode
IsDir bool
// IsLink is a path that is itself a symbolic link: Stat does not
// follow it.
IsLink bool
}
// System is everything install, doctor and uninstall do to the machine.
type System interface {
Geteuid() int
Hostname() (string, error)
// UserHome is the home directory of the user running the program,
// where a per-user install on macOS keeps everything.
UserHome() (string, error)
// Executable is the running program, the one install copies.
Executable() (string, error)
LookPath(name string) (string, error)
// Run runs a command as the current user; RunAs runs it as user.
Run(ctx context.Context, name string, args ...string) ([]byte, error)
RunAs(ctx context.Context, user, name string, args ...string) ([]byte, error)
UserExists(name string) bool
GroupExists(name string) bool
InGroup(user, group string) bool
AddGroup(name string) error
AddUser(u User) error
AddToGroup(user, group string) error
DelUser(name string) error
DelGroup(name string) error
// Mkdir makes one directory (its parent exists) and sets owner and
// mode, also on one that is already there.
Mkdir(path, owner, group string, mode fs.FileMode) error
// WriteFile replaces path atomically with data, owner and mode.
WriteFile(path string, data []byte, owner, group string, mode fs.FileMode) error
// CopyFile does the same with another file's bytes.
CopyFile(src, dst, owner, group string, mode fs.FileMode) error
Rename(from, to string) error
// ReadFile reads a small file whole (a manifest, an env file, a
// unit); a file past its limit is an error, never a short read.
ReadFile(path string) ([]byte, error)
// Sum256 is the hex SHA-256 of a file of any size, read as a stream.
Sum256(path string) (string, error)
ReadDir(path string) ([]string, error)
Stat(path string) (Info, error)
Exists(path string) bool
// Remove removes a file or an empty directory; an absent path is
// not an error, a non-empty directory is.
Remove(path string) error
RemoveAll(path string) error
// DiskFree is the bytes free to an unprivileged writer at path.
DiskFree(path string) (uint64, error)
}