2014-03-30 03:10:52 +00:00
|
|
|
module Property.GitHome where
|
|
|
|
|
2014-03-30 19:31:57 +00:00
|
|
|
import Common
|
2014-03-30 04:52:02 +00:00
|
|
|
import qualified Property.Apt as Apt
|
2014-03-30 19:31:57 +00:00
|
|
|
import Property.User
|
2014-03-30 03:10:52 +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"
|
|
|
|
ok <- boolSystem "git" [Param "clone", Param url, Param tmpdir]
|
|
|
|
<&&> (and <$> moveout tmpdir home)
|
|
|
|
<&&> (catchBoolIO $ removeDirectory tmpdir >> return True)
|
2014-03-30 04:42:04 +00:00
|
|
|
<&&> boolSystem "su" [Param "-c", Param "cd; rm -rf .aptitude/ .bashrc .profile; mr checkout; bin/fixups", Param user]
|
2014-03-30 03:10:52 +00:00
|
|
|
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")
|