| 1 |
require 'rake/contrib/compositepublisher' |
| 2 |
|
| 3 |
module Rake |
| 4 |
|
| 5 |
# Publish an entire directory to an existing remote directory using |
| 6 |
# SSH. |
| 7 |
class SshDirPublisher |
| 8 |
def initialize(host, remote_dir, local_dir) |
| 9 |
@host = host |
| 10 |
@remote_dir = remote_dir |
| 11 |
@local_dir = local_dir |
| 12 |
end |
| 13 |
|
| 14 |
def upload |
| 15 |
sh %{scp -rq #{@local_dir}/* #{@host}:#{@remote_dir}} |
| 16 |
end |
| 17 |
end |
| 18 |
|
| 19 |
# Publish an entire directory to a fresh remote directory using SSH. |
| 20 |
class SshFreshDirPublisher < SshDirPublisher |
| 21 |
def upload |
| 22 |
sh %{ssh #{@host} rm -rf #{@remote_dir}} rescue nil |
| 23 |
sh %{ssh #{@host} mkdir #{@remote_dir}} |
| 24 |
super |
| 25 |
end |
| 26 |
end |
| 27 |
|
| 28 |
# Publish a list of files to an existing remote directory. |
| 29 |
class SshFilePublisher |
| 30 |
# Create a publisher using the give host information. |
| 31 |
def initialize(host, remote_dir, local_dir, *files) |
| 32 |
@host = host |
| 33 |
@remote_dir = remote_dir |
| 34 |
@local_dir = local_dir |
| 35 |
@files = files |
| 36 |
end |
| 37 |
|
| 38 |
# Upload the local directory to the remote directory. |
| 39 |
def upload |
| 40 |
@files.each do |fn| |
| 41 |
sh %{scp -q #{@local_dir}/#{fn} #{@host}:#{@remote_dir}} |
| 42 |
end |
| 43 |
end |
| 44 |
end |
| 45 |
end |