git-annex/Build/DistributionUpdate.hs

163 lines
4.8 KiB
Haskell
Raw Normal View History

{- Downloads git-annex autobuilds and installs them into the git-annex
- repository in ~/lib/downloads that is used to distribute git-annex
- releases.
-
- Generates info files, containing the version (of the corresponding file
- from the autobuild).
2014-04-21 15:24:34 +00:00
-
- 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.Url
2013-11-22 16:21:53 +00:00
import qualified Git.Construct
import qualified Annex
import Annex.Content
import Backend
import Git.Command
import Data.Default
2013-11-22 16:21:53 +00:00
import Data.Time.Clock
2014-04-21 15:24:34 +00:00
-- git-annex distribution signing key (for Joey Hess)
signingKey :: String
signingKey = "89C809CB"
-- URL to an autobuilt git-annex file, and the place to install
-- it in the repository.
autobuilds :: [(URLString, FilePath)]
autobuilds =
(map linuxarch ["i386", "amd64", "armel"]) ++
(map androidversion ["4.0", "4.3"]) ++
[ ("https://downloads.kitenet.net/git-annex/autobuild/x86_64-apple-mavericks/git-annex.dmg", "OSX/current/10.9_Mavericks")
, ("https://qa.nest-initiative.org/view/msysGit/job/msysgit-git-annex-assistant-test/lastSuccessfulBuild/artifact/git-annex/git-annex-installer.exe", "windows/current/git-annex-installer.exe")
]
where
linuxarch a =
( "https://downloads.kitenet.net/git-annex/autobuild/i386/git-annex-standalone-" ++ a ++ ".tar.gz"
, "git-annex/linux/current/git-annex-standalone-" ++ a ++ ".tar.gz"
)
androidversion v =
( "http://downloads.kitenet.net/git-annex/autobuild/android/" ++ v ++ "/git-annex.apk"
, "android/current/" ++ v ++ "/git-annex.apk"
)
main :: IO ()
2013-11-22 16:21:53 +00:00
main = do
repodir <- getRepoDir
updated <- catMaybes <$> mapM (getbuild repodir) autobuilds
state <- Annex.new =<< Git.Construct.fromPath repodir
Annex.eval state (makeinfos updated)
-- Download a build from the autobuilder, and return its version.
-- It's very important that the version matches the build, otherwise
-- auto-upgrades can loop reatedly. So, check build-version before
-- and after downloading the file.
getbuild :: FilePath -> (URLString, FilePath) -> IO (Maybe (FilePath, Version))
getbuild repodir (url, f) = do
bv1 <- getbv
createDirectoryIfMissing True repodir
let dest = repodir </> f
let tmp = dest ++ ".tmp"
nukeFile tmp
ifM (download url tmp def)
( do
bv2 <- getbv
case bv2 of
Nothing -> return Nothing
(Just v)
| bv2 == bv1 -> do
nukeFile dest
renameFile tmp dest
-- remove git rev part of version
let v' = takeWhile (/= '-') v
return $ Just (f, v')
| otherwise -> do
nukeFile tmp
error $ "build version changed while downloading " ++ url ++ " " ++ show (bv1, bv2)
, return Nothing
)
where
getbv = do
bv <- catchDefaultIO "" $
readProcess "curl" [takeDirectory url ++ "build-version"]
return $ if null bv then Nothing else Just bv
2013-11-22 16:21:53 +00:00
makeinfos :: [(FilePath, Version)] -> Annex ()
makeinfos updated = 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 in " ++ basedir
forM_ updated $ \(f, bv) -> do
2013-11-22 16:21:53 +00:00
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 = bv
2013-11-22 16:21:53 +00:00
, 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")]