propellor/Propellor/Property/SiteSpecific/GitAnnexBuilder.hs

54 lines
1.8 KiB
Haskell
Raw Normal View History

2014-04-01 20:58:11 +00:00
module Propellor.Property.SiteSpecific.GitAnnexBuilder where
import Propellor
import qualified Propellor.Property.Apt as Apt
import qualified Propellor.Property.User as User
2014-04-01 22:06:02 +00:00
import qualified Propellor.Property.Cron as Cron
2014-04-01 20:58:11 +00:00
import Propellor.Property.Cron (CronTimes)
2014-04-01 22:06:02 +00:00
import Data.Char
2014-04-01 20:58:11 +00:00
builduser :: UserName
builduser = "builder"
builddir :: FilePath
builddir = "gitbuilder"
2014-04-01 22:06:02 +00:00
builder :: Architecture -> CronTimes -> Property
2014-04-01 21:32:37 +00:00
builder arch crontimes = combineProperties "gitannexbuilder"
2014-04-01 21:08:48 +00:00
[ Apt.stdSourcesList Unstable
, Apt.buildDep ["git-annex"]
2014-04-01 22:06:02 +00:00
, Apt.installed ["git", "rsync", "moreutils",
2014-04-01 22:07:49 +00:00
"liblockfile-simple-perl", "cabal-install"]
2014-04-01 20:58:11 +00:00
, serviceRunning "cron" `requires` Apt.installed ["cron"]
, User.accountFor builduser
2014-04-01 21:08:48 +00:00
, check (lacksdir builddir) $ userScriptProperty builduser
2014-04-01 21:26:16 +00:00
[ "git clone https://github.com/joeyh/gitbuilder/"
2014-04-01 21:08:48 +00:00
, "cd gitbuilder"
2014-04-01 22:06:02 +00:00
, "git checkout " ++ map toLower (show arch)
, "git clone https://git-annex.branchable.com/ build"
2014-04-01 20:58:11 +00:00
]
`describe` "gitbuilder setup"
2014-04-01 22:06:02 +00:00
, Cron.niceJob "gitannexbuilder" crontimes builduser "~/gitbuilder" "./autobuild"
2014-04-01 21:08:48 +00:00
, check (lacksdir $ builddir </> "git-annex") $ userScriptProperty builduser
[ "cd gitbuilder"
, "git clone https://git-annex.branchable.com/ git-annex"
]
2014-04-01 20:58:11 +00:00
-- The builduser account does not have a password set,
-- instead use the password privdata to hold the rsync server
-- password used to upload the built image.
, Property "rsync password" $ do
d <- homedir
let f = d </> "rsyncpassword"
withPrivData (Password builduser) $ \p -> do
oldp <- catchDefaultIO "" $ readFileStrict f
if p /= oldp
then makeChange $ writeFile f p
else noChange
]
where
homedir = fromMaybe ("/home/" ++ builduser) <$> User.homedir builduser
2014-04-01 21:08:48 +00:00
lacksdir d = do
h <- homedir
not <$> doesDirectoryExist (h </> d)