Skip to content

Commit e599994

Browse files
Fix interactivity in rill upgrade (#9049)
* Fix interactivity in `rill upgrade` * Preserve interactivity in install.sh when parent process is rill * Cleaner comment * Add PPID guard and move basename inline in parent process check
1 parent 871ab37 commit e599994

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

cli/pkg/installscript/installscript.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func execScript(ctx context.Context, version string, args ...string) error {
2626

2727
scriptArgs := append([]string{script}, args...)
2828
cmd := exec.CommandContext(ctx, "/bin/sh", scriptArgs...)
29+
cmd.Stdin = os.Stdin
2930
cmd.Stdout = os.Stdout
3031
cmd.Stderr = os.Stderr
3132
return cmd.Run()

scripts/install.sh

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,24 @@ set -e
303303

304304
# Default values
305305
INSTALL_DIR_EXPLICIT=false
306-
if ! [ -t 0 ]; then # Detect non-interactive environments (e.g. piped input, CI, subprocesses)
307-
NON_INTERACTIVE=${NON_INTERACTIVE:-true}
306+
307+
# Default to non-interactive if STDIN is not a terminal (usually indicates e.g. agent, CI, subprocess).
308+
# Backwards compatibility: Old versions of `rill upgrade` didn't pass STDIN through, so we stay interactive if the parent process is named `rill`.
309+
if ! [ -t 0 ]; then
310+
# Get parent process name
311+
PARENT_NAME=""
312+
if [ -n "$PPID" ]; then
313+
if [ -f "/proc/$PPID/comm" ]; then
314+
PARENT_NAME=$(basename "$(cat "/proc/$PPID/comm" 2>/dev/null)" 2>/dev/null)
315+
elif command -v ps >/dev/null 2>&1; then
316+
PARENT_NAME=$(basename "$(ps -o comm= -p "$PPID" 2>/dev/null)" 2>/dev/null)
317+
fi
318+
fi
319+
320+
# Apply the default
321+
if [ "$PARENT_NAME" != "rill" ]; then
322+
NON_INTERACTIVE=${NON_INTERACTIVE:-true}
323+
fi
308324
fi
309325
NON_INTERACTIVE=${NON_INTERACTIVE:-false}
310326

0 commit comments

Comments
 (0)