Module: OsCtld::DistConfig::Helpers::RedHat

Included in:
Distributions::RedHat::Configurator, Network::RedHatInitScripts, Network::RedHatNetworkManager
Defined in:
lib/osctld/dist_config/helpers/redhat.rb

Instance Method Summary collapse

Instance Method Details

#set_params(file, params) ⇒ Object

Parameters:

  • file (String)
  • params (Hash)


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
# File 'lib/osctld/dist_config/helpers/redhat.rb', line 5

def set_params(file, params)
  return unless writable?(file)

  regenerate_file(file, 0o644) do |new, old|
    if old
      # Overwrite existing params and keep unchanged ones
      old.each_line do |line|
        param, value = params.detect { |k, _v| /^#{k}=/ =~ line }

        if param
          new.puts("#{param}=\"#{value}\"")
          params.delete(param)

        else
          new.write(line)
        end
      end
    end

    # Write params
    params.each do |k, v|
      new.puts("#{k}=\"#{v}\"")
    end
  end
end