diff --git a/cli/pkg/installscript/installscript.go b/cli/pkg/installscript/installscript.go index c7ca38210d3..a997405593f 100644 --- a/cli/pkg/installscript/installscript.go +++ b/cli/pkg/installscript/installscript.go @@ -26,6 +26,7 @@ func execScript(ctx context.Context, version string, args ...string) error { scriptArgs := append([]string{script}, args...) cmd := exec.CommandContext(ctx, "/bin/sh", scriptArgs...) + cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr return cmd.Run() diff --git a/scripts/install.sh b/scripts/install.sh index 2ae400d2d43..29720928ea5 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -303,8 +303,24 @@ set -e # Default values INSTALL_DIR_EXPLICIT=false -if ! [ -t 0 ]; then # Detect non-interactive environments (e.g. piped input, CI, subprocesses) - NON_INTERACTIVE=${NON_INTERACTIVE:-true} + +# Default to non-interactive if STDIN is not a terminal (usually indicates e.g. agent, CI, subprocess). +# Backwards compatibility: Old versions of `rill upgrade` didn't pass STDIN through, so we stay interactive if the parent process is named `rill`. +if ! [ -t 0 ]; then + # Get parent process name + PARENT_NAME="" + if [ -n "$PPID" ]; then + if [ -f "/proc/$PPID/comm" ]; then + PARENT_NAME=$(basename "$(cat "/proc/$PPID/comm" 2>/dev/null)" 2>/dev/null) + elif command -v ps >/dev/null 2>&1; then + PARENT_NAME=$(basename "$(ps -o comm= -p "$PPID" 2>/dev/null)" 2>/dev/null) + fi + fi + + # Apply the default + if [ "$PARENT_NAME" != "rill" ]; then + NON_INTERACTIVE=${NON_INTERACTIVE:-true} + fi fi NON_INTERACTIVE=${NON_INTERACTIVE:-false}