rigup 0.1.0 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rigup +7 -1
- data/lib/rigup/base.rb +35 -42
- data/lib/rigup/cli.rb +125 -116
- data/lib/rigup/config.rb +15 -14
- data/lib/rigup/context.rb +2 -2
- data/lib/rigup/utils/config.rb +133 -0
- data/lib/rigup/utils/extend_stdlib.rb +293 -0
- data/lib/rigup/utils/file.rb +127 -0
- data/lib/rigup/utils/install.rb +16 -17
- data/lib/rigup/utils/run.rb +33 -5
- data/lib/rigup/version.rb +1 -1
- data/lib/rigup.rb +14 -11
- data/rigup.gemspec +3 -22
- data/rigup.iml +1 -2
- metadata +14 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53fa8f63e51425add51231d1d1d544c56d151beb
|
4
|
+
data.tar.gz: f5d4c4574b1564804186da641f96b660c1388207
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e9f97961dfdf05271284723c8d7d6cdf2cac4d11c9790fe6c86fd4968bacca54cbedba9e94b812c501f567acc93be9c395fcb8fef726c057d819beabb6c3163
|
7
|
+
data.tar.gz: 6397a477957a80e3833fddce8b43fc29b6c482758a85710dc72689a23d09a5243c33aad3bd46af8971b5210daa0fb5343535ad16f5a9830d45d7e42191b8b7ad
|
data/bin/rigup
CHANGED
data/lib/rigup/base.rb
CHANGED
@@ -1,48 +1,41 @@
|
|
1
1
|
module Rigup
|
2
2
|
module Base
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
def logger
|
5
|
+
@logger ||= ::Logger.new(STDOUT)
|
6
|
+
end
|
7
|
+
|
8
|
+
def config
|
9
|
+
unless @config
|
10
|
+
@config = {}
|
11
|
+
if ::File.exists?(f=::File.join(release_path,'rigup.yml'))
|
12
|
+
file_config = ::YAML.load(String.from_file(f))
|
13
|
+
@config.merge!(file_config)
|
14
|
+
@config = ::Rigup::Config.new(@config)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
@config
|
18
|
+
end
|
19
|
+
|
20
|
+
def context
|
21
|
+
@context ||= ::Rigup::Context.new({
|
22
|
+
:config => config,
|
23
|
+
:logger => logger,
|
24
|
+
:pwd => ::Dir.pwd
|
25
|
+
})
|
26
|
+
end
|
27
|
+
|
28
|
+
def release_path
|
29
|
+
@release_path ||= ::File.expand_path('.')
|
30
|
+
end
|
31
|
+
|
32
|
+
def site_dir
|
33
|
+
@site_dir ||= ::File.expand_path('../..',release_path)
|
34
|
+
end
|
35
|
+
|
36
|
+
def shared_path
|
37
|
+
@shared_path ||= ::File.expand_path('shared',site_dir)
|
38
|
+
end
|
7
39
|
|
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
40
|
end
|
48
41
|
end
|
data/lib/rigup/cli.rb
CHANGED
@@ -1,139 +1,145 @@
|
|
1
1
|
module Rigup
|
2
|
-
|
3
|
-
|
4
|
-
include Rigup::Utils::Run
|
5
|
-
include Rigup::Utils::Install
|
6
|
-
|
7
|
-
no_commands do
|
2
|
+
module CliMethods
|
8
3
|
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
def logger
|
5
|
+
@logger ||= ::Logger.new(STDOUT)
|
6
|
+
end
|
7
|
+
#remove_command :logger
|
12
8
|
|
13
|
-
|
14
|
-
|
9
|
+
def config
|
10
|
+
@context.config
|
11
|
+
end
|
12
|
+
#remove_command :config
|
13
|
+
|
14
|
+
def init(aPath=nil,aConfig={})
|
15
|
+
return if @initialised
|
16
|
+
@initialised = true
|
17
|
+
aPath ||= aConfig[:site_dir] || ::Dir.pwd
|
18
|
+
@site_dir = ::Rigup::Utils::File.real_path(aPath) rescue ::File.expand_path(aPath)
|
19
|
+
@releases_path = ::File.join(@site_dir,'releases')
|
20
|
+
if ::File.exists?(f=::File.join(@site_dir,'rigup.yml'))
|
21
|
+
file_config = ::YAML.load(String.from_file(f))
|
22
|
+
aConfig.merge!(file_config)
|
15
23
|
end
|
24
|
+
aConfig = aConfig.merge(:site_dir => @site_dir)
|
25
|
+
aConfig[:user] ||= ENV['USER']
|
26
|
+
config = ::Rigup::Config.new(aConfig)
|
27
|
+
@context = ::Rigup::Context.new({
|
28
|
+
:config => config,
|
29
|
+
:logger => ::Logger.new(STDOUT),
|
30
|
+
:pwd => ::Dir.pwd
|
31
|
+
})
|
32
|
+
end
|
16
33
|
|
17
|
-
|
18
|
-
return if @initialised
|
19
|
-
@initialised = true
|
20
|
-
aPath ||= aConfig[:site_dir] || Dir.pwd
|
21
|
-
@site_dir = Buzztools::File.real_path(aPath) rescue File.expand_path(aPath)
|
22
|
-
@releases_path = File.join(@site_dir,'releases')
|
23
|
-
if File.exists?(f=File.join(@site_dir,'rigup.yml'))
|
24
|
-
file_config = YAML.load(String.from_file(f))
|
25
|
-
aConfig.merge!(file_config)
|
26
|
-
end
|
27
|
-
aConfig = aConfig.merge(site_dir: @site_dir)
|
28
|
-
aConfig[:user] ||= ENV['USER']
|
29
|
-
config = Rigup::Config.new(aConfig)
|
30
|
-
@context = Rigup::Context.new(
|
31
|
-
config: config,
|
32
|
-
logger: ::Logger.new(STDOUT),
|
33
|
-
pwd: Dir.pwd
|
34
|
-
)
|
35
|
-
end
|
34
|
+
attr_reader :context, :release_path, :site_dir
|
36
35
|
|
37
|
-
|
36
|
+
def shared_path
|
37
|
+
@shared_path ||= ::File.expand_path('shared',site_dir)
|
38
|
+
end
|
39
|
+
#remove_command :shared_path
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
def cache_dir
|
42
|
+
::File.join(site_dir,'shared','cached-copy')
|
43
|
+
end
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
|
45
|
+
def repo
|
46
|
+
@repo ||= ::Rigup::GitRepo.new(context)
|
47
|
+
end
|
46
48
|
|
47
|
-
|
48
|
-
|
49
|
+
# Prepares repo in cache dir for site
|
50
|
+
# requires params: repo_url,site
|
51
|
+
def prepare_cache # {:url=>'git://github.com/ddssda', :branch=>'master', :commit=>'ad452bcd'}
|
52
|
+
url = config[:git_url]
|
53
|
+
wd = cache_dir
|
54
|
+
|
55
|
+
suitable = if ::File.exists?(wd)
|
56
|
+
repo.open wd
|
57
|
+
repo.origin.url==url
|
58
|
+
else
|
59
|
+
false
|
49
60
|
end
|
50
61
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
suitable = if File.exists?(wd)
|
58
|
-
repo.open wd
|
59
|
-
repo.origin.url==url
|
60
|
-
else
|
61
|
-
false
|
62
|
-
end
|
63
|
-
|
64
|
-
if suitable
|
65
|
-
repo.fetch
|
66
|
-
else
|
67
|
-
if File.exists? wd
|
68
|
-
#raise RuntimeError.new('almost did bad delete') if !@core.cache_dir || @core.cache_dir.length<3 || !wd.begins_with?(@core.cache_dir)
|
69
|
-
FileUtils.rm_rf wd
|
70
|
-
end
|
71
|
-
repo.clone(url, wd)
|
62
|
+
if suitable
|
63
|
+
repo.fetch
|
64
|
+
else
|
65
|
+
if ::File.exists? wd
|
66
|
+
#raise RuntimeError.new('almost did bad delete') if !@core.cache_dir || @core.cache_dir.length<3 || !wd.begins_with?(@core.cache_dir)
|
67
|
+
::FileUtils.rm_rf wd
|
72
68
|
end
|
69
|
+
repo.clone(url, wd)
|
73
70
|
end
|
71
|
+
end
|
74
72
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
end
|
73
|
+
# Switches @repo to given branch and/or commit
|
74
|
+
# Should call prepare_cache first to create @repo
|
75
|
+
# requires params: branch and/or commit
|
76
|
+
def checkout_branch_commit
|
77
|
+
branch = config[:branch] || 'master'
|
78
|
+
commit = config[:commit]
|
79
|
+
repo.open(cache_dir)
|
80
|
+
repo.checkout(commit,branch)
|
81
|
+
#perhaps use reset --hard here
|
82
|
+
if (commit)
|
83
|
+
repo.merge(commit,['--ff-only'])
|
84
|
+
else
|
85
|
+
repo.merge('origin/'+branch,['--ff-only'])
|
89
86
|
end
|
87
|
+
end
|
90
88
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
89
|
+
def update_cache(aPath=nil)
|
90
|
+
prepare_cache
|
91
|
+
checkout_branch_commit
|
92
|
+
end
|
95
93
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
94
|
+
def release
|
95
|
+
release = ::Time.now.strftime('%Y%m%d%H%M%S')
|
96
|
+
@release_path = ::File.expand_path(release,@releases_path)
|
97
|
+
repo.open(cache_dir)
|
98
|
+
repo.export(@release_path)
|
99
|
+
release_config = context.config.to_hash
|
100
|
+
release_config[:commit] = repo.head.sha
|
101
|
+
release_config[:branch] = repo.branch
|
102
|
+
release_config.to_yaml.to_file(::File.join(@release_path,'rigup.yml'))
|
103
|
+
return @release_path
|
104
|
+
end
|
107
105
|
|
108
|
-
|
109
|
-
|
110
|
-
|
106
|
+
def link_live
|
107
|
+
ensure_link(release_path,::File.expand_path(::File.join(site_dir,'current')),"#{config[:user]}:#{config[:group]}")
|
108
|
+
end
|
111
109
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
110
|
+
def cleanup
|
111
|
+
@releases = run("ls -x #{@releases_path}").split.sort
|
112
|
+
count = (@keep_releases || 3).to_i
|
113
|
+
if count >= @releases.length
|
114
|
+
logger.info "no old releases to clean up"
|
115
|
+
else
|
116
|
+
logger.info "keeping #{count} of #{@releases.length} deployed releases"
|
119
117
|
|
120
|
-
|
121
|
-
|
122
|
-
|
118
|
+
directories = (@releases - @releases.last(count)).map { |r|
|
119
|
+
File.join(@releases_path, r)
|
120
|
+
}.join(" ")
|
123
121
|
|
124
|
-
|
125
|
-
|
126
|
-
|
122
|
+
run "rm -rf #{directories}"
|
123
|
+
end
|
124
|
+
end
|
127
125
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
end
|
126
|
+
def call_release_command(aCommand)
|
127
|
+
return unless cmdline = config["#{aCommand}_command".to_sym].to_s.strip.to_nil
|
128
|
+
cd release_path do
|
129
|
+
run cmdline
|
133
130
|
end
|
134
131
|
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
module Rigup
|
136
|
+
class Cli < Thor
|
137
|
+
|
138
|
+
include Rigup::Utils::Run
|
139
|
+
include Rigup::Utils::Install
|
140
|
+
include Rigup::CliMethods
|
135
141
|
|
136
|
-
public
|
142
|
+
#public
|
137
143
|
|
138
144
|
desc "new GIT_URL [PATH]", "setup new site"
|
139
145
|
def new(aGitUrl,aPath=nil)
|
@@ -141,23 +147,26 @@ module Rigup
|
|
141
147
|
aPath ||= app_name
|
142
148
|
init(
|
143
149
|
aPath,
|
144
|
-
|
145
|
-
|
146
|
-
|
150
|
+
{
|
151
|
+
:git_url => aGitUrl,
|
152
|
+
:app_name => app_name,
|
153
|
+
:user => ENV['USER']
|
154
|
+
}
|
147
155
|
)
|
148
156
|
FileUtils.mkdir_p(site_dir)
|
149
157
|
FileUtils.mkdir_p(File.join(site_dir,'releases'))
|
150
158
|
FileUtils.mkdir_p(File.join(site_dir,'shared'))
|
151
159
|
|
152
160
|
#+ create rigup.yml if doesn't exist, including option values
|
153
|
-
context.config.to_hash
|
161
|
+
h = context.config.to_hash
|
162
|
+
h.delete :site_dir
|
163
|
+
h.to_yaml.to_file(File.join(site_dir,'rigup.yml'))
|
154
164
|
end
|
155
165
|
|
156
166
|
desc "deploy [PATH]", "deploy the given site"
|
157
167
|
def deploy(aPath=nil)
|
158
168
|
init(aPath)
|
159
169
|
update_cache
|
160
|
-
#gem 'debugger'; require 'debugger'; debugger
|
161
170
|
release
|
162
171
|
call_release_command(:install) # call install_command if defined eg. defaults to "thor deploy:install" eg. make changes to files
|
163
172
|
call_release_command(:block)
|
data/lib/rigup/config.rb
CHANGED
@@ -1,21 +1,22 @@
|
|
1
1
|
module Rigup
|
2
2
|
|
3
|
-
class Config <
|
3
|
+
class Config < Rigup::Utils::Config
|
4
4
|
|
5
5
|
DEFAULTS = {
|
6
|
-
app_name
|
7
|
-
user
|
8
|
-
group
|
9
|
-
site_dir
|
10
|
-
git_url
|
11
|
-
branch
|
12
|
-
commit
|
13
|
-
stage
|
14
|
-
sudo
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
6
|
+
:app_name => String,
|
7
|
+
:user => String,
|
8
|
+
:group => 'www',
|
9
|
+
:site_dir => String,
|
10
|
+
:git_url => String,
|
11
|
+
:branch => String,
|
12
|
+
:commit => String,
|
13
|
+
:stage => 'live', # or 'staging' or 'development'
|
14
|
+
:sudo => 'sudo', # deprecated
|
15
|
+
:sudo_available => true,
|
16
|
+
:block_command => nil,
|
17
|
+
:install_command => 'bundle exec thor deploy:install',
|
18
|
+
:restart_command => 'bundle exec thor deploy:restart',
|
19
|
+
:unblock_command => nil
|
19
20
|
}
|
20
21
|
|
21
22
|
def initialize(aValues=nil)
|
data/lib/rigup/context.rb
CHANGED
@@ -9,7 +9,7 @@ module Rigup
|
|
9
9
|
|
10
10
|
#is_client = !!(aValues[:key_chain] || aValues[:global_options] || aValues[:options])
|
11
11
|
@config = aValues[:config]
|
12
|
-
@pwd =
|
12
|
+
@pwd = Rigup::Utils::File.real_path(aValues[:pwd] || (@config && @config[:folder]) || Dir.pwd)
|
13
13
|
@options = aValues[:options]
|
14
14
|
@argv = aValues[:argv]
|
15
15
|
@env = aValues[:env]
|
@@ -47,7 +47,7 @@ module Rigup
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def find_git_root
|
50
|
-
git_folder =
|
50
|
+
git_folder = Rigup::Utils::File.find_upwards(@pwd,'.git')
|
51
51
|
return git_folder && git_folder.chomp('/.git')
|
52
52
|
end
|
53
53
|
|
@@ -0,0 +1,133 @@
|
|
1
|
+
module Rigup
|
2
|
+
module Utils
|
3
|
+
class Config < Hash
|
4
|
+
|
5
|
+
attr_reader :default_values
|
6
|
+
|
7
|
+
def initialize(aDefaultValues, aNewValues=nil, &aBlock)
|
8
|
+
@default_values = aDefaultValues.clone
|
9
|
+
reset()
|
10
|
+
if aNewValues
|
11
|
+
block_given? ? read(aNewValues, &aBlock) : read(aNewValues)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# aBlock allows values to be filtered based on key,default and new values
|
16
|
+
def read(aSource, &aBlock)
|
17
|
+
default_values.each do |k, v|
|
18
|
+
done = false
|
19
|
+
if block_given? && ((newv = yield(k, v, aSource && aSource[k])) != nil)
|
20
|
+
self[k] = newv
|
21
|
+
done = true
|
22
|
+
end
|
23
|
+
copy_item(aSource, k) if !done && aSource && !aSource[k].nil?
|
24
|
+
end
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
# reset values back to defaults
|
29
|
+
def reset
|
30
|
+
self.clear
|
31
|
+
me = self
|
32
|
+
@default_values.each { |n, v| me[n] = v.is_a?(Class) ? nil : v }
|
33
|
+
end
|
34
|
+
|
35
|
+
def set_int(aKey, aValue)
|
36
|
+
case aValue
|
37
|
+
when String then
|
38
|
+
self[aKey] = aValue.to_integer(self[aKey]);
|
39
|
+
when Fixnum then
|
40
|
+
self[aKey] = aValue;
|
41
|
+
when Float then
|
42
|
+
self[aKey] = aValue.to_i;
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def set_float(aKey, aValue)
|
47
|
+
case aValue
|
48
|
+
when String then
|
49
|
+
self[aKey] = aValue.to_float(self[aKey]);
|
50
|
+
when Fixnum then
|
51
|
+
self[aKey] = aValue.to_f;
|
52
|
+
when Float then
|
53
|
+
self[aKey] = aValue;
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def set_boolean(aKey, aValue)
|
58
|
+
case aValue
|
59
|
+
when TrueClass, FalseClass then
|
60
|
+
self[aKey] = aValue;
|
61
|
+
when String then
|
62
|
+
self[aKey] = (['1', 'yes', 'y', 'true', 'on'].include?(aValue.downcase))
|
63
|
+
else
|
64
|
+
set_boolean(aKey, aValue.to_s)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def set_symbol(aKey, aValue)
|
69
|
+
case aValue
|
70
|
+
when String then
|
71
|
+
self[aKey] = (aValue.to_sym rescue nil);
|
72
|
+
when Symbol then
|
73
|
+
self[aKey] = aValue;
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def copy_item(aHash, aKey)
|
78
|
+
d = default_values[aKey]
|
79
|
+
d_class = (d.is_a?(Class) ? d : d.class)
|
80
|
+
cname = d_class.name.to_sym
|
81
|
+
case cname
|
82
|
+
when :NilClass then
|
83
|
+
self[aKey] = aHash[aKey];
|
84
|
+
when :String then
|
85
|
+
self[aKey] = aHash[aKey].to_s unless aHash[aKey].nil?
|
86
|
+
when :Float then
|
87
|
+
set_float(aKey, aHash[aKey]);
|
88
|
+
when :Fixnum then
|
89
|
+
set_int(aKey, aHash[aKey]);
|
90
|
+
when :TrueClass, :FalseClass then
|
91
|
+
set_boolean(aKey, aHash[aKey]);
|
92
|
+
when :Symbol then
|
93
|
+
self[aKey] = (aHash[aKey].to_sym rescue nil)
|
94
|
+
when :Proc then
|
95
|
+
self[aKey] = aHash[aKey] if aHash[aKey].is_a?(Proc)
|
96
|
+
else
|
97
|
+
raise StandardError.new('unsupported type')
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def copy_strings(aHash, *aKeys)
|
102
|
+
aKeys.each do |k|
|
103
|
+
self[k] = aHash[k].to_s unless aHash[k].nil?
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def copy_ints(*aDb)
|
108
|
+
aHash = aDb.shift
|
109
|
+
aKeys = aDb
|
110
|
+
aKeys.each do |k|
|
111
|
+
set_int(k, aHash[k])
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def copy_floats(aHash, *aKeys)
|
116
|
+
aKeys.each do |k|
|
117
|
+
set_float(k, aHash[k])
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def copy_booleans(aHash, *aKeys)
|
122
|
+
aKeys.each do |k|
|
123
|
+
set_boolean(k, aHash[k])
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def to_hash
|
128
|
+
{}.merge(self)
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,293 @@
|
|
1
|
+
unless defined? Buzztools
|
2
|
+
|
3
|
+
Array.class_eval do
|
4
|
+
def to_nil
|
5
|
+
self.empty? ? nil : self
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
Bignum.class_eval do
|
10
|
+
def to_nil
|
11
|
+
self==0 ? nil : self
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Float.class_eval do
|
16
|
+
def to_nil
|
17
|
+
(self==0 || !self.finite?) ? nil : self
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Fixnum.class_eval do
|
22
|
+
def to_nil
|
23
|
+
self==0 ? nil : self
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
Hash.class_eval do
|
28
|
+
def to_nil
|
29
|
+
self.empty? ? nil : self
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
TrueClass.class_eval do
|
34
|
+
def to_nil
|
35
|
+
self
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
FalseClass.class_eval do
|
40
|
+
def to_nil
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
NilClass.class_eval do
|
46
|
+
def to_nil
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
Symbol.class_eval do
|
52
|
+
def to_nil
|
53
|
+
self
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
String.class_eval do
|
58
|
+
def to_nil(aPattern=nil)
|
59
|
+
return nil if self.empty?
|
60
|
+
if aPattern
|
61
|
+
return nil if (aPattern.is_a? Regexp) && (self =~ aPattern)
|
62
|
+
return nil if aPattern.to_s == self
|
63
|
+
end
|
64
|
+
self
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
String.class_eval do
|
69
|
+
|
70
|
+
def self.random_word(min=4,max=8)
|
71
|
+
len = min + rand(max-min+1)
|
72
|
+
result = ' '*len
|
73
|
+
(len-1).downto(0) {|i| result[i] = (?a.ord + rand(?z.ord-?a.ord+1)).chr}
|
74
|
+
return result
|
75
|
+
end
|
76
|
+
|
77
|
+
def pad_left(value)
|
78
|
+
increase = value-self.length
|
79
|
+
return self if increase==0
|
80
|
+
if increase > 0
|
81
|
+
return self + ' '*increase
|
82
|
+
else
|
83
|
+
return self[0,value]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def pad_right(value)
|
88
|
+
increase = value-self.length
|
89
|
+
return self if increase==0
|
90
|
+
if increase > 0
|
91
|
+
return ' '*increase + self
|
92
|
+
else
|
93
|
+
return self[0,value]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Like bite, but returns the first match instead of the subject, and removes the match from the subject, modifying it
|
98
|
+
def extract!(aValue=$/,aString=self)
|
99
|
+
if aValue.is_a? String
|
100
|
+
if i = aString.index(aValue)
|
101
|
+
aString[i,aValue.length] = ''
|
102
|
+
return aValue
|
103
|
+
else
|
104
|
+
return nil
|
105
|
+
end
|
106
|
+
elsif aValue.is_a? Regexp
|
107
|
+
if md = aValue.match(aString)
|
108
|
+
aString[md.begin(0),md.end(0)-md.begin(0)] = ''
|
109
|
+
return md.to_s
|
110
|
+
else
|
111
|
+
return nil
|
112
|
+
end
|
113
|
+
else
|
114
|
+
return aString
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def extract(aValue=$/)
|
119
|
+
extract!(aValue,self.clone)
|
120
|
+
end
|
121
|
+
|
122
|
+
# Like chomp! but operates on the leading characters instead.
|
123
|
+
# The aString parameter would not normally be used.
|
124
|
+
def bite!(aValue=$/,aString=self)
|
125
|
+
if aValue.is_a? String
|
126
|
+
if aString[0,aValue.length] == aValue
|
127
|
+
aString[0,aValue.length] = ''
|
128
|
+
return aString
|
129
|
+
else
|
130
|
+
return aString
|
131
|
+
end
|
132
|
+
elsif aValue.is_a? Regexp
|
133
|
+
return aString.sub!(aValue,'') if aString.index(aValue)==0
|
134
|
+
else
|
135
|
+
return aString
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def bite(aValue=$/)
|
140
|
+
bite!(aValue,self.clone)
|
141
|
+
end
|
142
|
+
|
143
|
+
def deprefix!(aPrefix=$/,aString=self)
|
144
|
+
if aString[0,aPrefix.length] == aPrefix
|
145
|
+
aString[0,aPrefix.length] = ''
|
146
|
+
return aString
|
147
|
+
else
|
148
|
+
return aString
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def deprefix(aValue=$/)
|
153
|
+
deprefix!(aValue,self.clone)
|
154
|
+
end
|
155
|
+
|
156
|
+
def desuffix!(aString,aSuffix)
|
157
|
+
if aString[-aSuffix.length,aSuffix.length] == aSuffix
|
158
|
+
aString[-aSuffix.length,aSuffix.length] = ''
|
159
|
+
return aString
|
160
|
+
else
|
161
|
+
return aString
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def desuffix(aValue=$/)
|
166
|
+
desuffix!(aValue,self.clone)
|
167
|
+
end
|
168
|
+
|
169
|
+
def begins_with?(aString)
|
170
|
+
self[0,aString.length]==aString
|
171
|
+
end
|
172
|
+
|
173
|
+
def ends_with?(aString)
|
174
|
+
self[-aString.length,aString.length]==aString
|
175
|
+
end
|
176
|
+
|
177
|
+
def ensure_prefix!(aPrefix=$/,aString=self)
|
178
|
+
aString[0,0]=aPrefix unless aString.begins_with?(aPrefix)
|
179
|
+
aString
|
180
|
+
end
|
181
|
+
|
182
|
+
def ensure_prefix(aValue=$/)
|
183
|
+
ensure_prefix!(aValue,self.clone)
|
184
|
+
end
|
185
|
+
|
186
|
+
def ensure_suffix!(aSuffix=$/,aString=self)
|
187
|
+
aString.insert(-1,aSuffix) unless aString.ends_with?(aSuffix)
|
188
|
+
aString
|
189
|
+
end
|
190
|
+
|
191
|
+
def ensure_suffix(aValue=$/)
|
192
|
+
ensure_suffix!(aValue,self.clone)
|
193
|
+
end
|
194
|
+
|
195
|
+
def to_integer(aDefault=nil)
|
196
|
+
t = self.strip
|
197
|
+
return aDefault if t.empty? || !t.index(/^-{0,1}[0-9]+$/)
|
198
|
+
return t.to_i
|
199
|
+
end
|
200
|
+
|
201
|
+
def is_i?
|
202
|
+
self.to_integer(false) and true
|
203
|
+
end
|
204
|
+
|
205
|
+
def to_float(aDefault=nil)
|
206
|
+
t = self.strip
|
207
|
+
return aDefault if !t =~ /(\+|-)?([0-9]+\.?[0-9]*|\.[0-9]+)([eE](\+|-)?[0-9]+)?/
|
208
|
+
return t.to_f
|
209
|
+
end
|
210
|
+
|
211
|
+
def is_f?
|
212
|
+
self.to_float(false) and true
|
213
|
+
end
|
214
|
+
|
215
|
+
# like scan but returns array of MatchData's.
|
216
|
+
# doesn't yet support blocks
|
217
|
+
def scan_md(aPattern)
|
218
|
+
result = []
|
219
|
+
self.scan(aPattern) {|s| result << $~ }
|
220
|
+
result
|
221
|
+
end
|
222
|
+
|
223
|
+
def to_b(aDefault=false)
|
224
|
+
return true if ['1','yes','y','true','on'].include?(self.downcase)
|
225
|
+
return false if ['0','no','n','false','off'].include?(self.downcase)
|
226
|
+
aDefault
|
227
|
+
end
|
228
|
+
|
229
|
+
# "...Only alphanumerics [0-9a-zA-Z], the special characters "$-_.+!*'()," [not including the quotes - ed], and reserved characters used for their reserved purposes may be used unencoded within a URL."
|
230
|
+
|
231
|
+
URLIZE_SEPARATORS = /[ \\\(\)\[\]\.*,]/ # was /[ \\\(\)\[\]\.*,]/
|
232
|
+
URLIZE_EXTENSIONS = %w(html htm jpg jpeg png gif bmp mov avi mp3 zip pdf css js doc xdoc)
|
233
|
+
URLIZE_REMOVE = /[^a-z0-9\_\-+~\/]/ # was 'a-z0-9_-+~/'
|
234
|
+
# aKeepExtensions may be an array of extensions to keep, or :none (will remove periods) or :all (any extension <= 4 chars)
|
235
|
+
def urlize(aSlashChar='+',aRemove=nil,aKeepExtensions=nil)
|
236
|
+
aKeepExtensions=URLIZE_EXTENSIONS if !aKeepExtensions
|
237
|
+
aRemove=URLIZE_REMOVE if !aRemove
|
238
|
+
return self if self.empty?
|
239
|
+
result = self.downcase
|
240
|
+
ext = nil
|
241
|
+
if (aKeepExtensions!=:none) && last_dot = result.rindex('.')
|
242
|
+
if (ext_len = result.length-last_dot-1) <= 4 # preserve extension without dot if <= 4 chars long
|
243
|
+
ext = result[last_dot+1..-1]
|
244
|
+
ext = nil unless aKeepExtensions==:all || (aKeepExtensions.is_a?(Array) && aKeepExtensions.include?(ext))
|
245
|
+
result = result[0,last_dot] if ext
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
result = result.gsub(URLIZE_SEPARATORS,'-')
|
250
|
+
result = result.gsub(aRemove,'').sub(/-+$/,'').sub(/^-+/,'')
|
251
|
+
result.gsub!('/',aSlashChar) unless aSlashChar=='/'
|
252
|
+
result.gsub!(/-{2,}/,'-')
|
253
|
+
result += '.'+ext if ext
|
254
|
+
result
|
255
|
+
end
|
256
|
+
|
257
|
+
def has_tags?
|
258
|
+
index(/<[a-zA-Z\-:0-9]+(\b|>)/) && (index('/>') || index('</')) # contains an opening and closing tag
|
259
|
+
end
|
260
|
+
|
261
|
+
def snake_case
|
262
|
+
underscore.tr(' ','_')
|
263
|
+
end
|
264
|
+
|
265
|
+
def relative_url?
|
266
|
+
!begins_with?('http') || !begins_with?('/')
|
267
|
+
end
|
268
|
+
|
269
|
+
def to_file(aFilename)
|
270
|
+
File.open(aFilename,'wb') {|file| file.write self }
|
271
|
+
end
|
272
|
+
|
273
|
+
def self.from_file(aFilename)
|
274
|
+
File.open(aFilename, "rb") { |f| f.read }
|
275
|
+
end
|
276
|
+
|
277
|
+
# given ('abcdefg','c.*?e') returns ['ab','cde','fg'] so you can manipulate the head, match and tail seperately, and potentially rejoin
|
278
|
+
def split3(aPattern,aOccurence=0)
|
279
|
+
aString = self
|
280
|
+
matches = aString.scan_md(aPattern)
|
281
|
+
match = matches[aOccurence]
|
282
|
+
parts = (match ? [match.pre_match,match.to_s,match.post_match] : [aString,nil,''])
|
283
|
+
|
284
|
+
if !block_given? # return head,match,tail
|
285
|
+
parts
|
286
|
+
else # return string
|
287
|
+
parts[1] = yield *parts if match
|
288
|
+
parts.join
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module Rigup
|
4
|
+
module Utils
|
5
|
+
module File
|
6
|
+
|
7
|
+
module_function
|
8
|
+
|
9
|
+
def sniff_seperator(aPath)
|
10
|
+
result = 0.upto(aPath.length-1) do |i|
|
11
|
+
char = aPath[i, 1]
|
12
|
+
break char if char=='\\' || char=='/'
|
13
|
+
end
|
14
|
+
result = ::File::SEPARATOR if result==0
|
15
|
+
return result
|
16
|
+
end
|
17
|
+
|
18
|
+
def append_slash(aPath, aSep=nil)
|
19
|
+
aSep = sniff_seperator(aPath) unless aSep
|
20
|
+
aPath.ensure_suffix(aSep)
|
21
|
+
end
|
22
|
+
|
23
|
+
def remove_slash(aPath)
|
24
|
+
last_char = aPath[-1, 1]
|
25
|
+
aPath = aPath[0..-2] if last_char=='\\' || last_char=='/'
|
26
|
+
return aPath
|
27
|
+
end
|
28
|
+
|
29
|
+
#def ensure_prefix(aString,aPrefix)
|
30
|
+
# aString.begins_with?(aPrefix) ? aString : aPrefix+aString
|
31
|
+
#end
|
32
|
+
#
|
33
|
+
#def ensure_suffix(aString,aSuffix)
|
34
|
+
# aString.ends_with?(aSuffix) ? aString : aString+aSuffix
|
35
|
+
#end
|
36
|
+
|
37
|
+
# Remove base dir from given path. Result will be relative to base dir and not have a leading or trailing slash
|
38
|
+
#'/a/b/c','/a' = 'b/c'
|
39
|
+
#'/a/b/c','/' = 'a/b/c'
|
40
|
+
#'/','/' = ''
|
41
|
+
def path_debase(aPath, aBase)
|
42
|
+
aBase = append_slash(aBase)
|
43
|
+
aPath = remove_slash(aPath) unless aPath=='/'
|
44
|
+
aPath[0, aBase.length]==aBase ? aPath[aBase.length, aPath.length-aBase.length] : aPath
|
45
|
+
end
|
46
|
+
|
47
|
+
def path_rebase(aPath, aOldBase, aNewBase)
|
48
|
+
rel_path = path_debase(aPath, aOldBase)
|
49
|
+
append_slash(aNewBase)+rel_path
|
50
|
+
end
|
51
|
+
|
52
|
+
def path_combine(aBasePath, aPath)
|
53
|
+
return aBasePath if !aPath
|
54
|
+
return aPath if !aBasePath
|
55
|
+
return path_relative?(aPath) ? ::File.join(aBasePath, aPath) : aPath
|
56
|
+
end
|
57
|
+
|
58
|
+
# make path real according to file system
|
59
|
+
def real_path(aPath)
|
60
|
+
(path = Pathname.new(::File.expand_path(aPath))) && path.realpath.to_s
|
61
|
+
end
|
62
|
+
|
63
|
+
# takes a path and combines it with a root path (which defaults to Dir.pwd) unless it is absolute
|
64
|
+
# the final result is then expanded
|
65
|
+
def canonize_path(aPath, aRootPath=nil)
|
66
|
+
path = path_combine(aRootPath, aPath)
|
67
|
+
path = real_path(path) if path
|
68
|
+
path
|
69
|
+
end
|
70
|
+
|
71
|
+
def find_upwards(aStartPath, aPath)
|
72
|
+
curr_path = ::File.expand_path(aStartPath)
|
73
|
+
while curr_path && !(test_path_exists = ::File.exists?(test_path = ::File.join(curr_path, aPath))) do
|
74
|
+
curr_path = path_parent(curr_path)
|
75
|
+
end
|
76
|
+
curr_path && test_path_exists ? test_path : nil
|
77
|
+
end
|
78
|
+
|
79
|
+
# allows special symbols in path
|
80
|
+
# currently only ... supported, which looks upward in the filesystem for the following relative path from the basepath
|
81
|
+
def expand_magic_path(aPath, aBasePath=nil)
|
82
|
+
aBasePath ||= Dir.pwd
|
83
|
+
path = aPath
|
84
|
+
if path.begins_with?('...')
|
85
|
+
rel_part = path.split3(/\.\.\.[\/\\]/)[2]
|
86
|
+
path = find_upwards(aBasePath, rel_part)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def path_parent(aPath)
|
91
|
+
return nil if is_root_path?(aPath)
|
92
|
+
append_slash(::File.dirname(remove_slash(expand_path(aPath))))
|
93
|
+
end
|
94
|
+
|
95
|
+
def simple_dir_name(aPath)
|
96
|
+
::File.basename(remove_slash(aPath))
|
97
|
+
end
|
98
|
+
|
99
|
+
def simple_file_name(aPath)
|
100
|
+
f = ::File.basename(aPath)
|
101
|
+
dot = f.index('.')
|
102
|
+
return dot ? f[0, dot] : f
|
103
|
+
end
|
104
|
+
|
105
|
+
def path_parts(aPath)
|
106
|
+
sep = sniff_seperator(aPath)
|
107
|
+
aPath.split(sep)
|
108
|
+
end
|
109
|
+
|
110
|
+
def extension(aFile, aExtended=true)
|
111
|
+
f = ::File.basename(aFile)
|
112
|
+
dot = aExtended ? f.index('.') : f.rindex('.')
|
113
|
+
return dot ? f[dot+1..-1] : f
|
114
|
+
end
|
115
|
+
|
116
|
+
def no_extension(aFile, aExtended=true)
|
117
|
+
ext = extension(aFile, aExtended)
|
118
|
+
return aFile.chomp('.'+ext)
|
119
|
+
end
|
120
|
+
|
121
|
+
def change_ext(aFile, aExt, aExtend=false)
|
122
|
+
no_extension(aFile, false)+(aExtend ? '.'+aExt+'.'+extension(aFile, false) : '.'+aExt)
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
data/lib/rigup/utils/install.rb
CHANGED
@@ -3,11 +3,11 @@ module Rigup
|
|
3
3
|
module Install
|
4
4
|
|
5
5
|
def select_suffixed_file(aFile,aExtendedExtension=false)
|
6
|
-
ext =
|
7
|
-
no_ext =
|
8
|
-
dir = File.dirname(aFile)
|
9
|
-
run "
|
10
|
-
run "
|
6
|
+
ext = Rigup::Utils::File.extension(aFile,aExtendedExtension)
|
7
|
+
no_ext = Rigup::Utils::File.no_extension(aFile,aExtendedExtension)
|
8
|
+
dir = ::File.dirname(aFile)
|
9
|
+
run "mv -f #{no_ext}.#{context.config[:stage]}.#{ext} #{aFile}"
|
10
|
+
run "rm -f #{no_ext}.*.#{ext}"
|
11
11
|
end
|
12
12
|
|
13
13
|
# Especially for modifiying behaviour eg. of FCKEditor without upsetting the standard files
|
@@ -18,8 +18,8 @@ module Rigup
|
|
18
18
|
def override_folder(aFolder,aOverrideFolder=nil,aRemove=true)
|
19
19
|
aFolder = aFolder.desuffix('/')
|
20
20
|
aOverrideFolder ||= (aFolder+'_override')
|
21
|
-
run "
|
22
|
-
run "
|
21
|
+
run "cp -vrf #{aOverrideFolder}/* #{aFolder}/"
|
22
|
+
run "rm -rf #{aOverrideFolder}" if aRemove
|
23
23
|
end
|
24
24
|
|
25
25
|
|
@@ -28,7 +28,7 @@ module Rigup
|
|
28
28
|
aUser ||= @user
|
29
29
|
aGroup ||= @group
|
30
30
|
|
31
|
-
|
31
|
+
sudo? "chown -R #{aUser}:#{aGroup} #{aPath.ensure_suffix('/')}"
|
32
32
|
run_for_all("chmod 755",aPath,:dirs) # !!! perhaps reduce other permissions
|
33
33
|
run_for_all("chmod 644",aPath,:files)
|
34
34
|
run_for_all("chmod g+s",aPath,:dirs)
|
@@ -39,7 +39,7 @@ module Rigup
|
|
39
39
|
|
40
40
|
# run this after permissions_for_web() on dirs that need to be writable by group (apache)
|
41
41
|
def permissions_for_web_writable(aPath)
|
42
|
-
|
42
|
+
sudo? "chmod -R g+w #{aPath.ensure_suffix('/')}"
|
43
43
|
run_for_all("chmod -R 700",aPath,:dirs,"*/.svn")
|
44
44
|
end
|
45
45
|
|
@@ -60,7 +60,7 @@ module Rigup
|
|
60
60
|
#permissions_for_web_writable("#{aPath}/tmp")
|
61
61
|
make_public_cache_dir("#{aPath}/tmp")
|
62
62
|
|
63
|
-
|
63
|
+
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
64
|
|
65
65
|
when 'spree' then
|
66
66
|
internal_permissions(aPath,'rails')
|
@@ -75,17 +75,16 @@ module Rigup
|
|
75
75
|
internal_permissions(aPath, aKind)
|
76
76
|
end
|
77
77
|
|
78
|
-
def ensure_link(aTo,aFrom,aUserGroup=nil
|
79
|
-
raise "Must supply from" if !aFrom
|
78
|
+
def ensure_link(aTo,aFrom,aUserGroup=nil)
|
80
79
|
cmd = []
|
81
|
-
cmd << "#{
|
82
|
-
cmd << "#{
|
83
|
-
cmd << "#{
|
84
|
-
run(cmd.join(' && '),raise
|
80
|
+
cmd << "#{sudo_s}rm -rf #{aFrom}"
|
81
|
+
cmd << "#{sudo_s}ln -sf #{aTo} #{aFrom}"
|
82
|
+
cmd << "#{sudo_s}chown -h #{aUserGroup} #{aFrom}" if aUserGroup
|
83
|
+
run(cmd.join(' && '),{:raise => false})
|
85
84
|
end
|
86
85
|
|
87
86
|
def make_public_cache_dir(aStartPath)
|
88
|
-
|
87
|
+
sudo? "mkdir -p #{aStartPath}"
|
89
88
|
permissions_for_web(aStartPath)
|
90
89
|
permissions_for_web_writable(aStartPath)
|
91
90
|
end
|
data/lib/rigup/utils/run.rb
CHANGED
@@ -7,7 +7,7 @@ module Rigup
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def pwd
|
10
|
-
bash.execute("pwd", stdout
|
10
|
+
bash.execute("pwd", {:stdout => nil}).first.strip
|
11
11
|
end
|
12
12
|
|
13
13
|
def cd(aPath,&block)
|
@@ -22,28 +22,56 @@ module Rigup
|
|
22
22
|
cd(before_path)
|
23
23
|
end
|
24
24
|
else
|
25
|
-
aPath = File.expand_path(aPath)
|
25
|
+
aPath = ::File.expand_path(aPath)
|
26
26
|
Dir.chdir(aPath)
|
27
27
|
bash.execute("cd \"#{aPath}\"")
|
28
28
|
end
|
29
29
|
aPath
|
30
30
|
end
|
31
31
|
|
32
|
+
# execute the given command in the bash session
|
32
33
|
def run(aCommand,aOptions=nil)
|
33
34
|
aOptions ||= {}
|
34
35
|
logger.debug aCommand
|
35
|
-
response,errout = bash.execute(aCommand
|
36
|
+
response,errout = bash.execute(aCommand,:stdout => STDOUT) # ::POpen4::shell(aCommand,aDir || @context.pwd)
|
36
37
|
logger.debug errout if errout.to_nil
|
37
38
|
logger.debug response if response.to_nil
|
38
39
|
raise "Command Failed" unless bash.exit_status==0 or aOptions[:raise]==false
|
39
40
|
return response
|
40
41
|
end
|
41
42
|
|
42
|
-
|
43
|
+
# returns true if sudo is available for the current user, otherwise false. Default = true
|
44
|
+
def sudo_available?
|
45
|
+
return !!config[:sudo_available] if config.has_key?(:sudo_available)
|
46
|
+
return false if !config[:sudo].to_nil # false if old config item blank
|
47
|
+
true
|
48
|
+
end
|
49
|
+
|
50
|
+
# execute the command using sudo. Raises an exception if sudo is not available
|
51
|
+
def sudo(aCommand,aOptions=nil)
|
52
|
+
raise "sudo not available" unless sudo_available?
|
53
|
+
run('sudo '+aCommand,aOptions)
|
54
|
+
end
|
55
|
+
|
56
|
+
# uses sudo if available, otherwise plain run
|
57
|
+
def sudo?(aCommand,aOptions=nil)
|
58
|
+
if sudo_available?
|
59
|
+
sudo(aCommand,aOptions)
|
60
|
+
else
|
61
|
+
run(aCommand,aOptions)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# for embedding into command line strings
|
66
|
+
def sudo_s
|
67
|
+
sudo_available? ? 'sudo ' : ''
|
68
|
+
end
|
69
|
+
|
70
|
+
def run_for_all(aCommand,aPath,aFilesOrDirs,aPattern=nil,aInvertPattern=false)
|
43
71
|
#run "#{sudo} find . -wholename '*/.svn' -prune -o -type d -print0 |xargs -0 #{sudo} chmod 750"
|
44
72
|
#sudo find . -type f -exec echo {} \;
|
45
73
|
cmd = []
|
46
|
-
cmd <<
|
74
|
+
cmd << sudo_s
|
47
75
|
cmd << "find #{aPath.ensure_suffix('/')}"
|
48
76
|
cmd << "-wholename '#{aPattern}'" if aPattern
|
49
77
|
cmd << "-prune -o" if aInvertPattern
|
data/lib/rigup/version.rb
CHANGED
data/lib/rigup.rb
CHANGED
@@ -1,16 +1,19 @@
|
|
1
1
|
require 'thor'
|
2
|
-
require 'buzztools'
|
3
2
|
require 'logger'
|
4
3
|
require 'yaml'
|
5
4
|
require 'session'
|
6
|
-
#require 'buzztools/extras/shell_extras'
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
6
|
+
Dir.chdir(File.dirname(__FILE__)) do
|
7
|
+
require "rigup/version"
|
8
|
+
require "rigup/utils/extend_stdlib"
|
9
|
+
require "rigup/utils/config"
|
10
|
+
require "rigup/utils/file"
|
11
|
+
require "rigup/utils/run"
|
12
|
+
require "rigup/utils/install"
|
13
|
+
require "rigup/config"
|
14
|
+
require "rigup/context"
|
15
|
+
require "rigup/git_repo"
|
16
|
+
require "rigup/cli"
|
17
|
+
require "rigup/base"
|
18
|
+
require "rigup/deploy_base"
|
19
|
+
end
|
data/rigup.gemspec
CHANGED
@@ -20,29 +20,10 @@ Gem::Specification.new do |s|
|
|
20
20
|
|
21
21
|
s.add_dependency 'bundler'#, '~>1.5.3'
|
22
22
|
s.add_dependency 'thor'#, '~> 0.19.1'
|
23
|
-
|
24
|
-
|
25
|
-
s.add_development_dependency 'rspec', '~>2.14.0'
|
26
|
-
#s.add_development_dependency('rspec')
|
27
|
-
|
28
|
-
s.add_development_dependency('rake')
|
29
|
-
#s.add_development_dependency('rspec-core')
|
30
|
-
#s.add_development_dependency('rdoc')
|
31
|
-
#s.add_development_dependency('aruba')
|
32
|
-
#s.add_development_dependency('debugger')
|
33
|
-
#s.add_runtime_dependency('gli','2.5.0')
|
34
|
-
#s.add_runtime_dependency('termios')
|
35
|
-
#s.add_runtime_dependency('highline')
|
36
23
|
s.add_runtime_dependency('git')
|
37
|
-
#s.add_runtime_dependency('middleman')
|
38
|
-
s.add_runtime_dependency 'buzztools', '~>0.0.6'
|
39
|
-
#s.add_runtime_dependency('POpen4')
|
40
24
|
s.add_runtime_dependency('session')
|
41
25
|
# https://github.com/geemus/formatador
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
#s.add_runtime_dependency('net_dav')
|
46
|
-
#s.add_runtime_dependency('net-ssh')
|
47
|
-
#s.add_runtime_dependency('system_timer')
|
26
|
+
|
27
|
+
s.add_development_dependency 'rspec', '~>2.14.0'
|
28
|
+
s.add_development_dependency('rake')
|
48
29
|
end
|
data/rigup.iml
CHANGED
@@ -14,9 +14,8 @@
|
|
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" />
|
18
17
|
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.2.5, RVM: ruby-2.0.0-p247) [gem]" level="application" />
|
19
|
-
<orderEntry type="library" scope="PROVIDED" name="git (v1.2.
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="git (v1.2.8, RVM: ruby-2.0.0-p247) [gem]" level="application" />
|
20
19
|
<orderEntry type="library" scope="PROVIDED" name="rake (v10.2.0, RVM: ruby-2.0.0-p247) [gem]" level="application" />
|
21
20
|
<orderEntry type="library" scope="PROVIDED" name="rspec (v2.14.1, RVM: ruby-2.0.0-p247) [gem]" level="application" />
|
22
21
|
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v2.14.8, RVM: ruby-2.0.0-p247) [gem]" level="application" />
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rigup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.10
|
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-
|
11
|
+
date: 2014-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -39,27 +39,13 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ~>
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 2.14.0
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ~>
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 2.14.0
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rake
|
42
|
+
name: git
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
45
|
- - '>='
|
60
46
|
- !ruby/object:Gem::Version
|
61
47
|
version: '0'
|
62
|
-
type: :
|
48
|
+
type: :runtime
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
@@ -67,7 +53,7 @@ dependencies:
|
|
67
53
|
- !ruby/object:Gem::Version
|
68
54
|
version: '0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
56
|
+
name: session
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
59
|
- - '>='
|
@@ -81,27 +67,27 @@ dependencies:
|
|
81
67
|
- !ruby/object:Gem::Version
|
82
68
|
version: '0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
70
|
+
name: rspec
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
73
|
- - ~>
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
90
|
-
type: :
|
75
|
+
version: 2.14.0
|
76
|
+
type: :development
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
80
|
- - ~>
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
82
|
+
version: 2.14.0
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
84
|
+
name: rake
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
87
|
- - '>='
|
102
88
|
- !ruby/object:Gem::Version
|
103
89
|
version: '0'
|
104
|
-
type: :
|
90
|
+
type: :development
|
105
91
|
prerelease: false
|
106
92
|
version_requirements: !ruby/object:Gem::Requirement
|
107
93
|
requirements:
|
@@ -126,6 +112,9 @@ files:
|
|
126
112
|
- lib/rigup/deploy_base.rb
|
127
113
|
- lib/rigup/git_repo.rb
|
128
114
|
- lib/rigup/svn.rb
|
115
|
+
- lib/rigup/utils/config.rb
|
116
|
+
- lib/rigup/utils/extend_stdlib.rb
|
117
|
+
- lib/rigup/utils/file.rb
|
129
118
|
- lib/rigup/utils/install.rb
|
130
119
|
- lib/rigup/utils/run.rb
|
131
120
|
- lib/rigup/version.rb
|