default-settings 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. uci set dockerd.firewall.extra_iptables_args='--match conntrack ! --ctstate RELATED,ESTABLISHED'
  12. uci commit dockerd
  13. sed -i '/profile.d/d' /lib/upgrade/keep.d/base-files
  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. /etc/init.d/wizard disable
  17. [ -f /usr/bin/wget ] &&
  18. ln -s /usr/bin/wget /usr/bin/wget-ssl
  19. sed -i "s/git-.*-\(.*\)/git-\1/g" /usr/lib/lua/luci/version.lua
  20. [[ "$(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
  21. grep -q op.supes.top /etc/bypass/white.list ||
  22. echo "op.supes.top" >> /etc/bypass/white.list
  23. processor=`cat /proc/cpuinfo | grep 'processor' | wc -l`
  24. test -n "$processor" || processor=3
  25. sed -i "/^threads =/c\threads = $processor" /etc/uwsgi/vassals/luci-webui.ini
  26. test $version -lt 1 && {
  27. uci -q set luci.main.lang='auto'
  28. uci -q set luci.main.mediaurlbase=/luci-static/edge
  29. uci commit luci
  30. uci -q set dropbear.@dropbear[0].Interface='lan'
  31. uci commit dropbear
  32. uci -q get system.@system[0] >/dev/null 2>&1 && {
  33. uci -q set system.@system[0].hostname="${DISTRIB_ID}"
  34. uci -q set system.@system[0].zonename='Asia/Shanghai'
  35. uci -q set system.@system[0].timezone='CST-8'
  36. uci -q del system.ntp.server
  37. uci -q add_list system.ntp.server='ntp.aliyun.com'
  38. uci -q add_list system.ntp.server='0.openwrt.pool.ntp.org'
  39. uci commit system
  40. }
  41. uci -q set uhttpd.main.rfc1918_filter=0
  42. uci -q set uhttpd.main.redirect_https=0
  43. uci -q set uhttpd.main.script_timeout='120'
  44. uci commit uhttpd
  45. wifi_setup_radio(){
  46. local radio=$1
  47. uci -q get wireless.${radio} >/dev/null 2>&1 && {
  48. uci -q batch <<-EOT
  49. set -q wireless.${radio}.disabled='0'
  50. EOT
  51. if [ "$(uci -q get wireless.${radio}.hwmode)" = "11a" ]; then
  52. uci -q set wireless.${radio}.htmode='VHT80'
  53. else
  54. uci -q set wireless.${radio}.htmode='VHT40'
  55. fi
  56. obj=`uci -q add wireless wifi-iface`
  57. test -n "$obj" && {
  58. uci -q set wireless.$obj.device="${radio}"
  59. uci -q set wireless.$obj.network='lan'
  60. uci -q set wireless.$obj.mode='ap'
  61. if [ "$(uci -q get wireless.${radio}.hwmode)" == "11a" ]; then
  62. uci -q set wireless.$obj.ssid="${SSID}_5G"
  63. else
  64. uci -q set wireless.$obj.ssid="${SSID}_2.4G"
  65. fi
  66. if [ "${SSID_PASSWD}" ]; then
  67. uci -q set wireless.$obj.encryption='psk2'
  68. uci -q set wireless.$obj.key="${SSID_PASSWD}"
  69. else
  70. uci -q set wireless.$obj.encryption='none'
  71. fi
  72. }
  73. }
  74. }
  75. [ -f /etc/config/wireless ] && {
  76. SSID=${DISTRIB_ID}
  77. SSID_PASSWD=""
  78. while uci delete wireless.@wifi-iface[0] >/dev/null 2>&1; do :; done
  79. for radio in radio0 radio1 radio2 radio3 wifi0 wifi1 wifi2 wifi3; do
  80. wifi_setup_radio ${radio}
  81. done
  82. uci commit wireless
  83. }
  84. uci -q set upnpd.config.enabled='1'
  85. uci commit upnpd
  86. grep -q log-facility /etc/dnsmasq.conf ||
  87. echo "log-facility=/dev/null" >> /etc/dnsmasq.conf
  88. grep -q /etc/dnsmasq.d /etc/dnsmasq.conf ||
  89. echo "conf-dir=/etc/dnsmasq.d" >> /etc/dnsmasq.conf
  90. uci -q set firewall.@defaults[0].fullcone='1'
  91. uci commit firewall
  92. uci -q set fstab.@global[0].anon_mount=1
  93. uci commit fstab
  94. uci -q set network.lan.ipaddr="10.0.0.1"
  95. uci -q set network.@globals[0].packet_steering=1
  96. uci commit network
  97. uci -q set dhcp.@dnsmasq[0].dns_redirect='1'
  98. uci -q set dhcp.@dnsmasq[0].allservers='1'
  99. uci -q del dhcp.@dnsmasq[0].noresolv
  100. uci -q set dhcp.@dnsmasq[0].cachesize='1500'
  101. uci -q set dhcp.@dnsmasq[0].min_ttl='3600'
  102. uci -q set dhcp.lan.force='1'
  103. uci -q set dhcp.lan.ra='hybrid'
  104. uci -q set dhcp.lan.ndp='hybrid'
  105. uci -q set dhcp.lan.dhcpv6='hybrid'
  106. uci -q set dhcp.lan.force='1'
  107. uci commit dhcp
  108. uci -q set nft-qos.default.limit_enable='0'
  109. uci commit nft-qos
  110. uci -q set system.@system[0].conloglevel='4'
  111. uci -q set system.@system[0].cronloglevel='8'
  112. uci commit system
  113. }
  114. # kB
  115. memtotal=`grep MemTotal /proc/meminfo | awk '{print $2}'`
  116. if test $memtotal -ge 1048576; then
  117. # > 1024M
  118. cachesize=10000
  119. dnsforwardmax=10000
  120. nf_conntrack_max=262144
  121. elif test $memtotal -ge 524288; then
  122. # <= 1024M
  123. cachesize=10000
  124. dnsforwardmax=10000
  125. nf_conntrack_max=131072
  126. elif test $memtotal -ge 262144; then
  127. # <= 512M
  128. cachesize=8192
  129. dnsforwardmax=8192
  130. nf_conntrack_max=65536
  131. elif test $memtotal -ge 131072; then
  132. # <= 256M
  133. cachesize=4096
  134. dnsforwardmax=4096
  135. nf_conntrack_max=65536
  136. elif test $memtotal -ge 65536; then
  137. # <= 128M
  138. cachesize=2048
  139. dnsforwardmax=2048
  140. nf_conntrack_max=32768
  141. else
  142. # < 64M
  143. cachesize=1024
  144. dnsforwardmax=1024
  145. nf_conntrack_max=16384
  146. fi
  147. test $version -lt 1 && {
  148. uci -q get dhcp.@dnsmasq[0] || uci -q add dhcp dnsmasq
  149. uci -q set dhcp.@dnsmasq[0].cachesize="$cachesize"
  150. uci -q set dhcp.@dnsmasq[0].dnsforwardmax="$dnsforwardmax"
  151. uci -q set dhcp.@dnsmasq[0].localservice='0'
  152. uci -q set dhcp.@dnsmasq[0].localise_queries='1'
  153. uci -q set dhcp.@dnsmasq[0].rebind_protection='0'
  154. uci -q set dhcp.@dnsmasq[0].rebind_localhost='1'
  155. uci commit dhcp
  156. uci -q set system.@system[0].zram_comp_algo='zstd'
  157. uci -q set system.@system[0].zram_size_mb="$(expr $memtotal / 1024 / 3)"
  158. uci commit system
  159. version=1
  160. }
  161. # sysctl overwrite
  162. SYSCTL_LOCAL=/etc/sysctl.d/50-local.conf
  163. mkdir -p /etc/sysctl.d
  164. echo -n >$SYSCTL_LOCAL
  165. echo net.nf_conntrack_max=$nf_conntrack_max >>$SYSCTL_LOCAL
  166. echo net.ipv4.ip_early_demux=0 >>$SYSCTL_LOCAL
  167. echo net.bridge.bridge-nf-call-iptables=0 >>$SYSCTL_LOCAL
  168. echo net.ipv4.fib_multipath_hash_policy=1 >>$SYSCTL_LOCAL
  169. echo net.ipv4.tcp_congestion_control=cubic >>$SYSCTL_LOCAL
  170. echo net.netfilter.nf_conntrack_helper=1 >>$SYSCTL_LOCAL
  171. echo kernel.msgmax = 65536 >>$SYSCTL_LOCAL
  172. echo kernel.msgmnb = 65536 >>$SYSCTL_LOCAL
  173. echo vm.swappiness=0 >>$SYSCTL_LOCAL
  174. cp -pR /www/cgi-bin/* /www/
  175. rm -rf /tmp/luci-*
  176. uci -q set base_config.@status[0].version=$version
  177. uci commit base_config
  178. (
  179. [[ -f "/bin/coremark" && ! -f "/etc/bench.log" && "$(uci -q get wizard.default.coremark)" == '1' ]] && {
  180. sleep 30
  181. /bin/coremark >/tmp/coremark.log
  182. cat /tmp/coremark.log | grep "CoreMark 1.0" | cut -d "/" -f 1 | cut -d "." -f -2 >/etc/bench.log
  183. sed -i 's/CoreMark 1.0/(CpuMark/g' /etc/bench.log
  184. echo " Scores)" >>/etc/bench.log
  185. }
  186. ) &