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_apt_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
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/prm/repo.rb', line 16 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
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 150 151 152 153 154 155 |
# File 'lib/prm/repo.rb', line 78 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| algs = { 'md5' => Digest::MD5.new, 'sha1' => Digest::SHA1.new, 'sha256' => Digest::SHA256.new } sums = { 'md5' => '', 'sha1' => '', 'sha256' => '' } tdeb = File.basename(deb) init_size = File.size(deb) deb_contents = nil FileUtils.mkdir_p "tmp/#{tdeb}/" if not nocache sums.keys.each do |s| sum_path = "#{path}/dists/#{r}/#{c}/binary-#{a}/#{s}-results/#{tdeb}" FileUtils.mkdir_p File.dirname(sum_path) if File.exist?(sum_path) stored_sum = File.read(sum_path) sum = stored_sum unless nocache.nil? end unless sum deb_contents ||= File.read(deb) sum = algs[s].hexdigest(deb_contents) end sums[s] = sum if nocache.nil? File.open(sum_path, 'w') { |f| f.write(sum) } elsif sum != stored_sum puts "WARN: #{s}sum mismatch on #{deb}\n" end end end `ar p #{deb} control.tar.gz | tar zx -C tmp/#{tdeb}/` package_info = [ "Filename: #{npath}#{s3_compatible_encode(tdeb)}", "MD5sum: #{sums['md5']}", "SHA1: #{sums['sha1']}", "SHA256: #{sums['sha256']}", "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\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
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 192 193 194 195 196 197 198 |
# File 'lib/prm/repo.rb', line 157 def generate_release(path,release,component,arch,label,origin) date = Time.now.utc release_info = Hash.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 file_contents = File.read("#{tmp_path}/#{unr}") tmp_hash['size'] = byte_size tmp_hash['md5'] = Digest::MD5.hexdigest(file_contents) tmp_hash['sha1'] = Digest::SHA1.hexdigest(file_contents) tmp_hash['sha256'] = Digest::SHA256.hexdigest(file_contents) 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
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/prm/repo.rb', line 201 def generate_release_gpg(path,release,gpg) Dir.chdir("#{path}/dists/#{release}") do if gpg_sign_algorithm.nil? sign_algorithm = "none" else sign_algorithm = gpg_sign_algorithm end if gpg.nil? sign_cmd = "gpg --digest-algo \"#{sign_algorithm}\" --yes --output Release.gpg -b Release" elsif !gpg_passphrase.nil? sign_cmd = "echo \'#{gpg_passphrase}\' | gpg --digest-algo \"#{sign_algorithm}\" -u #{gpg} --passphrase-fd 0 --yes --output Release.gpg -b Release" else sign_cmd = "gpg --digest-algo \"#{sign_algorithm}\" -u #{gpg} --yes --output Release.gpg -b Release" end system sign_cmd end end |
#move_apt_packages(path, component, arch, release, directory) ⇒ Object
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 76 |
# File 'lib/prm/repo.rb', line 42 def move_apt_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
220 221 222 |
# File 'lib/prm/repo.rb', line 220 def s3_compatible_encode(str) str.gsub(/[#\$&'\(\)\*\+,\/:;=\?@\[\]]/) { |x| x.each_byte.map { |b| '%' + b.to_s(16) }.join } end |