read_ifcfg

in cookbooks/fb_network_scripts/libraries/rh_int_helpers.rb [87:116]


      def read_ifcfg(file)
        d = {}
        Chef::Log.debug("fb_network_scripts: reading #{file}")
        cont = false
        prevline = ''
        ::File.read(file).each_line do |line|
          Chef::Log.debug("fb_network_scripts: --> line: #{line}")
          next if line.start_with?('#')
          line.strip!
          if line.end_with?('\\')
            prevline += line[0..-2]
            cont = true
            next
          end
          if cont
            line = prevline + line
            prevline = ''
            cont = false
          end
          key, val = line.split('=')
          val = '' if val.nil?
          
          if !val.empty? && val[0] == '"' && val[-1] == '"'
            val = val[1..-2]
          end
          d[key] = val
        end
        d
      end