46 lines
1.2 KiB
Ruby
46 lines
1.2 KiB
Ruby
#!/usr/bin/env ruby
|
|
|
|
require "json"
|
|
|
|
|
|
appUpdateTemplateFile = "updateAppFromDnsCache-template.rsc"
|
|
|
|
templateFile = File.open(appUpdateTemplateFile)
|
|
|
|
appUpdateTemplateString = templateFile.readlines
|
|
|
|
templateFile.close
|
|
|
|
appJsonFile = ARGV[0]
|
|
|
|
file = File.open(appJsonFile)
|
|
data = JSON.load(file)
|
|
file.close
|
|
|
|
#puts JSON.pretty_generate(data)
|
|
domainsString = "\"#{data["staticDomains"].join("\"; \"")}\""
|
|
domainsRegexString = "\"#{data["regexPatterns"].join("\"; \"")}\""
|
|
domainsRegexString = domainsRegexString.gsub("$",'\$').gsub("\.", "\\.")
|
|
#puts domainsRegexString
|
|
|
|
appUpdateTemplateString.each do |line|
|
|
case line
|
|
when /##INSERT_LINES.*/
|
|
if data["staticDomains"].nil? or data["staticDomains"].empty?
|
|
puts(" :local staticDomains;")
|
|
|
|
else
|
|
puts(" :local staticDomains { \"#{data["staticDomains"].join("\"; \"")}\" };")
|
|
end
|
|
if data["regexPatterns"].nil? or data["regexPatterns"].empty?
|
|
puts(" :local regexString;")
|
|
else
|
|
puts(" :local regexString { #{domainsRegexString} };")
|
|
end
|
|
when /:local addressList "###ADDRESS_LIST###"/
|
|
puts(" :local addressList \"#{data["appName"]}\"")
|
|
else
|
|
puts(line)
|
|
end
|
|
end
|