| 1 |
# Copyright 2003-2010 by Jim Weirich ([email protected]) |
| 2 |
# All rights reserved. |
| 3 |
|
| 4 |
# Configuration information about an upload host system. |
| 5 |
# * name :: Name of host system. |
| 6 |
# * webdir :: Base directory for the web information for the |
| 7 |
# application. The application name (APP) is appended to |
| 8 |
# this directory before using. |
| 9 |
# * pkgdir :: Directory on the host system where packages can be |
| 10 |
# placed. |
| 11 |
HostInfo = Struct.new(:name, :webdir, :pkgdir) |
| 12 |
|
| 13 |
# Manage several publishers as a single entity. |
| 14 |
class CompositePublisher |
| 15 |
def initialize |
| 16 |
@publishers = [] |
| 17 |
end |
| 18 |
|
| 19 |
# Add a publisher to the composite. |
| 20 |
def add(pub) |
| 21 |
@publishers << pub |
| 22 |
end |
| 23 |
|
| 24 |
# Upload all the individual publishers. |
| 25 |
def upload |
| 26 |
@publishers.each { |p| p.upload } |
| 27 |
end |
| 28 |
end |
| 29 |
|
| 30 |
# Publish an entire directory to an existing remote directory using |
| 31 |
# SSH. |
| 32 |
class SshDirPublisher |
| 33 |
def initialize(host, remote_dir, local_dir) |
| 34 |
@host = host |
| 35 |
@remote_dir = remote_dir |
| 36 |
@local_dir = local_dir |
| 37 |
end |
| 38 |
|
| 39 |
def upload |
| 40 |
run %{scp -rq #{@local_dir}/* #{@host}:#{@remote_dir}} |
| 41 |
end |
| 42 |
end |
| 43 |
|
| 44 |
# Publish an entire directory to a fresh remote directory using SSH. |
| 45 |
class SshFreshDirPublisher < SshDirPublisher |
| 46 |
def upload |
| 47 |
run %{ssh #{@host} rm -rf #{@remote_dir}} rescue nil |
| 48 |
run %{ssh #{@host} mkdir #{@remote_dir}} |
| 49 |
super |
| 50 |
end |
| 51 |
end |
| 52 |
|
| 53 |
# Publish a list of files to an existing remote directory. |
| 54 |
class SshFilePublisher |
| 55 |
# Create a publisher using the give host information. |
| 56 |
def initialize(host, remote_dir, local_dir, *files) |
| 57 |
@host = host |
| 58 |
@remote_dir = remote_dir |
| 59 |
@local_dir = local_dir |
| 60 |
@files = files |
| 61 |
end |
| 62 |
|
| 63 |
# Upload the local directory to the remote directory. |
| 64 |
def upload |
| 65 |
@files.each do |fn| |
| 66 |
run %{scp -q #{@local_dir}/#{fn} #{@host}:#{@remote_dir}} |
| 67 |
end |
| 68 |
end |
| 69 |
end |