diff options
| author | Joey Hess <joeyh@joeyh.name> | 2017-07-30 11:29:12 -0400 |
|---|---|---|
| committer | Joey Hess <joeyh@joeyh.name> | 2017-07-30 11:29:12 -0400 |
| commit | 6f281e87084587987929dbb6a27671ad96858535 (patch) | |
| tree | aaa336fbdf556ec89260e3974cc65cc754ab4dd1 /src/Propellor/Gpg.hs | |
| parent | 31709484a6fe162cd66d38f61858fb14be9efddd (diff) | |
Set GPG_TTY when run at a terminal
so that gpg can do password prompting despite being connected by pipes to
propellor (or git).
Diffstat (limited to 'src/Propellor/Gpg.hs')
| -rw-r--r-- | src/Propellor/Gpg.hs | 21 |
1 files changed, 21 insertions, 0 deletions
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 |
