From d749a99fbed8265097a75de8b82a7f4b5a28ff60 Mon Sep 17 00:00:00 2001 From: Tom Vaughan Date: Thu, 8 Aug 2013 19:39:10 -0400 Subject: [PATCH] Let user be optional in the rsync method. --- README.md | 2 +- lib/middleman-deploy/commands.rb | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 5bedf83..51dd114 100644 --- a/README.md +++ b/README.md @@ -42,10 +42,10 @@ following to `config.rb`: ```ruby activate :deploy do |deploy| deploy.method = :rsync - deploy.user = "tvaughan" deploy.host = "www.example.com" deploy.path = "/srv/www/site" # Optional Settings + # deploy.user = "tvaughan" # no default # deploy.port = 5309 # ssh port, default: 22 # deploy.clean = true # remove orphaned files on remote host, default: false end diff --git a/lib/middleman-deploy/commands.rb b/lib/middleman-deploy/commands.rb index a3f2bd7..113cbca 100644 --- a/lib/middleman-deploy/commands.rb +++ b/lib/middleman-deploy/commands.rb @@ -49,10 +49,11 @@ extension in config.rb. # To deploy the build directory to a remote host via rsync: activate :deploy do |deploy| deploy.method = :rsync - # host, user, and path *must* be set - deploy.user = "tvaughan" + # host and path *must* be set deploy.host = "www.example.com" deploy.path = "/srv/www/site" + # user is optional (no default) + deploy.user = "tvaughan" # clean is optional (default is false) deploy.clean = true end @@ -109,8 +110,8 @@ EOF case options.method when :rsync - if (!options.host || !options.user || !options.path) - print_usage_and_die "The rsync deploy method requires host, user, and path to be set." + if (!options.host || !options.path) + print_usage_and_die "The rsync deploy method requires host and path to be set." end when :ftp, :sftp if (!options.host || !options.user || !options.password || !options.path) @@ -124,12 +125,17 @@ EOF def deploy_rsync host = self.deploy_options.host port = self.deploy_options.port - user = self.deploy_options.user path = self.deploy_options.path - puts "## Deploying via rsync to #{user}@#{host}:#{path} port=#{port}" + # Append "@" to user if provided. + user = self.deploy_options.user + user = "#{user}@" if user && !user.empty? - command = "rsync -avze '" + "ssh -p #{port}" + "' #{self.inst.build_dir}/ #{user}@#{host}:#{path}" + dest_url = "#{user}#{host}:#{path}" + + puts "## Deploying via rsync to #{dest_url} port=#{port}" + + command = "rsync -avze '" + "ssh -p #{port}" + "' #{self.inst.build_dir}/ #{dest_url}" if self.deploy_options.clean command += " --delete"