propellor/Propellor/Property/SiteSpecific/GitAnnexBuilder.hs

60 lines
2.0 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)
builduser :: UserName
builduser = "builder"
builddir :: FilePath
builddir = "gitbuilder"
builder :: Architecture -> CronTimes -> Bool -> Property
builder arch crontimes rsyncupload = combineProperties "gitannexbuilder"
2014-04-01 21:08:48 +00:00
[ Apt.stdSourcesList Unstable
, Apt.buildDep ["git-annex"]
2014-04-01 22:15:21 +00:00
, Apt.installed ["git", "rsync", "moreutils", "ca-certificates",
2014-04-03 00:26:38 +00:00
"liblockfile-simple-perl", "cabal-install", "vim", "less"]
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 22:31:04 +00:00
[ "git clone git://git.kitenet.net/gitannexbuilder " ++ builddir
, "cd " ++ builddir
2014-04-02 03:49:15 +00:00
, "git checkout " ++ arch
2014-04-01 20:58:11 +00:00
]
`describe` "gitbuilder setup"
2014-04-01 22:35:46 +00:00
, check (lacksdir $ builddir </> "build") $ userScriptProperty builduser
2014-04-01 22:31:04 +00:00
[ "cd " ++ builddir
2014-04-01 22:34:01 +00:00
, "git clone git://git-annex.branchable.com/ build"
2014-04-01 21:08:48 +00:00
]
2014-04-03 00:26:38 +00:00
, Property "git-annex source build deps installed" $ do
d <- homedir
ensureProperty $ Apt.buildDepIn (d </> builddir </> "build")
2014-04-01 22:31:04 +00:00
, Cron.niceJob "gitannexbuilder" crontimes builduser ("~/" ++ builddir) "git pull ; ./autobuild"
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"
if rsyncupload
then withPrivData (Password builduser) $ \p -> do
oldp <- catchDefaultIO "" $ readFileStrict f
if p /= oldp
then makeChange $ writeFile f p
else noChange
else do
ifM (doesFileExist f)
( noChange
, makeChange $ writeFile f "no password configured"
)
2014-04-01 20:58:11 +00:00
]
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)