summaryrefslogtreecommitdiff
path: root/src/Propellor/DotDir.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Propellor/DotDir.hs')
-rw-r--r--src/Propellor/DotDir.hs47
1 files changed, 39 insertions, 8 deletions
diff --git a/src/Propellor/DotDir.hs b/src/Propellor/DotDir.hs
index f0dace2f..90147abe 100644
--- a/src/Propellor/DotDir.hs
+++ b/src/Propellor/DotDir.hs
@@ -1,3 +1,5 @@
+{-# LANGUAGE CPP #-}
+
module Propellor.DotDir where
import Propellor.Message
@@ -11,9 +13,12 @@ import Utility.Process
import Utility.SafeCommand
import Utility.Exception
import Utility.Path
+-- This module is autogenerated by the build system.
+import qualified Paths_propellor as Package
import Data.Char
import Data.List
+import Data.Version
import Control.Monad
import Control.Monad.IfElse
import System.Directory
@@ -48,6 +53,15 @@ dotPropellor = do
home <- myHomeDir
return (home </> ".propellor")
+data InitCfg = UseCabal | UseStack
+
+initCfg :: InitCfg
+#ifdef USE_STACK
+initCfg = UseStack
+#else
+initCfg = UseCabal
+#endif
+
interactiveInit :: IO ()
interactiveInit = ifM (doesDirectoryExist =<< dotPropellor)
( error "~/.propellor/ already exists, not doing anything"
@@ -95,7 +109,7 @@ section = do
putStrLn ""
setup :: IO ()
-setup = do
+setup initcfg = do
putStrLn "Propellor's configuration file is ~/.propellor/config.hs"
putStrLn ""
putStrLn "Lets get you started with a simple config that you can adapt"
@@ -103,14 +117,21 @@ setup = do
putStrLn " A: A clone of propellor's git repository (most flexible)"
putStrLn " B: The bare minimum files to use propellor (most simple)"
prompt "Which would you prefer?"
- [ ("A", actionMessage "Cloning propellor's git repository" fullClone >> return ())
- , ("B", actionMessage "Creating minimal config" minimalConfig >> return ())
+ [ ("A", void $ actionMessage "Cloning propellor's git repository" fullClone)
+ , ("B", void $ actionMessage "Creating minimal config" minimalConfig)
]
changeWorkingDirectory =<< dotPropellor
section
putStrLn "Let's try building the propellor configuration, to make sure it will work..."
putStrLn ""
+ void $ boolSystem "git"
+ [ Param "config"
+ , Param "propellor.buildsystem"
+ , Param $ case initCfg of
+ UseCabal -> "cabal"
+ UseStack -> "stack"
+ ]
buildPropellor Nothing
putStrLn ""
putStrLn "Great! Propellor is bootstrapped."
@@ -197,15 +218,16 @@ minimalConfig :: IO Result
minimalConfig = do
d <- dotPropellor
createDirectoryIfMissing True d
- let cabalfile = d </> "config.cabal"
- let configfile = d </> "config.hs"
- writeFile cabalfile (unlines cabalcontent)
- writeFile configfile (unlines configcontent)
changeWorkingDirectory d
void $ boolSystem "git" [Param "init"]
- void $ boolSystem "git" [Param "add" , File cabalfile, File configfile]
+ addfile "config.cabal" cabalcontent
+ addfile "config.hs" configcontent
+ addfile "stack.yaml" stackcontent
return MadeChange
where
+ addfile f content = do
+ writeFile f (unlines content)
+ void $ boolSystem "git" [Param "add" , File f]
cabalcontent =
[ "-- This is a cabal file to use to build your propellor configuration."
, ""
@@ -252,6 +274,15 @@ minimalConfig = do
, " & Cron.runPropellor (Cron.Times \"30 * * * *\")"
, ""
]
+ stackcontent =
+ -- This should be the same resolver version in propellor's
+ -- own stack.yaml
+ [ "resolver: lts-5.10"
+ , "packages:"
+ , "- '.'"
+ , "extra-deps:"
+ , "- propellor-" ++ showVersion Package.version
+ ]
fullClone :: IO Result
fullClone = do