rubycut-babushka 0.10.8 → 0.15.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +17 -15
- data/README.markdown +163 -41
- data/Rakefile +1 -1
- data/bin/babushka +1 -1
- data/deps/apt.rb +44 -0
- data/deps/babushka.rb +54 -42
- data/deps/deprecated.rb +16 -0
- data/deps/dev.rb +28 -3
- data/deps/git.rb +27 -12
- data/deps/homebrew.rb +2 -2
- data/deps/packages.rb +14 -15
- data/deps/pkg_managers.rb +21 -75
- data/deps/ruby.rb +5 -19
- data/deps/rubygems.rb +3 -3
- data/deps/system.rb +2 -2
- data/deps/templates/app.rb +60 -41
- data/deps/templates/bin.rb +16 -0
- data/deps/templates/installer.rb +9 -9
- data/deps/templates/lib.rb +17 -0
- data/deps/templates/managed.rb +1 -38
- data/deps/templates/src.rb +16 -8
- data/deps/templates/task.rb +11 -0
- data/deps/templates/tmbundle.rb +16 -2
- data/lib/babushka.rb +2 -3
- data/lib/babushka/accepts_block_for.rb +5 -3
- data/lib/babushka/asset.rb +172 -0
- data/lib/babushka/base.rb +37 -8
- data/lib/babushka/bug_reporter.rb +6 -6
- data/lib/babushka/cmdline.rb +11 -10
- data/lib/babushka/cmdline/handler.rb +7 -3
- data/lib/babushka/cmdline/helpers.rb +15 -23
- data/lib/babushka/cmdline/parser.rb +1 -1
- data/lib/babushka/core_patches/object.rb +1 -1
- data/lib/babushka/core_patches/string.rb +8 -3
- data/lib/babushka/current_ruby.rb +44 -0
- data/lib/babushka/dep.rb +111 -185
- data/lib/babushka/dep_context.rb +8 -3
- data/lib/babushka/dep_definer.rb +45 -15
- data/lib/babushka/dep_pool.rb +5 -8
- data/lib/babushka/{meta_dep.rb → dep_template.rb} +21 -2
- data/lib/babushka/dsl.rb +3 -0
- data/lib/babushka/git_repo.rb +143 -49
- data/lib/babushka/helpers/git_helpers.rb +7 -6
- data/lib/babushka/helpers/log_helpers.rb +51 -13
- data/lib/babushka/helpers/path_helpers.rb +5 -7
- data/lib/babushka/helpers/run_helpers.rb +15 -55
- data/lib/babushka/helpers/shell_helpers.rb +18 -26
- data/lib/babushka/helpers/uri_helpers.rb +9 -18
- data/lib/babushka/lambda_chooser.rb +20 -13
- data/lib/babushka/parameter.rb +20 -4
- data/lib/babushka/path_checker.rb +72 -0
- data/lib/babushka/pkg_helper.rb +38 -13
- data/lib/babushka/pkg_helpers/apt_helper.rb +15 -8
- data/lib/babushka/pkg_helpers/binpkgsrc_helper.rb +15 -14
- data/lib/babushka/pkg_helpers/binports_helper.rb +7 -7
- data/lib/babushka/pkg_helpers/brew_helper.rb +17 -25
- data/lib/babushka/pkg_helpers/gem_helper.rb +36 -27
- data/lib/babushka/pkg_helpers/npm_helper.rb +9 -9
- data/lib/babushka/pkg_helpers/pacman_helper.rb +5 -4
- data/lib/babushka/pkg_helpers/pip_helper.rb +14 -10
- data/lib/babushka/pkg_helpers/unknown_pkg_helper.rb +19 -0
- data/lib/babushka/pkg_helpers/yum_helper.rb +1 -1
- data/lib/babushka/popen.rb +13 -10
- data/lib/babushka/prompt.rb +14 -1
- data/lib/babushka/renderable.rb +11 -9
- data/lib/babushka/resource.rb +5 -166
- data/lib/babushka/run_reporter.rb +12 -3
- data/lib/babushka/shell.rb +54 -44
- data/lib/babushka/source.rb +41 -20
- data/lib/babushka/source_pool.rb +20 -13
- data/lib/babushka/system_definitions.rb +11 -3
- data/lib/babushka/system_detector.rb +31 -0
- data/lib/babushka/system_matcher.rb +53 -0
- data/lib/babushka/system_profile.rb +67 -89
- data/lib/babushka/task.rb +36 -8
- data/lib/babushka/{meta_dep_context.rb → templated_dep_context.rb} +1 -1
- data/lib/babushka/vars.rb +46 -4
- data/lib/babushka/version_of.rb +35 -17
- data/lib/babushka/version_str.rb +12 -8
- data/lib/components.rb +9 -8
- data/lib/fancypath/fancypath.rb +109 -83
- data/lib/inkan/inkan.rb +14 -14
- data/lib/{babushka → levenshtein}/levenshtein.rb +0 -0
- data/spec/acceptance/acceptance.rb +4 -4
- data/spec/acceptance_helper.rb +10 -6
- data/spec/babushka/accepts_for_spec.rb +137 -142
- data/spec/babushka/accepts_for_support.rb +13 -6
- data/spec/babushka/asset_spec.rb +165 -0
- data/spec/babushka/cmdline/help_spec.rb +11 -9
- data/spec/babushka/cmdline/meet_spec.rb +15 -0
- data/spec/babushka/cmdline/version_spec.rb +1 -1
- data/spec/babushka/core_patches_spec.rb +9 -0
- data/spec/babushka/current_ruby_spec.rb +73 -0
- data/spec/babushka/dep_context_spec.rb +27 -13
- data/spec/babushka/dep_definer_spec.rb +108 -16
- data/spec/babushka/dep_spec.rb +87 -104
- data/spec/babushka/dep_template_spec.rb +176 -0
- data/spec/babushka/deps_spec.rb +48 -19
- data/spec/babushka/gem_helper_spec.rb +46 -59
- data/spec/babushka/git_repo_spec.rb +242 -51
- data/spec/babushka/ip_spec.rb +11 -11
- data/spec/babushka/lambda_chooser_spec.rb +47 -9
- data/spec/babushka/parameter_spec.rb +21 -0
- data/spec/babushka/path_checker_spec.rb +35 -0
- data/spec/babushka/path_helpers_spec.rb +51 -50
- data/spec/babushka/prompt_spec.rb +4 -4
- data/spec/babushka/renderable_spec.rb +61 -28
- data/spec/babushka/shell_helpers_spec.rb +110 -85
- data/spec/babushka/shell_spec.rb +15 -0
- data/spec/babushka/source_pool_spec.rb +204 -210
- data/spec/babushka/source_spec.rb +125 -42
- data/spec/babushka/source_support.rb +1 -1
- data/spec/babushka/system_profile_spec.rb +86 -49
- data/spec/babushka/task_spec.rb +80 -13
- data/spec/babushka/vars_spec.rb +2 -1
- data/spec/babushka/version_of_spec.rb +29 -2
- data/spec/babushka/version_str_spec.rb +91 -65
- data/spec/babushka/xml_string_spec.rb +1 -1
- data/spec/deps/bad/broken.rb +2 -2
- data/spec/deps/bad/working.rb +0 -1
- data/spec/deps/good/{meta.rb → template.rb} +0 -0
- data/spec/deps/good/test.rb +0 -3
- data/spec/deps/outer/deps.rb +0 -2
- data/spec/fancypath/fancypath_spec.rb +30 -0
- data/spec/inkan/inkan_spec.rb +34 -32
- data/spec/spec_helper.rb +7 -50
- data/spec/system_detector_spec.rb +70 -0
- metadata +163 -177
- data/deps/os_x.rb +0 -33
- data/deps/templates/ppa.rb +0 -24
- data/lib/babushka/core_patches/io.rb +0 -8
- data/lib/babushka/dep_runner.rb +0 -85
- data/lib/babushka/helpers/suggest_helpers.rb +0 -16
- data/lib/babushka/pkg_helpers/base_helper.rb +0 -19
- data/lib/babushka/pkg_helpers/macports_helper.rb +0 -22
- data/spec/babushka/dep_definer_support.rb +0 -36
- data/spec/babushka/meta_dep_definer_spec.rb +0 -127
- data/spec/babushka/meta_dep_wrapper_spec.rb +0 -32
- data/spec/babushka/resource_spec.rb +0 -141
- data/spec/babushka/run_helpers_spec.rb +0 -26
- data/spec/babushka/source_pool_support.rb +0 -31
data/lib/babushka/source_pool.rb
CHANGED
@@ -7,8 +7,8 @@ module Babushka
|
|
7
7
|
SEPARATOR = ':'
|
8
8
|
|
9
9
|
def current
|
10
|
-
@
|
11
|
-
@
|
10
|
+
@current ||= default.concat(standard)
|
11
|
+
@current.dup
|
12
12
|
end
|
13
13
|
|
14
14
|
def default
|
@@ -24,16 +24,19 @@ module Babushka
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def anonymous
|
27
|
-
@
|
27
|
+
@anonymous ||= Source.new(nil, :name => 'anonymous')
|
28
28
|
end
|
29
|
+
|
29
30
|
def core
|
30
|
-
@
|
31
|
+
@core ||= Source.new(Path.path / 'deps', :name => 'core')
|
31
32
|
end
|
33
|
+
|
32
34
|
def current_dir
|
33
|
-
@
|
35
|
+
@current_dir ||= Source.new('./babushka-deps', :name => 'current dir')
|
34
36
|
end
|
37
|
+
|
35
38
|
def personal
|
36
|
-
@
|
39
|
+
@personal ||= Source.new('~/.babushka/deps', :name => 'personal')
|
37
40
|
end
|
38
41
|
|
39
42
|
def standard
|
@@ -41,7 +44,12 @@ module Babushka
|
|
41
44
|
end
|
42
45
|
|
43
46
|
def source_for name
|
44
|
-
|
47
|
+
(
|
48
|
+
all_present.detect {|source| source.name == name } ||
|
49
|
+
Source.for_remote(name)
|
50
|
+
).tap {|source|
|
51
|
+
source.load!(Base.task.opt(:update))
|
52
|
+
}
|
45
53
|
end
|
46
54
|
|
47
55
|
def dep_for dep_spec, opts = {}
|
@@ -50,9 +58,9 @@ module Babushka
|
|
50
58
|
elsif dep_spec[/#{SEPARATOR}/] # If a source was specified, that's where we load from.
|
51
59
|
source_name, dep_name = dep_spec.split(SEPARATOR, 2)
|
52
60
|
source_for(source_name).find(dep_name)
|
53
|
-
elsif opts[:from]
|
61
|
+
elsif opts[:from] # Next, try opts[:from], the requiring dep's source.
|
54
62
|
opts[:from].find(dep_spec) || dep_for(dep_spec)
|
55
|
-
else # Otherwise,
|
63
|
+
else # Otherwise, try the standard set.
|
56
64
|
matches = Base.sources.current.map {|source| source.find(dep_spec) }.flatten.compact
|
57
65
|
if matches.length > 1
|
58
66
|
log "Multiple sources (#{matches.map(&:dep_source).map(&:name).join(',')}) contain a dep called '#{dep_spec}'."
|
@@ -100,10 +108,6 @@ module Babushka
|
|
100
108
|
)
|
101
109
|
end
|
102
110
|
|
103
|
-
def uncache!
|
104
|
-
current.each {|source| source.deps.uncache! }
|
105
|
-
end
|
106
|
-
|
107
111
|
def local_only?
|
108
112
|
@local_only
|
109
113
|
end
|
@@ -126,12 +130,15 @@ module Babushka
|
|
126
130
|
def current_real_load_source
|
127
131
|
current_load_context[:source]
|
128
132
|
end
|
133
|
+
|
129
134
|
def current_load_source
|
130
135
|
current_real_load_source || Base.sources.anonymous
|
131
136
|
end
|
137
|
+
|
132
138
|
def current_load_path
|
133
139
|
current_load_context[:path].try(:p)
|
134
140
|
end
|
141
|
+
|
135
142
|
def current_load_opts
|
136
143
|
current_load_context[:opts] || {}
|
137
144
|
end
|
@@ -3,12 +3,15 @@ module Babushka
|
|
3
3
|
def self.all_systems
|
4
4
|
names.keys
|
5
5
|
end
|
6
|
+
|
6
7
|
def self.all_flavours
|
7
8
|
names.values.map(&:keys).flatten
|
8
9
|
end
|
10
|
+
|
9
11
|
def self.all_names
|
10
12
|
names.values.map(&:values).map {|s| s.map(&:values) }.flatten
|
11
13
|
end
|
14
|
+
|
12
15
|
def self.all_tokens
|
13
16
|
all_systems + PkgHelper.all_manager_keys + all_flavours + all_names
|
14
17
|
end
|
@@ -39,14 +42,17 @@ module Babushka
|
|
39
42
|
'9.10' => :karmic,
|
40
43
|
'10.04' => :lucid,
|
41
44
|
'10.10' => :maverick,
|
42
|
-
'11.04' => :natty
|
45
|
+
'11.04' => :natty,
|
46
|
+
'11.10' => :oneiric,
|
47
|
+
'12.04' => :precise
|
43
48
|
},
|
44
49
|
:debian => {
|
45
50
|
'4.0' => :etch,
|
46
51
|
'5.0' => :lenny,
|
47
52
|
'6.0' => :squeeze,
|
48
53
|
'7.0' => :wheezy
|
49
|
-
}
|
54
|
+
},
|
55
|
+
:arch => {}
|
50
56
|
},
|
51
57
|
:bsd => {
|
52
58
|
:dragonfly => {},
|
@@ -81,7 +87,9 @@ module Babushka
|
|
81
87
|
'9.10' => 'Karmic Koala',
|
82
88
|
'10.04' => 'Lucid Lynx',
|
83
89
|
'10.10' => 'Maverick Meerkat',
|
84
|
-
'11.04' => 'Natty Narwhal'
|
90
|
+
'11.04' => 'Natty Narwhal',
|
91
|
+
'11.10' => 'Oneiric Ocelot',
|
92
|
+
'12.04' => 'Precise Pangolin'
|
85
93
|
},
|
86
94
|
:debian => {
|
87
95
|
'5.0.4' => 'Lenny'
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Babushka
|
2
|
+
class SystemDetector
|
3
|
+
def self.profile_for_host
|
4
|
+
(detect_using_uname || UnknownSystem).new
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def self.detect_using_uname
|
10
|
+
case ShellHelpers.shell('uname -s')
|
11
|
+
when 'Darwin'; OSXSystemProfile
|
12
|
+
when 'DragonFly'; DragonFlySystemProfile
|
13
|
+
when 'FreeBSD'; FreeBSDSystemProfile
|
14
|
+
when 'Linux'; detect_using_release_file || LinuxSystemProfile
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.detect_using_release_file
|
19
|
+
{
|
20
|
+
'debian_version' => DebianSystemProfile,
|
21
|
+
'redhat-release' => RedhatSystemProfile,
|
22
|
+
'arch-release' => ArchSystemProfile,
|
23
|
+
'system-release' => FedoraSystemProfile,
|
24
|
+
# 'gentoo-release' =>
|
25
|
+
# 'SuSE-release' =>
|
26
|
+
}.selekt {|release_file, system_profile|
|
27
|
+
File.exists? "/etc/#{release_file}"
|
28
|
+
}.values.first
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Babushka
|
2
|
+
class SystemMatcher
|
3
|
+
attr_reader :system, :flavour, :name, :pkg_helper_key
|
4
|
+
|
5
|
+
def initialize system, flavour, name, pkg_helper_key
|
6
|
+
@system, @flavour, @name, @pkg_helper_key = system, flavour, name, pkg_helper_key
|
7
|
+
end
|
8
|
+
|
9
|
+
def list
|
10
|
+
[name, flavour, pkg_helper_key, system, :all].compact
|
11
|
+
end
|
12
|
+
|
13
|
+
def matches? specs
|
14
|
+
# TODO: shouldn't this just be:
|
15
|
+
# (list & [*specs]).any?
|
16
|
+
[*specs].any? {|spec| first_nonmatch_for(spec).nil? }
|
17
|
+
end
|
18
|
+
|
19
|
+
def differentiator_for specs
|
20
|
+
[*specs].map {|spec|
|
21
|
+
first_nonmatch_for spec
|
22
|
+
}.sort_by {|spec|
|
23
|
+
[:system, :flavour, :name].index spec
|
24
|
+
}.compact.last
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def first_nonmatch_for spec
|
30
|
+
if spec == :all
|
31
|
+
nil
|
32
|
+
elsif SystemDefinitions.all_systems.include? spec
|
33
|
+
spec == system ? nil : :system
|
34
|
+
elsif PkgHelper.all_manager_keys.include? spec
|
35
|
+
spec == pkg_helper_key ? nil : :pkg_helper
|
36
|
+
elsif our_flavours.include? spec
|
37
|
+
spec == flavour ? nil : :flavour
|
38
|
+
elsif our_flavour_names.include? spec
|
39
|
+
spec == name ? nil : :name
|
40
|
+
else
|
41
|
+
:system
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def our_flavours
|
46
|
+
SystemDefinitions.names[system].keys
|
47
|
+
end
|
48
|
+
|
49
|
+
def our_flavour_names
|
50
|
+
SystemDefinitions.names[system][flavour].values
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -3,27 +3,27 @@ module Babushka
|
|
3
3
|
include ShellHelpers
|
4
4
|
extend ShellHelpers
|
5
5
|
|
6
|
-
def
|
7
|
-
|
8
|
-
'Linux' => LinuxSystemProfile,
|
9
|
-
'Darwin' => OSXSystemProfile,
|
10
|
-
'DragonFly' => DragonFlySystemProfile,
|
11
|
-
'FreeBSD' => FreeBSDSystemProfile
|
12
|
-
}[shell('uname -s')].try(:for_flavour)
|
6
|
+
def matcher
|
7
|
+
@matcher ||= SystemMatcher.new(system, flavour, name, pkg_helper_key)
|
13
8
|
end
|
14
9
|
|
15
|
-
def
|
16
|
-
|
10
|
+
def matches?(specs) matcher.matches?(specs) end
|
11
|
+
def match_list() matcher.list end
|
12
|
+
|
13
|
+
def differentiator_for(specs)
|
14
|
+
differentiator = matcher.differentiator_for(specs)
|
15
|
+
send("#{differentiator}_str") unless differentiator.nil?
|
17
16
|
end
|
18
17
|
|
19
18
|
def version_info
|
20
19
|
@_version_info ||= get_version_info
|
21
20
|
end
|
22
21
|
|
23
|
-
def linux?;
|
24
|
-
def osx?;
|
25
|
-
def bsd?;
|
26
|
-
|
22
|
+
def linux?; system == :linux end
|
23
|
+
def osx?; system == :osx end
|
24
|
+
def bsd?; system == :bsd end
|
25
|
+
|
26
|
+
def pkg_helper; UnknownPkgHelper end
|
27
27
|
def pkg_helper_key; pkg_helper.try(:manager_key) end
|
28
28
|
def pkg_helper_str; pkg_helper_key.to_s.capitalize end
|
29
29
|
# The extension that dynamic libraries are given on this system. On linux
|
@@ -31,18 +31,25 @@ module Babushka
|
|
31
31
|
def library_ext; 'so' end
|
32
32
|
|
33
33
|
def cpu_type
|
34
|
-
shell('uname -
|
35
|
-
result.replace shell('uname -m') if result[/unknown|\s/]
|
34
|
+
shell('uname -m').tap {|result|
|
36
35
|
# These replacements are taken from PhusionPassenger::PlatformInfo.cpu_architectures
|
37
36
|
result.replace 'x86' if result[/^i.86$/]
|
38
37
|
result.replace 'x86_64' if result == 'amd64'
|
39
38
|
}
|
40
39
|
end
|
41
40
|
|
41
|
+
def cpus
|
42
|
+
raise "#{self.class}#cpus is unimplemented."
|
43
|
+
end
|
44
|
+
|
42
45
|
def total_memory
|
43
46
|
raise "#{self.class}#total_memory is unimplemented."
|
44
47
|
end
|
45
48
|
|
49
|
+
def public_ip
|
50
|
+
raise "#{self.class}#public_ip is unimplemented."
|
51
|
+
end
|
52
|
+
|
46
53
|
def description
|
47
54
|
[
|
48
55
|
(flavour_str unless flavour_str == system_str),
|
@@ -55,65 +62,23 @@ module Babushka
|
|
55
62
|
def name
|
56
63
|
(SystemDefinitions.names[system][flavour] || {})[release]
|
57
64
|
end
|
65
|
+
|
58
66
|
def name_str
|
59
67
|
(SystemDefinitions.descriptions[system][flavour] || {})[release]
|
60
68
|
end
|
69
|
+
end
|
61
70
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
def matches? specs
|
67
|
-
[*specs].any? {|spec| first_nonmatch_for(spec).nil? }
|
68
|
-
end
|
69
|
-
|
70
|
-
def first_nonmatch_for spec
|
71
|
-
if spec == :all
|
72
|
-
nil
|
73
|
-
elsif SystemDefinitions.all_systems.include? spec
|
74
|
-
spec == system ? nil : :system
|
75
|
-
elsif PkgHelper.all_manager_keys.include? spec
|
76
|
-
spec == pkg_helper_key ? nil : :pkg_helper
|
77
|
-
elsif our_flavours.include? spec
|
78
|
-
spec == flavour ? nil : :flavour
|
79
|
-
elsif our_flavour_names.include? spec
|
80
|
-
spec == name ? nil : :name
|
81
|
-
else
|
82
|
-
:system
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def differentiator_for specs
|
87
|
-
nonmatches = [*specs].map {|spec|
|
88
|
-
first_nonmatch_for spec
|
89
|
-
}.sort_by {|spec|
|
90
|
-
[:system, :flavour, :name].index spec
|
91
|
-
}.compact
|
92
|
-
send "#{nonmatches.last}_str" unless nonmatches.empty?
|
93
|
-
end
|
94
|
-
|
95
|
-
def our_flavours
|
96
|
-
SystemDefinitions.names[system].keys
|
97
|
-
end
|
98
|
-
def our_flavour_names
|
99
|
-
SystemDefinitions.names[system][flavour].values
|
100
|
-
end
|
101
|
-
|
102
|
-
def flavour_str_map
|
103
|
-
# Only required for names that can't be auto-capitalized,
|
104
|
-
# e.g. :ubuntu => 'Ubuntu' isn't required.
|
105
|
-
{
|
106
|
-
:linux => {
|
107
|
-
:centos => 'CentOS',
|
108
|
-
:redhat => 'Red Hat'
|
109
|
-
}
|
110
|
-
}
|
71
|
+
class UnknownSystem < SystemProfile
|
72
|
+
def description
|
73
|
+
"Unknown system"
|
111
74
|
end
|
112
75
|
|
76
|
+
def system; :unknown end
|
77
|
+
def flavour; :unknown end
|
78
|
+
def name; :unknown end
|
113
79
|
end
|
114
80
|
|
115
81
|
class OSXSystemProfile < SystemProfile
|
116
|
-
def osx?; true end
|
117
82
|
def library_ext; 'bundle' end
|
118
83
|
def system; :osx end
|
119
84
|
def system_str; 'Mac OS X' end
|
@@ -123,11 +88,18 @@ module Babushka
|
|
123
88
|
def release; version.match(/^\d+\.\d+/).to_s end
|
124
89
|
def get_version_info; shell 'sw_vers' end
|
125
90
|
def pkg_helper; BrewHelper end
|
91
|
+
def cpus; shell('sysctl -n hw.ncpu').to_i end
|
126
92
|
def total_memory; shell("sysctl -a").val_for("hw.memsize").to_i end
|
93
|
+
|
94
|
+
def public_ip
|
95
|
+
shell('ifconfig',
|
96
|
+
shell('netstat -nr').val_for("default").scan(/\w+$/).first
|
97
|
+
).val_for("inet").scan(/^[\d\.]+/).first
|
98
|
+
end
|
99
|
+
|
127
100
|
end
|
128
101
|
|
129
102
|
class BSDSystemProfile < SystemProfile
|
130
|
-
def bsd?; true end
|
131
103
|
def system; :bsd end
|
132
104
|
def system_str; 'BSD' end
|
133
105
|
def flavour; :unknown end
|
@@ -152,30 +124,19 @@ module Babushka
|
|
152
124
|
end
|
153
125
|
|
154
126
|
class LinuxSystemProfile < SystemProfile
|
155
|
-
def linux?; true end
|
156
127
|
def system; :linux end
|
157
128
|
def system_str; 'Linux' end
|
158
129
|
def flavour; :unknown end
|
159
|
-
def flavour_str;
|
130
|
+
def flavour_str; 'Linux' end
|
160
131
|
def version; 'unknown' end
|
161
132
|
def release; version end
|
133
|
+
def cpus; shell("cat /proc/cpuinfo | grep '^processor\\b' | wc -l").to_i end
|
134
|
+
def total_memory; shell("free -b").val_for("Mem").scan(/^\d+\b/).first.to_i end
|
162
135
|
|
163
|
-
def
|
164
|
-
(
|
165
|
-
|
166
|
-
|
167
|
-
private
|
168
|
-
|
169
|
-
def self.detect_using_release_file
|
170
|
-
{
|
171
|
-
'debian_version' => DebianSystemProfile,
|
172
|
-
'redhat-release' => RedhatSystemProfile,
|
173
|
-
'arch-release' => ArchSystemProfile,
|
174
|
-
# 'gentoo-release' =>
|
175
|
-
# 'SuSE-release' =>
|
176
|
-
}.selekt {|release_file, system_profile|
|
177
|
-
File.exists? "/etc/#{release_file}"
|
178
|
-
}.values.first
|
136
|
+
def public_ip
|
137
|
+
shell('ifconfig',
|
138
|
+
shell('netstat -nr').val_for("0.0.0.0").scan(/\w+$/).first
|
139
|
+
).val_for("inet addr").scan(/^[\d\.]+/).first
|
179
140
|
end
|
180
141
|
end
|
181
142
|
|
@@ -185,22 +146,39 @@ module Babushka
|
|
185
146
|
def version; version_info.val_for 'Release' end
|
186
147
|
def name; version_info.val_for('Codename').to_sym end
|
187
148
|
def get_version_info; ensure_lsb_release and shell('lsb_release -a') end
|
149
|
+
def pkg_helper; AptHelper end
|
150
|
+
|
188
151
|
def ensure_lsb_release
|
189
152
|
which('lsb_release') or log("Babushka uses `lsb_release` to learn about debian-based systems.") {
|
190
153
|
AptHelper.install!('lsb-release')
|
191
154
|
}
|
192
155
|
end
|
193
|
-
def pkg_helper; AptHelper end
|
194
|
-
def total_memory; shell("free -b").val_for("Mem").scan(/^\d+\b/).first.to_i end
|
195
156
|
end
|
196
157
|
|
197
158
|
class RedhatSystemProfile < LinuxSystemProfile
|
198
|
-
def flavour
|
199
|
-
|
200
|
-
|
159
|
+
def flavour
|
160
|
+
version_info[/^Red Hat/i] ? :redhat : version_info[/^\w+/].downcase.to_sym
|
161
|
+
end
|
162
|
+
|
163
|
+
def flavour_str
|
164
|
+
{
|
165
|
+
:centos => 'CentOS',
|
166
|
+
:redhat => 'Red Hat'
|
167
|
+
}[flavour]
|
168
|
+
end
|
169
|
+
|
170
|
+
def version
|
171
|
+
version_info[/release [\d\.]+ \((\w+)\)/i, 1] || version_info[/release ([\d\.]+)/i, 1]
|
172
|
+
end
|
173
|
+
|
174
|
+
def get_version_info; File.read('/etc/redhat-release') end
|
201
175
|
def pkg_helper; YumHelper end
|
202
176
|
end
|
203
177
|
|
178
|
+
class FedoraSystemProfile < RedhatSystemProfile
|
179
|
+
def get_version_info; File.read('/etc/system-release') end
|
180
|
+
end
|
181
|
+
|
204
182
|
class ArchSystemProfile < LinuxSystemProfile
|
205
183
|
def get_version_info; 'rolling' end
|
206
184
|
def pkg_helper; PacmanHelper end
|