rigup 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2bd213b9441445c62e0fc69fba5161efcc6800f0
4
- data.tar.gz: bb70b3a65e78ccdf4d8d4dba82e0867eb8522517
3
+ metadata.gz: 95b30c63738163b65a0865b0f1a9d254c609640c
4
+ data.tar.gz: d31adf3237a4c76ff0cf5fb623cd4c608edcb1a1
5
5
  SHA512:
6
- metadata.gz: 4e20c19f4cde6aa31c0ca561f4f8c1c9d43df640704a95c9c32bde372fafad017c0230de67a42efaecc348c6de6b978d381cca63218e3e054513375d63a33a25
7
- data.tar.gz: ad3230ac2d49a3c150a0c44afada8eaad68410890c2bbe7dca6789055dea0eb556b225a703a9a9f036ebdb7a32c9ccdad86ce8fbcde5f3fce2c77817a46c8105
6
+ metadata.gz: 88c817645adfdf47a9f0ff3f4749763ce279904c936120777c701ea6524034e3d8b0efb0fe411548dbc65da874cd44b18ee92e250c9d303b4fcc8379706086bb
7
+ data.tar.gz: a66440a2d61f0753977d20894b4ba20bf01753c206762c3dfc1e3abc894d5e5c7e10879f2da6213eb6f9fb592ce6c6607b7e982b7f5154b045a66440a5c2b141
data/bin/rigup CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require "rubygems"
3
- require_relative '../lib/rigup.rb'
4
-
2
+ #require "rubygems" - checkout rake for an interesting example of the bin command
3
+ require 'rigup'
5
4
  Rigup::Cli.start(ARGV)
data/lib/rigup/base.rb ADDED
@@ -0,0 +1,48 @@
1
+ module Rigup
2
+ module Base
3
+
4
+ def self.included(aClass)
5
+ aClass.class_eval do
6
+ no_commands do
7
+
8
+ def logger
9
+ @logger ||= ::Logger.new(STDOUT)
10
+ end
11
+
12
+ def config
13
+ unless @config
14
+ @config = {}
15
+ if File.exists?(f=File.join(release_path,'rigup.yml'))
16
+ file_config = YAML.load(String.from_file(f))
17
+ @config.merge!(file_config)
18
+ @config = Rigup::Config.new(@config)
19
+ end
20
+ end
21
+ @config
22
+ end
23
+
24
+ def context
25
+ @context ||= Rigup::Context.new(
26
+ config: config,
27
+ logger: logger,
28
+ pwd: Dir.pwd,
29
+ )
30
+ end
31
+
32
+ def release_path
33
+ @release_path ||= File.expand_path('.')
34
+ end
35
+
36
+ def site_dir
37
+ @site_dir ||= File.expand_path('../..',release_path)
38
+ end
39
+
40
+ def shared_path
41
+ @shared_path ||= File.expand_path('shared',site_dir)
42
+ end
43
+ end
44
+ end
45
+
46
+ end
47
+ end
48
+ end
data/lib/rigup/cli.rb CHANGED
@@ -1,13 +1,19 @@
1
1
  module Rigup
2
2
  class Cli < Thor
3
3
 
4
- include Rigup::Runability
5
- include Rigup::InstallUtils
6
-
7
- attr_reader :context, :release_path
4
+ include Rigup::Utils::Run
5
+ include Rigup::Utils::Install
8
6
 
9
7
  no_commands do
10
8
 
9
+ def logger
10
+ @logger ||= ::Logger.new(STDOUT)
11
+ end
12
+
13
+ def config
14
+ @context.config
15
+ end
16
+
11
17
  def init(aPath=nil,aConfig={})
12
18
  return if @initialised
13
19
  @initialised = true
@@ -28,20 +34,18 @@ module Rigup
28
34
  )
29
35
  end
30
36
 
31
- def site_dir
32
- @site_dir
33
- end
37
+ attr_reader :context, :release_path, :site_dir
38
+
39
+ def shared_path
40
+ @shared_path ||= File.expand_path('shared',site_dir)
41
+ end
34
42
 
35
43
  def cache_dir
36
- File.join(@site_dir,'shared','cached-copy')
44
+ File.join(site_dir,'shared','cached-copy')
37
45
  end
38
46
 
39
- def config
40
- @context.config
41
- end
42
-
43
47
  def repo
44
- @repo ||= GitRepo.new(@context)
48
+ @repo ||= GitRepo.new(context)
45
49
  end
46
50
 
47
51
  # Prepares repo in cache dir for site
@@ -102,16 +106,16 @@ module Rigup
102
106
  end
103
107
 
104
108
  def link_live
105
- ensure_link(@release_path,File.expand_path(File.join(site_dir,'current')),"#{config[:user]}:#{config[:group]}")
109
+ ensure_link(release_path,File.expand_path(File.join(site_dir,'current')),"#{config[:user]}:#{config[:group]}")
106
110
  end
107
111
 
108
112
  def cleanup
109
113
  @releases = run("ls -x #{@releases_path}").split.sort
110
114
  count = (@keep_releases || 3).to_i
111
115
  if count >= @releases.length
112
- @context.logger.info "no old releases to clean up"
116
+ logger.info "no old releases to clean up"
113
117
  else
114
- @context.logger.info "keeping #{count} of #{@releases.length} deployed releases"
118
+ logger.info "keeping #{count} of #{@releases.length} deployed releases"
115
119
 
116
120
  directories = (@releases - @releases.last(count)).map { |r|
117
121
  File.join(@releases_path, r)
@@ -123,7 +127,7 @@ module Rigup
123
127
 
124
128
  def call_release_command(aCommand)
125
129
  return unless cmdline = config["#{aCommand}_command".to_sym].to_s.strip.to_nil
126
- cd @release_path do
130
+ cd release_path do
127
131
  run cmdline
128
132
  end
129
133
  end
@@ -162,5 +166,15 @@ module Rigup
162
166
  call_release_command(:unblock)
163
167
  cleanup
164
168
  end
169
+
170
+ desc "restart [PATH]", "restart the given site"
171
+ def restart(aPath=nil)
172
+ init(aPath)
173
+ return unless cmdline = config["restart_command".to_sym].to_s.strip.to_nil
174
+ cd File.join(site_dir,'current') do
175
+ run cmdline
176
+ end
177
+ end
178
+
165
179
  end
166
180
  end
@@ -1,32 +1,11 @@
1
1
  module Rigup
2
2
 
3
+ # Thor base class extended with rigup utilities
3
4
  class DeployBase < Thor
4
5
 
5
- include Rigup::Runability
6
- include Rigup::InstallUtils
7
-
8
- no_commands do
9
- def initialize(*args)
10
- super
11
- @release_path = Dir.pwd
12
- @site_dir = File.expand_path('../..')
13
- @shared_path = File.expand_path('shared',@site_dir)
14
- config = {}
15
- if File.exists?(f=File.join(@release_path,'rigup.yml'))
16
- file_config = YAML.load(String.from_file(f))
17
- config.merge!(file_config)
18
- end
19
- @context = Rigup::Context.new(
20
- config: Rigup::Config.new(config),
21
- logger: ::Logger.new(STDOUT),
22
- pwd: Dir.pwd,
23
- )
24
- end
25
-
26
- def config
27
- @context.config
28
- end
29
- end
6
+ include Rigup::Base
7
+ include Rigup::Utils::Run
8
+ include Rigup::Utils::Install
30
9
 
31
10
  end
32
11
 
@@ -3,7 +3,7 @@ require 'git'
3
3
  module Rigup
4
4
  class GitRepo
5
5
 
6
- include Rigup::Runability
6
+ include Rigup::Utils::Run
7
7
 
8
8
  attr_reader :git,:configured
9
9
 
data/lib/rigup/svn.rb CHANGED
@@ -46,7 +46,7 @@ module Rigup
46
46
  'repository' => @repository,
47
47
  'source' => @vcs_app_path,
48
48
  'branch' => @branch,
49
- 'destination' => @release_path,
49
+ 'destination' => release_path,
50
50
  'revision' => @revision
51
51
  }
52
52
  result.merge!(aMergeOptions) if aMergeOptions
@@ -0,0 +1,95 @@
1
+ module Rigup
2
+ module Utils
3
+ module Install
4
+
5
+ def select_suffixed_file(aFile,aExtendedExtension=false)
6
+ ext = Buzztools::File.extension(aFile,aExtendedExtension)
7
+ no_ext = Buzztools::File.no_extension(aFile,aExtendedExtension)
8
+ dir = File.dirname(aFile)
9
+ run "#{context.config[:sudo]} mv -f #{no_ext}.#{context.config[:stage]}.#{ext} #{aFile}"
10
+ run "#{context.config[:sudo]} rm -f #{no_ext}.*.#{ext}"
11
+ end
12
+
13
+ # Especially for modifiying behaviour eg. of FCKEditor without upsetting the standard files
14
+ # eg. create a public_override folder that duplicates the same structure as public,
15
+ # and contains the modified files. On deployment call
16
+ # override_folder("#{@release_path}/public") # equiv to override_folder("#{@release_path}/public", "#{@release_path}/public_override")
17
+ # and the files in public_override will be copied over public, then public_override removed
18
+ def override_folder(aFolder,aOverrideFolder=nil,aRemove=true)
19
+ aFolder = aFolder.desuffix('/')
20
+ aOverrideFolder ||= (aFolder+'_override')
21
+ run "#{context.config[:sudo]} cp -vrf #{aOverrideFolder}/* #{aFolder}/"
22
+ run "#{context.config[:sudo]} rm -rf #{aOverrideFolder}" if aRemove
23
+ end
24
+
25
+
26
+ # set standard permissions for web sites - readonly for apache user
27
+ def permissions_for_web(aPath,aUser=nil,aGroup=nil,aHideScm=nil)
28
+ aUser ||= @user
29
+ aGroup ||= @group
30
+
31
+ run "#{context.config[:sudo]} chown -R #{aUser}:#{aGroup} #{aPath.ensure_suffix('/')}"
32
+ run_for_all("chmod 755",aPath,:dirs) # !!! perhaps reduce other permissions
33
+ run_for_all("chmod 644",aPath,:files)
34
+ run_for_all("chmod g+s",aPath,:dirs)
35
+ case aHideScm
36
+ when :svn then run_for_all("chmod -R 700",aPath,:dirs,"*/.svn")
37
+ end
38
+ end
39
+
40
+ # run this after permissions_for_web() on dirs that need to be writable by group (apache)
41
+ def permissions_for_web_writable(aPath)
42
+ run "chmod -R g+w #{aPath.ensure_suffix('/')}"
43
+ run_for_all("chmod -R 700",aPath,:dirs,"*/.svn")
44
+ end
45
+
46
+ def internal_permissions(aPath,aKind)
47
+ case aKind
48
+ when 'rails' then
49
+ permissions_for_web(aPath,@user,@group,true)
50
+
51
+ run_for_all("chmod +x",File.join(aPath,'script'),:files)
52
+
53
+
54
+ uploads = shared_path+'/uploads'
55
+ make_public_cache_dir(uploads)
56
+ #if File.exists?(uploads)
57
+ # permissions_for_web(uploads,@user,@group,true)
58
+ # permissions_for_web_writable(uploads)
59
+ #end
60
+ #permissions_for_web_writable("#{aPath}/tmp")
61
+ make_public_cache_dir("#{aPath}/tmp")
62
+
63
+ run "#{context.config[:sudo]} chown #{@user} #{aPath}/config/environment.rb" #unless DEV_MODE # very important for passenger, which uses the owner of this file to run as
64
+
65
+ when 'spree' then
66
+ internal_permissions(aPath,'rails')
67
+ when 'browsercms' then
68
+ internal_permissions(aPath,'rails')
69
+ end
70
+ end
71
+
72
+ def apply_permissions(aPath=nil,aKind=nil)
73
+ aPath ||= release_path
74
+ aKind ||= @kind || 'rails'
75
+ internal_permissions(aPath, aKind)
76
+ end
77
+
78
+ def ensure_link(aTo,aFrom,aUserGroup=nil,aSudo='')
79
+ raise "Must supply from" if !aFrom
80
+ cmd = []
81
+ cmd << "#{aSudo} rm -rf #{aFrom}"
82
+ cmd << "#{aSudo} ln -sf #{aTo} #{aFrom}"
83
+ cmd << "#{aSudo} chown -h #{aUserGroup} #{aFrom}" if aUserGroup
84
+ run(cmd.join(' && '),raise: false)
85
+ end
86
+
87
+ def make_public_cache_dir(aStartPath)
88
+ run "#{context.config[:sudo]} mkdir -p #{aStartPath}"
89
+ permissions_for_web(aStartPath)
90
+ permissions_for_web_writable(aStartPath)
91
+ end
92
+
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,64 @@
1
+ module Rigup
2
+ module Utils
3
+ module Run
4
+
5
+ def bash
6
+ @bash ||= ::Session::Bash.new
7
+ end
8
+
9
+ def pwd
10
+ bash.execute("pwd", stdout: nil).first.strip
11
+ end
12
+
13
+ def cd(aPath,&block)
14
+ if block_given?
15
+ begin
16
+ before_path = pwd
17
+ cd(aPath)
18
+ yield aPath,before_path
19
+ rescue Exception => e
20
+ logger.info e.message
21
+ ensure
22
+ cd(before_path)
23
+ end
24
+ else
25
+ aPath = File.expand_path(aPath)
26
+ Dir.chdir(aPath)
27
+ bash.execute("cd \"#{aPath}\"")
28
+ end
29
+ aPath
30
+ end
31
+
32
+ def run(aCommand,aOptions=nil)
33
+ aOptions ||= {}
34
+ logger.debug aCommand
35
+ response,errout = bash.execute(aCommand,stdout: STDOUT) # ::POpen4::shell(aCommand,aDir || @context.pwd)
36
+ logger.debug errout if errout.to_nil
37
+ logger.debug response if response.to_nil
38
+ raise "Command Failed" unless bash.exit_status==0 or aOptions[:raise]==false
39
+ return response
40
+ end
41
+
42
+ def run_for_all(aCommand,aPath,aFilesOrDirs,aPattern=nil,aInvertPattern=false,aSudo=false)
43
+ #run "#{sudo} find . -wholename '*/.svn' -prune -o -type d -print0 |xargs -0 #{sudo} chmod 750"
44
+ #sudo find . -type f -exec echo {} \;
45
+ cmd = []
46
+ cmd << "sudo" if aSudo
47
+ cmd << "find #{aPath.ensure_suffix('/')}"
48
+ cmd << "-wholename '#{aPattern}'" if aPattern
49
+ cmd << "-prune -o" if aInvertPattern
50
+ cmd << case aFilesOrDirs.to_s[0,1]
51
+ when 'f' then '-type f'
52
+ when 'd' then '-type d'
53
+ else ''
54
+ end
55
+ cmd << "-exec"
56
+ cmd << aCommand
57
+ cmd << "'{}' \\;"
58
+ cmd = cmd.join(' ')
59
+ run cmd
60
+ end
61
+
62
+ end
63
+ end
64
+ end
data/lib/rigup/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rigup
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/rigup.rb CHANGED
@@ -8,8 +8,9 @@ require 'session'
8
8
  require_relative "rigup/version"
9
9
  require_relative "rigup/config"
10
10
  require_relative "rigup/context"
11
- require_relative "rigup/runability"
12
- require_relative "rigup/install_utils"
11
+ require_relative "rigup/utils/run"
12
+ require_relative "rigup/utils/install"
13
13
  require_relative "rigup/git_repo"
14
14
  require_relative "rigup/cli"
15
+ require_relative "rigup/base"
15
16
  require_relative "rigup/deploy_base"
data/rigup.gemspec CHANGED
@@ -18,8 +18,8 @@ Gem::Specification.new do |s|
18
18
  s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
19
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
20
20
 
21
- s.add_dependency 'bundler', '~>1.5.3'
22
- s.add_dependency 'thor', '~> 0.19.1'
21
+ s.add_dependency 'bundler'#, '~>1.5.3'
22
+ s.add_dependency 'thor'#, '~> 0.19.1'
23
23
 
24
24
 
25
25
  s.add_development_dependency 'rspec', '~>2.14.0'
data/rigup.iml CHANGED
@@ -14,6 +14,7 @@
14
14
  <orderEntry type="inheritedJdk" />
15
15
  <orderEntry type="sourceFolder" forTests="false" />
16
16
  <orderEntry type="library" scope="PROVIDED" name="bundler (v1.5.3, RVM: ruby-2.0.0-p247) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="buzztools (v0.0.6, RVM: ruby-2.0.0-p247) [gem]" level="application" />
17
18
  <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.2.5, RVM: ruby-2.0.0-p247) [gem]" level="application" />
18
19
  <orderEntry type="library" scope="PROVIDED" name="git (v1.2.6, RVM: ruby-2.0.0-p247) [gem]" level="application" />
19
20
  <orderEntry type="library" scope="PROVIDED" name="rake (v10.2.0, RVM: ruby-2.0.0-p247) [gem]" level="application" />
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rigup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary McGhee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-18 00:00:00.000000000 Z
11
+ date: 2014-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: 1.5.3
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
- version: 1.5.3
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: thor
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.19.1
33
+ version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
- version: 0.19.1
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -119,14 +119,15 @@ files:
119
119
  - bin/rigup
120
120
  - example deploy.thor
121
121
  - Gemfile
122
+ - lib/rigup/base.rb
122
123
  - lib/rigup/cli.rb
123
124
  - lib/rigup/config.rb
124
125
  - lib/rigup/context.rb
125
126
  - lib/rigup/deploy_base.rb
126
127
  - lib/rigup/git_repo.rb
127
- - lib/rigup/install_utils.rb
128
- - lib/rigup/runability.rb
129
128
  - lib/rigup/svn.rb
129
+ - lib/rigup/utils/install.rb
130
+ - lib/rigup/utils/run.rb
130
131
  - lib/rigup/version.rb
131
132
  - lib/rigup.rb
132
133
  - LICENSE
@@ -1,93 +0,0 @@
1
- module Rigup
2
- module InstallUtils
3
-
4
- def select_suffixed_file(aFile,aExtendedExtension=false)
5
- ext = Buzztools::File.extension(aFile,aExtendedExtension)
6
- no_ext = Buzztools::File.no_extension(aFile,aExtendedExtension)
7
- dir = File.dirname(aFile)
8
- run "#{@context.config[:sudo]} mv -f #{no_ext}.#{@context.config[:stage]}.#{ext} #{aFile}"
9
- run "#{@context.config[:sudo]} rm -f #{no_ext}.*.#{ext}"
10
- end
11
-
12
- # Especially for modifiying behaviour eg. of FCKEditor without upsetting the standard files
13
- # eg. create a public_override folder that duplicates the same structure as public,
14
- # and contains the modified files. On deployment call
15
- # override_folder("#{@release_path}/public") # equiv to override_folder("#{@release_path}/public", "#{@release_path}/public_override")
16
- # and the files in public_override will be copied over public, then public_override removed
17
- def override_folder(aFolder,aOverrideFolder=nil,aRemove=true)
18
- aFolder = aFolder.desuffix('/')
19
- aOverrideFolder ||= (aFolder+'_override')
20
- run "#{@context.config[:sudo]} cp -vrf #{aOverrideFolder}/* #{aFolder}/"
21
- run "#{@context.config[:sudo]} rm -rf #{aOverrideFolder}" if aRemove
22
- end
23
-
24
-
25
- # set standard permissions for web sites - readonly for apache user
26
- def permissions_for_web(aPath,aUser=nil,aGroup=nil,aHideScm=nil)
27
- aUser ||= @user
28
- aGroup ||= @group
29
-
30
- run "#{@context.config[:sudo]} chown -R #{aUser}:#{aGroup} #{aPath.ensure_suffix('/')}"
31
- run_for_all("chmod 755",aPath,:dirs) # !!! perhaps reduce other permissions
32
- run_for_all("chmod 644",aPath,:files)
33
- run_for_all("chmod g+s",aPath,:dirs)
34
- case aHideScm
35
- when :svn then run_for_all("chmod -R 700",aPath,:dirs,"*/.svn")
36
- end
37
- end
38
-
39
- # run this after permissions_for_web() on dirs that need to be writable by group (apache)
40
- def permissions_for_web_writable(aPath)
41
- run "chmod -R g+w #{aPath.ensure_suffix('/')}"
42
- run_for_all("chmod -R 700",aPath,:dirs,"*/.svn")
43
- end
44
-
45
- def internal_permissions(aPath,aKind)
46
- case aKind
47
- when 'rails' then
48
- permissions_for_web(aPath,@user,@group,true)
49
-
50
- run_for_all("chmod +x",File.join(aPath,'script'),:files)
51
-
52
-
53
- uploads = @shared_path+'/uploads'
54
- make_public_cache_dir(uploads)
55
- #if File.exists?(uploads)
56
- # permissions_for_web(uploads,@user,@group,true)
57
- # permissions_for_web_writable(uploads)
58
- #end
59
- #permissions_for_web_writable("#{aPath}/tmp")
60
- make_public_cache_dir("#{aPath}/tmp")
61
-
62
- run "#{@context.config[:sudo]} chown #{@apache_user} #{aPath}/config/environment.rb" unless DEV_MODE # very important for passenger, which uses the owner of this file to run as
63
-
64
- when 'spree' then
65
- internal_permissions(aPath,'rails')
66
- when 'browsercms' then
67
- internal_permissions(aPath,'rails')
68
- end
69
- end
70
-
71
- def apply_permissions(aPath=nil,aKind=nil)
72
- aPath ||= @release_path
73
- aKind ||= @kind || 'rails'
74
- internal_permissions(aPath, aKind)
75
- end
76
-
77
- def ensure_link(aTo,aFrom,aUserGroup=nil,aSudo='')
78
- raise "Must supply from" if !aFrom
79
- cmd = []
80
- cmd << "#{aSudo} rm -rf #{aFrom}"
81
- cmd << "#{aSudo} ln -sf #{aTo} #{aFrom}"
82
- cmd << "#{aSudo} chown -h #{aUserGroup} #{aFrom}" if aUserGroup
83
- run(cmd.join(' && '),raise: false)
84
- end
85
-
86
- def make_public_cache_dir(aStartPath)
87
- run "#{@context.config[:sudo]} mkdir -p #{aStartPath}"
88
- permissions_for_web(aStartPath)
89
- permissions_for_web_writable(aStartPath)
90
- end
91
-
92
- end
93
- end
@@ -1,62 +0,0 @@
1
- module Rigup
2
- module Runability
3
-
4
- def bash
5
- @bash ||= ::Session::Bash.new
6
- end
7
-
8
- def pwd
9
- bash.execute("pwd", stdout: nil).first.strip
10
- end
11
-
12
- def cd(aPath,&block)
13
- if block_given?
14
- begin
15
- before_path = pwd
16
- cd(aPath)
17
- yield aPath,before_path
18
- rescue Exception => e
19
- @context.logger.info e.message
20
- ensure
21
- cd(before_path)
22
- end
23
- else
24
- aPath = File.expand_path(aPath)
25
- Dir.chdir(aPath)
26
- bash.execute("cd \"#{aPath}\"")
27
- end
28
- aPath
29
- end
30
-
31
- def run(aCommand,aOptions=nil)
32
- aOptions ||= {}
33
- @context.logger.debug aCommand
34
- response,errout = bash.execute(aCommand,stdout: STDOUT) # ::POpen4::shell(aCommand,aDir || @context.pwd)
35
- @context.logger.debug errout if errout.to_nil
36
- @context.logger.debug response if response.to_nil
37
- raise "Command Failed" unless bash.exit_status==0 or aOptions[:raise]==false
38
- return response
39
- end
40
-
41
- def run_for_all(aCommand,aPath,aFilesOrDirs,aPattern=nil,aInvertPattern=false,aSudo=false)
42
- #run "#{sudo} find . -wholename '*/.svn' -prune -o -type d -print0 |xargs -0 #{sudo} chmod 750"
43
- #sudo find . -type f -exec echo {} \;
44
- cmd = []
45
- cmd << "sudo" if aSudo
46
- cmd << "find #{aPath.ensure_suffix('/')}"
47
- cmd << "-wholename '#{aPattern}'" if aPattern
48
- cmd << "-prune -o" if aInvertPattern
49
- cmd << case aFilesOrDirs.to_s[0,1]
50
- when 'f' then '-type f'
51
- when 'd' then '-type d'
52
- else ''
53
- end
54
- cmd << "-exec"
55
- cmd << aCommand
56
- cmd << "'{}' \\;"
57
- cmd = cmd.join(' ')
58
- run cmd
59
- end
60
-
61
- end
62
- end