default-settings 6.6 KB

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