diff options
author | Matthew Bloch <mattbee@yoga.home.bloch.tv> | 2014-12-04 15:37:58 +0000 |
---|---|---|
committer | Matthew Bloch <matthew@bytemark.co.uk> | 2014-12-04 15:40:39 +0000 |
commit | 2fb6dde5a5bf3d7090d2a4b8f8770341c9cb3781 (patch) | |
tree | db8da5003af62bfde13682d8baee8547749b8b5c /byteback-setup-client | |
parent | 0158f0de3fd0a9bae070dfee9a5df4c2deb5c6f7 (diff) |
Bug fixes to new client setup code.
Diffstat (limited to 'byteback-setup-client')
-rwxr-xr-x | byteback-setup-client | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/byteback-setup-client b/byteback-setup-client index ddb6672..afcbee4 100755 --- a/byteback-setup-client +++ b/byteback-setup-client @@ -2,8 +2,13 @@ # # Run on a client machine to set up backups for the first time +$: << '/usr/lib/byteback' require 'fileutils' require 'trollop' +require 'byteback/util' +require 'byteback/log' +include Byteback::Util +include Byteback::Log def error(message) STDERR.print "*** #{message}\n" @@ -32,23 +37,29 @@ _dummy, @destination_user, @destination_host, colon, @destination_path = error("Must be a remote path") unless colon if !@hostname - @hostname = `hostname -f` - print "No hostname set, using #{@hostname}" + @hostname = `hostname -f`.chomp + print "No hostname set, using #{@hostname}\n" end -error "This host already appears set up - you need to delete /etc/byteback if not" if - File.readable?("/etc/byteback/key") - FileUtils.mkdir_p("/etc/byteback") -error "Couldn't generate SSH key" unless - system("ssh-keygen -q -t rsa -C \"byteback client key\" -N \"\" -f /etc/byteback/key") +if File.readable?("/etc/byteback/key") + warn "Skipping key generation, delete /etc/byteback/key if that's wrong" +else + + error "Couldn't generate SSH key" unless + system <<-KEYGEN + ssh-keygen -q -t rsa -C "byteback client key" \ + -N "" -f /etc/byteback/key + KEYGEN + +end -key_pub = File.read("/etc/byteback/key.pub") +key_pub = File.read("/etc/byteback/key.pub").chomp -error "Setup didn't work" unless +error "Remote setup didn't work" unless system("ssh -i /etc/byteback/key -l #{@destination_user} #{@destination_host} byteback-setup-client-receive #{@hostname} #{key_pub}") -File.open("/etc/byteback/destination", "w") { |f| f.print @destination } +File.open("/etc/byteback/host", "w") { |f| f.print @destination } print "Setup worked! To take your first backup run: byteback-backup --verbose\n" |