Module: Debian
- Included in:
- PRM::Repo
- Defined in:
- lib/prm/repo.rb
Instance Method Summary collapse
- #build_apt_repo(path, component, arch, release, label, origin, gpg, silent, nocache) ⇒ Object
- #generate_packages_gz(fpath, pfpath, path, rfpath, r, c, a, silent) ⇒ Object
- #generate_release(path, release, component, arch, label, origin) ⇒ Object
-
#generate_release_gpg(path, release, gpg) ⇒ Object
We expect that GPG is installed and a key has already been made.
- #move_packages(path, component, arch, release, directory) ⇒ Object
- #s3_compatible_encode(str) ⇒ Object
Instance Method Details
#build_apt_repo(path, component, arch, release, label, origin, gpg, silent, nocache) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/prm/repo.rb', line 15 def build_apt_repo(path, component, arch, release, label, origin, gpg, silent, nocache) 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,label,origin) unless gpg == false generate_release_gpg(path,r, gpg) end } end |
#generate_packages_gz(fpath, pfpath, path, rfpath, r, c, a, silent) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/prm/repo.rb', line 77 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 + "/" 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}/" if not nocache FileUtils.mkdir_p path + "/dists/" + r + "/" + c + "/" + "binary-" + a + "/md5-results/" end `ar p #{deb} control.tar.gz | tar zx -C tmp/#{tdeb}/` init_size = `wc -c < #{deb}` if deb.split("/").last.to_s == md5sum_path.split("/").last.to_s end if File.exists?("#{md5sum_path}") && nocache.nil? file = File.open(md5sum_path, 'r') md5sum = file.read file.close else md5sum = Digest::MD5.file(deb) if nocache.nil? File.open(md5sum_path, 'w') { |file| file.write(md5sum) } end end if File.exists?("#{md5sum_path}") && nocache file = File.open(md5sum_path, 'r') temp_md5sum = file.read file.close if md5sum != temp_md5sum puts "WARN: md5sum mismatch on #{deb}\n" end end package_info = [ "Filename: #{npath}#{s3_compatible_encode(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").gsub!(/\n+/, "\n")) 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, label, origin) ⇒ Object
151 152 153 154 155 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 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/prm/repo.rb', line 151 def generate_release(path,release,component,arch,label,origin) 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.read("#{template_dir}/deb_release.erb"), nil, "-").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, gpg) ⇒ Object
We expect that GPG is installed and a key has already been made
194 195 196 197 198 199 200 201 202 203 |
# File 'lib/prm/repo.rb', line 194 def generate_release_gpg(path,release,gpg) Dir.chdir("#{path}/dists/#{release}") do if gpg.nil? sign_cmd = "gpg --yes --output Release.gpg -b Release" else sign_cmd = "gpg -u #{gpg} --yes --output Release.gpg -b Release" end system sign_cmd end end |
#move_packages(path, component, arch, release, directory) ⇒ Object
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 |
# File 'lib/prm/repo.rb', line 41 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 |
#s3_compatible_encode(str) ⇒ Object
205 206 207 |
# File 'lib/prm/repo.rb', line 205 def s3_compatible_encode(str) str.gsub(/[#\$&'\(\)\*\+,\/:;=\?@\[\]]/) { |x| x.each_byte.map { |b| '%' + b.to_s(16) }.join } end |