class RBT::StaticOverviewOfTheAvailableBinariesOnThisComputerSystem

Public Class Methods

[](i = ARGV) click to toggle source
#

RBT::StaticOverviewOfTheAvailableBinariesOnThisComputerSystem[]

#
# File lib/rbt/utility_scripts/static_overview_of_the_available_binaries_on_this_computer_system.rb, line 151
def self.[](i = ARGV)
  new(i)
end
new( commandline_arguments = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/utility_scripts/static_overview_of_the_available_binaries_on_this_computer_system.rb, line 29
def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  run if run_already
end

Public Instance Methods

report_how_many_statically_compiled_programs_were_encountered() click to toggle source
#

report_how_many_statically_compiled_programs_were_encountered

#
# File lib/rbt/utility_scripts/static_overview_of_the_available_binaries_on_this_computer_system.rb, line 143
def report_how_many_statically_compiled_programs_were_encountered
  e "#{+sfancy(@encountered_n_statically_compiled_programs.to_s)} statically"\
    " compiled programs were discovered on this computer system."
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Base#reset
# File lib/rbt/utility_scripts/static_overview_of_the_available_binaries_on_this_computer_system.rb, line 43
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @encountered_n_statically_compiled_programs
  # ======================================================================= #
  @encountered_n_statically_compiled_programs = 0
  # ======================================================================= #
  # === @array_work_on_these_directories
  # ======================================================================= #
  @array_work_on_these_directories = %w(
    /usr/bin/
    /bin/
  )
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/utility_scripts/static_overview_of_the_available_binaries_on_this_computer_system.rb, line 62
def run
  opnn { :no_trailing }
  e
  e
  e 'Showing an overview of all static binaries on this system (at the '\
    'least in '+sdir('/usr/bin/')
  e 'and '+sdir('/bin/')+') next:'
  e
  @array_work_on_these_directories.each {|this_directory|
    Dir["#{this_directory}*"].sort_by {|entry| entry.downcase }.each {|this_file|
      if File.directory? this_file
        e 'Note that '+sdir(this_file)+' is a directory.'
        if is_on_roebe?
          e 'This is questionable: check on this perhaps before '\
            'continuing here.'
          exit
        end
      end
      # =================================================================== #
      # We will exclude files that are e. g. perl files such as .pl
      # or .py.
      # =================================================================== #
      next if this_file.include? '.'
      next if File.empty?(this_file) # Ignore empty files.
      # =================================================================== #
      # We can not ignore symlinks because of stuff like this:
      #
      #   /usr/bin/ls -> /home/Programs/Coreutils/8.31/bin/ls
      #
      # next if File.symlink?(this_file)
      # =================================================================== #
      # =================================================================== #
      # If the first line includes '#!/' then we will assume this to
      # be a "scripting" file.
      # =================================================================== #
      is_it_a_scripting_file = false
      begin
        if File.exist?(this_file)
          File.open(this_file) {|file|
            first_line = file.readline
            if first_line.include?('#!/')  or # Assume this to be a "scripting" file.
               first_line.start_with?('#!')
              is_it_a_scripting_file = true
            end
          }
        end
      rescue EOFError => error
        e orange('Problem with ')+sfile(this_file)
        pp error
        pp error.class
      end
      next if is_it_a_scripting_file
      # =================================================================== #
      # Next we will run "ldd" on the binary at hand.
      # =================================================================== #
      cmd_to_use = "ldd #{this_file}"
      # e tomato(cmd_to_use)+': '
      result = `#{cmd_to_use}`
      if result.include?('not a dynamic executable')
        raw_name = File.basename(this_file)
        result = "#{rev}  #{steelblue(this_file.ljust(35))} is "\
                 "most likely a #{olivedrab('static executable')}."
        hash_all_binaries = RBT.all_binaries?
        if hash_all_binaries.include?(raw_name)
          result = result.dup if result.frozen?
          result << " It belongs to the program called "\
                    "#{lightgreen(hash_all_binaries[raw_name])}."
        end
        e result
        @encountered_n_statically_compiled_programs += 1
      end
    }
  }
  e
  report_how_many_statically_compiled_programs_were_encountered
  e
end