Class: Proxy::Omaha::Release

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/smart_proxy_omaha/release.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Release

Returns a new instance of Release.



14
15
16
17
18
19
# File 'lib/smart_proxy_omaha/release.rb', line 14

def initialize(options)
  @distribution = options.fetch(:distribution)
  @track = options.fetch(:track).to_s
  @architecture = options.fetch(:architecture)
  @version = Gem::Version.new(options.fetch(:version))
end

Instance Attribute Details

#architectureObject

Returns the value of attribute architecture.



11
12
13
# File 'lib/smart_proxy_omaha/release.rb', line 11

def architecture
  @architecture
end

#digestsObject



174
175
176
# File 'lib/smart_proxy_omaha/release.rb', line 174

def digests
  @digests ||= load_digests!
end

#distributionObject

Returns the value of attribute distribution.



11
12
13
# File 'lib/smart_proxy_omaha/release.rb', line 11

def distribution
  @distribution
end

#trackObject

Returns the value of attribute track.



11
12
13
# File 'lib/smart_proxy_omaha/release.rb', line 11

def track
  @track
end

#versionObject

Returns the value of attribute version.



11
12
13
# File 'lib/smart_proxy_omaha/release.rb', line 11

def version
  @version
end

Instance Method Details

#<=>(other) ⇒ Object



67
68
69
70
# File 'lib/smart_proxy_omaha/release.rb', line 67

def <=>(other)
  return unless self.class === other
  version.<=>(other.version)
end

#==(other) ⇒ Object



72
73
74
# File 'lib/smart_proxy_omaha/release.rb', line 72

def ==(other)
  self.class === other && track == other.track && version == other.version && architecture == other.architecture
end

#base_pathObject



21
22
23
# File 'lib/smart_proxy_omaha/release.rb', line 21

def base_path
  @base_path ||= File.join(Proxy::Omaha::Plugin.settings.contentpath, track, architecture)
end

#complete?Boolean

Returns:

  • (Boolean)


158
159
160
# File 'lib/smart_proxy_omaha/release.rb', line 158

def complete?
  missing_files.empty?
end

#createObject



48
49
50
51
52
53
54
# File 'lib/smart_proxy_omaha/release.rb', line 48

def create
  logger.debug "Creating #{track} #{version} #{architecture}"
  return false unless create_path
  return false unless download
  return false unless 
  true
end

#create_metadataObject



92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/smart_proxy_omaha/release.rb', line 92

def 
  .store(Metadata.new(
    :track => track,
    :release => version.to_s,
    :architecture => architecture,
    :size => File.size(updatefile),
    :sha1_b64 => Digest::SHA1.file(updatefile).base64digest,
    :sha256_b64 => Digest::SHA256.file(updatefile).base64digest
  ))
  true
rescue
  false
end

#create_pathObject



106
107
108
109
110
111
# File 'lib/smart_proxy_omaha/release.rb', line 106

def create_path
  FileUtils.mkdir_p(path)
  true
rescue
  false
end

#current?Boolean

Returns:

  • (Boolean)


56
57
58
59
# File 'lib/smart_proxy_omaha/release.rb', line 56

def current?
  return false unless File.symlink?(current_path)
  File.readlink(current_path) == path
end

#current_pathObject



29
30
31
# File 'lib/smart_proxy_omaha/release.rb', line 29

def current_path
  @current_path ||= File.join(base_path, 'current')
end

#digest_filesObject



154
155
156
# File 'lib/smart_proxy_omaha/release.rb', line 154

def digest_files
  Dir.glob(File.join(path, '*.DIGESTS')).map { |file| File.basename(file) }
end

#downloadObject



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/smart_proxy_omaha/release.rb', line 80

def download
  sources.map do |url|
    file = URI.parse(url).path.split('/').last
    next if file_exists?(file)
    dst = File.join(path, file)
    logger.debug "Downloading file #{url} to #{dst}"
    task = ::Proxy::Omaha::HttpDownload.new(url, dst)
    task.start
    task
  end.compact.each(&:join).map(&:result).all?
end

#existing_filesObject



146
147
148
# File 'lib/smart_proxy_omaha/release.rb', line 146

def existing_files
  Dir.glob(File.join(path, '*')).map { |file| File.basename(file) }
end

#exists?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/smart_proxy_omaha/release.rb', line 37

def exists?
  File.directory?(path)
end

#expected_filesObject



142
143
144
# File 'lib/smart_proxy_omaha/release.rb', line 142

def expected_files
  sources.map { |source| File.basename(source) }
end

#file_exists?(file) ⇒ Boolean

Returns:

  • (Boolean)


162
163
164
# File 'lib/smart_proxy_omaha/release.rb', line 162

def file_exists?(file)
  File.file?(File.join(path, file))
end

#file_urls(base_url) ⇒ Object



207
208
209
210
211
# File 'lib/smart_proxy_omaha/release.rb', line 207

def file_urls(base_url)
  existing_files.map do |file|
    [base_url, 'omahareleases', track, architecture, self, file].join('/')
  end
end

#load_digests!Object



178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/smart_proxy_omaha/release.rb', line 178

def load_digests!
  self.digests = {}
  digest_files.each do |digest_file|
    file = File.basename(digest_file, '.DIGESTS')
    File.readlines(File.join(path, digest_file)).each do |line|
      next unless line =~ /^\w+[ ]+\S+$/
      hexdigest = line.split(/[ ]+/).first
      self.digests[file] ||= []
      self.digests[file] << hexdigest
    end
  end
  self.digests
end

#mark_as_current!Object



61
62
63
64
65
# File 'lib/smart_proxy_omaha/release.rb', line 61

def mark_as_current!
  return true if current?
  File.unlink(current_path) if File.symlink?(current_path)
  FileUtils.ln_s(path, current_path)
end

#metadataObject



33
34
35
# File 'lib/smart_proxy_omaha/release.rb', line 33

def 
  .get(track, release, architecture)
end

#missing_filesObject



150
151
152
# File 'lib/smart_proxy_omaha/release.rb', line 150

def missing_files
  expected_files - existing_files
end

#pathObject



25
26
27
# File 'lib/smart_proxy_omaha/release.rb', line 25

def path
  @path ||= File.join(base_path, version.to_s)
end

#purgeObject



166
167
168
169
170
171
172
# File 'lib/smart_proxy_omaha/release.rb', line 166

def purge
  FileUtils.rm(Dir.glob(File.join(path, '*')), :force => true)
  FileUtils.remove_dir(path)
  true
rescue
  false
end

#sourcesObject



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/smart_proxy_omaha/release.rb', line 121

def sources
  upstream = distribution.upstream(track, architecture, version)
  update_upstream = distribution.update_upstream(architecture, version)
  prefix = distribution.prefix
  [
    "#{upstream}/#{prefix}_production_pxe.vmlinuz",
    "#{upstream}/#{prefix}_production_pxe.DIGESTS",
    "#{upstream}/#{prefix}_production_image.bin.bz2",
    "#{upstream}/#{prefix}_production_image.bin.bz2.sig",
    "#{upstream}/#{prefix}_production_image.bin.bz2.DIGESTS",
    "#{upstream}/#{prefix}_production_pxe_image.cpio.gz",
    "#{upstream}/#{prefix}_production_pxe_image.cpio.gz.DIGESTS",
    "#{upstream}/#{prefix}_production_vmware_raw_image.bin.bz2",
    "#{upstream}/#{prefix}_production_vmware_raw_image.bin.bz2.sig",
    "#{upstream}/#{prefix}_production_vmware_raw_image.bin.bz2.DIGESTS",
    "#{upstream}/version.txt",
    "#{upstream}/version.txt.DIGESTS",
    "#{update_upstream}/#{update_filename}"
  ]
end

#to_hObject



192
193
194
195
196
197
198
199
200
201
# File 'lib/smart_proxy_omaha/release.rb', line 192

def to_h
  {
    :name => to_s,
    :current => current?,
    :architecture => architecture,
    :track => track,
    :complete => complete?,
    :files => existing_files
  }
end

#to_jsonObject



203
204
205
# File 'lib/smart_proxy_omaha/release.rb', line 203

def to_json
  to_h.to_json
end

#to_sObject



76
77
78
# File 'lib/smart_proxy_omaha/release.rb', line 76

def to_s
  version.to_s
end

#update_filenameObject



113
114
115
# File 'lib/smart_proxy_omaha/release.rb', line 113

def update_filename
  distribution.update_filename
end

#updatefileObject



117
118
119
# File 'lib/smart_proxy_omaha/release.rb', line 117

def updatefile
  File.join(path, update_filename)
end

#valid?Boolean

Returns:

  • (Boolean)


41
42
43
44
45
46
# File 'lib/smart_proxy_omaha/release.rb', line 41

def valid?
  existing_files.select { |file| file !~ /\.(DIGESTS|sig)$/ }.map do |file|
    next unless digests[file]
    digests[file].include?(Digest::MD5.file(File.join(path, file)).hexdigest)
  end.compact.all?
end