update.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/lua
  2. ------------------------------------------------
  3. -- This file is part of the luci-app-ssr-plus update.lua
  4. -- By Mattraks
  5. ------------------------------------------------
  6. require "luci.sys"
  7. require "luci.model.uci"
  8. local icount = 0
  9. local uci = luci.model.uci.cursor()
  10. local log = function(...)
  11. print(os.date("%Y-%m-%d %H:%M:%S ") .. table.concat({ ... }, " "))
  12. end
  13. local function update(url, file, type, file2)
  14. local Num = 1
  15. refresh_cmd = "wget-ssl --no-check-certificate -t 3 -T 10 -O- " .. url .. " > /tmp/ssr-update." .. type
  16. sret = luci.sys.call(refresh_cmd .. " 2>/dev/null")
  17. if sret == 0 then
  18. if type == "gfw_data" then
  19. luci.sys.call("/usr/bin/ssr-gfw " .. type)
  20. Num = 2
  21. end
  22. if type == "ad_data" then
  23. luci.sys.call("/usr/bin/ssr-ad " .. type)
  24. end
  25. local new_md5 = luci.sys.exec("echo -n $([ -f '/tmp/ssr-update." .. type .. "' ] && md5sum /tmp/ssr-update." .. type .. " | awk '{print $1}')")
  26. local old_md5 = luci.sys.exec("echo -n $([ -f '" .. file .. "' ] && md5sum " .. file .. " | awk '{print $1}')")
  27. if new_md5 == old_md5 then
  28. log("你已经是最新数据,无需更新!")
  29. else
  30. icount = luci.sys.exec("cat /tmp/ssr-update." .. type .. " | wc -l")
  31. luci.sys.exec("cp -f /tmp/ssr-update." .. type .. " " .. file)
  32. if file2 then luci.sys.exec("cp -f /tmp/ssr-update." .. type .. " " .. file2) end
  33. log("更新成功! 新的总纪录数:" .. tostring(tonumber(icount)/Num))
  34. end
  35. else
  36. log("更新失败!")
  37. end
  38. luci.sys.exec("rm -f /tmp/ssr-update." .. type)
  39. end
  40. log("正在更新【GFW列表】数据库")
  41. update(uci:get_first("shadowsocksr", "global", "gfwlist_url", "https://cdn.jsdelivr.net/gh/v2fly/domain-list-community@release/gfwlist.txt"), "/etc/ssr/gfw_list.conf", "gfw_data", "/tmp/dnsmasq.ssr/gfw_list.conf")
  42. log("正在更新【国内IP段】数据库")
  43. update(uci:get_first("shadowsocksr", "global", "chnroute_url","https://ispip.clang.cn/all_cn.txt"), "/etc/ssr/china_ssr.txt", "cnip", "/tmp/etc/china_ssr.txt")
  44. if uci:get_first("shadowsocksr", "global", "adblock","0") == "1" then
  45. log("正在更新【广告屏蔽】数据库")
  46. update(uci:get_first("shadowsocksr", "global", "adblock_url","https://easylist-downloads.adblockplus.org/easylistchina+easylist.txt"), "/etc/ssr/ad.conf", "ad_data", "/tmp/dnsmasq.ssr/ad.conf")
  47. end
  48. -- log("正在更新【Netflix IP段】数据库")
  49. -- update(uci:get_first("shadowsocksr", "global", "nfip_url","https://raw.githubusercontent.com/QiuSimons/Netflix_IP/master/NF_only.txt"), "/etc/ssr/netflixip.list", "nfip_data")