2
# Author:: Stephen Haynes (<sh@nomitor.com>)
3
# Copyright:: Copyright (c) 2009 Opscode, Inc.
4
# License:: Apache License, Version 2.0
6
# Licensed under the Apache License, Version 2.0 (the "License");
7
# you may not use this file except in compliance with the License.
8
# You may obtain a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS,
14
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
# See the License for the specific language governing permissions and
16
# limitations under the License.
22
class Pw < Chef::Provider::Group
24
def load_current_resource
26
raise Chef::Exceptions::Group, "Could not find binary /usr/sbin/pw for #{@new_resource}" unless ::File.exists?("/usr/sbin/pw")
31
command = "pw groupadd"
32
command << set_options
33
command << set_members_option
34
run_command(:command => command)
37
# Manage the group when it already exists
39
command = "pw groupmod"
40
command << set_options
41
command << set_members_option
42
run_command(:command => command)
47
run_command(:command => "pw groupdel #{@new_resource.group_name}")
50
# Little bit of magic as per Adam's useradd provider to pull and assign the command line flags
53
# <string>:: A string containing the option and then the quoted value
55
opts = " #{@new_resource.group_name}"
56
{ :gid => "-g" }.sort { |a,b| a[0] <=> b[0] }.each do |field, option|
57
if @current_resource.send(field) != @new_resource.send(field)
58
if @new_resource.send(field)
59
Chef::Log.debug("#{@new_resource}: setting #{field.to_s} to #{@new_resource.send(field)}")
60
opts << " #{option} '#{@new_resource.send(field)}'"
67
# Set the membership option depending on the current resource states
68
def set_members_option
70
unless @new_resource.members.empty?
71
opt << " -M #{@new_resource.members.join(',')}"
72
Chef::Log.debug("#{@new_resource}: setting group members to #{@new_resource.members.join(', ')}")
74
# New member list is empty so we should delete any old group members
75
unless @current_resource.members.empty?
76
opt << " -d #{@current_resource.members.join(',')}"
77
Chef::Log.debug("#{@new_resource}: removing group members #{@current_resource.members.join(', ')}")
79
Chef::Log.debug("#{@new_resource}: not changing group members, the group has no members")
b'\\ No newline at end of file'