Class: Tweemux::Action::Hubkey
Instance Attribute Summary collapse
Instance Method Summary
collapse
#call, colorize_tmux_command, explain, #explained_run, explained_run, #explained_run_as, explained_run_as, highlight_command, highlight_explanation, #initialize, load_all!, pseudo_restarts, system_or_raise, tmux_S, #tmux_S
Instance Attribute Details
#github_user ⇒ Object
Returns the value of attribute github_user.
2
3
4
|
# File 'lib/tweemux/action/hubkey.rb', line 2
def github_user
@github_user
end
|
#unix_user ⇒ Object
Returns the value of attribute unix_user.
2
3
4
|
# File 'lib/tweemux/action/hubkey.rb', line 2
def unix_user
@unix_user
end
|
Instance Method Details
#authorized_keys_path ⇒ Object
44
|
# File 'lib/tweemux/action/hubkey.rb', line 44
def authorized_keys_path; home_dir+'/.ssh/authorized_keys' end
|
#ensure_ssh_dir_exists ⇒ Object
15
16
17
18
|
# File 'lib/tweemux/action/hubkey.rb', line 15
def ensure_ssh_dir_exists
explained_run_as unix_user, %W(mkdir -p -m700 #{home_dir}/.ssh),
"Make sure #{unix_user} has a ~/.ssh/ dir"
end
|
#home_dir ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/tweemux/action/hubkey.rb', line 36
def home_dir
begin
their_dir = File.expand_path '~'+unix_user
rescue ArgumentError
raise NoSuchHomeDir
end
end
|
#install_github_keys ⇒ Object
30
31
32
33
34
|
# File 'lib/tweemux/action/hubkey.rb', line 30
def install_github_keys
key_url = "https://github.com/#{github_user}.keys"
explained_run_as unix_user, %W(curl #{key_url} -o #{authorized_keys_path}),
"Download #{github_user}'s 'keyholes' from Github"
end
|
#refuse_to_overwrite_authorized_keys_file ⇒ Object
20
21
22
23
24
25
26
27
28
|
# File 'lib/tweemux/action/hubkey.rb', line 20
def refuse_to_overwrite_authorized_keys_file
return unless File.exists? authorized_keys_path
raise NoRestartsException, <<-EOT
Refusing to overwrite #{authorized_keys_path}
Try: sudo cat #{authorized_keys_path}
Then maybe: sudo rm #{authorized_keys_path}
EOT
end
|
#run(args) ⇒ Object
3
4
5
6
7
|
# File 'lib/tweemux/action/hubkey.rb', line 3
def run args
@unix_user, @github_user = args
@github_user ||= @unix_user
run_with_both_usernames
end
|
#run_with_both_usernames ⇒ Object
9
10
11
12
13
|
# File 'lib/tweemux/action/hubkey.rb', line 9
def run_with_both_usernames
ensure_ssh_dir_exists
refuse_to_overwrite_authorized_keys_file
install_github_keys
end
|