diff options
| author | Steve Kemp <steve@steve.org.uk> | 2015-06-03 14:56:50 +0100 | 
|---|---|---|
| committer | Steve Kemp <steve@steve.org.uk> | 2015-06-03 14:56:50 +0100 | 
| commit | fb24c99820c74964d71790387d0f7fe93dca073a (patch) | |
| tree | ff4f9c39f321228a03cc81b7fe9e68b9b098f0fe | |
| parent | 963ad5f8b1773881ab1f5a51702a99e931626786 (diff) | |
Reformatted.
This involved reformatting the code to remove TAB characters,
changing " -> ', & etc.
| -rwxr-xr-x | byteback-setup-client | 51 | ||||
| -rwxr-xr-x | byteback-setup-client-receive | 30 | 
2 files changed, 39 insertions, 42 deletions
| diff --git a/byteback-setup-client b/byteback-setup-client index 2c00e6a..d8ffbfa 100755 --- a/byteback-setup-client +++ b/byteback-setup-client @@ -3,8 +3,7 @@  # Run on a client machine to set up backups for the first time  # - -$LOAD_PATH.unshift("/usr/lib/byteback") +$LOAD_PATH.unshift('/usr/lib/byteback')  require 'fileutils'  require 'trollop' @@ -14,60 +13,58 @@ include Byteback::Util  include Byteback::Log  def error(message) -	STDERR.print "*** #{message}\n" -	exit 1 +  STDERR.print "*** #{message}\n" +  exit 1  end  def verbose(message) -	print "#{message}\n" +  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 +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 +                                                     /^(.*)?(?:@)([^:]+)(:)(.*)?$/.match(@destination).to_a  @destination_user ||= 'byteback'  @destination_path ||= ''  @destination_host ||= @destination -if !@hostname -	@hostname = `hostname -f`.chomp -	warn "No hostname set, using #{@hostname}\n" +unless @hostname +  @hostname = `hostname -f`.chomp +  warn "No hostname set, using #{@hostname}\n"  end -FileUtils.mkdir_p("/etc/byteback") +FileUtils.mkdir_p('/etc/byteback') -if File.readable?("/etc/byteback/key") -	warn "Skipping key generation, delete /etc/byteback/key if that's wrong" +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 +  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").chomp +key_pub = File.read('/etc/byteback/key.pub').chomp  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") do |f| -	f.print "#{@destination_user}@#{@destination_host}:#{@destination_path}" +File.open('/etc/byteback/destination', 'w') do |f| +  f.print "#{@destination_user}@#{@destination_host}:#{@destination_path}"  end  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 5cf6dd0..3673b6a 100755 --- a/byteback-setup-client-receive +++ b/byteback-setup-client-receive @@ -3,7 +3,7 @@  # Called by byteback-setup-client to set up a new byteback-setup-client  # -$LOAD_PATH.unshift("/usr/lib/byteback") +$LOAD_PATH.unshift('/usr/lib/byteback')  require 'fileutils'  require 'trollop' @@ -13,42 +13,42 @@ include Byteback::Util  include Byteback::Log  def error(message) -	STDERR.print "*** #{message}\n" -	exit 1 +  STDERR.print "*** #{message}\n" +  exit 1  end  @hostname = ARGV.shift -@pubkey = ARGV.join(" ") +@pubkey = ARGV.join(' ') -error("You must call this from byteback-setup-client on remote host") unless +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 +@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") +  system("/sbin/btrfs subvolume create #{@hostname}/current") -FileUtils.mkdir_p(".ssh") +FileUtils.mkdir_p('.ssh') -if File.exists?(".ssh/authorized_keys") && -	File.read(".ssh/authorized_keys").match(@pubkey.split(/\s+/)[1]) +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!") +  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" +  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 +    LINE +  end  end | 
