In Development Package, API may change between versions.

import "github.com/egdaemon/eg/runtime/x/wasi/egbash"

Package egbash interprets shell commands inside the guest with egdaemon/sh, so expansion, redirects, pipes, builtins, the bash and sh scripts a command starts and the coreutils egdaemon/sh/x provides stay in the sandbox, and only the other external commands reach the module, through execproxy/v2. eg/shell runs through it with EG_EXPERIMENTAL_GUEST_SHELL, which requires EG_EXPERIMENTAL_PROC_SOCKETS for the module.

Constants

const (
    DefaultTimeout = 5 * time.Minute
)

func Run

func Run(ctx context.Context, cmds ...Command) error

Run interprets the commands in order, stopping at the first that fails.

type Command

Command is a shell command to interpret, configured like eg/shell's Command.

type Command struct {
    // contains filtered or unexported fields
}

func Env

func Env() Command

Env creates a runtime command pre-populated with the current process environment.

func New

func New(cmd string) Command

New create a new command with reasonable defaults. unlike eg/shell, external commands run as the module's own user until User, Group or As say otherwise. defaults:

timeout: 5 minutes.

func Newf

func Newf(cmd string, options ...any) Command

Newf provides a simple printf form of creating commands.

func Runtime

func Runtime() Command

Runtime creates a Command with no specified command to run, for use as a template.

func (Command) As

func (t Command) As(u string) Command

convience function that sets both user and group to the provided value.

func (Command) Directory

func (t Command) Directory(d string) Command

directory to run the command in, relative to the working directory.

func (Command) Environ

func (t Command) Environ(k string, v any) Command

append a specific key/value environment variable.

func (Command) EnvironFrom

func (t Command) EnvironFrom(environ ...string) Command

append a set of environment variables in the form KEY=VALUE to the environment.

func (Command) Group

func (t Command) Group(g string) Command

group the module runs external commands as.

func (Command) Lenient

func (t Command) Lenient(d bool) Command

ignore a failure of the command, it is logged instead.

func (Command) MaybePrivileged

func (t Command) MaybePrivileged(b bool) Command

specialized for As("root") which runs the command as root when true. allows conditional flagging privileged. when false the command is unchanged.

func (Command) New

func (t Command) New(cmd string) Command

New clone the current command configuration and replace the command that will be executed.

func (Command) Newf

func (t Command) Newf(cmd string, options ...any) Command

Newf provides a simple printf form of creating commands.

func (Command) Privileged

func (t Command) Privileged() Command

specialized for As("root") which runs the command as root.

func (Command) Timeout

func (t Command) Timeout(d time.Duration) Command

maximum duration for a command to run. default is 5 minutes.

func (Command) User

func (t Command) User(u string) Command

user the module runs external commands as.

⬤