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 | |
parent | 0158f0de3fd0a9bae070dfee9a5df4c2deb5c6f7 (diff) |
Bug fixes to new client setup code.
-rwxr-xr-x | byteback-setup-client | 31 | ||||
-rwxr-xr-x | byteback-setup-client-receive | 20 | ||||
-rw-r--r-- | debian/changelog | 12 |
3 files changed, 48 insertions, 15 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" diff --git a/byteback-setup-client-receive b/byteback-setup-client-receive index 35a3b65..79df12b 100755 --- a/byteback-setup-client-receive +++ b/byteback-setup-client-receive @@ -2,7 +2,13 @@ # # Called by byteback-setup-client to set up a new byteback-setup-client +$: << '/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" @@ -28,15 +34,19 @@ error("Couldn't create btrfs subvolume (needs sudo)") unless FileUtils.mkdir_p(".ssh") -error("This key already exists in .ssh/authorized_keys on server") if - File.exists?(".ssh/authorized_keys") && +if File.exists?(".ssh/authorized_keys") && File.read(".ssh/authorized_keys").match(@pubkey.split(/\s+/)[1]) -File.open(".ssh/authorized_keys", "a+") do |fh| - fh.print <<-LINE.gsub(/\n/,"") + warn("This key already exists in .ssh/authorized_keys on server, nothing to do!") + +else + + File.open(".ssh/authorized_keys", "a+") do |fh| + fh.print <<-LINE.gsub(/\n/,"") command="byteback-receive", from="#{@client_ip}", environment="BYTEBACK_HOST=#{@hostname}" #{@pubkey} - LINE + LINE + end end diff --git a/debian/changelog b/debian/changelog index e4103b5..5ecacb1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,15 @@ +byteback (0.3.1) stable; urgency=medium + + * Bug fixes to byteback-setup-client and byteback-setup-client-receive + + -- Matthew Bloch <matthew@bytemark.co.uk> Thu, 04 Dec 2014 15:38:46 +0000 + +byteback (0.3.0) stable; urgency=medium + + * Many bug fixes + + -- Matthew Bloch <matthew@bytemark.co.uk> Sat, 22 Nov 2014 03:11:00 +0000 + byteback (0.2.9) stable; urgency=medium * Added byteback-prune |