Documentation
¶
Overview ¶
Package shell provides process execution and shell operations.
Package shell provides process execution and shell operations.
Package shell provides process execution and shell operations.
Index ¶
- Variables
- func Exec(ctx context.Context, excludeStdout bool, dir, name string, args ...string) error
- func ExecCapture(ctx context.Context, out io.Writer, dir, name string, args ...string) error
- func ExecWithContext(ctx context.Context, excludeStdout bool, dir, name string, args ...string) error
- func ExecWithSudo(ctx context.Context, excludeStdout bool, dir, name string, args ...string) error
- func ExecWithSudoContext(ctx context.Context, excludeStdout bool, dir, name string, args ...string) error
- func FilterEnv(allowList map[string]bool, defaults map[string]string) []string
- func HasEnvKey(env []string, key string) bool
- func Join(args []string) string
- func RunScript(cmds string) error
- func RunScriptInFakeroot(ctx context.Context, cmds, packageName string, extraEnv ...[]string) error
- func RunScriptWithPackage(ctx context.Context, cmds, packageName string, extraEnv ...[]string) error
- func SingleQuote(s string) string
- type GitProgressWriter
- type PackageDecoratedWriter
Constants ¶
This section is empty.
Variables ¶
var ( // SetVerbose configures verbose logging output. SetVerbose = logger.SetVerbose // MultiPrinter handles concurrent output formatting. MultiPrinter = logger.MultiPrinter )
Functions ¶
func ExecCapture ¶ added in v2.2.0
ExecCapture runs the command with stdout and stderr written to out. Use this when a caller needs to collect process output into a buffer (e.g. MCP session logs) instead of streaming it via the global MultiPrinter. Internally relies on os/exec.CommandContext with out as the combined sink; no extra dependencies.
func ExecWithContext ¶
func ExecWithContext( ctx context.Context, excludeStdout bool, dir, name string, args ...string, ) error
ExecWithContext executes a command with context for cancellation control.
func ExecWithSudo ¶
ExecWithSudo executes a command with sudo if the user is not running as root. This is specifically for package manager commands that need elevated privileges.
func ExecWithSudoContext ¶
func ExecWithSudoContext( ctx context.Context, excludeStdout bool, dir, name string, args ...string, ) error
ExecWithSudoContext executes a command with sudo if needed, with context for cancellation.
func FilterEnv ¶ added in v2.3.3
FilterEnv returns the subset of os.Environ() whose keys are present in allowList, then appends "key=value" for every defaults entry whose key is still missing. Package installers use this to build the minimal, secret-free environment forwarded to maintainer scriptlets: everything not allow-listed (CI secrets, signing passphrases, cloud credentials) is stripped so a malicious or buggy scriptlet cannot exfiltrate it.
Each format keeps its own allow-list and defaults (dpkg and rpm filter slightly different sets); this helper provides the shared mechanics.
func HasEnvKey ¶ added in v2.3.3
HasEnvKey reports whether an environment variable key exists in a list of "key=value" entries.
func Join ¶ added in v2.2.0
Join single-quotes each arg and joins them with a space — suitable for concatenating an argv into a single `/bin/sh -c` script.
func RunScriptInFakeroot ¶
RunScriptInFakeroot executes a shell script identically to RunScriptWithPackage but wraps every subprocess in a Linux user-namespace fakeroot so that ownership operations (install -o root, chown, etc.) succeed without real root privileges. Use this for the package() stage of PKGBUILD execution.
func RunScriptWithPackage ¶
func RunScriptWithPackage(ctx context.Context, cmds, packageName string, extraEnv ...[]string) error
RunScriptWithPackage executes a shell script with package-specific output formatting. An optional extraEnv slice of "KEY=VALUE" pairs may be supplied; each entry overrides or extends the inherited process environment for this script invocation only, without mutating os.Environ(). This makes the function safe to call concurrently from parallel build goroutines.
func SingleQuote ¶ added in v2.2.0
SingleQuote wraps s in single quotes, escaping any inner single quote via the standard POSIX `'\”` trick. Safe for use in arbitrary `/bin/sh -c` command bodies. The empty string returns `”`.
Types ¶
type GitProgressWriter ¶
type GitProgressWriter struct {
// contains filtered or unexported fields
}
GitProgressWriter handles git command output with progress formatting.
func NewGitProgressWriter ¶
func NewGitProgressWriter(writer io.Writer, packageName string) *GitProgressWriter
NewGitProgressWriter creates a new GitProgressWriter instance.
func (*GitProgressWriter) Close ¶
func (gpw *GitProgressWriter) Close() error
Close returns the buffer to the pool and should be called when done with the writer.
type PackageDecoratedWriter ¶
type PackageDecoratedWriter struct {
// contains filtered or unexported fields
}
PackageDecoratedWriter decorates output with package name prefixes.
func NewPackageDecoratedWriter ¶
func NewPackageDecoratedWriter(writer io.Writer, packageName string) *PackageDecoratedWriter
NewPackageDecoratedWriter creates a new PackageDecoratedWriter instance.
func (*PackageDecoratedWriter) Close ¶
func (pdw *PackageDecoratedWriter) Close() error
Close returns the buffer to the pool and should be called when done with the writer.