"Fossies" - the Fresh Open Source Software Archive

Member "vagrant-2.2.14/plugins/guests/darwin/cap/darwin_version.rb" (20 Nov 2020, 1104 Bytes) of package /linux/misc/vagrant-2.2.14.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ruby source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 module VagrantPlugins
    2   module GuestDarwin
    3     module Cap
    4       class DarwinVersion
    5         
    6         VERSION_REGEX = /\d+.\d+.?\d*/.freeze
    7 
    8         # Get the darwin version
    9         #
   10         # @param [Machine]
   11         # @return [String] version of drawin
   12         def self.darwin_version(machine)
   13           output = ""
   14           machine.communicate.sudo("sysctl kern.osrelease") do |_, data|
   15             output = data
   16           end
   17           output.scan(VERSION_REGEX).first
   18         end
   19 
   20         # Get the darwin major version
   21         #
   22         # @param [Machine]
   23         # @return [int] major version of drawin (nil if version is not detected)
   24         def self.darwin_major_version(machine)
   25           output = ""
   26           machine.communicate.sudo("sysctl kern.osrelease") do |_, data|
   27             output = data
   28           end
   29           version_string = output.scan(VERSION_REGEX).first
   30           if version_string
   31             major_version = version_string.split(".").first.to_i
   32           else
   33             major_version = nil
   34           end
   35           major_version
   36         end
   37       end
   38     end
   39   end
   40 end