2014-06-18 19:21:29 +00:00
|
|
|
{- 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
|
2014-06-18 19:21:29 +00:00
|
|
|
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.Time.Clock
|
2014-06-18 20:11:20 +00:00
|
|
|
import Data.Char
|
2015-01-13 16:43:22 +00:00
|
|
|
import System.Posix.Directory
|
2013-11-22 16:21:53 +00:00
|
|
|
|
2014-04-21 15:24:34 +00:00
|
|
|
-- git-annex distribution signing key (for Joey Hess)
|
|
|
|
signingKey :: String
|
|
|
|
signingKey = "89C809CB"
|
|
|
|
|
2014-06-18 19:21:29 +00:00
|
|
|
-- 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"]) ++
|
2015-01-08 23:29:17 +00:00
|
|
|
(map androidversion ["4.0", "4.3", "5.0"]) ++
|
2014-11-11 20:18:51 +00:00
|
|
|
[ (autobuild "x86_64-apple-yosemite/git-annex.dmg", "git-annex/OSX/current/10.10_Yosemite/git-annex.dmg")
|
2014-06-19 18:21:34 +00:00
|
|
|
, (autobuild "windows/git-annex-installer.exe", "git-annex/windows/current/git-annex-installer.exe")
|
2014-06-18 19:21:29 +00:00
|
|
|
]
|
|
|
|
where
|
|
|
|
linuxarch a =
|
2014-06-19 18:21:34 +00:00
|
|
|
( autobuild (a ++ "/git-annex-standalone-" ++ a ++ ".tar.gz")
|
2014-06-18 19:21:29 +00:00
|
|
|
, "git-annex/linux/current/git-annex-standalone-" ++ a ++ ".tar.gz"
|
|
|
|
)
|
|
|
|
androidversion v =
|
2014-06-19 18:21:34 +00:00
|
|
|
( autobuild ("android/" ++ v ++ "/git-annex.apk")
|
2014-06-18 19:49:43 +00:00
|
|
|
, "git-annex/android/current/" ++ v ++ "/git-annex.apk"
|
2014-06-18 19:21:29 +00:00
|
|
|
)
|
2014-07-07 18:30:38 +00:00
|
|
|
autobuild f = "https://downloads.kitenet.net/git-annex/autobuild/" ++ f
|
2014-06-18 19:21:29 +00:00
|
|
|
|
|
|
|
main :: IO ()
|
2013-11-22 16:21:53 +00:00
|
|
|
main = do
|
2015-01-13 16:43:22 +00:00
|
|
|
version <- liftIO getChangelogVersion
|
2014-06-18 19:21:29 +00:00
|
|
|
repodir <- getRepoDir
|
2015-01-13 16:43:22 +00:00
|
|
|
changeWorkingDirectory repodir
|
2014-06-18 19:21:29 +00:00
|
|
|
updated <- catMaybes <$> mapM (getbuild repodir) autobuilds
|
2015-01-13 16:43:22 +00:00
|
|
|
state <- Annex.new =<< Git.Construct.fromPath "."
|
|
|
|
Annex.eval state (makeinfos updated version)
|
2014-06-18 19:21:29 +00:00
|
|
|
|
|
|
|
-- 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
|
|
|
|
let dest = repodir </> f
|
|
|
|
let tmp = dest ++ ".tmp"
|
|
|
|
nukeFile tmp
|
2015-01-09 17:11:56 +00:00
|
|
|
createDirectoryIfMissing True (parentDir dest)
|
2014-06-18 19:44:16 +00:00
|
|
|
let oops s = do
|
|
|
|
nukeFile tmp
|
|
|
|
putStrLn $ "*** " ++ s
|
|
|
|
return Nothing
|
2014-06-18 19:21:29 +00:00
|
|
|
ifM (download url tmp def)
|
|
|
|
( do
|
|
|
|
bv2 <- getbv
|
|
|
|
case bv2 of
|
2014-06-18 19:44:16 +00:00
|
|
|
Nothing -> oops $ "no build-version file for " ++ url
|
2014-06-18 19:21:29 +00:00
|
|
|
(Just v)
|
|
|
|
| bv2 == bv1 -> do
|
|
|
|
nukeFile dest
|
|
|
|
renameFile tmp dest
|
|
|
|
-- remove git rev part of version
|
|
|
|
let v' = takeWhile (/= '-') v
|
|
|
|
return $ Just (f, v')
|
2014-06-18 19:44:16 +00:00
|
|
|
| otherwise -> oops $ "build version changed while downloading " ++ url ++ " " ++ show (bv1, bv2)
|
|
|
|
, oops $ "failed to download " ++ url
|
2014-06-18 19:21:29 +00:00
|
|
|
)
|
|
|
|
where
|
2014-06-18 20:24:46 +00:00
|
|
|
bvurl = takeDirectory url ++ "/build-version"
|
2014-06-18 19:21:29 +00:00
|
|
|
getbv = do
|
2014-06-18 20:24:46 +00:00
|
|
|
bv <- catchDefaultIO "" $ readProcess "curl" ["--silent", bvurl]
|
2014-06-18 20:11:20 +00:00
|
|
|
return $ if null bv || any (not . versionchar) bv then Nothing else Just bv
|
|
|
|
versionchar c = isAlphaNum c || c == '.' || c == '-'
|
2013-11-22 16:21:53 +00:00
|
|
|
|
2015-01-13 16:43:22 +00:00
|
|
|
makeinfos :: [(FilePath, Version)] -> Version -> Annex ()
|
|
|
|
makeinfos updated version = do
|
2014-11-11 20:49:24 +00:00
|
|
|
mapM_ (\f -> inRepo $ runBool [Param "annex", Param "add", File f]) (map fst updated)
|
2014-02-21 16:12:56 +00:00
|
|
|
void $ inRepo $ runBool
|
|
|
|
[ Param "commit"
|
2014-02-27 16:20:53 +00:00
|
|
|
, Param "-a"
|
2015-01-22 01:27:12 +00:00
|
|
|
, Param "-S89C809CB" -- git-annex distribution signing key
|
2014-02-21 16:12:56 +00:00
|
|
|
, Param "-m"
|
|
|
|
, Param $ "publishing git-annex " ++ version
|
|
|
|
]
|
2013-11-22 16:21:53 +00:00
|
|
|
now <- liftIO getCurrentTime
|
2015-01-13 16:43:22 +00:00
|
|
|
liftIO $ putStrLn $ "building info files"
|
2014-06-18 19:21:29 +00:00
|
|
|
forM_ updated $ \(f, bv) -> do
|
2015-01-13 16:43:22 +00:00
|
|
|
v <- lookupFile f
|
2013-11-22 16:21:53 +00:00
|
|
|
case v of
|
|
|
|
Nothing -> noop
|
2014-04-21 14:47:26 +00:00
|
|
|
Just k -> whenM (inAnnex k) $ do
|
2013-11-22 16:21:53 +00:00
|
|
|
liftIO $ putStrLn f
|
2015-01-13 16:43:22 +00:00
|
|
|
let infofile = f ++ ".info"
|
2013-11-22 16:21:53 +00:00
|
|
|
liftIO $ writeFile infofile $ show $ GitAnnexDistribution
|
2014-06-18 20:34:28 +00:00
|
|
|
{ distributionUrl = mkUrl f
|
2013-11-22 16:21:53 +00:00
|
|
|
, distributionKey = k
|
2014-06-18 19:21:29 +00:00
|
|
|
, 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
|
2015-01-13 16:43:22 +00:00
|
|
|
signFile f
|
2013-11-22 16:21:53 +00:00
|
|
|
void $ inRepo $ runBool
|
|
|
|
[ Param "commit"
|
|
|
|
, Param "-m"
|
2015-01-22 01:27:12 +00:00
|
|
|
, Param "-S89C809CB" -- git-annex distribution signing key
|
2014-02-21 16:12:56 +00:00
|
|
|
, 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"
|
|
|
|
]
|
2014-02-10 19:28:00 +00:00
|
|
|
|
2014-06-18 19:21:29 +00:00
|
|
|
-- Check for out of date info files.
|
2014-02-10 19:33:37 +00:00
|
|
|
infos <- liftIO $ filter (".info" `isSuffixOf`)
|
2015-01-13 16:43:22 +00:00
|
|
|
<$> dirContentsRecursive "git-annex"
|
2014-02-10 19:28:00 +00:00
|
|
|
ds <- liftIO $ forM infos (readish <$$> readFile)
|
|
|
|
let dis = zip infos ds
|
2015-01-13 16:43:22 +00:00
|
|
|
let ood = filter outofdate dis
|
2014-02-10 19:28:00 +00:00
|
|
|
unless (null ood) $
|
|
|
|
error $ "Some info files are out of date: " ++ show (map fst ood)
|
|
|
|
where
|
2015-01-13 16:43:22 +00:00
|
|
|
outofdate (_, md) = case md of
|
2014-02-10 19:28:00 +00:00
|
|
|
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"
|
|
|
|
|
2014-06-18 20:34:28 +00:00
|
|
|
mkUrl :: FilePath -> String
|
|
|
|
mkUrl f = "https://downloads.kitenet.net/" ++ 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")]
|