sysutil 0.1.0 → 0.2.0
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/README.md +4 -4
- data/lib/sysutil.rb +4 -3
- data/lib/sysutil/config.rb +2 -2
- data/lib/sysutil/functions.rb +29 -0
- data/lib/sysutil/package.rb +78 -0
- data/lib/sysutil/{users.rb → user.rb} +16 -27
- data/lib/sysutil/version/version.rb +1 -1
- data/sysutil-0.1.0.gem +0 -0
- data/sysutil.gemspec +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2597c873a67e046107efaca3fb70770fd443b0f
|
4
|
+
data.tar.gz: 1c73413186de1faef98e595ed47bfabc6d4b3523
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c37d39a062c3b4dfb44e89b9186ccfc67b243be518ab1c4116d814b8e42737b697beff5a8c18421d9c4681a6973d08b058e051353442b05b10dedd52df5103e
|
7
|
+
data.tar.gz: 4267f0c9f78447567fc147df90faca7dd0bcfcaa8b3d9b55ae4668378f0803cd5cdd3a4f12f23b2dbcac822a2872827ca374860b63ef9d4b9623f50742cc35e7
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Sysutil
|
2
2
|
|
3
|
-
|
3
|
+
[](https://badge.fury.io/rb/sysutil)
|
4
4
|
|
5
|
-
|
5
|
+
Sysutil is a gem wrapper for a host of linux system functions such as modifying users.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -22,7 +22,7 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
Usage instructions will be in the [Wiki](https://github.com/iDev0urer/sysutil_gem/wiki)
|
26
26
|
|
27
27
|
## Development
|
28
28
|
|
@@ -32,7 +32,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
32
|
|
33
33
|
## Contributing
|
34
34
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/iDevourer/sysutil. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
36
36
|
|
37
37
|
|
38
38
|
## License
|
data/lib/sysutil.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
require "sysutil/version/version"
|
2
|
+
require "sysutil/functions"
|
2
3
|
require "sysutil/config"
|
3
4
|
|
4
5
|
module Sysutil
|
5
|
-
|
6
|
+
include Config
|
6
7
|
end
|
7
8
|
|
8
|
-
require "sysutil/
|
9
|
-
require "sysutil/
|
9
|
+
require "sysutil/user"
|
10
|
+
require "sysutil/package"
|
10
11
|
|
11
12
|
|
12
13
|
|
data/lib/sysutil/config.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
module
|
1
|
+
module Config
|
2
2
|
# Configuration defaults
|
3
3
|
@config = {
|
4
4
|
log_level: 'verbose', # print all the things
|
5
|
-
root_password: '' # not necessary if your running this as root
|
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
@@ -0,0 +1,29 @@
|
|
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
|
@@ -0,0 +1,78 @@
|
|
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
|
@@ -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
|
-
out.split("\n")
|
20
|
+
{success: true, output: out.split("\n")}
|
21
21
|
else
|
22
|
-
"Error: #{err}"
|
22
|
+
{success: false, message: "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 = conditional_sudo + "adduser #{name}"
|
30
30
|
|
31
31
|
out, err, status = Open3.capture3(add_user_command)
|
32
32
|
|
33
33
|
if status.success?
|
34
|
-
true
|
34
|
+
{success: true, output: out}
|
35
35
|
else
|
36
|
-
"Error: #{err}"
|
36
|
+
{success: false, output: "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 = conditional_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
|
-
true
|
51
|
+
{succesS: true, output: out}
|
52
52
|
else
|
53
|
-
"Error: #{err}"
|
53
|
+
{success: false, output: "Error: #{err}"}
|
54
54
|
end
|
55
55
|
else
|
56
|
-
"Error: Passwords don't match"
|
56
|
+
{success: false, output: "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 = conditional_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
|
-
true
|
76
|
+
{success: true, output: out}
|
77
77
|
else
|
78
|
-
"Error: #{err}"
|
78
|
+
{success: false, output: "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
|
-
true
|
92
|
+
{success: true, output: out}
|
93
93
|
else
|
94
|
-
"Error: #{err}"
|
94
|
+
{success: false, output: "Error: #{err}"}
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
@@ -103,23 +103,12 @@ module Sysutil
|
|
103
103
|
|
104
104
|
if status.success?
|
105
105
|
groups = /(?<=\: )([a-z ]+)/.match(out).to_s.split(' ')
|
106
|
-
|
106
|
+
{success: true, output: groups}
|
107
107
|
else
|
108
|
-
"Error: #{err}"
|
108
|
+
{success: true, message: "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
|
123
112
|
|
124
113
|
end
|
125
114
|
|
data/sysutil-0.1.0.gem
ADDED
Binary file
|
data/sysutil.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
|
12
12
|
spec.summary = "Control linux with ruby"
|
13
13
|
spec.description = "Library that acts as a wrapper for various linux commands"
|
14
|
-
spec.homepage = "
|
14
|
+
spec.homepage = "https://github.com/iDev0urer/sysutil_gem"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sysutil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Watson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,11 +86,13 @@ files:
|
|
86
86
|
- lib/sysutil.rb
|
87
87
|
- lib/sysutil/config.rb
|
88
88
|
- lib/sysutil/functions.rb
|
89
|
+
- lib/sysutil/package.rb
|
89
90
|
- lib/sysutil/railtie.rb
|
90
|
-
- lib/sysutil/
|
91
|
+
- lib/sysutil/user.rb
|
91
92
|
- lib/sysutil/version/version.rb
|
93
|
+
- sysutil-0.1.0.gem
|
92
94
|
- sysutil.gemspec
|
93
|
-
homepage:
|
95
|
+
homepage: https://github.com/iDev0urer/sysutil_gem
|
94
96
|
licenses:
|
95
97
|
- MIT
|
96
98
|
metadata: {}
|