Sha256: 6474ebbb125320739b74cd963b2496a5683cf68e75de6df97b9db3f2078578b2

Contents?: true

Size: 1.56 KB

Versions: 6

Compression:

Stored size: 1.56 KB

Contents

module OSType
  OTHER = 0
  RHEL = 1
  GENTOO = 2
  UBUNTU = 3
end

class Os
  def self.l
    @l ||= SemanticLogger["os"]
  end

  def self.get_os
    case File.foreach("/etc/os-release").lazy.grep(/^ID=/).first
    when /fedora/
      OSType::RHEL
    when /gentoo/
      OSType::GENTOO
    when /rocky/
      OSType::RHEL
    when /ubuntu/
      OSType::UBUNTU
    else
      OSType::OTHER
    end
  end

  def self.pkg_update
    l.info "pulling from package mgr repos, then upgrading OS packages"
    case get_os
    when OSType::RHEL
      l.info "detected RHEL-like OS"
      system "sudo dnf update -y"
    when OSType::GENTOO
      l.info "detected gentoo (you are hard-core)"
      if Date.today > (DateTime.parse File.read "/var/db/repos/gentoo/metadata/timestamp.chk")
        (system "sudo emaint --auto sync") || return
      end
      system "sudo emerge -vuDN @world"
    when OSType::UBUNTU
      l.info "detected ubuntu"
      (system "sudo apt update") || return
      system "sudo apt upgrade -y"
    else
      l.error "i don't know what OS we're using"
      return
    end
    pkg_clean
  end

  def self.pkg_clean
    l.info "cleaning packages"
    case get_os
    when OSType::RHEL
      l.info "detected RHEL-like OS"
      system "sudo dnf autoremove -y"
    when OSType::GENTOO
      l.info "detected gentoo (you are hard-core)"
      system "sudo emerge --depclean"
    when OSType::UBUNTU
      l.info "detected ubuntu"
      system "sudo apt autoremove -y"
    else
      l.error "i don't know what OS we're using"
    end
  end

  def self.all
    pkg_update
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cvefixer-0.6.8 lib/taskgroups/os.rb
cvefixer-0.6.7 lib/taskgroups/os.rb
cvefixer-0.6.6 lib/taskgroups/os.rb
cvefixer-0.6.5 lib/taskgroups/os.rb
cvefixer-0.6.4 lib/taskgroups/os.rb
cvefixer-0.6.3 lib/taskgroups/os.rb