This repository has been archived by the owner on Feb 28, 2020. It is now read-only.
forked from fosskers/aura
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arel.hs
59 lines (47 loc) · 1.56 KB
/
arel.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
-- arel - Helps create aura releases.
import System.FilePath ((</>))
import Text.Regex.PCRE ((=~))
import Control.Monad (liftM, void)
import System.Exit (ExitCode(..))
import Data.List (sortBy)
import Aura.Utils (comparableVer)
import Utilities (tripleSnd, inDir)
import Shell
---
sourceDir :: String
sourceDir = "/home/colin/code/haskell/aura/"
main :: IO ()
main = do
cd sourceDir
result <- shellCmd "cabal" ["check"]
case result of
ExitFailure _ -> putStrLn "arel: cabal check failed"
ExitSuccess -> do
removeOldFiles
makeNewPkgFile
alterPKGBUILD
makeTarball
putStrLn "Done."
removeOldFiles :: IO ()
removeOldFiles = filter isPkgFile `liftM` ls sourceDir >>= mapM_ rm
isPkgFile :: String -> Bool
isPkgFile f = f =~ "^aura-"
makeNewPkgFile :: IO ()
makeNewPkgFile = shellCmd "cabal" ["sdist"] >> inDir "dist/" (do
pkgs <- ls "."
let latest = last . sortPkgFiles . filter isPkgFile $ pkgs
cp latest $ sourceDir </> latest)
sortPkgFiles :: [String] -> [String]
sortPkgFiles [] = []
sortPkgFiles fs = sortBy verNums fs
where verNums a b = compare (ver a) (ver b)
ver f = comparableVer (f =~ "-[0-9.]+.tar" :: String)
alterPKGBUILD :: IO ()
alterPKGBUILD = do
md5 <- (init . tripleSnd) `liftM` quietShellCmd' "makepkg" ["-g"]
pbLines <- lines `liftM` readFile "PKGBUILD"
let newLines = map (\l -> if l =~ "^md5sums=" then md5 else l) pbLines
writeFile "PKGBUILD.new" $ unlines newLines
mv "PKGBUILD.new" "PKGBUILD"
makeTarball :: IO ()
makeTarball = void (quietShellCmd' "makepkg" ["--source"])