Skip to content

Commit 4366da0

Browse files
authored
Merge pull request #96 from ObolNetwork/obolup.sh-fixings
Multiple cleanup
2 parents 11d2c52 + 2005710 commit 4366da0

File tree

4 files changed

+62
-12
lines changed

4 files changed

+62
-12
lines changed

internal/embed/k3d-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ports:
2525
options:
2626
k3d:
2727
wait: true
28-
timeout: "300s"
28+
timeout: "600s"
2929
disableLoadbalancer: false
3030
k3s:
3131
extraArgs:

internal/executor/executor.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,32 @@ import (
66
"log/slog"
77
"os"
88
"os/exec"
9+
"strings"
910
"sync"
1011
)
1112

1213
// Executor wraps subprocess execution with automatic output logging via slog
1314
type Executor struct {
1415
logger *slog.Logger
16+
binDir string // Directory containing obol binaries (added to PATH)
1517
}
1618

1719
// New creates a new Executor that logs subprocess output via slog
1820
// The logger should be configured to handle subprocess output appropriately
21+
// binDir is prepended to PATH for all commands (so tools can find dependencies)
1922
func New(logger *slog.Logger) *Executor {
2023
return &Executor{
2124
logger: logger,
25+
binDir: "",
26+
}
27+
}
28+
29+
// NewWithBinDir creates an Executor with a custom bin directory
30+
// The binDir will be prepended to PATH for all subprocess executions
31+
func NewWithBinDir(logger *slog.Logger, binDir string) *Executor {
32+
return &Executor{
33+
logger: logger,
34+
binDir: binDir,
2235
}
2336
}
2437

@@ -74,11 +87,45 @@ func (c *cmdLogger) logComplete() {
7487
}
7588
}
7689

90+
// setupEnv configures the command environment with PATH including binDir
91+
func (e *Executor) setupEnv(cmd *exec.Cmd) {
92+
if e.binDir == "" {
93+
return
94+
}
95+
96+
// Get current environment or inherit from parent
97+
env := os.Environ()
98+
99+
// Find and update PATH, or add it if not present
100+
pathUpdated := false
101+
for i, envVar := range env {
102+
if strings.HasPrefix(envVar, "PATH=") {
103+
currentPath := strings.TrimPrefix(envVar, "PATH=")
104+
// Prepend binDir to PATH if not already present
105+
if !strings.Contains(currentPath, e.binDir) {
106+
env[i] = "PATH=" + e.binDir + string(os.PathListSeparator) + currentPath
107+
}
108+
pathUpdated = true
109+
break
110+
}
111+
}
112+
113+
// If PATH wasn't found, add it
114+
if !pathUpdated {
115+
env = append(env, "PATH="+e.binDir)
116+
}
117+
118+
cmd.Env = env
119+
}
120+
77121
// Command creates a new command for use with Output()
78122
// Only stderr is logged/displayed, stdout is captured by Output()
79123
func (e *Executor) Command(name string, args ...string) *exec.Cmd {
80124
cmd := exec.Command(name, args...)
81125

126+
// Configure PATH to include binDir
127+
e.setupEnv(cmd)
128+
82129
if e.logger != nil {
83130
// Capture stderr for display with indentation
84131
cmd.Stderr = &outputAccumulator{
@@ -98,6 +145,9 @@ func (e *Executor) Command(name string, args ...string) *exec.Cmd {
98145
func (e *Executor) CommandWithOutput(name string, args ...string) CmdRunner {
99146
cmd := exec.Command(name, args...)
100147

148+
// Configure PATH to include binDir
149+
e.setupEnv(cmd)
150+
101151
if e.logger != nil {
102152
// Create command logger to accumulate output
103153
cmdLog := newCmdLogger(e.logger, name, args)

internal/stack/stack.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func Up(cfg *config.Config) error {
131131
stackName := getStackName(cfg)
132132

133133
// Create executor for subprocess calls with the logger
134-
exec := executor.New(l.Logger)
134+
exec := executor.NewWithBinDir(l.Logger, cfg.BinDir)
135135
defer exec.Close()
136136

137137
// Check if cluster already exists using cluster list
@@ -227,7 +227,7 @@ func Down(cfg *config.Config) error {
227227
})
228228
defer cleanup()
229229

230-
exec := executor.New(l.Logger)
230+
exec := executor.NewWithBinDir(l.Logger, cfg.BinDir)
231231
defer exec.Close()
232232

233233
l.Info("Stopping stack gracefully", "name", stackName, "id", stackID)
@@ -266,7 +266,7 @@ func Purge(cfg *config.Config, force bool) error {
266266
defer cleanup()
267267

268268
// Create executor for subprocess calls
269-
exec := executor.New(l.Logger)
269+
exec := executor.NewWithBinDir(l.Logger, cfg.BinDir)
270270
defer exec.Close()
271271

272272
// Delete cluster containers

obolup.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,8 +1178,8 @@ configure_path() {
11781178
return 0
11791179
fi
11801180

1181-
# Interactive terminal: ask for consent
1182-
if [[ -t 0 ]]; then
1181+
# Check if we can prompt the user via /dev/tty (works even with curl | bash)
1182+
if [[ -c /dev/tty ]]; then
11831183
echo ""
11841184
log_info "To use 'obol' command, $OBOL_BIN_DIR needs to be in your PATH"
11851185
echo ""
@@ -1191,7 +1191,7 @@ configure_path() {
11911191
echo ""
11921192

11931193
local choice
1194-
read -p "Choose [1/2]: " choice
1194+
read -p "Choose [1/2]: " choice </dev/tty
11951195

11961196
case "$choice" in
11971197
1)
@@ -1211,7 +1211,7 @@ configure_path() {
12111211
;;
12121212
esac
12131213
else
1214-
# Non-interactive: check environment variable override
1214+
# Truly non-interactive (CI/CD, no terminal): check environment variable override
12151215
if [[ "${OBOL_MODIFY_PATH:-no}" == "yes" ]]; then
12161216
add_to_profile "$profile"
12171217
log_info "Will be available in new shell sessions"
@@ -1234,8 +1234,8 @@ print_instructions() {
12341234
fi
12351235
echo ""
12361236

1237-
# Check if terminal is interactive for bootstrap prompt
1238-
if [[ -t 0 ]] && [[ -f "$OBOL_BIN_DIR/obol" ]]; then
1237+
# Check if we can prompt the user for bootstrap (works with curl | bash via /dev/tty)
1238+
if [[ -c /dev/tty ]] && [[ -f "$OBOL_BIN_DIR/obol" ]]; then
12391239
echo ""
12401240
log_info "Would you like to start the cluster now?"
12411241
echo ""
@@ -1246,7 +1246,7 @@ print_instructions() {
12461246
echo ""
12471247

12481248
local choice
1249-
read -p "Start cluster now? [y/N]: " choice
1249+
read -p "Start cluster now? [y/N]: " choice </dev/tty
12501250

12511251
case "$choice" in
12521252
[Yy]*)
@@ -1281,7 +1281,7 @@ print_instructions() {
12811281
;;
12821282
esac
12831283
else
1284-
# Non-interactive or no binary - show manual instructions
1284+
# Truly non-interactive (CI/CD, no terminal) or no binary - show manual instructions
12851285
echo "Verify installation:"
12861286
echo ""
12871287
echo " obol version"

0 commit comments

Comments
 (0)