propellor/Propellor/Property/SiteSpecific/GitHome.hs

35 lines
1.1 KiB
Haskell
Raw Normal View History

2014-04-01 20:58:11 +00:00
module Propellor.Property.SiteSpecific.GitHome where
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-04-01 20:58:11 +00:00
-- | 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 =<< liftIO (homedir user))
2014-04-10 05:06:54 +00:00
`requires` Apt.installed ["git"]
where
2014-04-13 06:28:40 +00:00
go 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 $
2014-04-01 20:58:11 +00:00
moveout tmpdir home
, property "rmdir" $ makeChange $ void $
2014-04-01 20:58:11 +00:00
catchMaybeIO $ removeDirectory tmpdir
2014-04-10 05:06:54 +00:00
, userScriptProperty user ["rm -rf .aptitude/ .bashrc .profile; bin/mr checkout; bin/fixups"]
2014-04-01 20:58:11 +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"
hasGitDir :: UserName -> IO Bool
hasGitDir user = go =<< homedir user
where
2014-04-13 06:28:40 +00:00
go home = doesDirectoryExist (home </> ".git")