summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/User.hs
diff options
context:
space:
mode:
authorJoey Hess2015-11-24 17:05:55 -0400
committerJoey Hess2015-11-24 17:06:46 -0400
commit93d698a803d8ca2d8290dc7b79ee8c319fad2522 (patch)
tree93cd1786b58a1cc4b4a373dcdf5b0dbd65bf07bb /src/Propellor/Property/User.hs
parent6f949b35602f7b2095b7248981dce7381a09852d (diff)
User.hasDesktopGroups changed to avoid trying to add the user to groups that don't exist.
This is the same method user-setup uses.
Diffstat (limited to 'src/Propellor/Property/User.hs')
-rw-r--r--src/Propellor/Property/User.hs11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/Propellor/Property/User.hs b/src/Propellor/Property/User.hs
index f3842892..5bb4e1a7 100644
--- a/src/Propellor/Property/User.hs
+++ b/src/Propellor/Property/User.hs
@@ -1,6 +1,7 @@
module Propellor.Property.User where
import System.Posix
+import Data.List
import Propellor.Base
import qualified Propellor.Property.File as File
@@ -109,9 +110,15 @@ hasGroup (User user) (Group group') = check test $ cmdProperty "adduser"
-- | Gives a user access to the secondary groups, including audio and
-- video, that the OS installer normally gives a desktop user access to.
+--
+-- Note that some groups may only exit after installation of other
+-- software. When a group does not exist yet, the user won't be added to it.
hasDesktopGroups :: User -> Property NoInfo
-hasDesktopGroups user@(User u) = combineProperties desc $
- map (hasGroup user . Group) desktopgroups
+hasDesktopGroups user@(User u) = property desc $ do
+ existinggroups <- map (fst . break (== ':')) . lines
+ <$> liftIO (readFile "/etc/group")
+ let toadd = filter (`elem` existinggroups) desktopgroups
+ ensureProperty $ propertyList desc $ map (hasGroup user . Group) toadd
where
desc = "user " ++ u ++ " is in standard desktop groups"
-- This list comes from user-setup's debconf