-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkdeps.rb
executable file
·134 lines (109 loc) · 2.11 KB
/
checkdeps.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
40
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
76
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
#!/usr/bin/ruby -w
# Licensed under GPL-2 or later
# Author: Petteri Räty <[email protected]>
$: << 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 qlist 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_lib(obj,lib)
puts 'library: ' + lib if $DEBUG
if ! pkg = $lib_hash[lib]
begin
pkg = get_pkg_of_lib(lib)
rescue
pkg = "Not found"
end
$lib_hash[lib] = pkg
end
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_lib(elf_obj,lib)
end
else
puts "#{obj} is not an elf binary" 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