summaryrefslogtreecommitdiff
path: root/Property/GitHome.hs
blob: f0764db96fca3b9ad72252c04f464698e773ab0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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. -}
installedFor :: UserName -> Property
installedFor 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")