Class: Flow::Base

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

Instance Method Summary collapse

Instance Method Details

#step_adduserObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/yorobot.rb', line 48

def step_adduser
  ##############
  ## setup ssh

  ssh_key  = ENV['SSH_KEY']

  if ssh_key.nil?
    STDERR.puts "!! ERROR - required SSH_KEY env(ironment) variable missing"
    exit 1
  end

  ssh_path = File.expand_path( '~/.ssh' )

  if File.exist?( "#{ssh_path}/id_ed25519" )
    STDERR.puts "!! ERROR - ssh key >#{ssh_path}/id_ed25519< already exists"
    exit 1
  end

  ## make sure path exists
  FileUtils.mkdir_p( ssh_path )   unless Dir.exist?( ssh_path )
  puts "--> writing ssh key to >#{ssh_path}/id_ed25519<..."
  File.open( "#{ssh_path}/id_ed25519", 'w:utf-8' ) do |f|
    f.write( ssh_key )
  end
  ## note: ssh key must be "private" only access by owner (otherwise) WILL NOT work
  ## res = File.chmod( 0600, "#{ssh_path}/id_rsa" )
  ## puts res  ## returns number of files processed; should be 1 - assert - why? why not?
  Computer::Shell.run( %Q{chmod 600 #{ssh_path}/id_ed25519} )

  Computer::Shell.run( %Q{ls -la #{ssh_path}} )

  ## todo - fix/fix/fix - maybe add a flag to turn on/off debugging
  ##           or connection test - why? why not?
  ##  note - if test is successful still returns
  ##     with exit code 1 (NOT 0 for success)
  ##  e.g.
  ##   Hi yorobot! You've successfully authenticated,
  ##               but GitHub does not provide shell access.
  ##
  ## Computer::Shell.run( %Q{ssh -vT git@github.com} )

  #####
  ## setup git
  ## git --version
  Git.version

  user_name  = ENV['YOROBOT_NAME']  || ENV['YO_NAME']  || 'Yo Robot'
  user_email = ENV['YOROBOT_EMAIL'] || ENV['YO_EMAIL'] || 'gerald.bauer+yorobot@gmail.com'

  Computer::Shell.run( %Q{git config --global user.name  "#{user_name}"} )
  Computer::Shell.run( %Q{git config --global user.email "#{user_email}"} )

  Computer::Shell.run( %Q{git config -l --show-origin} )
end