require 'digest/md5'
require 'paint'
require 'fileutils'
+require 'pathname'
require 'erb'
require 'pty'
`which #{cmd}`.strip.chars.any?
end
+ #
+ # creates a relative symlink from absolute paths, removing prior symlink if necessary
+ #
+ # symlink 'new' is created, pointing to 'old'
+ #
+ def relative_symlink(old, new)
+ relative_path = Pathname.new(old).relative_path_from(Pathname.new(new))
+ if File.symlink?(new)
+ if File.readlink(new) != relative_path.to_s
+ File.unlink(new)
+ log :updated, 'symlink %s' % Path.relative_path(new)
+ end
+ else
+ log :created, 'symlink %s' % Path.relative_path(new)
+ end
+ FileUtils.ln_s(relative_path, new)
+ end
+
#
# compares md5 fingerprints to see if the contents of a file match the string we have in memory
#