From 5f1eba453842c90bb19ef4443051cacb7dde3b2b Mon Sep 17 00:00:00 2001 From: Dan Moran Date: Mon, 13 Sep 2021 09:38:29 -0400 Subject: [PATCH] fix: detect noninteractive prompt when displaying warning in buildtsi --- cmd/influxd/inspect/build_tsi/build_tsi.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/influxd/inspect/build_tsi/build_tsi.go b/cmd/influxd/inspect/build_tsi/build_tsi.go index b616bd1ef6d..e989360b6a2 100644 --- a/cmd/influxd/inspect/build_tsi/build_tsi.go +++ b/cmd/influxd/inspect/build_tsi/build_tsi.go @@ -123,13 +123,18 @@ func (buildTSICmd *buildTSI) run() error { // Verify the user actually wants to run as root. if isRoot() { cli := clients.CLI{StdIO: stdio.TerminalStdio} - if confirmed := cli.StdIO.GetConfirm(` + if cli.StdIO.IsInteractive() { + if confirmed := cli.StdIO.GetConfirm(` You are currently running as root. This will build your index files with root ownership and will be inaccessible if you run influxd as a non-root user. You should run build-tsi as the same user you are running influxd. Are you sure you want to continue?`); !confirmed { - return errors.New("operation aborted") + return errors.New("operation aborted") + } + } else { + buildTSICmd.Logger.Warn( + "You are current running as root. This will build your index files with root ownership and will be inaccessible if you run influxd as a non-root user.") } }