#!/usr/bin/env ruby require 'find' def diff(old, new) # a little safety for not embedding commands in system() return if old.include?(';') or new.include?(';') or old.include?('&&') or new.include?('&&') or old.include?('||') or new.include?('||') system("/usr/bin/diff -urN #{old} #{new} | /usr/bin/less -E") end LOCAL_MIRROR = ENV['LOCAL_MIRROR'] || "#{ENV['HOME']}/slackware/slackware/slackware64-current" WORKING_DIR = ENV['WORKING_DIR'] || "#{ENV['HOME']}/slackware/pam/" SOURCE_DIR = "#{WORKING_DIR}/source" SECTIONS = %w{a ap f l k kde n tcl x xap} PKGS = %w{ Linux-PAM cups shadow hplip screen sudo kde ConsoleKit cracklib polkit openssh openvpn popa3d proftpd samba vsftpd xlockmore xscreensaver libcgroup } CWD = Dir.pwd RE_SECTION = Regexp.new(/#{SOURCE_DIR}\/(#{SECTIONS.join("|")})\/(\w+-?\w*)\/?$/) if not(File.directory?(WORKING_DIR)) STDERR.write("ERROR: #{WORKING_DIR} is not a directory\n") STDERR.write("ERROR: try setting WORKING_DIR environment variable with your correct path to the pam/ working directory\n") exit 1 end if not(File.directory?(LOCAL_MIRROR)) STDERR.write("ERROR: #{LOCAL_MIRROR} is not a directory\n") STDERR.write("ERROR: try setting LOCAL_MIRROR environment variable with your correct path to a local slackware mirror\n") exit 1 end @pkgs = Hash.new Find.find("%s/source/" % [LOCAL_MIRROR]) do |spath| if File.directory?(spath) if PKGS.include?(File.basename(spath)) Find.find(SOURCE_DIR) do |ppath| if File.directory?(ppath) if File.basename(ppath) == File.basename(spath) @pkgs[File.basename(spath)] = {:stock => spath, :pam => ppath} Find.prune end end end Find.prune end end end def show_all() @pkgs.each {|pkg| diff(pkg[1][:stock], pkg[1][:pam]) } end def menu() printf("which package would you like a diff of?:\n") @pkgs.each {|pkg| num = @pkgs.to_a.index(pkg) next if num.nil? printf("\s[%d] %s\n", num, @pkgs.to_a[num][0] ) } printf(" [q] to quit\n") printf(" [a] to show all\n") response = gets.chomp if response =~ /^q$/i exit elsif response =~ /^a$/i show_all exit else diff(@pkgs.to_a[response.to_i][1][:stock], @pkgs.to_a[response.to_i][1][:pam]) end menu end if __FILE__ == $PROGRAM_NAME if ARGV.include?("-a") || ARGV.include?("--all") show_all elsif ARGV.include?("-l") || ARGV.include?("--list") puts @pkgs.keys elsif ARGV.include?("-h") || ARGV.include?("--help") puts "either add -a / --all to see all,\n -l / --list to see package names,\n #> #{__FILE__} ,\n or enter in to the menuu" elsif ARGV.count > 0 for arg in ARGV if @pkgs.keys.include?(arg) diff(@pkgs[arg][:stock], @pkgs[arg][:pam]) end end else menu end end