diff options
author | Matthew Bloch <matthew@bytemark.co.uk> | 2014-01-06 02:19:54 +0000 |
---|---|---|
committer | Matthew Bloch <matthew@bytemark.co.uk> | 2014-01-06 02:19:54 +0000 |
commit | c138effe83fe68234d9f630b62b52c3fdfdaca6a (patch) | |
tree | 2d44db957098eff9e73a3b09785413a2467d7b3a /byteback-setup-client-receive | |
parent | 103d4e4278feed14dc5cf732d9c9875220cb8eff (diff) |
First commit of working code, needs a lot more writing and testing
Diffstat (limited to 'byteback-setup-client-receive')
-rw-r--r-- | byteback-setup-client-receive | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/byteback-setup-client-receive b/byteback-setup-client-receive new file mode 100644 index 0000000..35a3b65 --- /dev/null +++ b/byteback-setup-client-receive @@ -0,0 +1,42 @@ +#!/usr/bin/ruby +# +# Called by byteback-setup-client to set up a new byteback-setup-client + +require 'fileutils' + +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 + +Dir.mkdir(@hostname) + +error("Couldn't create btrfs subvolume (needs sudo)") unless + system("sudo btrfs subvolume create #{@hostname}/current") + +FileUtils.mkdir_p(".ssh") + +error("This key already exists in .ssh/authorized_keys on server") 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/,"") +command="byteback-receive", +from="#{@client_ip}", +environment="BYTEBACK_HOST=#{@hostname}" + #{@pubkey} + LINE +end |