summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debian/changelog1
-rw-r--r--joeyconfig.hs2
-rw-r--r--src/Propellor/Property/File.hs9
-rw-r--r--src/Propellor/Property/XFCE.hs20
4 files changed, 18 insertions, 14 deletions
diff --git a/debian/changelog b/debian/changelog
index 7917bbf6..ea9f43bf 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -21,6 +21,7 @@ propellor (4.1.0) UNRELEASED; urgency=medium
* Propellor.Property.XFCE added with some useful properties for the
desktop environment.
* Added File.applyPath property.
+ * Added File.checkOverwrite.
* File.isCopyOf: Fix bug that prevented this property from working
when the destination file did not yet exist.
diff --git a/joeyconfig.hs b/joeyconfig.hs
index 20e73cef..4286097b 100644
--- a/joeyconfig.hs
+++ b/joeyconfig.hs
@@ -118,7 +118,7 @@ demo = host "demo" $ props
& root `User.hasInsecurePassword` "debian"
& user `User.hasInsecurePassword` "debian"
& XFCE.installedMin
- & XFCE.defaultPanelFor user OverwriteExisting
+ & XFCE.defaultPanelFor user File.OverwriteExisting
& LightDM.autoLogin user
& Apt.installed ["firefox"]
where
diff --git a/src/Propellor/Property/File.hs b/src/Propellor/Property/File.hs
index 8d10b94c..3293599a 100644
--- a/src/Propellor/Property/File.hs
+++ b/src/Propellor/Property/File.hs
@@ -307,3 +307,12 @@ readConfigFileName = readish . unescape
Nothing -> '_' : ns ++ unescape cs'
Just n -> chr n : unescape cs'
unescape (c:cs) = c : unescape cs
+
+data Overwrite = OverwriteExisting | PreserveExisting
+
+-- | When passed PreserveExisting, only ensures the property when the file
+-- does not exist.
+checkOverwrite :: Overwrite -> FilePath -> (FilePath -> Property i) -> Property i
+checkOverwrite OverwriteExisting f mkp = mkp f
+checkOverwrite PreserveExisting f mkp =
+ check (not <$> doesFileExist f) (mkp f)
diff --git a/src/Propellor/Property/XFCE.hs b/src/Propellor/Property/XFCE.hs
index e0c062ae..6241326e 100644
--- a/src/Propellor/Property/XFCE.hs
+++ b/src/Propellor/Property/XFCE.hs
@@ -15,11 +15,9 @@ installedMin :: Property DebianLike
installedMin = Apt.installedMin ["xfce4", "xfce4-terminal", "task-desktop"]
`describe` "minimal XFCE desktop installed"
-data Overwrite = OverwriteExisting | PreserveExisting
-
-- | Normally at first login, XFCE asks what kind of panel the user wants.
-- This enables the default configuration noninteractively.
-defaultPanelFor :: User -> Overwrite -> Property DebianLike
+defaultPanelFor :: User -> File.Overwrite -> Property DebianLike
defaultPanelFor u@(User username) overwrite = property' desc $ \w -> do
home <- liftIO $ User.homedir u
ensureProperty w (go home)
@@ -30,13 +28,9 @@ defaultPanelFor u@(User username) overwrite = property' desc $ \w -> do
-- This location is probably Debian-specific.
defcf = "/etc/xdg/xfce4/panel/default.xml"
go :: FilePath -> Property DebianLike
- go home = tightenTargets $ checkoverwrite cf
- cf `File.isCopyOf` defcf
- `before` File.applyPath home basecf
- (\f -> File.ownerGroup f u (userGroup u))
- `requires` Apt.installed ["xfce4-panel"]
- where
- cf = home </> basecf
- checkoverwrite cf p = case overwrite of
- OverwriteExisting -> p
- PreserveExisting -> check (not <$> doesFileExist cf) p
+ go home = tightenTargets $
+ File.checkOverwrite overwrite (home </> basecf) $ \cf ->
+ cf `File.isCopyOf` defcf
+ `before` File.applyPath home basecf
+ (\f -> File.ownerGroup f u (userGroup u))
+ `requires` Apt.installed ["xfce4-panel"]