Class: SshConfigurator

Inherits:
Object
  • Object
show all
Defined in:
lib/ssh_configurator.rb

Class Method Summary collapse

Class Method Details

.error_messageObject



25
26
27
28
29
30
31
# File 'lib/ssh_configurator.rb', line 25

def self.error_message
  "Creating ~/.ssh/config for you.\n" \
  "Please edit it before you continue.\n" \
  "Pairest will manage a symbolic link called\n" \
  "current_key in ~/.ssh, so you probably want to\n" \
  "keep that part of the ssh config the same.\n"
end


4
5
6
7
8
9
10
11
# File 'lib/ssh_configurator.rb', line 4

def self.link_current_key(name)
  verify_ssh_config_exists

  FileUtils.ln_sf(
    File.expand_path("~/.ssh/#{name}"),
    File.expand_path('~/.ssh/current_key')
  )
end

.skeleton_ssh_configObject



33
34
35
36
37
38
# File 'lib/ssh_configurator.rb', line 33

def self.skeleton_ssh_config
  "Host dev.example.com\n" \
  "  HostName dev.example.com\n" \
  "  User git\n" \
  "  IdentityFile ~/.ssh/current_key\n"
end

.verify_ssh_config_existsObject



15
16
17
18
19
20
21
22
23
# File 'lib/ssh_configurator.rb', line 15

def self.verify_ssh_config_exists
  full_config_path = File.expand_path('~/.ssh/config')

  unless File.exist? full_config_path
    File.write(full_config_path, skeleton_ssh_config)
    puts error_message
    raise SystemExit
  end
end