2014-04-01 20:58:11 +00:00
|
|
|
module Propellor.Property.SiteSpecific.GitHome where
|
2014-03-30 03:10:52 +00:00
|
|
|
|
2014-03-31 03:55:59 +00:00
|
|
|
import Propellor
|
2014-03-31 03:37:54 +00:00
|
|
|
import qualified Propellor.Property.Apt as Apt
|
|
|
|
import Propellor.Property.User
|
2014-03-31 03:55:59 +00:00
|
|
|
import Utility.SafeCommand
|
2014-03-30 03:10:52 +00:00
|
|
|
|
2014-04-01 20:58:11 +00:00
|
|
|
-- | Clones Joey Hess's git home directory, and runs its fixups script.
|
2014-03-30 03:24:40 +00:00
|
|
|
installedFor :: UserName -> Property
|
|
|
|
installedFor user = check (not <$> hasGitDir user) $
|
2014-03-30 19:31:57 +00:00
|
|
|
Property ("githome " ++ user) (go =<< homedir user)
|
2014-03-30 04:52:02 +00:00
|
|
|
`requires` Apt.installed ["git", "myrepos"]
|
2014-03-30 03:10:52 +00:00
|
|
|
where
|
|
|
|
go Nothing = noChange
|
|
|
|
go (Just home) = do
|
|
|
|
let tmpdir = home </> "githome"
|
2014-04-01 21:32:37 +00:00
|
|
|
ensureProperty $ combineProperties "githome setup"
|
2014-04-01 20:58:11 +00:00
|
|
|
[ 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"]
|
|
|
|
]
|
2014-03-30 03:10:52 +00:00
|
|
|
moveout tmpdir home = do
|
|
|
|
fs <- dirContents tmpdir
|
|
|
|
forM fs $ \f -> boolSystem "mv" [File f, File home]
|
2014-04-01 20:58:11 +00:00
|
|
|
|
|
|
|
url :: String
|
|
|
|
url = "git://git.kitenet.net/joey/home"
|
2014-03-30 03:10:52 +00:00
|
|
|
|
|
|
|
hasGitDir :: UserName -> IO Bool
|
|
|
|
hasGitDir user = go =<< homedir user
|
|
|
|
where
|
|
|
|
go Nothing = return False
|
|
|
|
go (Just home) = doesDirectoryExist (home </> ".git")
|