#!/usr/bin/env ruby begin require "slackware" rescue $stderr.puts "ERROR: please install the slack-utils pkg/gem" exit 1 end require "fileutils" DEFAULT_PKG_DIR = File.join(Dir.pwd, "pkgs") DEFAULT_TMP_DIR = "/tmp/pam_hackings" def collect_new_pkgs(tmp_dir = DEFAULT_TMP_DIR) Dir[File.join(tmp_dir, "*.t?z")] end def packages_in_dir(dir) collect_new_pkgs(dir).map {|file| package_from_filename(file) } end def get_ext(filename) filename.reverse.split(".",2)[0].reverse end def package_from_filename(file) b_name = File.basename(file) ext = get_ext(b_name) Slackware::Package.parse( b_name.sub(/\.#{ext}$/, "") ) end if __FILE__ == $0 abort("ERROR: there is no directory [#{DEFAULT_TMP_DIR}], have you built anything yet?") unless File.directory?(DEFAULT_TMP_DIR) collect_new_pkgs().each {|file| ext = get_ext(file) pkg = package_from_filename(file) dest = File.join(DEFAULT_PKG_DIR, pkg.arch) if FileTest.file?(File.join(dest,File.basename(file))) puts "INFO: #{File.join(dest,File.basename(file))} already exists" next else # first check if there is an older package for this file packages_in_dir(dest).each {|p| if p.name == pkg.name and p.arch == pkg.arch and (p.version != pkg.version or p.build != pkg.build) puts "DELETE: " + File.join(dest, p.fullname + "*") FileUtils.rm Dir[File.join(dest, p.fullname + "*")] end } # next copy the file puts "COPY: [#{file}] => [#{dest}]" FileUtils.copy(file,dest) end } # lastly, regenerate the MD5SUM %w{ i486 x86_64 }.each {|arch| Dir.chdir(File.join(DEFAULT_PKG_DIR, arch)) do sums = `md5sum *.t?z` File.open("MD5SUM", "w") {|file| file.write(sums) } puts "#{arch}/MD5SUM written" end } end