4 Star 18 Fork 4

felixonmars/dnsmasq-china-list

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
updater.rb 1.81 KB
一键复制 编辑 原始数据 按行查看 历史
#!/usr/bin/ruby
require 'domain_name'
require 'optparse'
require 'ostruct'
require_relative 'verify'
options = OpenStruct.new
options.sort = true
options.file = "accelerated-domains.china.conf"
options.add = []
options.delete = []
OptionParser.new do |opts|
opts.banner = "dnsmasq-china-list updater"
opts.on("-s", "--[no-]sort", "Sort the list (default action)") do |s|
options.sort = s
end
opts.on("-f", "--file FILE", "Specify the file to update (accelerated-domains.china.conf by default)") do |f|
options.file = f
end
opts.on("-a", "--add domain1,domain2", Array, "Add domain(s) to the list (implies -s)") do |a|
options.add = a
options.sort = true
end
opts.on("-d", "--delete domain1,domain2", Array, "Remove domain(s) from the list (implies -s)") do |d|
options.delete = d
options.sort = true
end
end.parse!
lines = File.readlines(options.file).filter { |line| !line.empty? }
disabled_lines = lines.filter { |line| line.start_with?("#") }
changed = false
options.add.each do |domain|
domain = DomainName.normalize(domain)
new_line = CheckRedundant(lines, disabled_lines, domain)
if new_line != false
puts "New domain added: #{domain}"
lines << new_line
changed = true
end
end
options.delete.each do |domain|
domain = DomainName.normalize(domain)
target_line = "server=/#{domain}/114.114.114.114\n"
unless lines.include? target_line
puts "Failed to remove domain #{domain}: not found."
else
puts "Domain removed: #{domain}"
lines.delete(target_line)
changed = true
end
end
fail "No changes made." if (options.add.length || options.delete.length) && !changed
lines.sort_by! { |x| x.delete_prefix("#") } if options.sort
File.write(options.file, lines.join)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/felixonmars/dnsmasq-china-list.git
[email protected]:felixonmars/dnsmasq-china-list.git
felixonmars
dnsmasq-china-list
dnsmasq-china-list
master

搜索帮助