From 347c02a38e120c973445195b86339ca358a0b50a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 11 Nov 2014 12:32:17 -0400 Subject: split out gpg keyring related stuff --- src/Propellor/Keyring.hs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/Propellor/Keyring.hs (limited to 'src/Propellor/Keyring.hs') diff --git a/src/Propellor/Keyring.hs b/src/Propellor/Keyring.hs new file mode 100644 index 00000000..8a9c833c --- /dev/null +++ b/src/Propellor/Keyring.hs @@ -0,0 +1,46 @@ +module Propellor.Keyring where + +import Propellor +import Utility.SafeCommand + +addKey :: String -> IO () +addKey keyid = exitBool =<< allM id [ gpg, gitadd, gitconfig, gitcommit ] + where + gpg = do + createDirectoryIfMissing True privDataDir + boolSystem "sh" + [ Param "-c" + , Param $ "gpg --export " ++ keyid ++ " | gpg " ++ + unwords (gpgopts ++ ["--import"]) + ] + gitadd = boolSystem "git" + [ Param "add" + , File keyring + ] + + gitconfig = boolSystem "git" + [ Param "config" + , Param "user.signingkey" + , Param keyid + ] + + gitcommit = gitCommit + [ File keyring + , Param "-m" + , Param "propellor addkey" + ] + +{- Automatically sign the commit if there'a a keyring. -} +gitCommit :: [CommandParam] -> IO Bool +gitCommit ps = do + k <- doesFileExist keyring + boolSystem "git" $ catMaybes $ + [ Just (Param "commit") + , if k then Just (Param "--gpg-sign") else Nothing + ] ++ map Just ps + +keyring :: FilePath +keyring = privDataDir "keyring.gpg" + +gpgopts :: [String] +gpgopts = ["--options", "/dev/null", "--no-default-keyring", "--keyring", keyring] -- cgit v1.3-2-g0d8e