summaryrefslogtreecommitdiff
path: root/src/wrapper.hs
diff options
context:
space:
mode:
authorJoey Hess2014-08-19 15:22:42 -0400
committerJoey Hess2014-08-19 15:22:42 -0400
commit1830f501ee7d8ca7832cbd337629b0d9225baedb (patch)
treea558a5c76929553d852877509518270374b00d1c /src/wrapper.hs
parent527ae1dc208599bee15afd8167eeec17744a6b0b (diff)
debian upgrade handling
The /usr/bin/propellor wrapper will warn when ~/.propellor/ is out of date and a newer version is available from origin.
Diffstat (limited to 'src/wrapper.hs')
-rw-r--r--src/wrapper.hs39
1 files changed, 30 insertions, 9 deletions
diff --git a/src/wrapper.hs b/src/wrapper.hs
index 3c1231ee..7f681641 100644
--- a/src/wrapper.hs
+++ b/src/wrapper.hs
@@ -19,6 +19,7 @@ import Utility.Monad
import Utility.Process
import Utility.SafeCommand
import Utility.Directory
+import Utility.Exception
import Control.Monad
import Control.Monad.IfElse
@@ -27,9 +28,10 @@ import System.FilePath
import System.Environment (getArgs)
import System.Exit
import System.Posix.Directory
+import System.IO
-localrepo :: FilePath
-localrepo = "/usr/src/propellor/propellor.git"
+distrepo :: FilePath
+distrepo = "/usr/src/propellor/propellor.git"
-- Using the github mirror of the main propellor repo because
-- it is accessible over https for better security.
@@ -46,19 +48,34 @@ main = do
wrapper :: [String] -> FilePath -> FilePath -> IO ()
wrapper args propellordir propellorbin = do
- unlessM (doesDirectoryExist propellordir) $
- makeRepo
+ ifM (doesDirectoryExist propellordir)
+ ( checkRepo
+ , makeRepo
+ )
buildruncfg
where
- chain = do
- (_, _, _, pid) <- createProcess (proc propellorbin args)
- exitWith =<< waitForProcess pid
makeRepo = do
putStrLn $ "Setting up your propellor repo in " ++ propellordir
putStrLn ""
- localexists <- doesFileExist localrepo <||> doesDirectoryExist localrepo
- let repo = if localexists then localrepo else netrepo
+ distexists <- doesFileExist distrepo <||> doesDirectoryExist distrepo
+ let repo = if distexists then distrepo else netrepo
void $ boolSystem "git" [Param "clone", File repo, File propellordir]
+
+ disthead = propellordir </> "head"
+
+ checkRepo = whenM (doesFileExist disthead) $ do
+ head <- readFile disthead
+ changeWorkingDirectory propellordir
+ headknown <- catchMaybeIO $
+ withQuietOutput createProcessSuccess $
+ proc "git" ["log", head]
+ when (headknown == Nothing)
+ warnoutofdate
+ warnoutofdate = do
+ let n = hPutStrLn stderr
+ n ("** Your " ++ propellordir ++ " is out of date..")
+ n (" A newer upstream version is available in " ++ distrepo)
+ n (" To merge it, run eg: git pull origin master")
buildruncfg = do
changeWorkingDirectory propellordir
ifM (boolSystem "make" [Param "build"])
@@ -68,3 +85,7 @@ wrapper args propellordir propellorbin = do
chain
, error "Propellor build failed."
)
+ chain = do
+ (_, _, _, pid) <- createProcess (proc propellorbin args)
+ exitWith =<< waitForProcess pid
+