syncwrap 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/History.rdoc +30 -0
  3. data/Manifest.txt +14 -0
  4. data/README.rdoc +15 -5
  5. data/Rakefile +3 -14
  6. data/lib/syncwrap/base.rb +1 -1
  7. data/lib/syncwrap/components/amazon_linux.rb +50 -0
  8. data/lib/syncwrap/components/arch.rb +37 -0
  9. data/lib/syncwrap/components/bundle.rb +111 -0
  10. data/lib/syncwrap/components/bundled_iyyov_daemon.rb +130 -0
  11. data/lib/syncwrap/components/bundler_gem.rb +47 -0
  12. data/lib/syncwrap/components/centos.rb +28 -0
  13. data/lib/syncwrap/components/cruby_vm.rb +3 -6
  14. data/lib/syncwrap/components/debian.rb +89 -0
  15. data/lib/syncwrap/components/hashdot.rb +6 -4
  16. data/lib/syncwrap/components/iyyov.rb +2 -2
  17. data/lib/syncwrap/components/jruby_vm.rb +9 -5
  18. data/lib/syncwrap/components/network.rb +44 -24
  19. data/lib/syncwrap/components/open_jdk.rb +23 -7
  20. data/lib/syncwrap/components/postgresql.rb +77 -31
  21. data/lib/syncwrap/components/puma.rb +146 -0
  22. data/lib/syncwrap/components/qpid.rb +1 -1
  23. data/lib/syncwrap/components/rake_gem.rb +46 -0
  24. data/lib/syncwrap/components/rhel.rb +7 -3
  25. data/lib/syncwrap/components/run_user.rb +7 -3
  26. data/lib/syncwrap/components/source_tree.rb +128 -0
  27. data/lib/syncwrap/components/tarpit_gem.rb +60 -0
  28. data/lib/syncwrap/components/ubuntu.rb +14 -55
  29. data/lib/syncwrap/components/users.rb +1 -2
  30. data/lib/syncwrap/distro.rb +5 -5
  31. data/lib/syncwrap/ruby_support.rb +20 -4
  32. data/lib/syncwrap/version_support.rb +62 -0
  33. data/lib/syncwrap.rb +11 -0
  34. data/sync/postgresql/postgresql.conf.erb +4 -4
  35. data/sync/var/iyyov/default/bundled_daemon.rb.erb +31 -0
  36. data/test/test_components.rb +77 -18
  37. data/test/test_version_support.rb +65 -0
  38. metadata +16 -2
@@ -0,0 +1,146 @@
1
+ #--
2
+ # Copyright (c) 2011-2014 David Kellum
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
5
+ # may not use this file except in compliance with the License. You may
6
+ # obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
+ # implied. See the License for the specific language governing
14
+ # permissions and limitations under the License.
15
+ #++
16
+
17
+ require 'syncwrap/component'
18
+
19
+ module SyncWrap
20
+
21
+ # Provision to install, start/restart a Puma HTTP
22
+ # server, optionally triggered by a state change key.
23
+ #
24
+ # Host component dependencies: RunUser, <ruby>
25
+ class Puma < Component
26
+
27
+ # Puma version to install and run, if set. Otherwise assume puma
28
+ # is bundled with the application (i.e. Bundle) and use bin stubs
29
+ # to run. (Default: nil; Example: 2.9.0)
30
+ attr_accessor :puma_version
31
+
32
+ # Path to the application/configuration directory which
33
+ # contains the config.ru.
34
+ # (Default: SourceTree#remote_source_path)
35
+ attr_writer :rack_path
36
+
37
+ def rack_path
38
+ @rack_path || remote_source_path
39
+ end
40
+
41
+ # Hash of puma command line flag overrides.
42
+ # (Default: See #puma_flags)
43
+ attr_writer :puma_flags
44
+
45
+ def puma_flags
46
+ { dir: rack_path,
47
+ pidfile: "#{rack_path}/puma.pid",
48
+ state: "#{rack_path}/puma.state",
49
+ control: "unix://#{rack_path}/control",
50
+ environment: "production",
51
+ port: 5874,
52
+ daemon: true }.merge( @puma_flags )
53
+ end
54
+
55
+ protected
56
+
57
+ # An optional state key to check, indicating changes requiring
58
+ # a Puma restart (Default: nil; Example: :source_tree)
59
+ attr_accessor :change_key
60
+
61
+ # Should Puma be restarted even when there were no source bundle
62
+ # changes? (Default: false)
63
+ attr_writer :always_restart
64
+
65
+ def always_restart?
66
+ @always_restart
67
+ end
68
+
69
+ public
70
+
71
+ def initialize( opts = {} )
72
+ @puma_version = nil
73
+ @always_restart = false
74
+ @change_key = nil
75
+ @rack_path = nil
76
+ @puma_flags = {}
77
+ super
78
+ end
79
+
80
+ def install
81
+ if puma_version
82
+ gem_install( 'puma', version: puma_version )
83
+ end
84
+
85
+ changes = change_key && state[ change_key ]
86
+ rudo( "( cd #{rack_path}", close: ')' ) do
87
+ rudo( "if [ -f puma.state -a -e control ]; then", close: else_start ) do
88
+ if ( change_key && !changes ) && !always_restart?
89
+ rudo 'true' #no-op
90
+ else
91
+ restart
92
+ end
93
+ end
94
+ end
95
+ nil
96
+ end
97
+
98
+ protected
99
+
100
+ def restart
101
+ rudo( ( pumactl_command + %w[ --state puma.state restart ] ).join( ' ' ) )
102
+ end
103
+
104
+ def else_start
105
+ <<-SH
106
+ else
107
+ #{puma_start_command}
108
+ fi
109
+ SH
110
+ end
111
+
112
+ def puma_start_command
113
+ args = puma_flags.map do |key,value|
114
+ if value.is_a?( TrueClass )
115
+ key_to_arg( key )
116
+ elsif value.is_a?( FalseClass )
117
+ nil
118
+ else
119
+ [ key_to_arg( key ), value && value.to_s ]
120
+ end
121
+ end
122
+ ( puma_command + args.compact ).join( ' ' )
123
+ end
124
+
125
+ def puma_command
126
+ if puma_version
127
+ [ ruby_command, '-S', 'puma', "_#{puma_version}_" ]
128
+ else
129
+ [ "#{bundle_install_bin_stubs}/puma" ]
130
+ end
131
+ end
132
+
133
+ def pumactl_command
134
+ if puma_version
135
+ [ ruby_command, '-S', 'pumactl', "_#{puma_version}_" ]
136
+ else
137
+ [ "#{bundle_install_bin_stubs}/pumactl" ]
138
+ end
139
+ end
140
+
141
+ def key_to_arg( key )
142
+ '--' + key.to_s.gsub( /_/, '-' )
143
+ end
144
+
145
+ end
146
+ end
@@ -20,7 +20,7 @@ require 'syncwrap/components/rhel'
20
20
  module SyncWrap
21
21
 
22
22
  # Qpid AMQP broker provisioning. Currently this is RHEL (CentoOS,
23
- # Amazon Linux) centric; it has not been ported to Debian/Ubuntu.
23
+ # Amazon Linux) centric; it has not been ported to Debian.
24
24
  #
25
25
  # Host component dependencies: RHEL
26
26
  class Qpid < Component
@@ -0,0 +1,46 @@
1
+ #--
2
+ # Copyright (c) 2011-2014 David Kellum
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
5
+ # may not use this file except in compliance with the License. You may
6
+ # obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
+ # implied. See the License for the specific language governing
14
+ # permissions and limitations under the License.
15
+ #++
16
+
17
+ require 'syncwrap/component'
18
+
19
+ module SyncWrap
20
+
21
+ # Provision for the rake rubygem and its (j)rake command
22
+ #
23
+ # Host component dependencies: <Ruby>
24
+ #
25
+ class RakeGem < Component
26
+
27
+ # Rake version to install (Default: 10.3.2)
28
+ attr_accessor :rake_version
29
+
30
+ def initialize( opts = {} )
31
+ @rake_version = '10.3.2'
32
+ super
33
+ end
34
+
35
+ def rake_command
36
+ ( ruby_command == 'jruby' ) ? 'jrake' : 'rake'
37
+ end
38
+
39
+ def install
40
+ opts = { version: rake_version }
41
+ opts[ :format_executable ] = true unless rake_command == 'rake'
42
+ gem_install( 'rake', opts )
43
+ end
44
+
45
+ end
46
+ end
@@ -19,12 +19,16 @@ require 'syncwrap/distro'
19
19
 
20
20
  module SyncWrap
21
21
 
22
- # Customizations for RedHat Enterprise Linux and derivatives like
23
- # CentOS and Amazon Linux. Specific distros/versions may further
24
- # override these.
22
+ # Customizations for RedHat Enterprise Linux and base class for
23
+ # derivatives like CentOS and AmazonLinux.
25
24
  class RHEL < Component
26
25
  include SyncWrap::Distro
27
26
 
27
+ # RHEL version, i.e. '6'. No default value.
28
+ attr_accessor :rhel_version
29
+
30
+ alias :distro_version :rhel_version
31
+
28
32
  def initialize( opts = {} )
29
33
  super
30
34
  end
@@ -73,7 +73,7 @@ module SyncWrap
73
73
  # Create and set owner/permission of run_dir, such that run_user may
74
74
  # create new directories there.
75
75
  def create_run_dir
76
- make_dir( run_dir )
76
+ mkdir_run_user( run_dir )
77
77
  end
78
78
 
79
79
  def service_dir( sname, instance = nil )
@@ -84,15 +84,19 @@ module SyncWrap
84
84
  # run_dir.
85
85
  def create_service_dir( sname, instance = nil )
86
86
  sdir = service_dir( sname, instance )
87
- make_dir( sdir )
87
+ mkdir_run_user( sdir )
88
88
  end
89
89
 
90
- def make_dir( dir )
90
+ # Make dir including parents, chown to run_user and chmod 775.
91
+ def mkdir_run_user( dir )
91
92
  sudo "mkdir -p #{dir}"
92
93
  chown_run_user dir
93
94
  sudo "chmod 775 #{dir}"
94
95
  end
95
96
 
97
+ # Deprecated
98
+ alias make_dir mkdir_run_user
99
+
96
100
  # Chown to user:run_group where args may be flags and files/directories.
97
101
  def chown_run_user( *args )
98
102
  flags, paths = args.partition { |a| a =~ /^-/ }
@@ -0,0 +1,128 @@
1
+ #--
2
+ # Copyright (c) 2011-2014 David Kellum
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
5
+ # may not use this file except in compliance with the License. You may
6
+ # obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
+ # implied. See the License for the specific language governing
14
+ # permissions and limitations under the License.
15
+ #++
16
+
17
+ require 'syncwrap/component'
18
+
19
+ require 'syncwrap/git_help'
20
+ require 'syncwrap/path_util'
21
+
22
+ module SyncWrap
23
+
24
+ # Install/synchronize a source tree to remotes via rput. By default
25
+ # assumes the local source tree is in a Git DVCS repository and
26
+ # checks that it is clean before executing.
27
+ #
28
+ # The remote source directory will be owned by the RunUser#run_user
29
+ #
30
+ # Host component dependencies: RunUser
31
+ class SourceTree < Component
32
+ include PathUtil
33
+
34
+ # Local path to root directory in which #source_dir is found
35
+ # (Default: <sync-file directory>/..)
36
+ attr_accessor :local_source_root
37
+
38
+ # Source directory name (required)
39
+ attr_accessor :source_dir
40
+
41
+ # Remote path to the root directory in which #remote_dir should be
42
+ # installed. (Default: RunUser#run_dir)
43
+ attr_writer :remote_source_root
44
+
45
+ def remote_source_root
46
+ @remote_source_root || run_dir
47
+ end
48
+
49
+ # Remote directory name (Default: #source_dir)
50
+ attr_writer :remote_dir
51
+
52
+ def remote_dir
53
+ @remote_dir || source_dir
54
+ end
55
+
56
+ protected
57
+
58
+ # Require local source_dir to be clean per Git before #rput of the
59
+ # tree. (Default: true)
60
+ attr_writer :require_clean
61
+
62
+ def require_clean?
63
+ @require_clean
64
+ end
65
+
66
+ # The state key (or Array of keys) to set to if there are any
67
+ # changes to the tree
68
+ # (Default: :source_tree)
69
+ attr_accessor :change_key
70
+
71
+ # Any additional options for the rput (Default: {} -> none)
72
+ attr_accessor :rput_options
73
+
74
+ public
75
+
76
+ def initialize( opts = {} )
77
+ opts = opts.dup
78
+ clr = opts.delete(:caller) || caller
79
+ @local_source_root = path_relative_to_caller( '..', clr )
80
+ @source_dir = nil
81
+ @remote_dir = nil
82
+ @remote_source_root = nil
83
+ @require_clean = true
84
+ @rput_options = {}
85
+ @change_key = :source_tree
86
+ super
87
+
88
+ raise "SourceTree#source_dir not set" unless source_dir
89
+ end
90
+
91
+ def remote_source_path
92
+ File.join( remote_source_root, remote_dir )
93
+ end
94
+
95
+ def install
96
+ mkdir_run_user( remote_source_path )
97
+ changes = sync_source
98
+ on_change( changes ) unless changes.empty?
99
+ changes
100
+ end
101
+
102
+ protected
103
+
104
+ def local_source_path
105
+ File.join( local_source_root, source_dir )
106
+ end
107
+
108
+ def on_change( changes )
109
+ unless changes.empty? || change_key.nil?
110
+ Array(change_key).each do |key|
111
+ state[ key ] ||= []
112
+ state[ key ] += changes
113
+ end
114
+ end
115
+ end
116
+
117
+ def sync_source
118
+ GitHelp.require_clean!( local_source_path ) if require_clean?
119
+ opts = { erb_process: false,
120
+ excludes: [ :dev, '.bundle/' ],
121
+ user: run_user,
122
+ sync_paths: [ local_source_root ] }.
123
+ merge( rput_options )
124
+ rput( source_dir + '/', remote_source_path, opts )
125
+ end
126
+
127
+ end
128
+ end
@@ -0,0 +1,60 @@
1
+ #--
2
+ # Copyright (c) 2011-2014 David Kellum
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
5
+ # may not use this file except in compliance with the License. You may
6
+ # obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
+ # implied. See the License for the specific language governing
14
+ # permissions and limitations under the License.
15
+ #++
16
+
17
+ require 'syncwrap/component'
18
+
19
+ module SyncWrap
20
+
21
+ # Provision for the rjack-tarpit rubygem
22
+ #
23
+ # Host component dependencies: RunUser?, <ruby>
24
+ #
25
+ class TarpitGem < Component
26
+
27
+ # Tarpit version to install (Default: 1.1.0)
28
+ attr_accessor :tarpit_version
29
+
30
+ protected
31
+
32
+ # Perform a user_install as the run_user? (Default: false)
33
+ attr_writer :user_install
34
+
35
+ def user_install?
36
+ @user_install
37
+ end
38
+
39
+ public
40
+
41
+ def initialize( opts = {} )
42
+ @tarpit_version = '2.1.0'
43
+ @user_install = false
44
+ super
45
+ end
46
+
47
+ def install
48
+ opts = { version: tarpit_version, user_install: user_install? && run_user }
49
+
50
+ # tarpit depends on rake, etc. which could be installed with it,
51
+ # so use format_executable even though tarpit doesn't have any
52
+ # bin scripts
53
+ opts[ :format_executable ] = true if ruby_command == 'jruby'
54
+
55
+ gem_install( 'rjack-tarpit', opts )
56
+ end
57
+
58
+ end
59
+
60
+ end
@@ -14,67 +14,26 @@
14
14
  # permissions and limitations under the License.
15
15
  #++
16
16
 
17
- require 'syncwrap/component'
18
- require 'syncwrap/distro'
17
+ require 'syncwrap/components/debian'
19
18
 
20
19
  module SyncWrap
21
20
 
22
- # Customizations for \Ubuntu and possibly other Debian/apt packaged
23
- # derivatives. Specific distros/versions may further specialize.
24
- class Ubuntu < Component
25
- include SyncWrap::Distro
21
+ # Customizations for \Ubuntu and derivatives. Specific
22
+ # distros/versions may further specialize.
23
+ class Ubuntu < Debian
26
24
 
27
- def initialize( opts = {} )
28
- super
29
- end
30
-
31
- # Install the specified package names. The first time this is
32
- # applied to any given host, an "apt-get update" is issued as
33
- # well. A trailing hash is interpreted as options, see below.
34
- #
35
- # ==== Options
36
- # :minimal:: Eqv to --no-install-recommends
37
- #
38
- # Other options will be ignored.
39
- def dist_install( *args )
40
- opts = args.last.is_a?( Hash ) && args.pop || {}
41
- args.unshift "--no-install-recommends" if opts[ :minimal ]
42
-
43
- sudo( "apt-get -yqq update" ) if first_apt?
44
- sudo( "apt-get -yq install #{args.join ' '}" )
45
- end
46
-
47
- # Uninstall the specified package names.
48
- def dist_uninstall( *pkgs )
49
- sudo "aptitude -yq purge #{pkgs.join ' '}"
50
- end
51
-
52
- # Install a System V style init.d service script
53
- def dist_install_init_service( name )
54
- sudo "/usr/sbin/update-rc.d #{name} defaults"
55
- end
56
-
57
- # Enable the System V style init.d service
58
- def dist_enable_init_service( name )
59
- sudo "/usr/sbin/update-rc.d #{name} enable"
60
- end
61
-
62
- # Run via sudo, the service command typically supporting 'start',
63
- # 'stop', 'restart', 'status', etc. arguments.
64
- def dist_service( *args )
65
- sudo( [ '/usr/sbin/service', *args ].join( ' ' ) )
66
- end
25
+ # Ubuntu version, i.e. '14.04' or '12.04.4'. No default value.
26
+ attr_accessor :ubuntu_version
67
27
 
68
- protected
28
+ alias :distro_version :ubuntu_version
69
29
 
70
- def first_apt?
71
- s = state
72
- if s[ :ubuntu_apt_updated ]
73
- false
74
- else
75
- s[ :ubuntu_apt_updated ] = true
76
- true
77
- end
30
+ # Return Debian#debian_version if specified, or provide comparable
31
+ # default Debian version if #ubuntu_vesion is specified. This is
32
+ # an approximation of the LTS lineage.
33
+ def debian_version
34
+ super ||
35
+ ( version_gte?( ubuntu_version, [14,4] ) && '7' ) ||
36
+ ( version_gte?( ubuntu_version, [12,4] ) && '6' )
78
37
  end
79
38
 
80
39
  end
@@ -156,9 +156,8 @@ module SyncWrap
156
156
  end
157
157
 
158
158
  def set_sudoers( user )
159
- #FIXME: make this a template?
160
159
  #FIXME: Use local_root for secure_path? (Order issue)
161
- #Relax, less overrides needed for Ubuntu?
160
+
162
161
  sudo <<-SH
163
162
  echo '#{user} ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/#{user}
164
163
  echo 'Defaults:#{user} !requiretty' >> /etc/sudoers.d/#{user}
@@ -18,7 +18,7 @@ require 'syncwrap/base'
18
18
 
19
19
  module SyncWrap
20
20
 
21
- # Support module and inteface for (Linux) distribution components.
21
+ # Support module and interface for distribution components.
22
22
  module Distro
23
23
 
24
24
  # The root directory for local, non-distro managed installs
@@ -46,25 +46,25 @@ module SyncWrap
46
46
  #
47
47
  # :minimal:: Avoid additional "optional" packages when possible.
48
48
  def dist_install( *pkgs )
49
- raise "Include a distro-specific component, e.g. Ubuntu, RHEL"
49
+ raise "Include a distro-specific component, e.g. Debian, RHEL"
50
50
  end
51
51
 
52
52
  # Uninstall the specified package names.
53
53
  def dist_uninstall( *pkgs )
54
- raise "Include a distro-specific component, e.g. Ubuntu, RHEL"
54
+ raise "Include a distro-specific component, e.g. Debian, RHEL"
55
55
  end
56
56
 
57
57
  # Install a System V style init.d script (already placed at remote
58
58
  # /etc/init.d/<name>) via distro-specific command
59
59
  def dist_install_init_service( name )
60
- raise "Include a distro-specific component, e.g. Ubuntu, RHEL"
60
+ raise "Include a distro-specific component, e.g. Debian, RHEL"
61
61
  end
62
62
 
63
63
  # Run via sudo, the System V style, distro specific `service`
64
64
  # command, typically supporting 'start', 'stop', 'restart',
65
65
  # 'status', etc. arguments.
66
66
  def dist_service( *args )
67
- raise "Include a distro-specific component, e.g. Ubuntu, RHEL"
67
+ raise "Include a distro-specific component, e.g. Debian, RHEL"
68
68
  end
69
69
 
70
70
  end
@@ -26,7 +26,11 @@ module SyncWrap
26
26
  # Default gem install arguments (default: --no-rdoc, --no-ri)
27
27
  attr_accessor :gem_install_args
28
28
 
29
+ # Ruby VM command name (default: ruby; alt example: jruby)
30
+ attr_accessor :ruby_command
31
+
29
32
  def initialize( *args )
33
+ @ruby_command = 'ruby'
30
34
  @gem_command = 'gem'
31
35
  @gem_install_args = %w[ --no-rdoc --no-ri ]
32
36
 
@@ -53,9 +57,10 @@ module SyncWrap
53
57
  # '~> 1.1'
54
58
  # ['>=1.0', '<1.2']
55
59
  #
56
- # :user_install:: If true, perform a --user-install as the current
57
- # user. Otherwise system install with sudo (the
58
- # default, false).
60
+ # :user_install:: Perform a --user-install if true, as the
61
+ # indicated user if a String or as the login user.
62
+ # Otherwise system install with sudo (the default,
63
+ # false).
59
64
  #
60
65
  # :check:: If true, capture output and return the number of gems
61
66
  # actually installed. Combine with :minimize to only
@@ -67,17 +72,28 @@ module SyncWrap
67
72
  # installs to the minimum required to satisfy the
68
73
  # version requirements. (Default: true)
69
74
  #
75
+ # :format_executable:: Use --format-executable to prefix commands
76
+ # for specific ruby VMs if needed.
77
+ #
70
78
  def gem_install( gem, opts = {} )
71
79
  cmd = [ gem_command, 'install',
72
80
  gem_install_args,
73
81
  ( '--user-install' if opts[ :user_install ] ),
82
+ ( '--format-executable' if opts[ :format_executable ] ),
74
83
  ( '--conservative' if opts[ :minimize] != false ),
75
84
  ( '--minimal-deps' if opts[ :minimize] != false &&
76
85
  min_deps_supported? ),
77
86
  gem_version_flags( opts[ :version ] ),
78
87
  gem ].flatten.compact.join( ' ' )
79
88
 
80
- shopts = opts[ :user_install ] ? {} : {user: :root}
89
+ shopts = {}
90
+
91
+ case opts[ :user_install ]
92
+ when String
93
+ shopts[ :user ] = opts[ :user_install ]
94
+ when nil, false
95
+ shopts[ :user ] = :root
96
+ end
81
97
 
82
98
  clean_env( opts[ :user_install ] ) do
83
99
  if opts[ :check ]
@@ -0,0 +1,62 @@
1
+ #--
2
+ # Copyright (c) 2011-2014 David Kellum
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
5
+ # may not use this file except in compliance with the License. You may
6
+ # obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
+ # implied. See the License for the specific language governing
14
+ # permissions and limitations under the License.
15
+ #++
16
+
17
+ module SyncWrap
18
+
19
+ # A Support module for parsing and comparing version strings.
20
+ module VersionSupport
21
+
22
+ protected
23
+
24
+ # Convert version decimal String to Array of Integer or String
25
+ # values. The characters '.' and '-' are treated as
26
+ # delimiters. Any remaining non-digit in a segment results in a
27
+ # String being returned for that segment. Return v if not a
28
+ # String (incl nil).
29
+ def version_string_to_a( v )
30
+ if v.is_a?( String )
31
+ v.split(/[.\-]/).map do |p|
32
+ if p =~ /^\d+$/
33
+ p.to_i
34
+ else
35
+ p
36
+ end
37
+ end
38
+ else
39
+ v
40
+ end
41
+ end
42
+
43
+ # Return true if v1 and v2 are not nil, (auto converted) array
44
+ # positions are type compatible and compare as v1 >= v2.
45
+ def version_gte?( v1, v2 )
46
+ v1 = version_string_to_a( v1 )
47
+ v2 = version_string_to_a( v2 )
48
+ c = v1 && v2 && ( v1 <=> v2 ) #-> nil for String/Integer mix
49
+ c && c >= 0
50
+ end
51
+
52
+ # Return true if v1 and v2 are not nil, (auto converted) array
53
+ # positions are type compatible and compare v1 < v2.
54
+ def version_lt?( v1, v2 )
55
+ v1 = version_string_to_a( v1 )
56
+ v2 = version_string_to_a( v2 )
57
+ c = v1 && v2 && ( v1 <=> v2 ) #-> nil for String/Integer mix
58
+ c && c < 0
59
+ end
60
+ end
61
+
62
+ end