Add deputils / origin unknown (gentoo servers)
This commit is contained in:
parent
fcf5764dc0
commit
1505da1054
127
branches/devel/scripts/deputils/checkdeps.rb
Executable file
127
branches/devel/scripts/deputils/checkdeps.rb
Executable file
@ -0,0 +1,127 @@
|
||||
#!/usr/bin/ruby -w
|
||||
|
||||
# Licensed under GPL-2 or later
|
||||
# Author: Petteri Räty <betelgeuse@gentoo.org>
|
||||
|
||||
$: << File.dirname(__FILE__)
|
||||
require "pkgutil.rb"
|
||||
|
||||
$verbose = false
|
||||
$quiet = false
|
||||
|
||||
pkgs_to_check=[]
|
||||
|
||||
def print_help(exit_value)
|
||||
puts 'Usage: checkdeps.rb opts|pkgs'
|
||||
puts
|
||||
puts 'Options:'
|
||||
puts '-q, --quiet'
|
||||
puts '-v, --verbose'
|
||||
puts '-h, --help'
|
||||
puts '-d, --debug'
|
||||
puts
|
||||
puts 'Everything else is passed to qfile as it is'
|
||||
exit(exit_value)
|
||||
end
|
||||
|
||||
ARGV.each do | arg |
|
||||
if arg =~ /^(-v|--verbose)$/
|
||||
$verbose = true
|
||||
elsif arg =~ /^(-h|--help)$/
|
||||
print_help(0)
|
||||
elsif arg =~ /^(-q|--quiet)$/
|
||||
$quiet = true
|
||||
elsif arg =~ /^(-d|--debug)$/
|
||||
$DEBUG = true
|
||||
$verbose = true
|
||||
else
|
||||
pkgs_to_check << arg
|
||||
end
|
||||
end
|
||||
|
||||
pkgs_to_check.length == 0 && print_help(1)
|
||||
|
||||
class ElfObj
|
||||
attr_reader :path, :pkgs
|
||||
|
||||
def initialize(path)
|
||||
@path = path
|
||||
@pkgs = []
|
||||
end
|
||||
|
||||
def <<(pkg)
|
||||
if ! @pkgs.index(pkg)
|
||||
@pkgs << pkg
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def <=>(r)
|
||||
return @path <=> r.path
|
||||
end
|
||||
|
||||
def to_s()
|
||||
puts 'ElfObj to_s:' if $DEBUG
|
||||
s = "\t" + @path
|
||||
s+="\t" + @path + "\n\t\t" + @pkgs.sort.join("\n\t\t") if $DEBUG
|
||||
s
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def handle_new_lib(obj,lib)
|
||||
puts 'library: ' + lib if $DEBUG
|
||||
$lib_hash[lib]=nil
|
||||
pkg = get_pkg_of_lib(lib)
|
||||
|
||||
if ! pkg
|
||||
return
|
||||
end
|
||||
|
||||
if obj_table = $pkg_hash[pkg]
|
||||
obj_table << obj
|
||||
else
|
||||
$pkg_hash[pkg]=[obj]
|
||||
obj << pkg
|
||||
end
|
||||
end
|
||||
|
||||
$lib_hash ={}
|
||||
$pkg_hash ={}
|
||||
|
||||
qlist = IO.popen("qlist #{pkgs_to_check.join(' ')}")
|
||||
|
||||
scan_elf = ScanElf.instance
|
||||
|
||||
while obj = qlist.gets
|
||||
obj.rstrip!
|
||||
if is_elf(obj)
|
||||
puts 'obj: ' + obj if $DEBUG
|
||||
elf_obj = ElfObj.new(obj)
|
||||
scan_elf.each(obj) do | lib |
|
||||
handle_new_lib(elf_obj,lib) unless $lib_hash.key?(lib)
|
||||
end
|
||||
else
|
||||
puts "#{file} is not executable or a normal file" if $verbose
|
||||
end
|
||||
end
|
||||
|
||||
qlist.close
|
||||
|
||||
if $? != 0
|
||||
$stderr.puts('qlist did not run succesfully.')
|
||||
$stderr.puts('Please emerge portage-utils if you don\'t already have it.')
|
||||
end
|
||||
|
||||
$pkg_hash.sort.each do | pair |
|
||||
puts 'Key: ' if $DEBUG
|
||||
puts pair[0]
|
||||
puts 'Value: ' if $DEBUG
|
||||
puts pair[1].uniq.sort unless $quiet
|
||||
puts 'end Hash.' if $DEBUG
|
||||
end
|
||||
|
||||
if $verbose
|
||||
puts $lib_hash.keys
|
||||
end
|
19
branches/devel/scripts/deputils/oneelf.rb
Executable file
19
branches/devel/scripts/deputils/oneelf.rb
Executable file
@ -0,0 +1,19 @@
|
||||
#!/usr/bin/ruby -w
|
||||
|
||||
# Licensed under GPL-2 or later
|
||||
# Author: Petteri Räty <betelgeuse@gentoo.org>
|
||||
|
||||
$: << File.dirname(__FILE__)
|
||||
require "pkgutil.rb"
|
||||
|
||||
elf = ARGV[0]
|
||||
|
||||
if ! elf || ! is_elf(elf)
|
||||
$stderr.puts 'This program takes one arguments that should be an elf file.'
|
||||
exit 1
|
||||
end
|
||||
|
||||
run_scanelf(elf) do | lib |
|
||||
puts lib
|
||||
puts "\t" + get_pkg_of_lib(lib)
|
||||
end
|
60
branches/devel/scripts/deputils/pkgutil.rb
Executable file
60
branches/devel/scripts/deputils/pkgutil.rb
Executable file
@ -0,0 +1,60 @@
|
||||
# Licensed under GPL-2 or later
|
||||
# Author: Petteri Räty <betelgeuse@gentoo.org>
|
||||
|
||||
MAGIC="\x7FELF"
|
||||
def is_elf(file)
|
||||
File.executable?(file) && File.file?(file) && File.read(file, 4) == MAGIC
|
||||
end
|
||||
|
||||
def get_pkg_of_lib(lib)
|
||||
command='qfile -qC ' + lib
|
||||
output = `#{command}`.split("\n")
|
||||
output.uniq!
|
||||
output.join(' || ')
|
||||
end
|
||||
|
||||
def handle_extra_output(prog)
|
||||
$stderr.puts 'This program expects only one line'
|
||||
$stderr.puts 'of output from scanelf. Extra lines:'
|
||||
while line = scanelf.gets
|
||||
$stderr.puts line
|
||||
end
|
||||
exit 2
|
||||
end
|
||||
|
||||
def run_scanelf(elf)
|
||||
scanelf = IO.popen("scanelf -q -F '%n#F' #{elf}")
|
||||
first_line = scanelf.gets
|
||||
handle_extra_output(scanelf) if not scanelf.eof?
|
||||
scanelf.close
|
||||
|
||||
libs = first_line.split(',')
|
||||
for lib in libs
|
||||
yield lib
|
||||
end
|
||||
end
|
||||
|
||||
class ScanElf
|
||||
private_class_method :new
|
||||
@@instance = nil
|
||||
|
||||
def ScanElf.instance
|
||||
@@instance = new unless @@instance
|
||||
@@instance
|
||||
end
|
||||
|
||||
def initialize
|
||||
@process = IO.popen('scanelf -q -F "%n#F" -f /dev/stdin','r+')
|
||||
end
|
||||
|
||||
def each(elf)
|
||||
@process.puts(elf)
|
||||
result = @process.gets
|
||||
|
||||
libs = result.split(',')
|
||||
for lib in libs
|
||||
yield lib
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user