lib/shaddox/shadow.rb in shaddox-0.0.24 vs lib/shaddox/shadow.rb in shaddox-0.0.25
- old
+ new
@@ -8,11 +8,11 @@
class Shadow
require 'fileutils'
#include FileUtils
def initialize(options, &block)
- @debug = options[:debug] || false
+ @debug = options[:debug] || true # TODO: change to false for actual release
@installer = options[:installer]
@tmppath = options[:tmppath] || '/tmp/shaddox/'
@required = true
instance_eval(&block)
end
@@ -34,15 +34,14 @@
system(command)
raise "#{line} failed" unless $? == 0 or !@required
end
def cd(path, &block)
- current_path = Dir.pwd
mkdir(path)
- FileUtils.cd(path.exp_path)
- instance_eval(&block)
- FileUtils.cd(current_path)
+ FileUtils.cd(path.exp_path) do
+ instance_eval(&block)
+ end
end
def exists(path)
system("test -e #{path.exp_path}")
end
@@ -56,16 +55,16 @@
end
def ln_s(source, dest, opts = {})
ensure_parent_dir(source)
ensure_parent_dir(dest)
- info "Linking '#{source}' to '#{dest}'", 1 if @verbose
+ info "Linking '#{source}' to '#{dest}'", 1 if @debug
FileUtils::ln_s(source.exp_path, dest.exp_path, opts)
end
def mkdir(path)
- info "Ensuring directory '#{path}' exists", 1 if @verbose
+ info "Ensuring directory '#{path}' exists", 1 if @debug
FileUtils::mkdir_p(path.exp_path)
end
def ensure_parent_dir(path)
dir, base = File.split(path.exp_path)
@@ -100,10 +99,11 @@
release_path = "./releases/#{release}"
case repo.vcs
when :git
# Clone/update repo in vcs:
+ info 'Updating the repository', 1 if @debug
if exists_d('vcs')
cd 'vcs' do
exec "git fetch #{repo.url} #{repo.branch}:#{repo.branch} --force"
end
else
@@ -112,14 +112,16 @@
exec "git clone ./vcs #{release_path} --recursive --branch #{repo.branch}"
end
# Link shared paths
repo.shared.each do |shared_path|
+ info 'Linking shared paths', 1 if @debug
ln_s "#{release_path}/#{shared_path}", "./shared/#{shared_path}"
end
# Link ./current to the latest release
+ info 'Linking current to latest release', 1 if @debug
ln_s './current', release_path
end
end
def install(package)
@@ -135,10 +137,10 @@
menu.choice(:brew) { @installer = :brew }
end
puts "-------------------"
end
raise "No installer specified for this target!" unless @installer
- info "Ensuring #{package} is installed with #{@installer}", 1 if @verbose
+ info "Ensuring #{package} is installed with #{@installer}", 1 if @debug
package_installed = lambda { system("type #{package} >/dev/null 2>&1") }
unless package_installed.call()
case @installer
when :apt
exec "sudo apt-get install -y #{package}"