Skip to content

Commit 5c4fe53

Browse files
committed
Revert reverts of installer realted changes
1 parent 5ebf555 commit 5c4fe53

File tree

1 file changed

+50
-20
lines changed

1 file changed

+50
-20
lines changed

bin/install

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ begin
5252
def usage
5353
print <<EOF
5454
55-
install [--sanity-check] <package-type>
55+
install [--sanity-check] [--proxy http://hostname:port] <package-type>
5656
--sanity-check [optional]
57+
--proxy [optional]
5758
package-type: 'rpm', 'deb', or 'auto'
5859
5960
Installs fetches the latest package version of the specified type and
@@ -72,6 +73,9 @@ the gdebi will be installed using apt-get first.
7273
If --sanity-check is specified, the install script will wait for 3 minutes post installation
7374
to check for a running agent.
7475
76+
To use a HTTP proxy, specify --proxy followed by the proxy server
77+
defined by http://hostname:port
78+
7579
This install script needs Ruby version 2.0.x installed as a prerequisite.
7680
If you do not have Ruby version 2.0.x installed, please install it first.
7781
@@ -116,9 +120,10 @@ EOF
116120

117121
@sanity_check = false
118122
@reexeced = false
119-
123+
@http_proxy = nil
124+
120125
@args = Array.new(ARGV)
121-
opts = GetoptLong.new(['--sanity-check', GetoptLong::NO_ARGUMENT], ['--help', GetoptLong::NO_ARGUMENT], ['--re-execed', GetoptLong::NO_ARGUMENT])
126+
opts = GetoptLong.new(['--sanity-check', GetoptLong::NO_ARGUMENT], ['--help', GetoptLong::NO_ARGUMENT], ['--re-execed', GetoptLong::NO_ARGUMENT], ['--proxy', GetoptLong::OPTIONAL_ARGUMENT])
122127
opts.each do |opt, args|
123128
case opt
124129
when '--sanity-check'
@@ -127,6 +132,10 @@ EOF
127132
usage
128133
when '--re-execed'
129134
@reexeced = true
135+
when '--proxy'
136+
if (args != '')
137+
@http_proxy = args
138+
end
130139
end
131140
end
132141
if (ARGV.length < 1)
@@ -161,13 +170,13 @@ EOF
161170
@log.error('Must run as root to install packages')
162171
exit(1)
163172
end
164-
173+
165174
parse_args()
166175

167176
########## Force running as Ruby 2.0 or fail here ##########
168177
check_ruby_version_and_symlink()
169178
force_ruby20()
170-
179+
171180
def run_command(*args)
172181
exit_ok = system(*args)
173182
$stdout.flush
@@ -209,9 +218,9 @@ EOF
209218

210219
def get_s3_uri(region, bucket, key)
211220
if (region == 'us-east-1')
212-
URI.parse("https://s3.amazonaws.com/#{bucket}/#{key}")
221+
URI.parse("https://#{bucket}.s3.amazonaws.com/#{key}")
213222
else
214-
URI.parse("https://s3-#{region}.amazonaws.com/#{bucket}/#{key}")
223+
URI.parse("https://#{bucket}.s3-#{region}.amazonaws.com/#{key}")
215224
end
216225
end
217226

@@ -222,7 +231,7 @@ EOF
222231

223232
# stream package file to disk
224233
begin
225-
uri.open(:ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER, :redirect => true, :read_timeout => 120) do |s3|
234+
uri.open(:ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER, :redirect => true, :read_timeout => 120, :proxy => @http_proxy) do |s3|
226235
package_file.write(s3.read)
227236
end
228237
rescue OpenURI::HTTPError => e
@@ -239,7 +248,7 @@ EOF
239248
begin
240249
require 'json'
241250

242-
version_string = uri.read(:ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER, :redirect => true, :read_timeout => 120)
251+
version_string = uri.read(:ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER, :redirect => true, :read_timeout => 120, :proxy => @http_proxy)
243252
JSON.parse(version_string)
244253
rescue OpenURI::HTTPError => e
245254
@log.error("Could not find version file to download at '#{uri.to_s}'")
@@ -307,9 +316,9 @@ EOF
307316
elsif(has_apt_get)
308317
@type = 'deb'
309318

310-
@log.warn('apt-get found but no gdebi. Installing gdebi with `apt-get install gdebi -y`...')
319+
@log.warn('apt-get found but no gdebi. Installing gdebi with `apt-get install gdebi-core -y`...')
311320
#use -y to answer yes to confirmation prompts
312-
if(!run_command('/usr/bin/apt-get', 'install', 'gdebi', '-y'))
321+
if(!run_command('/usr/bin/apt-get', 'install', 'gdebi-core', '-y'))
313322
@log.error('Could not install gdebi.')
314323
exit(1)
315324
end
@@ -327,16 +336,37 @@ EOF
327336
when 'help'
328337
usage
329338
when 'rpm'
330-
#use -y to answer yes to confirmation prompts
331-
install_cmd = ['/usr/bin/yum', '-y', 'localinstall']
332-
install_from_s3(region, bucket, version_file_key, @type, install_cmd)
333-
do_sanity_check('/sbin/service')
339+
running_version = `rpm -q codedeploy-agent`
340+
running_version.strip!
341+
target_version = get_version_file_from_s3(region, bucket, version_file_key)['rpm']
342+
if target_version.include? running_version
343+
@log.info('Running version matches target version, skipping install')
344+
else
345+
#use -y to answer yes to confirmation prompts
346+
install_cmd = ['/usr/bin/yum', '-y', 'localinstall']
347+
install_from_s3(region, bucket, version_file_key, @type, install_cmd)
348+
do_sanity_check('/sbin/service')
349+
end
334350
when 'deb'
335-
#use -n for non-interactive mode
336-
#use -o to not overwrite config files unless they have not been changed
337-
install_cmd = ['/usr/bin/gdebi', '-n', '-o', 'Dpkg::Options::=--force-confdef', '-o', 'Dpkg::Options::=--force-confold']
338-
install_from_s3(region, bucket, version_file_key, @type, install_cmd)
339-
do_sanity_check('/usr/sbin/service')
351+
running_agent = `dpkg -s codedeploy-agent`
352+
running_agent_info = running_agent.split
353+
version_index = running_agent_info.index('Version:')
354+
if !version_index.nil?
355+
running_version = running_agent_info[version_index + 1]
356+
else
357+
running_version = "No running version"
358+
end
359+
@log.info("Running version " + running_version)
360+
target_version = get_version_file_from_s3(region, bucket, version_file_key)['deb']
361+
if target_version.include? running_version
362+
@log.info('Running version matches target version, skipping install')
363+
else
364+
#use -n for non-interactive mode
365+
#use -o to not overwrite config files unless they have not been changed
366+
install_cmd = ['/usr/bin/gdebi', '-n', '-o', 'Dpkg::Options::=--force-confdef', '-o', 'Dkpg::Options::=--force-confold']
367+
install_from_s3(region, bucket, version_file_key, @type, install_cmd)
368+
do_sanity_check('/usr/sbin/service')
369+
end
340370
when 'zypper'
341371
#use -n for non-interactive mode
342372
install_cmd = ['/usr/bin/zypper', 'install', '-n']

0 commit comments

Comments
 (0)