default-settings 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. sed -i 's/\(custom.*\)\/custom/\1/' /etc/opkg/distfeeds.conf
  15. sed -i 's?\(src/gz openwrt_\(core\|telephony\)\)?#\1?' /etc/opkg/distfeeds.conf
  16. echo $(uci -q get uhttpd.main.index_page) | grep -q "cgi-bin/luci" ||
  17. uci -q add_list uhttpd.main.index_page='cgi-bin/luci' && uci commit uhttpd
  18. [ -f /usr/bin/wget ] &&
  19. ln -s /usr/bin/wget /usr/bin/wget-ssl
  20. sed -i "s/git-.*-\(.*\)/git-\1/g" /usr/lib/lua/luci/version.lua
  21. /etc/init.d/packages enable
  22. sed -i '/S99packages/d' /etc/crontabs/root
  23. hour="$(grep -m1 -ao '[4-6]' /dev/urandom | head -n1)"
  24. min="$(grep -m1 -ao '[0-5][0-9]' /dev/urandom | head -n1)"
  25. echo "$min $hour * * * sh /etc/rc.d/S99packages >/dev/null 2>&1" >> /etc/crontabs/root
  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 "s/^threads =.*/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 get system.@system[0] >/dev/null 2>&1 && {
  37. uci -q set system.@system[0].hostname="${DISTRIB_ID}"
  38. uci -q set system.@system[0].zonename='Asia/Shanghai'
  39. uci -q set system.@system[0].timezone='CST-8'
  40. uci -q del system.ntp.server
  41. uci -q add_list system.ntp.server='ntp.aliyun.com'
  42. uci -q add_list system.ntp.server='0.openwrt.pool.ntp.org'
  43. uci commit system
  44. }
  45. uci -q set uhttpd.main.rfc1918_filter=0
  46. uci -q set uhttpd.main.redirect_https=0
  47. uci -q set uhttpd.main.script_timeout='120'
  48. uci commit uhttpd
  49. SSID=${DISTRIB_ID}
  50. SSID_PASSWD=88888888
  51. uci -q set base_config.@status[0].SSID=${SSID}
  52. # uci set base_config.@status[0].SSID_PASSWD=${SSID_PASSWD}
  53. uci -q set upnpd.config.enabled='1'
  54. uci commit upnpd
  55. grep -q log-facility /etc/dnsmasq.conf ||
  56. echo "log-facility=/dev/null" >> /etc/dnsmasq.conf
  57. grep -q /etc/dnsmasq.d /etc/dnsmasq.conf ||
  58. echo "conf-dir=/etc/dnsmasq.d" >> /etc/dnsmasq.conf
  59. uci -q set turboacc.config.sfe_flow='0'
  60. uci commit turboacc
  61. uci -q set fstab.@global[0].anon_mount=1
  62. uci commit fstab
  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. uci -q set dhcp.@dnsmasq[0].dns_redirect='1'
  67. uci -q set dhcp.dnsmasq[0].allservers='1'
  68. uci -q set dhcp.lan.force='1'
  69. uci -q set dhcp.@dnsmasq[0].cachesize='1500'
  70. uci -q set dhcp.@dnsmasq[0].min_ttl='3600'
  71. uci -q set dhcp.lan.ra='hybrid'
  72. uci -q set dhcp.lan.ndp='hybrid'
  73. uci -q set dhcp.lan.dhcpv6='hybrid'
  74. uci -q set dhcp.lan.force='1'
  75. uci commit dhcp
  76. uci -q set nft-qos.default.limit_enable='0'
  77. uci commit nft-qos
  78. uci -q set system.@system[0].conloglevel='4'
  79. uci -q set system.@system[0].cronloglevel='8'
  80. uci commit system
  81. /etc/init.d/fa-pwmfan disable >/dev/null 2>&1
  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. uci -q set system.@system[0].zram_comp_algo='zstd'
  126. uci -q set system.@system[0].zram_size_mb="$(expr $memtotal / 1024 / 3)"
  127. uci commit system
  128. version=1
  129. }
  130. # sysctl overwrite
  131. SYSCTL_LOCAL=/etc/sysctl.d/50-local.conf
  132. mkdir -p /etc/sysctl.d
  133. echo -n >$SYSCTL_LOCAL
  134. echo net.nf_conntrack_max=$nf_conntrack_max >>$SYSCTL_LOCAL
  135. echo net.ipv4.ip_early_demux=0 >>$SYSCTL_LOCAL
  136. echo net.bridge.bridge-nf-call-iptables=0 >>$SYSCTL_LOCAL
  137. echo net.ipv4.fib_multipath_hash_policy=1 >>$SYSCTL_LOCAL
  138. echo net.ipv4.tcp_congestion_control=cubic >>$SYSCTL_LOCAL
  139. echo net.netfilter.nf_conntrack_helper=1 >>$SYSCTL_LOCAL
  140. echo kernel.msgmax = 65536 >>$SYSCTL_LOCAL
  141. echo kernel.msgmnb = 65536 >>$SYSCTL_LOCAL
  142. echo vm.swappiness=0 >>$SYSCTL_LOCAL
  143. cp -pR /www/cgi-bin/* /www/
  144. rm -rf /tmp/luci-*
  145. uci -q set base_config.@status[0].version=$version
  146. uci commit base_config