git-annex/Build/DistributionUpdate.hs

104 lines
2.8 KiB
Haskell
Raw Normal View History

2013-11-22 16:21:53 +00:00
{- Builds distributon info files for each git-annex release in a directory
- tree, which must itself be part of a git-annex repository. Only files
2014-04-21 15:24:34 +00:00
- that are present have their info file created.
-
- Also gpg signs the files.
-}
2013-11-22 16:21:53 +00:00
import Common.Annex
import Types.Distribution
import Build.Version
import Utility.UserInfo
import Utility.Path
import qualified Git.Construct
import qualified Annex
import Annex.Content
import Backend
import Git.Command
import Data.Time.Clock
2014-04-21 15:24:34 +00:00
-- git-annex distribution signing key (for Joey Hess)
signingKey :: String
signingKey = "89C809CB"
2013-11-22 16:21:53 +00:00
main = do
state <- Annex.new =<< Git.Construct.fromPath =<< getRepoDir
Annex.eval state makeinfos
makeinfos :: Annex ()
makeinfos = do
2014-02-27 16:20:53 +00:00
version <- liftIO getChangelogVersion
void $ inRepo $ runBool
[ Param "commit"
2014-02-27 16:20:53 +00:00
, Param "-a"
, Param "-m"
, Param $ "publishing git-annex " ++ version
]
2013-11-22 16:21:53 +00:00
basedir <- liftIO getRepoDir
now <- liftIO getCurrentTime
liftIO $ putStrLn $ "building info files for version " ++ version ++ " in " ++ basedir
2014-02-10 19:33:37 +00:00
fs <- liftIO $ dirContentsRecursiveSkipping (const False) True (basedir </> "git-annex")
2013-11-22 16:21:53 +00:00
forM_ fs $ \f -> do
v <- lookupFile f
case v of
Nothing -> noop
Just k -> whenM (inAnnex k) $ do
2013-11-22 16:21:53 +00:00
liftIO $ putStrLn f
let infofile = f ++ ".info"
2013-11-22 16:21:53 +00:00
liftIO $ writeFile infofile $ show $ GitAnnexDistribution
{ distributionUrl = mkUrl basedir f
, distributionKey = k
, distributionVersion = version
, distributionReleasedate = now
, distributionUrgentUpgrade = Nothing
}
2014-04-21 15:24:34 +00:00
void $ inRepo $ runBool [Param "add", File infofile]
signFile infofile
signFile f
2013-11-22 16:21:53 +00:00
void $ inRepo $ runBool
[ Param "commit"
, Param "-m"
, Param $ "updated info files for git-annex " ++ version
2013-11-22 16:21:53 +00:00
]
2013-11-22 19:02:31 +00:00
void $ inRepo $ runBool
2013-11-25 18:14:45 +00:00
[ Param "annex"
2013-11-22 19:02:31 +00:00
, Params "move --to website"
]
void $ inRepo $ runBool
2013-11-25 18:14:45 +00:00
[ Param "annex"
2013-11-22 19:02:31 +00:00
, Params "sync"
]
{- Check for out of date info files. -}
2014-02-10 19:33:37 +00:00
infos <- liftIO $ filter (".info" `isSuffixOf`)
<$> dirContentsRecursive (basedir </> "git-annex")
ds <- liftIO $ forM infos (readish <$$> readFile)
let dis = zip infos ds
let ood = filter (outofdate version) dis
unless (null ood) $
error $ "Some info files are out of date: " ++ show (map fst ood)
where
outofdate version (_, md) = case md of
Nothing -> True
Just d -> distributionVersion d /= version
2013-11-22 16:21:53 +00:00
getRepoDir :: IO FilePath
getRepoDir = do
home <- liftIO myHomeDir
return $ home </> "lib" </> "downloads"
mkUrl :: FilePath -> FilePath -> String
mkUrl basedir f = "https://downloads.kitenet.net/" ++ relPathDirToFile basedir f
2014-04-21 15:24:34 +00:00
signFile :: FilePath -> Annex ()
signFile f = do
void $ liftIO $ boolSystem "gpg"
[ Param "-a"
, Param $ "--default-key=" ++ signingKey
2014-04-21 15:56:06 +00:00
, Param "--detach-sign"
2014-04-21 15:24:34 +00:00
, File f
]
liftIO $ rename (f ++ ".asc") (f ++ ".sig")
void $ inRepo $ runBool [Param "add", File (f ++ ".sig")]