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