default-settings 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #!/bin/sh
  2. [[ "$(df | grep overlay)" && ! "$(df | grep /rom/overlay)" ]] && firstboot
  3. version=`uci -q get base_config.@status[0].version`
  4. . /etc/openwrt_release
  5. test -n "${DISTRIB_ID}" || DISTRIB_ID=OpenWrt
  6. DISTRIB_ID=`echo -n $DISTRIB_ID | tr a-z A-Z`
  7. if [ "$(uci -q get dhcp.@dnsmasq[0].port)" != "53" ]; then
  8. uci -q set dhcp.@dnsmasq[0].port='53'
  9. uci commit dhcp
  10. fi
  11. sed -i '/profile.d/d' /lib/upgrade/keep.d/base-files
  12. sed -i 's/\(custom.*\)\/custom/\1/' /etc/opkg/distfeeds.conf
  13. sed -i 's?\(src/gz openwrt_core\)?#\1?' /etc/opkg/distfeeds.conf
  14. echo $(uci -q get uhttpd.main.index_page) | grep -q "cgi-bin/luci" ||
  15. uci -q add_list uhttpd.main.index_page='cgi-bin/luci' && uci commit uhttpd
  16. [ -f /usr/bin/wget ] &&
  17. ln -s /usr/bin/wget /usr/bin/wget-ssl
  18. sed -i "s/git-.*-\(.*\)/git-\1/g" /usr/lib/lua/luci/version.lua
  19. ln -s /sbin/poweroff /sbin/shutdown
  20. sed -i '/S99opkg/d' /etc/crontabs/root
  21. sec="$(grep -m1 -ao '[0-6][0-9]' /dev/urandom | head -n1)"
  22. echo "$sec 4 * * * sh /etc/rc.d/S99opkg >/dev/null 2>&1" >> /etc/crontabs/root
  23. [[ "$(echo "$(/sbin/cpuinfo 2>/dev/null)" | grep -i "MHz")" ]] || sed -i "s/_('CPU Info'),cpuinfo.cpufreq,//" /www/luci-static/resources/view/status/include/10_system.js
  24. grep -q op.supes.top /etc/bypass/white.list ||
  25. echo "op.supes.top" >> /etc/bypass/white.list
  26. processor=`cat /proc/cpuinfo | grep 'processor' | wc -l`
  27. test -n "$processor" || processor=3
  28. sed -i "s/^threads =.*/threads = $processor/" /etc/uwsgi/vassals/luci-webui.ini
  29. test $version -lt 1 && {
  30. uci -q set luci.main.lang='auto'
  31. uci -q set luci.main.mediaurlbase=/luci-static/edge
  32. uci commit luci
  33. uci -q get system.@system[0] >/dev/null 2>&1 && {
  34. uci -q set system.@system[0].hostname="${DISTRIB_ID}"
  35. uci -q set system.@system[0].zonename='Asia/Shanghai'
  36. uci -q set system.@system[0].timezone='CST-8'
  37. uci -q del system.ntp.server
  38. uci -q add_list system.ntp.server='ntp.aliyun.com'
  39. uci -q add_list system.ntp.server='0.openwrt.pool.ntp.org'
  40. uci -q set system.@system[0].autoupgrade_pkg='1'
  41. uci -q set system.@system[0].autoupgrade_fm='1'
  42. uci commit system
  43. }
  44. uci -q set uhttpd.main.rfc1918_filter=0
  45. uci -q set uhttpd.main.redirect_https=0
  46. uci -q set uhttpd.main.script_timeout='120'
  47. uci commit uhttpd
  48. SSID=${DISTRIB_ID}
  49. SSID_PASSWD=88888888
  50. uci -q set base_config.@status[0].SSID=${SSID}
  51. # uci set base_config.@status[0].SSID_PASSWD=${SSID_PASSWD}
  52. uci -q set upnpd.config.enabled='1'
  53. uci commit upnpd
  54. grep -q log-facility /etc/dnsmasq.conf ||
  55. echo "log-facility=/dev/null" >> /etc/dnsmasq.conf
  56. grep -q /etc/dnsmasq.d /etc/dnsmasq.conf ||
  57. echo "conf-dir=/etc/dnsmasq.d" >> /etc/dnsmasq.conf
  58. uci -q set turboacc.config.sfe_flow='0'
  59. uci commit turboacc
  60. uci -q set fstab.@global[0].anon_mount=1
  61. uci commit fstab
  62. test ! -f /etc/config/placeholder && {
  63. uci -q set network.lan.ipaddr="10.0.0.1"
  64. uci -q set network.@globals[0].packet_steering=1
  65. uci commit network
  66. }
  67. uci -q set dhcp.@dnsmasq[0].dns_redirect='1'
  68. uci -q set dhcp.dnsmasq[0].allservers='1'
  69. uci -q set dhcp.lan.force='1'
  70. uci -q set dhcp.@dnsmasq[0].cachesize='1500'
  71. uci -q set dhcp.@dnsmasq[0].min_ttl='3600'
  72. uci -q set dhcp.lan.ra='hybrid'
  73. uci -q set dhcp.lan.ndp='hybrid'
  74. uci -q set dhcp.lan.dhcpv6='hybrid'
  75. uci -q set dhcp.lan.force='1'
  76. uci commit dhcp
  77. uci -q set nft-qos.default.limit_enable='0'
  78. uci commit nft-qos
  79. uci -q set system.@system[0].conloglevel='4'
  80. uci -q set system.@system[0].cronloglevel='8'
  81. uci commit system
  82. }
  83. # kB
  84. memtotal=`grep MemTotal /proc/meminfo | awk '{print $2}'`
  85. if test $memtotal -ge 1048576; then
  86. # > 1024M
  87. cachesize=10000
  88. dnsforwardmax=10000
  89. nf_conntrack_max=262144
  90. elif test $memtotal -ge 524288; then
  91. # <= 1024M
  92. cachesize=10000
  93. dnsforwardmax=10000
  94. nf_conntrack_max=131072
  95. elif test $memtotal -ge 262144; then
  96. # <= 512M
  97. cachesize=8192
  98. dnsforwardmax=8192
  99. nf_conntrack_max=65536
  100. elif test $memtotal -ge 131072; then
  101. # <= 256M
  102. cachesize=4096
  103. dnsforwardmax=4096
  104. nf_conntrack_max=65536
  105. elif test $memtotal -ge 65536; then
  106. # <= 128M
  107. cachesize=2048
  108. dnsforwardmax=2048
  109. nf_conntrack_max=32768
  110. else
  111. # < 64M
  112. cachesize=1024
  113. dnsforwardmax=1024
  114. nf_conntrack_max=16384
  115. fi
  116. test $version -lt 1 && {
  117. uci -q get dhcp.@dnsmasq[0] || uci -q add dhcp dnsmasq
  118. uci -q set dhcp.@dnsmasq[0].cachesize="$cachesize"
  119. uci -q set dhcp.@dnsmasq[0].dnsforwardmax="$dnsforwardmax"
  120. uci -q set dhcp.@dnsmasq[0].localservice='0'
  121. uci -q set dhcp.@dnsmasq[0].localise_queries='1'
  122. uci -q set dhcp.@dnsmasq[0].rebind_protection='0'
  123. uci -q set dhcp.@dnsmasq[0].rebind_localhost='1'
  124. uci commit dhcp
  125. version=1
  126. }
  127. # sysctl overwrite
  128. SYSCTL_LOCAL=/etc/sysctl.d/50-local.conf
  129. mkdir -p /etc/sysctl.d
  130. echo -n >$SYSCTL_LOCAL
  131. echo net.nf_conntrack_max=$nf_conntrack_max >>$SYSCTL_LOCAL
  132. echo net.ipv4.ip_early_demux=0 >>$SYSCTL_LOCAL
  133. echo net.bridge.bridge-nf-call-iptables=0 >>$SYSCTL_LOCAL
  134. echo net.ipv4.fib_multipath_hash_policy=1 >>$SYSCTL_LOCAL
  135. echo net.ipv4.tcp_congestion_control=cubic >>$SYSCTL_LOCAL
  136. echo net.netfilter.nf_conntrack_helper=1 >>$SYSCTL_LOCAL
  137. echo kernel.msgmax = 65536 >>$SYSCTL_LOCAL
  138. echo kernel.msgmnb = 65536 >>$SYSCTL_LOCAL
  139. echo vm.swappiness=0 >>$SYSCTL_LOCAL
  140. cp -pR /www/cgi-bin/* /www/
  141. rm -rf /tmp/luci-*
  142. uci -q set base_config.@status[0].version=$version
  143. uci commit base_config