lib/rye/box.rb in rye-0.8.8 vs lib/rye/box.rb in rye-0.8.9
- old
+ new
@@ -222,11 +222,11 @@
# Add one or more private keys to the SSH Agent.
# * +additional_keys+ is a list of file paths to private keys
# Returns the instance of Box
def add_keys(*additional_keys)
- if Rye.sysinfo.os == :win32
+ if Rye.sysinfo.os == :windows
@rye_opts[:keys] ||= []
@rye_opts[:keys] += additional_keys.flatten
return @rye_opts[:keys]
end
additional_keys = [additional_keys].flatten.compact || []
@@ -346,11 +346,11 @@
# In Solaris, useradd -D says the default home path is /home
# but that directory is not writable. See: http://bit.ly/IJDD0
user_defaults['HOME'] = '/export/home'
elsif ostmp == "darwin"
user_defaults['HOME'] = '/Users'
- elsif ostmp == "win32"
+ elsif ostmp == "windows"
user_defaults['HOME'] = 'C:/Documents and Settings'
else
raw = self.quietly { useradd(:D) } rescue ["HOME=/home"]
raw.each do |nv|
n, v = nv.scan(/\A([\w_-]+?)=(.+)\z/).flatten
@@ -423,22 +423,33 @@
self.cd prevdir
rap.add_exit_code(0)
rap
end
-
+ require 'fileutils'
# Authorize the current user to login to the local machine via
# SSH without a password. This is the same functionality as
# authorize_keys_remote except run with local shell commands.
def authorize_keys_local
added_keys = []
+ ssh_dir = File.join(Rye.sysinfo.home, '.ssh')
Rye.keys.each do |path|
debug "# Public key for #{path}"
k = Rye::Key.from_file(path).public_key.to_ssh2
- Rye.shell(:mkdir, :p, :m, '700', '$HOME/.ssh') # Silently create dir if it doesn't exist
- Rye.shell(:echo, "'#{k}' >> $HOME/.ssh/authorized_keys")
- Rye.shell(:echo, "'#{k}' >> $HOME/.ssh/authorized_keys2")
- Rye.shell(:chmod, '-R', '0600', '$HOME/.ssh/authorized_keys*')
+ FileUtils.mkdir ssh_dir unless File.exists? ssh_dir
+
+ authkeys_file = File.join(ssh_dir, 'authorized_keys')
+
+ debug "Writing to #{authkeys_file}"
+ File.open(authkeys_file, 'a') {|f| f.write("#{$/}#{k}") }
+ File.open("#{authkeys_file}2", 'a') {|f| f.write("#{$/}#{k}") }
+
+ unless Rye.sysinfo.os == :windows
+ Rye.shell(:chmod, '700', ssh_dir)
+ Rye.shell(:chmod, '0600', authkeys_file)
+ Rye.shell(:chmod, '0600', "#{authkeys_file}2")
+ end
+
added_keys << path
end
added_keys
end