LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File CHEF-4015-group.patch of Package rubygem-chef (Project systemsmanagement:chef:master)

From 2c90179e0aad4a8e41c33bb10fa2ec25e2eadf46 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ionu=C8=9B=20Ar=C8=9B=C4=83ri=C8=99i?= <iartarisi@suse.cz>
Date: Tue, 19 Mar 2013 16:29:02 +0100
Subject: [PATCH] CHEF-4015 fix group provider for openSUSE 12.3

openSUSE 12.3 switched to shadow-utils where groupadd doesn't have the
-A option, instead the usermod command now works similar to other
distributions
---
 lib/chef/provider/group/suse.rb |   25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/lib/chef/provider/group/suse.rb b/lib/chef/provider/group/suse.rb
index 0b66c1f..b01bce0 100644
--- a/lib/chef/provider/group/suse.rb
+++ b/lib/chef/provider/group/suse.rb
@@ -41,19 +41,34 @@ class Chef
 
         def modify_group_members
           unless @new_resource.members.empty?
+            group = @new_resource.group_name
             if(@new_resource.append)
               @new_resource.members.each do |member|
-                Chef::Log.debug("#{@new_resource} appending member #{member} to group #{@new_resource.group_name}")
-                shell_out!("groupmod -A #{member} #{@new_resource.group_name}")
+                Chef::Log.debug("#{@new_resource} appending member #{member} "\
+                                "to group #{group}")
+                modify_group(group, member)
               end
             else
-              Chef::Log.debug("#{@new_resource} setting group members to #{@new_resource.members.join(', ')}")
-              shell_out!("groupmod -A #{@new_resource.members.join(',')} #{@new_resource.group_name}")
+              members = @new_resource.members.join(', ')
+              Chef::Log.debug("#{@new_resource} setting group members to "\
+                              "#{members}")
+              modify_group(group, members)
             end
           else
-            Chef::Log.debug("#{@new_resource} not changing group members, the group has no members")
+            Chef::Log.debug("#{@new_resource} not changing group members, "\
+                            "the group has no members")
           end
         end
+
+        private
+        def modify_group(group, member)
+          if node['platform_version'].to_f >= 12.3
+            modify_group_cmd = "usermod --append --groups #{group} #{member}"
+          else
+            modify_group_cmd = "groupmod -A #{member} #{group}"
+          end
+          shell_out!(modify_group_cmd)
+        end
       end
     end
   end
-- 
1.7.10.4