sysutil 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/sysutil.rb +3 -4
- data/lib/sysutil/config.rb +2 -2
- data/lib/sysutil/functions.rb +0 -29
- data/lib/sysutil/{user.rb → users.rb} +27 -16
- data/lib/sysutil/version/version.rb +1 -1
- metadata +2 -3
- data/lib/sysutil/package.rb +0 -78
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d81e1c128b1f874507dc9d3eeec6bf1995226a1
|
4
|
+
data.tar.gz: 9f8eb69342f660e32e1b3e02b951755dbdb59658
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 480017b1281b61f29baa67d363200921cddb203148dc14b96bbcb0f85c3da087732d3e316b213658373dc438d19d7afe283b64eeb7eb4916391dc51c4e08e89a
|
7
|
+
data.tar.gz: 177e750809b127c72ccb9abcbcbef7f59fa1c5750cc5b5de9c98fe492a052801fb889e1bcbe5b16e06c63e34927f30041aebbc543d313e3de2f3ab7363a413c2
|
data/lib/sysutil.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
require "sysutil/version/version"
|
2
|
-
require "sysutil/functions"
|
3
2
|
require "sysutil/config"
|
4
3
|
|
5
4
|
module Sysutil
|
6
|
-
|
5
|
+
|
7
6
|
end
|
8
7
|
|
9
|
-
require "sysutil/
|
10
|
-
require "sysutil/
|
8
|
+
require "sysutil/functions"
|
9
|
+
require "sysutil/users"
|
11
10
|
|
12
11
|
|
13
12
|
|
data/lib/sysutil/config.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
module
|
1
|
+
module Sysutil
|
2
2
|
# Configuration defaults
|
3
3
|
@config = {
|
4
4
|
log_level: 'verbose', # print all the things
|
5
|
-
root_password: ''
|
5
|
+
root_password: '' # not necessary if your running this as root
|
6
6
|
}
|
7
7
|
|
8
8
|
@valid_config_keys = @config.keys
|
data/lib/sysutil/functions.rb
CHANGED
@@ -1,29 +0,0 @@
|
|
1
|
-
def conditional_sudo
|
2
|
-
if `echo -n $USER` != "root"
|
3
|
-
"echo #{Config.config[:root_password]} | sudo -S "
|
4
|
-
else
|
5
|
-
""
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
def linux_variant
|
10
|
-
r = { :distro => nil, :family => nil }
|
11
|
-
|
12
|
-
if File.exists?('/etc/lsb-release')
|
13
|
-
File.open('/etc/lsb-release', 'r').read.each_line do |line|
|
14
|
-
r = { :distro => $1 } if line =~ /^DISTRIB_ID=(.*)/
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
if File.exists?('/etc/debian_version')
|
19
|
-
r[:distro] = 'Debian' if r[:distro].nil?
|
20
|
-
r[:family] = 'Debian' if r[:variant].nil?
|
21
|
-
elsif File.exists?('/etc/redhat-release') or File.exists?('/etc/centos-release')
|
22
|
-
r[:family] = 'RedHat' if r[:family].nil?
|
23
|
-
r[:distro] = 'CentOS' if File.exists?('/etc/centos-release')
|
24
|
-
elsif File.exists?('/etc/SuSE-release')
|
25
|
-
r[:distro] = 'SLES' if r[:distro].nil?
|
26
|
-
end
|
27
|
-
|
28
|
-
return r
|
29
|
-
end
|
@@ -17,23 +17,23 @@ module Sysutil
|
|
17
17
|
|
18
18
|
if status.success?
|
19
19
|
# Split the output on the newline to make an array of users
|
20
|
-
|
20
|
+
out.split("\n")
|
21
21
|
else
|
22
|
-
|
22
|
+
"Error: #{err}"
|
23
23
|
end
|
24
24
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def self.add!(name, opts={})
|
28
28
|
|
29
|
-
add_user_command =
|
29
|
+
add_user_command = cond_sudo + "adduser #{name}"
|
30
30
|
|
31
31
|
out, err, status = Open3.capture3(add_user_command)
|
32
32
|
|
33
33
|
if status.success?
|
34
|
-
|
34
|
+
true
|
35
35
|
else
|
36
|
-
|
36
|
+
"Error: #{err}"
|
37
37
|
end
|
38
38
|
|
39
39
|
end
|
@@ -41,26 +41,26 @@ module Sysutil
|
|
41
41
|
def self.set_password!(user, password, confirmation)
|
42
42
|
|
43
43
|
# TODO: Change user password in such a way that we don't need chpasswd
|
44
|
-
set_password_command =
|
44
|
+
set_password_command = cond_sudo + "echo \"#{user}:#{password}\" | /usr/sbin/chpasswd"
|
45
45
|
puts set_password_command
|
46
46
|
|
47
47
|
if password == confirmation
|
48
48
|
out, err, status = Open3.capture3(set_password_command)
|
49
49
|
|
50
50
|
if status.success?
|
51
|
-
|
51
|
+
true
|
52
52
|
else
|
53
|
-
|
53
|
+
"Error: #{err}"
|
54
54
|
end
|
55
55
|
else
|
56
|
-
|
56
|
+
"Error: Passwords don't match"
|
57
57
|
end
|
58
58
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def self.delete!(name, opts={})
|
62
62
|
|
63
|
-
delete_user_command =
|
63
|
+
delete_user_command = cond_sudo + "userdel #{name}"
|
64
64
|
|
65
65
|
if opts[:force]
|
66
66
|
delete_user_command += ' --force'
|
@@ -73,9 +73,9 @@ module Sysutil
|
|
73
73
|
out, err, status = Open3.capture3(delete_user_command)
|
74
74
|
|
75
75
|
if status.success?
|
76
|
-
|
76
|
+
true
|
77
77
|
else
|
78
|
-
|
78
|
+
"Error: #{err}"
|
79
79
|
end
|
80
80
|
|
81
81
|
end
|
@@ -89,9 +89,9 @@ module Sysutil
|
|
89
89
|
out, err, status = Open3.capture3(add_to_group_command)
|
90
90
|
|
91
91
|
if status.success?
|
92
|
-
|
92
|
+
true
|
93
93
|
else
|
94
|
-
|
94
|
+
"Error: #{err}"
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
@@ -103,12 +103,23 @@ module Sysutil
|
|
103
103
|
|
104
104
|
if status.success?
|
105
105
|
groups = /(?<=\: )([a-z ]+)/.match(out).to_s.split(' ')
|
106
|
-
|
106
|
+
return groups
|
107
107
|
else
|
108
|
-
|
108
|
+
"Error: #{err}"
|
109
109
|
end
|
110
110
|
|
111
111
|
end
|
112
|
+
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
def self.cond_sudo
|
117
|
+
if current_user != "root"
|
118
|
+
"echo #{Sysutil::config[:root_password]} | sudo -S "
|
119
|
+
else
|
120
|
+
""
|
121
|
+
end
|
122
|
+
end
|
112
123
|
|
113
124
|
end
|
114
125
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sysutil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Watson
|
@@ -86,9 +86,8 @@ files:
|
|
86
86
|
- lib/sysutil.rb
|
87
87
|
- lib/sysutil/config.rb
|
88
88
|
- lib/sysutil/functions.rb
|
89
|
-
- lib/sysutil/package.rb
|
90
89
|
- lib/sysutil/railtie.rb
|
91
|
-
- lib/sysutil/
|
90
|
+
- lib/sysutil/users.rb
|
92
91
|
- lib/sysutil/version/version.rb
|
93
92
|
- sysutil-0.1.0.gem
|
94
93
|
- sysutil.gemspec
|
data/lib/sysutil/package.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
require 'open3'
|
2
|
-
require_relative 'config.rb'
|
3
|
-
|
4
|
-
module Sysutil
|
5
|
-
|
6
|
-
class Package
|
7
|
-
|
8
|
-
def self.install!(*packages)
|
9
|
-
|
10
|
-
packages = packages.join(' ')
|
11
|
-
|
12
|
-
install_command = case linux_variant[:family]
|
13
|
-
when 'Debian'
|
14
|
-
'apt-get install -y'
|
15
|
-
when 'Redhat'
|
16
|
-
'yum install -y'
|
17
|
-
when 'Solaris'
|
18
|
-
'pkg install'
|
19
|
-
end
|
20
|
-
|
21
|
-
install_command = conditional_sudo + install_command
|
22
|
-
out, err, status = Open3.capture3(install_command)
|
23
|
-
|
24
|
-
if status.success?
|
25
|
-
{success: true, output: out}
|
26
|
-
else
|
27
|
-
{success: false, output: "Error: #{err}"}
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.remove!(*packages)
|
33
|
-
|
34
|
-
remove_command = case linux_variant[:family]
|
35
|
-
when 'Debian'
|
36
|
-
'apt-get remove -y'
|
37
|
-
when 'Redhat'
|
38
|
-
'yum remove -y'
|
39
|
-
when 'Solaris'
|
40
|
-
'pkg-delete'
|
41
|
-
end
|
42
|
-
|
43
|
-
remove_command = conditional_sudo + remove_command
|
44
|
-
out, err, status = Open3.capture3(remove_command)
|
45
|
-
|
46
|
-
if status.success?
|
47
|
-
{success: true, output: out}
|
48
|
-
else
|
49
|
-
{success: false, output: "Error: #{err}"}
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
def self.autoremove!
|
55
|
-
|
56
|
-
autoremove_command = case linux_variant[:family]
|
57
|
-
when 'Debian'
|
58
|
-
'apt-get autoremove -y'
|
59
|
-
when 'Redhat'
|
60
|
-
'yum autoremove'
|
61
|
-
when 'Solaris'
|
62
|
-
'pkg-delete -a'
|
63
|
-
end
|
64
|
-
|
65
|
-
autoremove_command = conditional_sudo + autoremove_command
|
66
|
-
out, err, status = Open3.capture3(autoremove_command)
|
67
|
-
|
68
|
-
if status.success?
|
69
|
-
{success: true, message: out}
|
70
|
-
else
|
71
|
-
{success: true, output: "Error: #{err}"}
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|