12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/vagrant/zscp/helper.rb', line 12
def self.scp(machine, ssh_info, opts)
guestpath = opts[:guestpath]
guestpath += "/" if !guestpath.end_with?("/")
hostpath = File.expand_path(opts[:hostpath], machine.env.root_path)
hostpath = Vagrant::Util::Platform.fs_real_path(hostpath).to_s
hostpath += "/" if !hostpath.end_with?("/")
if (opts[:zscp_include])
included_files = opts[:zscp_include].join(' ')
else
included_files = '.'
end
username = ssh_info[:username]
host = ssh_info[:host]
machine.ui.info("Sending #{hostpath} to #{guestpath}")
remotely_execute(ssh_info, "sudo mkdir -p #{guestpath} 2> /dev/null; sudo chown #{username}:$(id -gn #{username}) #{guestpath}")
temp_file = `mktemp -t 'temp.tar.gz' 2> /dev/null || mktemp -t 'temp.tar.gz.XXXX'`.strip
temp_file_name = Pathname.new(temp_file).basename
machine.ui.info("Compressing #{hostpath} into #{temp_file}")
`tar -czhf #{temp_file} -C #{hostpath} #{included_files}`
machine.ui.info("Copying #{temp_file} to #{guestpath}")
command = [
"scp",
'-o StrictHostKeyChecking=no',
'-o LogLevel=quiet',
'-o UserKnownHostsFile=/dev/null',
"-o port=#{ssh_info[:port]}",
"-i '#{ssh_info[:private_key_path][0]}'",
"#{temp_file}",
"#{username}@#{host}:#{guestpath}"
].join(' ')
`#{command}`
remotely_execute(ssh_info, "tar -xzf #{guestpath}#{temp_file_name} -C #{guestpath}; rm #{guestpath}#{temp_file_name}")
machine.ui.info("#{guestpath} synchronised")
end
|