lib/shaddox/shadow.rb in shaddox-0.0.19 vs lib/shaddox/shadow.rb in shaddox-0.0.20
- old
+ new
@@ -8,11 +8,11 @@
class Shadow
require 'fileutils'
#include FileUtils
def initialize(options, &block)
- @verbose = options[:verbose] || true
+ @debug = options[:debug] || false
@installer = options[:installer]
@tmppath = options[:tmppath] || '/tmp/shaddox/'
@required = true
instance_eval(&block)
end
@@ -24,12 +24,16 @@
end
def sh(command, args = nil)
line = "#{command}"
line += " #{args.join(" ")}" if args
- info "Running '#{line}' in '#{Dir.pwd}'", 1 if @verbose
- system(command, *args)
+ exec(line, :verbose => true)
+ end
+
+ def exec(command, opts = {:verbose => false})
+ info "Running '#{command}' in '#{Dir.pwd}'", 1 if opts[:verbose] or @debug
+ system(command)
raise "#{line} failed" unless $? == 0 or !@required
end
def cd(path, &block)
current_path = Dir.pwd
@@ -92,24 +96,31 @@
release = current_max.to_i + 1 if current_max
end
# Make a new release dir
release_path = "./releases/#{release}"
- mkdir(release_path)
case repo.vcs
when :git
# Clone/update repo in vcs:
if exists_d('vcs')
cd 'vcs' do
- sh "git fetch #{repo.url} #{repo.branch}:#{repo.branch} --force"
+ exec "git fetch #{repo.url} #{repo.branch}:#{repo.branch} --force"
end
else
- sh "git clone #{repo.url} vcs --bare"
+ exec "git clone #{repo.url} vcs --bare"
end
- sh "git clone ./vcs #{release_path} --recursive --branch #{repo.branch}"
+ exec "git clone ./vcs #{release_path} --recursive --branch #{repo.branch}"
end
+
+ # Link shared paths
+ repo.shared.each do |shared_path|
+ ln_s "./shared/#{shared_path}", "#{release_path}/#{shared_path}"
+ end
+
+ # Link ./current to the latest release
+ ln_s './current', release_path
end
end
def install(package)
unless @installer
@@ -129,12 +140,12 @@
info "Ensuring #{package} is installed with #{@installer}", 1 if @verbose
package_installed = lambda { system("type #{package} >/dev/null 2>&1") }
unless package_installed.call()
case @installer
when :apt
- sh "sudo apt-get install -y #{package}"
+ exec "sudo apt-get install -y #{package}"
when :brew
- sh "brew install #{package}"
+ exec "brew install #{package}"
end
end
raise "#{package} could not be installed." unless package_installed.call()
end
end