2011-06-23 18:11:55 -04:00
|
|
|
require 'rake/dsl_definition'
|
2009-10-03 11:40:20 -04:00
|
|
|
require 'rake/contrib/compositepublisher'
|
|
|
|
|
|
|
|
module Rake
|
|
|
|
|
|
|
|
# Publish an entire directory to an existing remote directory using
|
|
|
|
# SSH.
|
|
|
|
class SshDirPublisher
|
2011-06-23 18:11:55 -04:00
|
|
|
include Rake::DSL
|
|
|
|
|
2014-07-14 23:07:37 -04:00
|
|
|
# Creates an SSH publisher which will scp all files in +local_dir+ to
|
|
|
|
# +remote_dir+ on +host+
|
|
|
|
|
2009-10-03 11:40:20 -04:00
|
|
|
def initialize(host, remote_dir, local_dir)
|
|
|
|
@host = host
|
|
|
|
@remote_dir = remote_dir
|
|
|
|
@local_dir = local_dir
|
|
|
|
end
|
|
|
|
|
2014-07-14 23:07:37 -04:00
|
|
|
# Uploads the files
|
|
|
|
|
2009-10-03 11:40:20 -04:00
|
|
|
def upload
|
2014-07-14 23:07:37 -04:00
|
|
|
sh "scp", "-rq", "#{@local_dir}/*", "#{@host}:#{@remote_dir}"
|
2009-10-03 11:40:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Publish an entire directory to a fresh remote directory using SSH.
|
|
|
|
class SshFreshDirPublisher < SshDirPublisher
|
2014-07-14 23:07:37 -04:00
|
|
|
|
|
|
|
# Uploads the files after removing the existing remote directory.
|
|
|
|
|
2009-10-03 11:40:20 -04:00
|
|
|
def upload
|
2014-07-14 23:07:37 -04:00
|
|
|
sh "ssh", @host, "rm", "-rf", @remote_dir rescue nil
|
|
|
|
sh "ssh", @host, "mkdir", @remote_dir
|
2009-10-03 11:40:20 -04:00
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Publish a list of files to an existing remote directory.
|
|
|
|
class SshFilePublisher
|
2011-06-23 18:11:55 -04:00
|
|
|
include Rake::DSL
|
|
|
|
|
2014-07-14 23:07:37 -04:00
|
|
|
# Creates an SSH publisher which will scp all +files+ in +local_dir+ to
|
|
|
|
# +remote_dir+ on +host+.
|
|
|
|
|
2009-10-03 11:40:20 -04:00
|
|
|
def initialize(host, remote_dir, local_dir, *files)
|
|
|
|
@host = host
|
|
|
|
@remote_dir = remote_dir
|
|
|
|
@local_dir = local_dir
|
|
|
|
@files = files
|
|
|
|
end
|
|
|
|
|
2014-07-14 23:07:37 -04:00
|
|
|
# Uploads the files
|
|
|
|
|
2009-10-03 11:40:20 -04:00
|
|
|
def upload
|
|
|
|
@files.each do |fn|
|
2014-07-14 23:07:37 -04:00
|
|
|
sh "scp", "-q", "#{@local_dir}/#{fn}", "#{@host}:#{@remote_dir}"
|
2009-10-03 11:40:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|