summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess2014-03-30 13:12:33 -0400
committerJoey Hess2014-03-30 13:12:33 -0400
commit8e7b296e820e7513c7846ceeb3fbd87d60bc95f4 (patch)
tree4eb80ad32b42ee871f5704cd1af99baf9e8cacc6
parente741b7b82e0b5be2809d1da7f54d8b0fcd0449e3 (diff)
split out Property.FIle
-rw-r--r--Propellor.hs3
-rw-r--r--Property.hs19
-rw-r--r--Property/Apt.hs3
-rw-r--r--Property/File.hs22
-rw-r--r--Property/Hostname.hs6
-rw-r--r--Property/Ssh.hs5
-rw-r--r--Property/Tor.hs3
7 files changed, 34 insertions, 27 deletions
diff --git a/Propellor.hs b/Propellor.hs
index 1bc1373a..44673d10 100644
--- a/Propellor.hs
+++ b/Propellor.hs
@@ -1,5 +1,6 @@
import Property
import HostName
+import qualified Property.File as File
import qualified Property.Apt as Apt
import qualified Property.Ssh as Ssh
import qualified Property.User as User
@@ -47,7 +48,7 @@ standardSystem suite = propertyList "standard system"
, User.nonsystem "joey"
, Apt.installed ["sudo"]
-- nopasswd because no password is set up for joey.
- , lineInFile "/etc/sudoers" "joey ALL=(ALL:ALL) NOPASSWD:ALL"
+ , "/etc/sudoers" `File.containsLine` "joey ALL=(ALL:ALL) NOPASSWD:ALL"
, GitHome.installedFor "joey"
]
diff --git a/Property.hs b/Property.hs
index 4aba094f..f00ddfa2 100644
--- a/Property.hs
+++ b/Property.hs
@@ -127,25 +127,6 @@ cmdProperty' cmd params env = CmdProperty desc cmd params env
showp (Param s) = s
showp (File s) = s
-{- Replaces all the content of a file. -}
-fileHasContent :: FilePath -> [Line] -> Property
-fileHasContent f newcontent = FileProperty ("replace " ++ f)
- f (\_oldcontent -> newcontent)
-
-{- Ensures that a line is present in a file, adding it to the end if not. -}
-lineInFile :: FilePath -> Line -> Property
-lineInFile f l = FileProperty (f ++ " contains:" ++ l) f go
- where
- go ls
- | l `elem` ls = ls
- | otherwise = ls++[l]
-
-{- Ensures that a line is not present in a file.
- - Note that the file is ensured to exist, so if it doesn't, an empty
- - file will be written. -}
-lineNotInFile :: FilePath -> Line -> Property
-lineNotInFile f l = FileProperty (f ++ " remove: " ++ l) f (filter (/= l))
-
{- Makes a perhaps non-idempotent Property be idempotent by using a flag
- file to indicate whether it has run before.
- Use with caution. -}
diff --git a/Property/Apt.hs b/Property/Apt.hs
index 4d58574f..653c0fca 100644
--- a/Property/Apt.hs
+++ b/Property/Apt.hs
@@ -7,6 +7,7 @@ import System.IO
import Control.Monad
import Property
+import qualified Property.File as File
import Utility.SafeCommand
import Utility.Process
@@ -47,7 +48,7 @@ stdSourcesList :: Suite -> Property
stdSourcesList = setSourcesList . debCdn
setSourcesList :: [Line] -> Property
-setSourcesList ls = fileHasContent sourcesList ls `onChange` update
+setSourcesList ls = sourcesList `File.hasContent` ls `onChange` update
runApt :: [CommandParam] -> Property
runApt ps = cmdProperty' "apt-get" ps env
diff --git a/Property/File.hs b/Property/File.hs
new file mode 100644
index 00000000..a4b21961
--- /dev/null
+++ b/Property/File.hs
@@ -0,0 +1,22 @@
+module Property.File where
+
+import Property
+
+{- Replaces all the content of a file. -}
+hasContent :: FilePath -> [Line] -> Property
+f `hasContent` newcontent = FileProperty ("replace " ++ f)
+ f (\_oldcontent -> newcontent)
+
+{- Ensures that a line is present in a file, adding it to the end if not. -}
+containsLine :: FilePath -> Line -> Property
+f `containsLine` l = FileProperty (f ++ " contains:" ++ l) f go
+ where
+ go ls
+ | l `elem` ls = ls
+ | otherwise = ls++[l]
+
+{- Ensures that a line is not present in a file.
+ - Note that the file is ensured to exist, so if it doesn't, an empty
+ - file will be written. -}
+lacksLine :: FilePath -> Line -> Property
+f `lacksLine` l = FileProperty (f ++ " remove: " ++ l) f (filter (/= l))
diff --git a/Property/Hostname.hs b/Property/Hostname.hs
index 7baf7178..38e9dbe8 100644
--- a/Property/Hostname.hs
+++ b/Property/Hostname.hs
@@ -1,11 +1,11 @@
module Property.Hostname where
import Property
+import qualified Property.File as File
import Utility.SafeCommand
type HostName = String
set :: HostName -> Property
-set hostname =
- fileHasContent "/etc/hostname" [hostname]
- `onChange` cmdProperty "hostname" [Param hostname]
+set hostname = "/etc/hostname" `File.hasContent` [hostname]
+ `onChange` cmdProperty "hostname" [Param hostname]
diff --git a/Property/Ssh.hs b/Property/Ssh.hs
index 141e3495..98149bcb 100644
--- a/Property/Ssh.hs
+++ b/Property/Ssh.hs
@@ -6,6 +6,7 @@ import System.FilePath
import Property
import Property.User
+import qualified Property.File as File
import Utility.SafeCommand
import Utility.Exception
@@ -18,8 +19,8 @@ sshdConfig = "/etc/ssh/sshd_config"
setSshdConfig :: String -> Bool -> Property
setSshdConfig setting allowed = combineProperties desc
- [ lineNotInFile sshdConfig $ sshline (not allowed)
- , lineInFile sshdConfig $ sshline allowed
+ [ sshdConfig `File.lacksLine` (sshline $ not allowed)
+ , sshdConfig `File.containsLine` (sshline allowed)
] `onChange` restartSshd
where
desc = unwords [ "ssh config:", setting, sshBool allowed ]
diff --git a/Property/Tor.hs b/Property/Tor.hs
index b26ba68e..7f7e7245 100644
--- a/Property/Tor.hs
+++ b/Property/Tor.hs
@@ -2,12 +2,13 @@ module Property.Tor where
import Property
import Utility.SafeCommand
+import qualified Property.File as File
import qualified Property.Apt as Apt
isBridge :: Property
isBridge = setup `requires` Apt.installed ["tor"]
where
- setup = fileHasContent "/etc/tor/torrc"
+ setup = "/etc/tor/torrc" `File.hasContent`
[ "SocksPort 0"
, "ORPort 443"
, "BridgeRelay 1"