Module: Debian

Included in:
PRM::Repo
Defined in:
lib/prm/repo.rb

Instance Method Summary collapse

Instance Method Details

#build_apt_repo(path, component, arch, release, gpg, silent) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/prm/repo.rb', line 156

def build_apt_repo(path, component, arch, release, gpg, silent)
  release.each { |r|
    component.each { |c|
      arch.each { |a|
        fpath = path + "/dists/" + r + "/" + c + "/" + "binary-" + a + "/"
        pfpath = fpath + "Packages"
        rfpath = fpath + "Release"

        unless silent == true
          puts "Building Path: #{fpath}"
        end

        FileUtils.mkpath(fpath)
        FileUtils.touch(pfpath)
        FileUtils.touch(rfpath)
        generate_packages_gz(fpath,pfpath,path,rfpath,r,c,a, silent)
      }
    }
    generate_release(path,r,component,arch)

    if gpg == true
      generate_release_gpg(path,r)
    end
  }
end

#generate_packages_gz(fpath, pfpath, path, rfpath, r, c, a, silent) ⇒ Object



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/prm/repo.rb', line 218

def generate_packages_gz(fpath,pfpath,path,rfpath,r,c,a,silent)
  unless silent == true
    puts "Generating Packages: #{r} : #{c} : binary-#{a}"
  end

  npath = "dists/" + r + "/" + c + "/" + "binary-" + a + "/"
  packages_text = []

  d = File.open(pfpath, "w+") 
  write_mutex = Mutex.new

  Dir.glob("#{fpath}*.deb").peach do |deb|
    md5sum = ''
    tdeb = deb.split('/').last
    md5sum_path = path + "/dists/" + r + "/" + c + "/" + "binary-" + a + "/md5-results/" + tdeb

    FileUtils.mkdir_p "tmp/#{tdeb}/"
    FileUtils.mkdir_p path + "/dists/" + r + "/" + c + "/" + "binary-" + a + "/md5-results/"
    `ar p #{deb} control.tar.gz | tar zx -C tmp/#{tdeb}/`

    init_size = `wc -c < #{deb}`

    if File.exists? md5sum_path
      file = File.open(md5sum_path, 'r')
      md5sum = file.read
      file.close
    else
      md5sum = Digest::MD5.file(deb)
      File.open(md5sum_path, 'w') { |file| file.write(md5sum) }
    end

    package_info = [
      "Filename: #{npath}#{tdeb}",
      "MD5sum: #{md5sum}",
      "Size: #{init_size}"
    ]

    write_mutex.synchronize do
      # Copy the control file data into the Packages list
      d.write(File.read("tmp/#{tdeb}/control"))
      d.write(package_info.join("\n"))
      d.write("\n") # blank line between package info in the Packages file
    end
  end

  FileUtils.rmtree 'tmp/'

  d.close

  Zlib::GzipWriter.open(pfpath + ".gz") do |gz|
    f = File.new(pfpath, "r")
    f.each do |line|
      gz.write(line)
    end
  end
end

#generate_release(path, release, component, arch) ⇒ Object



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/prm/repo.rb', line 275

def generate_release(path,release,component,arch)
  date = Time.now.utc

  release_info = Hash.new()
  unreasonable_array = Array.new
  unreasonable_array = ["Packages", "Packages.gz", "Release"]
  component_ar = Array.new
  Dir.glob(path + "/dists/" + release + "/*").select { |f|
    f.slice!(path + "/dists/" + release + "/")
    unless f == "Release" or f == "Release.gpg"
      component_ar << f
    end
  }

  component_ar.each do |c| 
    arch.each do |ar|
      unreasonable_array.each do |unr|
        tmp_path = "#{path}/dists/#{release}/#{c}/binary-#{ar}"
        tmp_hash = Hash.new
        filename = "#{c}/binary-#{ar}/#{unr}".chomp

        byte_size = File.size("#{tmp_path}/#{unr}").to_s
        md5sum = Digest::MD5.file("#{tmp_path}/#{unr}").to_s

        tmp_hash['size'] = byte_size
        tmp_hash['md5sum'] = md5sum
        release_info[filename] = tmp_hash
      end
    end
  end


  template_dir = File.join(File.dirname(__FILE__), "..", "..", "templates")
  erb = ERB.new(File.open("#{template_dir}/deb_release.erb") { |file|
    file.read
  }).result(binding)

  release_file = File.new("#{path}/dists/#{release}/Release.tmp","wb")
  release_file.puts erb
  release_file.close

  FileUtils.move("#{path}/dists/#{release}/Release.tmp", "#{path}/dists/#{release}/Release")
end

#generate_release_gpg(path, release) ⇒ Object

We expect that GPG is installed and a key has already been made



320
321
322
323
324
# File 'lib/prm/repo.rb', line 320

def generate_release_gpg(path,release)
  Dir.chdir("#{path}/dists/#{release}") do
    system "gpg --yes --output Release.gpg -b Release"
  end
end

#move_packages(path, component, arch, release, directory) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/prm/repo.rb', line 182

def move_packages(path,component,arch,release,directory)
  unless File.exists?(directory)
    puts "ERROR: #{directory} doesn't exist... not doing anything\n"
    return false
  end

  files_moved = Array.new
  release.each { |r|
    component.each { |c|
      arch.each { |a|
          puts a
        Dir.glob(directory + "/*.deb") do |file|
          if file =~ /^.*#{a}.*\.deb$/i || file =~ /^.*all.*\.deb$/i || file =~ /^.*any.*\.deb$/i
            if file =~ /^.*#{r}.*\.deb$/i
              # Lets do this here to help mitigate packages like "asdf-123+wheezy.deb"
              FileUtils.cp(file, "#{path}/dists/#{r}/#{c}/binary-#{a}/")
              FileUtils.rm(file)
            else
              FileUtils.cp(file, "#{path}/dists/#{r}/#{c}/binary-#{a}/")
              files_moved << file
            end
          end
        end
      }
    }
  }

  files_moved.each do |f|
      if File.exists?(f)
          FileUtils.rm(f)
      end
  end
  # Regex?
  #/^.*#{arch}.*\.deb$/i
end