summaryrefslogtreecommitdiff
path: root/Property/GitHome.hs
diff options
context:
space:
mode:
authorJoey Hess2014-03-29 23:10:52 -0400
committerJoey Hess2014-03-29 23:16:43 -0400
commitd9af8bac5eb7836a3c90e37e870fd73d30b841fd (patch)
tree40443efd384415172cf393571fe3f1651ea57423 /Property/GitHome.hs
initial check-in
too young to have a name
Diffstat (limited to 'Property/GitHome.hs')
-rw-r--r--Property/GitHome.hs37
1 files changed, 37 insertions, 0 deletions
diff --git a/Property/GitHome.hs b/Property/GitHome.hs
new file mode 100644
index 00000000..6bbae254
--- /dev/null
+++ b/Property/GitHome.hs
@@ -0,0 +1,37 @@
+module Property.GitHome where
+
+import System.FilePath
+import System.Directory
+import Control.Applicative
+import Control.Monad
+
+import Property
+import Property.User
+import Utility.SafeCommand
+import Utility.Directory
+import Utility.Monad
+import Utility.Exception
+
+{- Clones Joey Hess's git home directory, and runs its fixups script. -}
+installed :: UserName -> Property
+installed user = check (not <$> hasGitDir user) $
+ IOProperty ("githome " ++ user) (go =<< homedir user)
+ where
+ go Nothing = noChange
+ go (Just home) = do
+ let tmpdir = home </> "githome"
+ ok <- boolSystem "git" [Param "clone", Param url, Param tmpdir]
+ <&&> (and <$> moveout tmpdir home)
+ <&&> (catchBoolIO $ removeDirectory tmpdir >> return True)
+ <&&> boolSystem "su" [Param "-c", Param "cd; bin/fixups", Param user]
+ return $ if ok then MadeChange else FailedChange
+ moveout tmpdir home = do
+ fs <- dirContents tmpdir
+ forM fs $ \f -> boolSystem "mv" [File f, File home]
+ url = "git://git.kitenet.net/joey/home"
+
+hasGitDir :: UserName -> IO Bool
+hasGitDir user = go =<< homedir user
+ where
+ go Nothing = return False
+ go (Just home) = doesDirectoryExist (home </> ".git")