From 93d698a803d8ca2d8290dc7b79ee8c319fad2522 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 24 Nov 2015 17:05:55 -0400 Subject: User.hasDesktopGroups changed to avoid trying to add the user to groups that don't exist. This is the same method user-setup uses. --- src/Propellor/Property/User.hs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/Propellor/Property/User.hs') 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 -- cgit v1.2.3