sysdeps 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/COPYING +121 -0
  3. data/README +19 -0
  4. data/bin/sysdeps +168 -0
  5. data/lib/sysdeps.rb +123 -0
  6. metadata +49 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b049bc12869573168bae746e7dc2d32ef34208fa0345dbd22ff57db43d20123f
4
+ data.tar.gz: a23f152be8710b210b2690beb713c7899747bbff45133fd2ac015b675df0ae95
5
+ SHA512:
6
+ metadata.gz: 3d462d0039710534402652461f0cbfa54d39e7d1fcd5713af1a09dbdc273bec260ff467ce8e893eccffa2397e0a4109e5aac7cf62aeb76fb3ba7f32ad6a566f3
7
+ data.tar.gz: a32ee64a4bf7803bebde727d817265b79912630a1e4731ec9acb522cd6bde0d84626dca7dbc76f8e820e33d8d86e700d15c561d948e61421d3e664b3c339da28
data/COPYING ADDED
@@ -0,0 +1,121 @@
1
+ Creative Commons Legal Code
2
+
3
+ CC0 1.0 Universal
4
+
5
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
6
+ LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
7
+ ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
8
+ INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
9
+ REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
10
+ PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
11
+ THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
12
+ HEREUNDER.
13
+
14
+ Statement of Purpose
15
+
16
+ The laws of most jurisdictions throughout the world automatically confer
17
+ exclusive Copyright and Related Rights (defined below) upon the creator
18
+ and subsequent owner(s) (each and all, an "owner") of an original work of
19
+ authorship and/or a database (each, a "Work").
20
+
21
+ Certain owners wish to permanently relinquish those rights to a Work for
22
+ the purpose of contributing to a commons of creative, cultural and
23
+ scientific works ("Commons") that the public can reliably and without fear
24
+ of later claims of infringement build upon, modify, incorporate in other
25
+ works, reuse and redistribute as freely as possible in any form whatsoever
26
+ and for any purposes, including without limitation commercial purposes.
27
+ These owners may contribute to the Commons to promote the ideal of a free
28
+ culture and the further production of creative, cultural and scientific
29
+ works, or to gain reputation or greater distribution for their Work in
30
+ part through the use and efforts of others.
31
+
32
+ For these and/or other purposes and motivations, and without any
33
+ expectation of additional consideration or compensation, the person
34
+ associating CC0 with a Work (the "Affirmer"), to the extent that he or she
35
+ is an owner of Copyright and Related Rights in the Work, voluntarily
36
+ elects to apply CC0 to the Work and publicly distribute the Work under its
37
+ terms, with knowledge of his or her Copyright and Related Rights in the
38
+ Work and the meaning and intended legal effect of CC0 on those rights.
39
+
40
+ 1. Copyright and Related Rights. A Work made available under CC0 may be
41
+ protected by copyright and related or neighboring rights ("Copyright and
42
+ Related Rights"). Copyright and Related Rights include, but are not
43
+ limited to, the following:
44
+
45
+ i. the right to reproduce, adapt, distribute, perform, display,
46
+ communicate, and translate a Work;
47
+ ii. moral rights retained by the original author(s) and/or performer(s);
48
+ iii. publicity and privacy rights pertaining to a person's image or
49
+ likeness depicted in a Work;
50
+ iv. rights protecting against unfair competition in regards to a Work,
51
+ subject to the limitations in paragraph 4(a), below;
52
+ v. rights protecting the extraction, dissemination, use and reuse of data
53
+ in a Work;
54
+ vi. database rights (such as those arising under Directive 96/9/EC of the
55
+ European Parliament and of the Council of 11 March 1996 on the legal
56
+ protection of databases, and under any national implementation
57
+ thereof, including any amended or successor version of such
58
+ directive); and
59
+ vii. other similar, equivalent or corresponding rights throughout the
60
+ world based on applicable law or treaty, and any national
61
+ implementations thereof.
62
+
63
+ 2. Waiver. To the greatest extent permitted by, but not in contravention
64
+ of, applicable law, Affirmer hereby overtly, fully, permanently,
65
+ irrevocably and unconditionally waives, abandons, and surrenders all of
66
+ Affirmer's Copyright and Related Rights and associated claims and causes
67
+ of action, whether now known or unknown (including existing as well as
68
+ future claims and causes of action), in the Work (i) in all territories
69
+ worldwide, (ii) for the maximum duration provided by applicable law or
70
+ treaty (including future time extensions), (iii) in any current or future
71
+ medium and for any number of copies, and (iv) for any purpose whatsoever,
72
+ including without limitation commercial, advertising or promotional
73
+ purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
74
+ member of the public at large and to the detriment of Affirmer's heirs and
75
+ successors, fully intending that such Waiver shall not be subject to
76
+ revocation, rescission, cancellation, termination, or any other legal or
77
+ equitable action to disrupt the quiet enjoyment of the Work by the public
78
+ as contemplated by Affirmer's express Statement of Purpose.
79
+
80
+ 3. Public License Fallback. Should any part of the Waiver for any reason
81
+ be judged legally invalid or ineffective under applicable law, then the
82
+ Waiver shall be preserved to the maximum extent permitted taking into
83
+ account Affirmer's express Statement of Purpose. In addition, to the
84
+ extent the Waiver is so judged Affirmer hereby grants to each affected
85
+ person a royalty-free, non transferable, non sublicensable, non exclusive,
86
+ irrevocable and unconditional license to exercise Affirmer's Copyright and
87
+ Related Rights in the Work (i) in all territories worldwide, (ii) for the
88
+ maximum duration provided by applicable law or treaty (including future
89
+ time extensions), (iii) in any current or future medium and for any number
90
+ of copies, and (iv) for any purpose whatsoever, including without
91
+ limitation commercial, advertising or promotional purposes (the
92
+ "License"). The License shall be deemed effective as of the date CC0 was
93
+ applied by Affirmer to the Work. Should any part of the License for any
94
+ reason be judged legally invalid or ineffective under applicable law, such
95
+ partial invalidity or ineffectiveness shall not invalidate the remainder
96
+ of the License, and in such case Affirmer hereby affirms that he or she
97
+ will not (i) exercise any of his or her remaining Copyright and Related
98
+ Rights in the Work or (ii) assert any associated claims and causes of
99
+ action with respect to the Work, in either case contrary to Affirmer's
100
+ express Statement of Purpose.
101
+
102
+ 4. Limitations and Disclaimers.
103
+
104
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
105
+ surrendered, licensed or otherwise affected by this document.
106
+ b. Affirmer offers the Work as-is and makes no representations or
107
+ warranties of any kind concerning the Work, express, implied,
108
+ statutory or otherwise, including without limitation warranties of
109
+ title, merchantability, fitness for a particular purpose, non
110
+ infringement, or the absence of latent or other defects, accuracy, or
111
+ the present or absence of errors, whether or not discoverable, all to
112
+ the greatest extent permissible under applicable law.
113
+ c. Affirmer disclaims responsibility for clearing rights of other persons
114
+ that may apply to the Work or any use thereof, including without
115
+ limitation any person's Copyright and Related Rights in the Work.
116
+ Further, Affirmer disclaims responsibility for obtaining any necessary
117
+ consents, permissions or other rights required for any use of the
118
+ Work.
119
+ d. Affirmer understands and acknowledges that Creative Commons is not a
120
+ party to this document and has no duty or obligation with respect to
121
+ this CC0 or use of the Work.
data/README ADDED
@@ -0,0 +1,19 @@
1
+ -------
2
+ sysdeps
3
+ -------
4
+
5
+ -----------------------------------------------------------
6
+ A little script to find missing libraries on a Linux system
7
+ -----------------------------------------------------------
8
+
9
+
10
+ Usage: sysdeps [ -u ][ -p <program name | path> ][ -d <pattern> ][ -j ][ -h ]
11
+ no args detects missing libraries
12
+ -u build or update dapendencies cache
13
+ -p <program name | path> prints program dependencies
14
+ -d <pattern> prints programs which depends on <pattern> (regex)
15
+ -j get results in JSON
16
+ -h guess
17
+
18
+
19
+ The dependencies cache must be built before. (sysdeps -u)
@@ -0,0 +1,168 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # sysdeps - find missing libraries under Linux
4
+ #
5
+ # Written in 2020 by Francesco Palumbo phranz@subfc.net
6
+ #
7
+ # To the extent possible under law, the author(s) have dedicated
8
+ # all copyright and related and neighboring rights to this software
9
+ # to the public domain worldwide.
10
+ # This software is distributed without any warranty.
11
+ # You should have received a copy of the CC0 Public Domain Dedication
12
+ # along with this software.
13
+ # If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
14
+
15
+ $LOAD_PATH << '../lib'
16
+
17
+ require 'sysdeps'
18
+ require 'json'
19
+
20
+ include SysDeps
21
+
22
+
23
+ CACHE_PATH = ENV['HOME'] + '/.sysdeps_cache.json'
24
+
25
+ KDEPENDENCIES = 'dependencies'.freeze
26
+ KDEPENDON = 'depend_on_by_pattern'.freeze
27
+
28
+ $to_json = false
29
+
30
+
31
+ trap('INT') {
32
+ STDERR.puts "\nQuitting"
33
+ exit 1 }
34
+
35
+
36
+ help = ->() {
37
+ STDERR.puts <<-EOF.gsub(/^\x20+/, '').gsub(/\x09/, ' ')
38
+ Usage: #{File.basename $0} [ -u ][ -p <program name | path> ][ -d <pattern> ][ -j ][ -h ]
39
+ \t\tno args detects missing libraries
40
+ \t\t-u build or update dapendencies cache
41
+ \t\t-p <program name | path> prints program dependencies
42
+ \t\t-d <pattern> prints programs which depends on <pattern> (regex)
43
+ \t\t-j get results in JSON
44
+ \t\t-h guess
45
+ EOF
46
+ }
47
+
48
+
49
+ build_cache = ->() {
50
+ STDERR.print 'Collecting system libs infos ... '
51
+ syslibs = SysDeps.get_syslibs ['/usr/lib', '/usr/libexec']
52
+ STDERR.puts 'done'
53
+
54
+ STDERR.print 'Collecting dependencies of programs ... '
55
+ prog_deps = get_programs_dependencies
56
+ STDERR.puts 'done'
57
+
58
+ STDERR.print 'Collecting dependencies of libraries ... '
59
+ lib_deps = get_libraries_dependencies syslibs
60
+ STDERR.puts 'done'
61
+
62
+ File.open(CACHE_PATH, 'w+') { |f|
63
+ f.write({syslibs: syslibs, prog_deps: prog_deps, lib_deps: lib_deps}.to_json) }}
64
+
65
+
66
+ get_data_from_cache = ->(path) {
67
+ o = {}
68
+
69
+ begin
70
+ File.open(CACHE_PATH, 'r') { |f| o = JSON.load(f.read) }
71
+ rescue Errno::ENOENT
72
+ STDERR.puts "Cache file doesn't exist, please build it with -u option."
73
+ exit 1
74
+ end
75
+
76
+ o }
77
+
78
+
79
+ missing_proc = ->() {
80
+ o = get_data_from_cache.call CACHE_PATH
81
+
82
+ total_progdeps = get_total_deps o['prog_deps']
83
+ total_libdeps = get_total_deps o['lib_deps']
84
+ missing_progdeps = get_missing_libs o['syslibs'], total_progdeps
85
+ missing_libdeps = get_missing_libs o['syslibs'], total_libdeps
86
+
87
+ deps = o['prog_deps'].merge(o['lib_deps'])
88
+ missing = (missing_progdeps + missing_libdeps).uniq
89
+
90
+ data = group_failed_by_lib(deps, missing)
91
+
92
+ if $to_json
93
+ puts data.to_json
94
+ else
95
+ data.each { |lib, deps|
96
+ puts "Missing #{lib} \nrequired by:"
97
+ deps.each { |p| puts "\t#{p}" }}
98
+ end }
99
+
100
+
101
+ depends_on = ->(patterns) {
102
+ o = get_data_from_cache.call CACHE_PATH
103
+ prog_deps = 'prog_deps'
104
+ patterns.each_with_object({KDEPENDON => {}}) { |p, obj|
105
+ pbd = get_programs_by_deps(o[prog_deps], p)
106
+ obj[KDEPENDON]["~#{p}"] = pbd if pbd }}
107
+
108
+
109
+ tell_deps = ->(progs) {
110
+ progs.each_with_object({KDEPENDENCIES => {}}) { |p, o|
111
+ pd = get_program_dependencies(p)
112
+ o[KDEPENDENCIES][p] = pd if pd }}
113
+
114
+
115
+ display_p_and_d_options = ->(prog_procs, deps_procs) {
116
+ prog_res = tell_deps.call(prog_procs) unless prog_procs.empty?
117
+ deps_res = depends_on.call(deps_procs) unless deps_procs.empty?
118
+
119
+ result = prog_res || deps_res
120
+ result = prog_res.merge(deps_res) if prog_res && deps_res
121
+
122
+ proc { puts(result.to_json) ; return }.call if $to_json
123
+
124
+ dependencies = result[KDEPENDENCIES]
125
+ dependon = result[KDEPENDON]
126
+
127
+ dependencies.each { |prog, deps|
128
+ puts "#{prog}:"
129
+ deps.each { |d| puts(("\x20" * 4) + d) }} unless dependencies.first.last.empty? rescue nil
130
+
131
+ dependon.each { |pattern, match|
132
+ puts "#{pattern}:"
133
+ match.each { |lib, deps|
134
+ puts(("\x20" * 4) + "#{lib}:")
135
+ deps.each { |d| puts(("\x20" * 8) + d) }}} unless dependon.first.last.empty? rescue nil }
136
+
137
+
138
+ main = ->{
139
+ proc_missing = !ARGV[0] || (ARGV[0] == '-j' && !ARGV[1])
140
+
141
+ prog_res = nil
142
+ deps_res = nil
143
+
144
+ prog_procs = []
145
+ deps_procs = []
146
+
147
+ loop {
148
+ a = ARGV.shift
149
+ break unless a
150
+
151
+ opts = { '-u' => ->{ build_cache.call ; exit },
152
+ '-p' => ->{ (arg = ARGV.shift) ? prog_procs.push(arg) : (help.call ; exit 1) },
153
+ '-d' => ->{ (arg = ARGV.shift) ? deps_procs.push(arg) : (help.call ; exit 1) },
154
+ '-j' => ->{ $to_json = true },
155
+ '-h' => ->{ help.call ; exit }, }
156
+
157
+ opts.default = ->{ help.call ; exit 1 }
158
+
159
+ opts[a].call }
160
+
161
+ if proc_missing
162
+ missing_proc.call
163
+ else
164
+ display_p_and_d_options.call prog_procs, deps_procs
165
+ end }
166
+
167
+
168
+ main.call
@@ -0,0 +1,123 @@
1
+ # sysdeps common
2
+ #
3
+ # Written in 2020 by Francesco Palumbo phranz@subfc.net
4
+ #
5
+ # To the extent possible under law, the author(s) have dedicated
6
+ # all copyright and related and neighboring rights to this software
7
+ # to the public domain worldwide.
8
+ # This software is distributed without any warranty.
9
+ # You should have received a copy of the CC0 Public Domain Dedication
10
+ # along with this software.
11
+ # If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
12
+
13
+
14
+ LDCONFPATH = '/etc/ld.so.conf'
15
+
16
+ DEPMARK = 'NEEDED'.freeze
17
+ ELF = 'ELF'.freeze
18
+ SYM = 'symbolic'.freeze
19
+ LINK = 'link'.freeze
20
+ EMPTY = ''.freeze
21
+
22
+
23
+ readlink_absolute = ->(path) {
24
+ curdir = Dir.getwd
25
+ Dir.chdir(File.dirname path)
26
+ abs = File.absolute_path(File.readlink(File.basename path))
27
+ Dir.chdir curdir
28
+ abs }
29
+
30
+
31
+ get_syslibs = ->(paths) {
32
+ ldpaths = (File.read(LDCONFPATH).split + paths).uniq.join ' '
33
+ sopat = /\.so\.?/
34
+
35
+ %x(find #{ldpaths} \\( -type f -o -type l \\) 2>/dev/null)
36
+ .split
37
+ .select { |l|
38
+ l[sopat] }
39
+ .map { |l|
40
+ File.ftype(l) == LINK ? [l, readlink_absolute(l)] : l }
41
+ .flatten }
42
+
43
+
44
+ get_program_dependencies = ->(prg) {
45
+ return prg if not prg
46
+ prgpath = nil
47
+
48
+ prgpath = File.exist?(prg) ? prg : %x(which #{prg} 2>/dev/null).chomp
49
+
50
+ return nil unless File.exist?(prgpath)
51
+
52
+ prgpath = readlink_absolute(prgpath) if File.ftype(prgpath) == LINK
53
+
54
+ return nil if %x(file #{prgpath}).split[1] != ELF
55
+
56
+ deppat = /\s+#{DEPMARK}\s+/
57
+ %x(objdump -p #{prgpath})
58
+ .split("\n")
59
+ .select { |r| r.include? DEPMARK }
60
+ .map { |r| r.gsub(deppat, EMPTY) }}
61
+
62
+
63
+ get_programs_dependencies = ->() {
64
+ prog_deps = {}
65
+ deppat = /\s+#{DEPMARK}\s+/
66
+ paths = ENV['PATH'].split(':').join(' ')
67
+
68
+ IO.popen("find #{paths} -type f -executable") { |find_io|
69
+ find_io.each_with_object({}) { |l, o|
70
+ next if %x{file #{l}}.split[1] != ELF
71
+
72
+ o[l.chomp] =
73
+ %x{objdump -p #{l}}
74
+ .split("\n")
75
+ .select { |r| r.include? DEPMARK }
76
+ .map { |r| r.gsub(deppat, EMPTY) }}}}
77
+
78
+
79
+ get_libraries_dependencies = ->(syslibs) {
80
+ deppat = /\s+#{DEPMARK}\s+/
81
+
82
+ syslibs.each_with_object({}) { |sl, o|
83
+ sl = readlink_absolute(sl) if File.ftype(sl) == LINK
84
+
85
+ next if %x{file #{sl}}.split[1] != ELF
86
+
87
+ o[sl.chomp] =
88
+ %x{objdump -p #{sl}}
89
+ .split("\n")
90
+ .select { |r| r.include? DEPMARK }
91
+ .map { |r| r.gsub(deppat, EMPTY) }}}
92
+
93
+
94
+ get_programs_by_deps = ->(prog_deps, pattern) {
95
+ rex = Regexp.new pattern, Regexp::IGNORECASE
96
+
97
+ prog_deps.each_with_object({}) { |(prog, deps), o|
98
+ deps.each { |d|
99
+ if d[rex]
100
+ lms = $~.string
101
+ o[lms] ? o[lms] << prog : o[lms] = [prog]
102
+ end }}}
103
+
104
+
105
+ get_total_deps = ->(deps) { deps.values.flatten.uniq }
106
+
107
+
108
+ get_missing_libs = ->(syslibs, libs) {
109
+ syslibs = syslibs.map { |l| File.basename l }
110
+ libs.select { |l| !syslibs.include? l }}
111
+
112
+
113
+ group_failed_by_lib = ->(deps, missing) {
114
+ missing.each_with_object({}) { |l, o|
115
+ o[l] = []
116
+
117
+ deps.each { |prg, libs|
118
+ o[l] << prg if libs.include? l }}}
119
+
120
+
121
+ SysDeps = Module.new {
122
+ local_variables.each { |f|
123
+ define_method(f, eval(f.to_s)) }}
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sysdeps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Francesco Palumbo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-05-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Detects missing libraries on Linux
14
+ email: phranz@subfc.net
15
+ executables:
16
+ - sysdeps
17
+ extensions: []
18
+ extra_rdoc_files:
19
+ - README
20
+ - COPYING
21
+ files:
22
+ - COPYING
23
+ - README
24
+ - bin/sysdeps
25
+ - lib/sysdeps.rb
26
+ homepage: https://gitlab.com/phranz/sysdeps
27
+ licenses:
28
+ - CC0-1.0
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubygems_version: 3.1.2
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Linux system dependencies helper
49
+ test_files: []