summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debian/changelog2
-rw-r--r--src/Propellor/CmdLine.hs1
-rw-r--r--src/Propellor/Gpg.hs21
3 files changed, 24 insertions, 0 deletions
diff --git a/debian/changelog b/debian/changelog
index 43abea1c..e314a88c 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,5 +1,7 @@
propellor (4.7.4) UNRELEASED; urgency=medium
+ * Set GPG_TTY when run at a terminal, so that gpg can do password
+ prompting despite being connected by pipes to propellor (or git).
* Rsync: Make rsync display less verbose.
-- Joey Hess <id@joeyh.name> Sat, 29 Jul 2017 20:02:32 -0400
diff --git a/src/Propellor/CmdLine.hs b/src/Propellor/CmdLine.hs
index cba5991d..bd01b34c 100644
--- a/src/Propellor/CmdLine.hs
+++ b/src/Propellor/CmdLine.hs
@@ -111,6 +111,7 @@ data CanRebuild = CanRebuild | NoRebuild
defaultMain :: [Host] -> IO ()
defaultMain hostlist = withConcurrentOutput $ do
useFileSystemEncoding
+ setupGpgEnv
Shim.cleanEnv
checkDebugMode
cmdline <- processCmdLine
diff --git a/src/Propellor/Gpg.hs b/src/Propellor/Gpg.hs
index 43c4eddf..5df16389 100644
--- a/src/Propellor/Gpg.hs
+++ b/src/Propellor/Gpg.hs
@@ -1,6 +1,8 @@
module Propellor.Gpg where
import System.IO
+import System.Posix.IO
+import System.Posix.Terminal
import Data.Maybe
import Control.Monad
import Control.Applicative
@@ -19,6 +21,25 @@ import Utility.Env
import Utility.Directory
import Utility.Split
+-- | When at a tty, set GPG_TTY to point to the tty device. This is needed
+-- so that when gpg is run with stio connected to a pipe, it is still able
+-- to display password prompts at the console.
+--
+-- This should not prevent gpg from using the GUI for prompting when one is
+-- available.
+setupGpgEnv :: IO ()
+setupGpgEnv = checkhandles [stdInput, stdOutput, stdError]
+ where
+ checkhandles [] = return ()
+ checkhandles (h:hs) = do
+ isterm <- queryTerminal h
+ if isterm
+ then do
+ ttyname <- getTerminalName h
+ -- do not overwrite
+ setEnv "GPG_TTY" ttyname False
+ else checkhandles hs
+
type KeyId = String
getGpgBin :: IO String