diff options
author | Steve Kemp <steve@steve.org.uk> | 2015-06-03 15:55:28 +0100 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2015-06-03 15:55:28 +0100 |
commit | a29380762b93737ae6949121010cd9bceb8196b2 (patch) | |
tree | 4dfe2931401d0cc73c38b9a90377e31210d6706e /bin/byteback-setup-client-receive | |
parent | c4da983bd2a1e35450dcb21bdc7110f5fc0d166a (diff) |
Relocated the binaries to bin/
Diffstat (limited to 'bin/byteback-setup-client-receive')
-rwxr-xr-x | bin/byteback-setup-client-receive | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/bin/byteback-setup-client-receive b/bin/byteback-setup-client-receive new file mode 100755 index 0000000..3673b6a --- /dev/null +++ b/bin/byteback-setup-client-receive @@ -0,0 +1,54 @@ +#!/usr/bin/ruby +# +# Called by byteback-setup-client to set up a new byteback-setup-client +# + +$LOAD_PATH.unshift('/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" + exit 1 +end + +@hostname = ARGV.shift +@pubkey = ARGV.join(' ') + +error('You must call this from byteback-setup-client on remote host') unless + @hostname && + /^ssh/.match(@pubkey) && + ENV['SSH_CONNECTION'] + +@client_ip = ENV['SSH_CONNECTION'].split(' ').first + +Dir.chdir(ENV['HOME']) # don't know why we wouldn't be here + +FileUtils.mkdir_p(@hostname) + +error("Couldn't create btrfs subvolume") unless + system("/sbin/btrfs subvolume create #{@hostname}/current") + +FileUtils.mkdir_p('.ssh') + +if File.exist?('.ssh/authorized_keys') && + File.read('.ssh/authorized_keys').match(@pubkey.split(/\s+/)[1]) + + 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/, '') + "\n" +command="byteback-receive", +from="#{@client_ip}", +environment="BYTEBACK_HOST=#{@hostname}" + #{@pubkey} + LINE + end +end |