From bde6a58ef862ab01ee89a07d815fad4a51361b5b Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 12 Nov 2016 01:41:30 -0400 Subject: check that config.hs mentions "Propellor" from eg, "import Propellor" --- src/wrapper.hs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/wrapper.hs b/src/wrapper.hs index 6b24a368..06051500 100644 --- a/src/wrapper.hs +++ b/src/wrapper.hs @@ -7,8 +7,8 @@ -- This bootstraps ~/.propellor/config.hs, builds it if -- it's not already built, and runs it. -- --- If ./config.hs exists, it instead builds and runs in the --- current working directory. +-- If ./config.hs exists and looks like a propellor config file, +-- it instead builds and runs in the current working directory. module Main where @@ -24,7 +24,10 @@ import Utility.Process.NonConcurrent import System.Environment (getArgs) import System.Exit import System.Posix +import Data.List import Control.Monad.IfElse +import Control.Applicative +import Prelude main :: IO () main = withConcurrentOutput $ go =<< getArgs @@ -66,8 +69,13 @@ configInCurrentWorkingDirectory = ifM (doesFileExist "config.hs") then unsafe "the current directory is group writable" else if checkMode otherWriteMode (fileMode s) then unsafe "the current directory is world-writable" - else return True + else ifM mentionspropellor + ( return True + , notusing "it does not seem to be a propellor config file" + ) , return False ) where - unsafe s = error $ "Not using ./config.hs because " ++ s ++ ". This seems unsafe." + unsafe s = notusing (s ++ ". This seems unsafe.") + notusing s = error $ "Not using ./config.hs because " ++ s + mentionspropellor = ("Propellor" `isInfixOf`) <$> readFile "config.hs" -- cgit v1.2.3