500-opkg 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/lua
  2. local fs = require 'nixio.fs'
  3. local site = require 'gluon.site_config'
  4. local util = require 'luci.util'
  5. local subst = {}
  6. subst['%%v'] = util.trim(fs.readfile('/etc/openwrt_version'))
  7. subst['%%n'], subst['%%S'], subst['%%A'] = util.exec('. /etc/openwrt_release; echo "$DISTRIB_CODENAME"; echo "$DISTRIB_TARGET"; echo "$DISTRIB_ARCH"'):match('([^\n]*)\n([^\n]*)\n([^\n]*)')
  8. subst['%%GS'] = site.site_code
  9. subst['%%GV'] = util.trim(fs.readfile('/lib/gluon/gluon-version'))
  10. subst['%%GR'] = util.trim(fs.readfile('/lib/gluon/release'))
  11. function replace_patterns(url)
  12. for k, v in pairs(subst) do
  13. url = url:gsub(k, v)
  14. end
  15. return url
  16. end
  17. local prefix = subst['%%n'] .. '_'
  18. if fs.access('/etc/opkg/distfeeds.conf') then
  19. local distfeeds = {}
  20. for line in io.lines('/etc/opkg/distfeeds.conf') do
  21. table.insert(distfeeds, line)
  22. end
  23. local f = io.open('/etc/opkg/distfeeds.conf', 'w')
  24. for _, line in ipairs(distfeeds) do
  25. local name = line:match('^src/gz%s' .. prefix .. '(%S+)%s')
  26. if name == 'core' then
  27. f:write('# ' .. line .. '\n')
  28. elseif name and site.opkg and site.opkg.lede then
  29. f:write(string.format('src/gz %s %s/%s\n', prefix .. name, replace_patterns(site.opkg.lede), name))
  30. else
  31. f:write(line .. '\n')
  32. end
  33. end
  34. f:close()
  35. if site.opkg and site.opkg.extra and next(site.opkg.extra) then
  36. local f = io.open('/etc/opkg/gluon.conf', 'w')
  37. for k, v in pairs(site.opkg.extra) do
  38. f:write(string.format('src/gz %s %s\n', k, replace_patterns(v)))
  39. end
  40. f:close()
  41. else
  42. os.remove('/etc/opkg/gluon.conf')
  43. end
  44. end