41
42
43
44
45
46
47
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
|
# File 'lib/mofa/upload_cmd.rb', line 41
def upload_cookbook_pkg
puts "Will use ssh_user #{Mofa::Config.config['binrepo_ssh_user']} and ssh_key_file #{Mofa::Config.config['binrepo_ssh_keyfile']}"
fail unless binrepo_up?
import_dir = Mofa::Config.config['binrepo_import_dir']
begin
unless Mofa::Config.config['binrepo_import_dir'].match(/import$/)
Net::SSH.start(Mofa::Config.config['binrepo_host'],
Mofa::Config.config['binrepo_ssh_user'],
:keys => [Mofa::Config.config['binrepo_ssh_keyfile']],
:port => Mofa::Config.config['binrepo_ssh_port'],
:verbose => :error,
:use_agent => false) do |ssh|
puts "Remotely creating target dir \"#{import_dir}/#{cookbook.name}/#{cookbook.version}\""
out = ssh_exec!(ssh, "[ -d #{import_dir}/#{cookbook.name}/#{cookbook.version} ] || mkdir -p #{import_dir}/#{cookbook.name}/#{cookbook.version}")
fail "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
import_dir = "#{import_dir}/#{cookbook.name}/#{cookbook.version}"
end
end
already_uploaded = false
Net::SSH.start(Mofa::Config.config['binrepo_host'],
Mofa::Config.config['binrepo_ssh_user'],
:keys => [Mofa::Config.config['binrepo_ssh_keyfile']],
:port => Mofa::Config.config['binrepo_ssh_port'],
:verbose => :error,
:use_agent => false) do |ssh|
out = ssh_exec!(ssh, "if [ -f #{import_dir}/#{cookbook.pkg_name} ];then echo -n already_exists;fi")
fail "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
already_uploaded = true if out[1] == 'already_exists'
end
unless already_uploaded
puts "Uploading cookbook pkg #{cookbook.pkg_name} to binrepo import folder #{Mofa::Config.config['binrepo_host']}:#{Mofa::Config.config['binrepo_import_dir']}..."
Net::SFTP.start(Mofa::Config.config['binrepo_host'],
Mofa::Config.config['binrepo_ssh_user'],
:keys => [Mofa::Config.config['binrepo_ssh_keyfile']],
:port => Mofa::Config.config['binrepo_ssh_port'],
:verbose => :error,
:use_agent => false) do |sftp|
sftp.upload!("#{cookbook.pkg_dir}/#{cookbook.pkg_name}", "#{import_dir}/#{cookbook.pkg_name}")
end
puts "OK."
else
puts "Cookbook pkg #{cookbook.pkg_name} already exists in the binrepo. Will NOT upload it again."
end
rescue RuntimeError => e
puts "Error: #{e.message}"
raise "Failed to upload cookbook #{cookbook.name}!"
end
end
|