Module: Ronin::Core::System
- Defined in:
- lib/ronin/core/system.rb
Overview
Utility methods for interacting with the system.
Defined Under Namespace
Classes: DownloadFailed
Class Method Summary collapse
-
.download(url, dest) ⇒ String
Downloads a file using either
curl
orwget
. -
.downloader ⇒ 'curl', ...
private
The detected download command.
-
.installed?(command) ⇒ Boolean
Determines if a command is installed.
-
.os ⇒ :linux, ...
The detected Operating System type.
-
.paths ⇒ Array<String>
The list of
bin/
directories containing executables.
Class Method Details
.download(url, dest) ⇒ String
Downloads a file using either curl
or wget
.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/ronin/core/system.rb', line 112 def self.download(url,dest) uri = URI(url) url = url.to_s if File.directory?(dest) dest = File.join(dest,File.basename(uri.path)) end FileUtils.mkdir_p(File.dirname(dest)) partial_dest = "#{dest}.part" case downloader when :wget unless system('wget','-c','-O',partial_dest,url) raise(DownloadFailed,"wget command failed: wget -c -O #{partial_dest} #{url}") end when :curl unless system('curl','-f','-L','-C','-','-o',partial_dest,url) raise(DownloadFailed,"curl command failed: curl -f -L -C - -o #{partial_dest} #{url}") end when nil raise(DownloadFailed,"could not find 'curl' or 'wget' on the system") else raise(NotImplementedError,"downloader not supported: #{downloader.inspect}") end FileUtils.mv(partial_dest,dest) return dest end |
.downloader ⇒ 'curl', ...
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The detected download command.
82 83 84 85 86 87 88 89 |
# File 'lib/ronin/core/system.rb', line 82 def self.downloader @downloader ||= if os == :macos then :curl else if installed?('wget') then :wget elsif installed?('curl') then :curl end end end |
.installed?(command) ⇒ Boolean
Determines if a command is installed.
69 70 71 72 73 |
# File 'lib/ronin/core/system.rb', line 69 def self.installed?(command) paths.any? do |bin_dir| File.executable?(File.join(bin_dir,command)) end end |
.os ⇒ :linux, ...
The detected Operating System type.
37 38 39 40 41 42 43 44 45 |
# File 'lib/ronin/core/system.rb', line 37 def self.os @os ||= if RUBY_PLATFORM.include?('linux') then :linux elsif RUBY_PLATFORM.include?('darwin') then :macos elsif RUBY_PLATFORM.include?('freebsd') then :freebsd elsif RUBY_PLATFORM.include?('openbsd') then :openbsd elsif RUBY_PLATFORM.include?('netbsd') then :netbsd elsif Gem.win_platform? then :windows end end |
.paths ⇒ Array<String>
The list of bin/
directories containing executables.
52 53 54 55 56 57 58 |
# File 'lib/ronin/core/system.rb', line 52 def self.paths @paths ||= if ENV['PATH'] ENV['PATH'].split(File::PATH_SEPARATOR) else [] end end |