Sha256: 35ebf8557a9a4b99b9711c5add7c1833511bf975eacf601172e0b0e2f27e6020

Contents?: true

Size: 1.6 KB

Versions: 2

Compression:

Stored size: 1.6 KB

Contents

# LinuxAdmin Distro Representation
#
# Copyright (C) 2013 Red Hat Inc.
# Licensed under the MIT License

class LinuxAdmin
  class Distro < LinuxAdmin
    attr_accessor :id

    def initialize(id)
      @id = id
    end

    def self.local
      @local ||= begin
        if File.exists?('/etc/issue')
          issue = File.read('/etc/issue')
          if issue.include?('ubuntu')
            return Distros.ubuntu
          elsif ['Fedora', 'red hat', 'centos'].any? { |d| issue.include?(d) }
            return Distros.redhat
          end

        elsif File.exists?('/etc/redhat-release') ||
              File.exists?('/etc/fedora-release')
          return Distros.redhat
        end

        Distros.generic
      end
    end

  end

  module Distros
    def self.generic
      @generic ||= Generic.new
    end

    def self.redhat
      @redhat ||= RedHat.new
    end

    def self.ubuntu
      @ubuntu ||= Ubuntu.new
    end

    def self.all
     @distros ||= [generic, redhat, ubuntu]
    end

    class Generic < Distro
      COMMANDS = {}

      def initialize
        @id = :generic
      end
    end

    class RedHat < Distro
      COMMANDS = {:service   => '/usr/sbin/service',
                  :systemctl => '/usr/bin/systemctl',
                  :parted    => '/usr/sbin/parted',
                  :mount     => '/usr/bin/mount',
                  :umount    => '/usr/bin/umount',
                  :shutdown  => '/usr/sbin/shutdown'}

      def initialize
        @id = :redhat
      end
    end

    class Ubuntu < Distro
      COMMANDS = {}

      def initialize
        @id = :ubuntu
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
linux_admin-0.1.2 lib/linux_admin/distro.rb
linux_admin-0.1.1 lib/linux_admin/distro.rb