summaryrefslogtreecommitdiff
path: root/lib/dslkeywords/package.rb
blob: 86903cfb85e8475279d325c4d15029e56ba31a9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'erb'
require 'fileutils'

require_relative 'resource'

module RCM
  class DNFPackageManager
    def installed?(pkg) = false
    def install(pkg) = `dnf install -y "#{pkg}"` unless installed?(pkg)
    def update(pkg) = `dnf update -y "#{pkg}"`
    def remove(pkg) = `dnf remove -y "#{pkg}"` if installed?(pkg)
  end

  # Managing packages
  class Package < Resource
    attr_reader :path

    class UnsupportedOS < StandardError; end

    def initialize(name)
      super(name)
      raise UnsupportedOS, 'OS is not supported' unless File.file?('/etc/fedora-release')

      @manager = DNFPackageManager.new

      @name = name
    end

    def packages(*pks)
      raise 'Not yet implemented'
    end

    def evaluate!
      nil unless super
    end
  end

  # Add file keyword to the DSL
  class DSL
    def package(name, &block)
      return unless @conds_met

      f = Package.new(name)
      f.packages(f.instance_eval(&block))
      self << f
      f
    end
  end
end