Sha256: 6e8aa4af215859907c218a72ca2b217c8d42c017a6ee1544e90cffd786b0b74d

Contents?: true

Size: 1.26 KB

Versions: 6

Compression:

Stored size: 1.26 KB

Contents

module Shutter
  class OS
    def initialize
      unless File.exist?('/proc/version')
        @version = "Unknown"
      end
    end

    def validate!
      if unknown?
        raise "ERROR: Unsupported operating system"
      end
    end

    def family
      @family ||= ENV['OS'] ? ENV['OS'] : RUBY_PLATFORM.split('-').last
    end

    def version
      @version ||= IO.read('/proc/version')
    end

    def linux?
      family == "linux"
    end

    def iptables_save
      "/sbin/iptables-save"
    end

    def iptables_restore
      "/sbin/iptables-restore"
    end

    def persist_file
      case version
      when /Red Hat/
        "/etc/sysconfig/iptables"
      when /Debian/
        "/etc/iptables/rules"
      when /Ubuntu/
        "/etc/iptables/rules"
      else
        "/tmp/iptables.rules"
      end
    end

    def dist
      case version
      when /Red Hat/
        "RedHat"
      when /Debian/
        "Debian"
      when /Ubuntu/
        "Ubuntu"
      else
        "Unknown"
      end
    end

    def redhat?
      dist == "RedHat"
    end

    def ubuntu?
      dist == "Ubuntu"
    end

    def debian?
      dist == "Debian"
    end

    def unknown?
      dist == "Unknown"
    end

    alias :centos? :redhat? 
    alias :fedora? :redhat?
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
shutter-0.2.5 lib/shutter/os.rb
shutter-0.2.4 lib/shutter/os.rb
shutter-0.2.3 lib/shutter/os.rb
shutter-0.2.2 lib/shutter/os.rb
shutter-0.2.0 lib/shutter/os.rb
shutter-0.1.0 lib/shutter/os.rb