Module: Kanrisuru::Core::Group
- Extended by:
- OsPackage::Define
- Defined in:
- lib/kanrisuru/core/group.rb,
lib/kanrisuru/core/group/types.rb,
lib/kanrisuru/core/group/parsers/gid.rb,
lib/kanrisuru/core/group/parsers/group.rb,
lib/kanrisuru/core/group/commands/get_gid.rb,
lib/kanrisuru/core/group/commands/is_group.rb,
lib/kanrisuru/core/group/commands/get_group.rb,
lib/kanrisuru/core/group/commands/create_group.rb,
lib/kanrisuru/core/group/commands/delete_group.rb,
lib/kanrisuru/core/group/commands/update_group.rb
Defined Under Namespace
Modules: Parser
Classes: Group, GroupUser
Instance Method Summary
collapse
extended, os_define
Instance Method Details
#create_group(group, opts = {}) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/kanrisuru/core/group/commands/create_group.rb', line 6
def create_group(group, opts = {})
gid = opts[:gid]
command = Kanrisuru::Command.new("groupadd #{group}")
command.append_arg('-g', gid)
command.append_flag('-o', opts[:non_unique])
command.append_flag('-r', opts[:system])
execute_shell(command)
Kanrisuru::Result.new(command) do
gid = Kanrisuru::Util.present?(gid) ? gid : get_gid(group).data
Group.new(gid, group)
end
end
|
#delete_group(group) ⇒ Object
6
7
8
9
10
11
12
13
|
# File 'lib/kanrisuru/core/group/commands/delete_group.rb', line 6
def delete_group(group)
return false unless group?(group)
command = Kanrisuru::Command.new("groupdel #{group}")
execute_shell(command)
Kanrisuru::Result.new(command)
end
|
#get_group(group) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/kanrisuru/core/group/commands/get_group.rb', line 6
def get_group(group)
command = Kanrisuru::Command.new("getent group #{group} | cut -d: -f4")
execute(command)
Kanrisuru::Result.new(command) do |cmd|
result = get_gid(group)
break if result.failure?
gid = result.to_i
users = Parser::Group.parse(cmd)
users = users.map do |user|
uid = get_uid(user)
GroupUser.new(uid.to_i, user)
end
Group.new(gid, group, users)
end
end
|
#group?(group) ⇒ Boolean
6
7
8
9
10
11
|
# File 'lib/kanrisuru/core/group/commands/is_group.rb', line 6
def group?(group)
result = get_gid(group)
return false if result.failure?
Kanrisuru::Util.present?(result.data) && result.data.instance_of?(Integer)
end
|
#update_group(group, opts = {}) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/kanrisuru/core/group/commands/update_group.rb', line 6
def update_group(group, opts = {})
gid = opts[:gid]
return if Kanrisuru::Util.blank?(gid) || Kanrisuru::Util.blank?(opts[:new_name])
command = Kanrisuru::Command.new("groupmod #{group}")
command.append_arg('-g', gid)
command.append_arg('-n', opts[:new_name])
execute_shell(command)
Kanrisuru::Result.new(command) do
gid = Kanrisuru::Util.present?(gid) ? gid : get_gid(group).data
Group.new(gid, group)
end
end
|