Sha256: 12bdd4c989defa070340a5c95a3cc0b2672aa6a12f0736c0529d2d4e03c4060b

Contents?: true

Size: 1.41 KB

Versions: 5

Compression:

Stored size: 1.41 KB

Contents

#!/usr/bin/env ruby

require 'rubygems'
require 'aws/s3'

include AWS::S3

USER_DATA = `wget -q -O - http://169.254.169.254/latest/user-data`.split("\n")

bucket_name = 'rhoconnect'
channel     = ARGV[0]
files       = []

exit if ARGV.length != 1

def cmd(cmd)
  puts cmd
  system(cmd)
end #cmd

def get_access_keys
  access_key        = USER_DATA[0].to_s.strip
  secret_access_key = USER_DATA[1].to_s.strip
  keys = { :access_key_id => access_key,
           :secret_access_key => secret_access_key}
end #get_access_keys

AWS::S3::Base.establish_connection!(get_access_keys)

objects = Bucket.objects(bucket_name)
objects.each do |obj|
  files << "#{obj.key}" if obj.key =~ /^#{channel}/
end

# Remove the files before downloading new in case they already exist
cmd "rm -rf #{channel}" if File.directory? channel
cmd "rm -f #{channel}/SHA1/checksum" if File.exists?("#{channel}/SHA1/checksum")

puts "Downloading S3 files"
files.each do |file|
  cmd = "wget -qx -t 3 -P #{channel} \"http://s3.amazonaws.com/#{bucket_name}/#{file}\""
  puts cmd
  puts "Failed to download #{file}" unless system(cmd)
end

# The download increases the depth of the files by two folders.
# Remove exess directory levels.
cmd "mv -f #{channel}/s3.amazonaws.com/#{bucket_name}/#{channel}/* #{channel}"
cmd "rm -rf #{channel}/s3.amazonaws.com"

# Pull the SHA1 checksum and hash out
cmd "mv -f #{channel}/SHA1/sha1_hash ./old_sha1_hash"
cmd "rm -rf #{channel}/SHA1"

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rhoconnect-3.4.5 installer/utils/download_from_s3.rb
rhoconnect-4.0.0.beta.10 installer/utils/download_from_s3.rb
rhoconnect-4.0.0.beta.12 installer/utils/download_from_s3.rb
rhoconnect-3.4.4 installer/utils/download_from_s3.rb
rhoconnect-3.4.3 installer/utils/download_from_s3.rb