Class: Specinfra::Command::Base::Group
Class Method Summary
collapse
create, escape
Class Method Details
.add(group, options) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/specinfra/command/base/group.rb', line 27
def add(group, options)
command = ['groupadd']
command << '-g' << escape(options[:gid]) if options[:gid]
command << '-r' if options[:system_group]
command << escape(group)
command.join(' ')
end
|
.check_exists(group) ⇒ Object
3
4
5
|
# File 'lib/specinfra/command/base/group.rb', line 3
def check_exists(group)
"getent group #{escape(group)}"
end
|
.check_has_gid(group, gid) ⇒ Object
7
8
9
|
# File 'lib/specinfra/command/base/group.rb', line 7
def check_has_gid(group, gid)
"getent group #{escape(group)} | cut -f 3 -d ':' | grep -w -- #{escape(gid)}"
end
|
.check_is_system_group(group) ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/specinfra/command/base/group.rb', line 11
def check_is_system_group(group)
exists = "getent group #{escape(group)} > /dev/null 2>&1"
gid = "getent group #{escape(group)} | cut -f 3 -d ':'"
sys_gid_min = "awk 'BEGIN{sys_gid_min=101} {if($1~/^SYS_GID_MIN/){sys_gid_min=$2}} END{print sys_gid_min}' /etc/login.defs"
sys_gid_max = "awk 'BEGIN{sys_gid_max=0;gid_min=1000} {if($1~/^SYS_GID_MAX/){sys_gid_max=$2}if($1~/^GID_MIN/){gid_min=$2}} END{if(sys_gid_max!=0){print sys_gid_max}else{print gid_min-1}}' /etc/login.defs"
%Q|#{exists} && test "$(#{gid})" -ge "$(#{sys_gid_min})" && test "$(#{gid})" -le "$(#{sys_gid_max})"|
end
|
.get_gid(group) ⇒ Object
19
20
21
|
# File 'lib/specinfra/command/base/group.rb', line 19
def get_gid(group)
"getent group #{escape(group)} | cut -f 3 -d ':'"
end
|
.update_gid(group, gid) ⇒ Object
23
24
25
|
# File 'lib/specinfra/command/base/group.rb', line 23
def update_gid(group, gid)
"groupmod -g #{escape(gid)} #{escape(group)}"
end
|