summaryrefslogtreecommitdiff
path: root/Propellor/Property/SiteSpecific/GitHome.hs
diff options
context:
space:
mode:
authorJoey Hess2014-04-01 16:58:11 -0400
committerJoey Hess2014-04-01 16:58:11 -0400
commite6d24b49b87de312776bee71a2a6f009f7f397a9 (patch)
treeceba3045f23ee1d3cf36bfe8e8ffa9cb090b9e54 /Propellor/Property/SiteSpecific/GitHome.hs
parent6a82cdc41c89cc249da4d941a32920ebfd14cb92 (diff)
various improvements
Diffstat (limited to 'Propellor/Property/SiteSpecific/GitHome.hs')
-rw-r--r--Propellor/Property/SiteSpecific/GitHome.hs36
1 files changed, 36 insertions, 0 deletions
diff --git a/Propellor/Property/SiteSpecific/GitHome.hs b/Propellor/Property/SiteSpecific/GitHome.hs
new file mode 100644
index 00000000..b3a8deff
--- /dev/null
+++ b/Propellor/Property/SiteSpecific/GitHome.hs
@@ -0,0 +1,36 @@
+module Propellor.Property.SiteSpecific.GitHome where
+
+import Propellor
+import qualified Propellor.Property.Apt as Apt
+import Propellor.Property.User
+import Utility.SafeCommand
+
+-- | Clones Joey Hess's git home directory, and runs its fixups script.
+installedFor :: UserName -> Property
+installedFor user = check (not <$> hasGitDir user) $
+ Property ("githome " ++ user) (go =<< homedir user)
+ `requires` Apt.installed ["git", "myrepos"]
+ where
+ go Nothing = noChange
+ go (Just home) = do
+ let tmpdir = home </> "githome"
+ ensureProperty $ combineProperties
+ [ userScriptProperty user ["git clone " ++ url ++ " " ++ tmpdir]
+ , Property "moveout" $ makeChange $ void $
+ moveout tmpdir home
+ , Property "rmdir" $ makeChange $ void $
+ catchMaybeIO $ removeDirectory tmpdir
+ , userScriptProperty user ["rm -rf .aptitude/ .bashrc .profile; mr checkout; bin/fixups"]
+ ]
+ moveout tmpdir home = do
+ fs <- dirContents tmpdir
+ forM fs $ \f -> boolSystem "mv" [File f, File home]
+
+url :: String
+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")