diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2014-05-14 14:09:07 +0100 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2014-05-14 14:09:07 +0100 |
commit | a77c7ac455aea4d7d7f49d7bc9313a2ecc9cfec3 (patch) | |
tree | c1c1ac1398595f24100a7f31b9e3e699408c5cf0 /debian/byteback/usr/sbin/byteback-setup-client | |
parent | 8217f1c120211845c7846ef4f57a3277b8a5e890 (diff) |
bytemark: Added debian packaging
Diffstat (limited to 'debian/byteback/usr/sbin/byteback-setup-client')
-rwxr-xr-x | debian/byteback/usr/sbin/byteback-setup-client | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/debian/byteback/usr/sbin/byteback-setup-client b/debian/byteback/usr/sbin/byteback-setup-client new file mode 100755 index 0000000..ddb6672 --- /dev/null +++ b/debian/byteback/usr/sbin/byteback-setup-client @@ -0,0 +1,54 @@ +#!/usr/bin/ruby +# +# Run on a client machine to set up backups for the first time + +require 'fileutils' +require 'trollop' + +def error(message) + STDERR.print "*** #{message}\n" + exit 1 +end + +def verbose(message) + print "#{message}\n" +end + +opts = Trollop::options do + + opt :hostname, "Set host name for backups", + :type => :string + + opt :destination, "Backup destination (i.e. user@host:/path)", + :type => :string + +end + +@destination = opts[:destination] +@hostname = opts[:hostname] + +_dummy, @destination_user, @destination_host, colon, @destination_path = + /^(.*)?(?:@)([^:]+)(:)(.*)?$/.match(@destination).to_a + +error("Must be a remote path") unless colon +if !@hostname + @hostname = `hostname -f` + print "No hostname set, using #{@hostname}" +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") + +key_pub = File.read("/etc/byteback/key.pub") + +error "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 } + +print "Setup worked! To take your first backup run: byteback-backup --verbose\n" |