default-settings 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 '/openwrt_kiddin9/d' /etc/opkg/distfeeds.conf
  15. sed -i 's?\(src/gz openwrt_\(core\|telephony\)\)?#\1?' /etc/opkg/distfeeds.conf
  16. KERNEL_V="$(uname -r)"
  17. ARCH="$(cat /etc/os-release | grep "OPENWRT_ARCH=" | cut -d \" -f 2)"
  18. sed -i "\$a src/gz openwrt_kmods https://op.supes.top/packages/$ARCH/kmods/$KERNEL_V" /etc/opkg/distfeeds.conf
  19. sed -i "\$a src/gz openwrt_kiddin9 https://op.supes.top/packages/$ARCH" /etc/opkg/distfeeds.conf
  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 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. wifi_setup_radio(){
  50. local radio=$1
  51. uci -q get wireless.${radio} >/dev/null 2>&1 && {
  52. uci -q batch <<-EOT
  53. set -q wireless.${radio}.disabled='0'
  54. EOT
  55. if [ "$(uci -q get wireless.${radio}.hwmode)" = "11a" ]; then
  56. uci -q set wireless.${radio}.htmode='VHT80'
  57. else
  58. uci -q set wireless.${radio}.htmode='VHT40'
  59. fi
  60. obj=`uci -q add wireless wifi-iface`
  61. test -n "$obj" && {
  62. uci -q set wireless.$obj.device="${radio}"
  63. uci -q set wireless.$obj.network='lan'
  64. uci -q set wireless.$obj.mode='ap'
  65. if [ "$(uci -q get wireless.${radio}.hwmode)" == "11a" ]; then
  66. uci -q set wireless.$obj.ssid="${SSID}_5G"
  67. else
  68. uci -q set wireless.$obj.ssid="${SSID}_2.4G"
  69. fi
  70. if [ "${SSID_PASSWD}" ]; then
  71. uci -q set wireless.$obj.encryption='psk2'
  72. uci -q set wireless.$obj.key="${SSID_PASSWD}"
  73. else
  74. uci -q set wireless.$obj.encryption='none'
  75. fi
  76. }
  77. }
  78. }
  79. [ -f /etc/config/wireless ] && {
  80. SSID=${DISTRIB_ID}
  81. SSID_PASSWD=""
  82. while uci delete wireless.@wifi-iface[0] >/dev/null 2>&1; do :; done
  83. for radio in radio0 radio1 radio2 radio3 wifi0 wifi1 wifi2 wifi3; do
  84. wifi_setup_radio ${radio}
  85. done
  86. uci commit wireless
  87. }
  88. uci -q set upnpd.config.enabled='1'
  89. uci commit upnpd
  90. grep -q log-facility /etc/dnsmasq.conf ||
  91. echo "log-facility=/dev/null" >> /etc/dnsmasq.conf
  92. grep -q /etc/dnsmasq.d /etc/dnsmasq.conf ||
  93. echo "conf-dir=/etc/dnsmasq.d" >> /etc/dnsmasq.conf
  94. uci -q set firewall.@defaults[0].fullcone='1'
  95. uci commit firewall
  96. uci -q set fstab.@global[0].anon_mount=1
  97. uci commit fstab
  98. uci -q set network.lan.ipaddr="10.0.0.1"
  99. uci -q set network.@globals[0].packet_steering=1
  100. uci commit network
  101. uci -q set dhcp.@dnsmasq[0].dns_redirect='1'
  102. uci -q set dhcp.@dnsmasq[0].allservers='1'
  103. uci -q del dhcp.@dnsmasq[0].noresolv
  104. uci -q set dhcp.@dnsmasq[0].cachesize='1500'
  105. uci -q set dhcp.@dnsmasq[0].min_ttl='3600'
  106. uci -q set dhcp.lan.force='1'
  107. uci -q set dhcp.lan.ra='hybrid'
  108. uci -q set dhcp.lan.ndp='hybrid'
  109. uci -q set dhcp.lan.dhcpv6='hybrid'
  110. uci -q set dhcp.lan.force='1'
  111. uci commit dhcp
  112. uci -q set nft-qos.default.limit_enable='0'
  113. uci commit nft-qos
  114. uci -q set system.@system[0].conloglevel='4'
  115. uci -q set system.@system[0].cronloglevel='8'
  116. uci commit system
  117. }
  118. # kB
  119. memtotal=`grep MemTotal /proc/meminfo | awk '{print $2}'`
  120. if test $memtotal -ge 1048576; then
  121. # > 1024M
  122. cachesize=10000
  123. dnsforwardmax=10000
  124. nf_conntrack_max=262144
  125. elif test $memtotal -ge 524288; then
  126. # <= 1024M
  127. cachesize=10000
  128. dnsforwardmax=10000
  129. nf_conntrack_max=131072
  130. elif test $memtotal -ge 262144; then
  131. # <= 512M
  132. cachesize=8192
  133. dnsforwardmax=8192
  134. nf_conntrack_max=65536
  135. elif test $memtotal -ge 131072; then
  136. # <= 256M
  137. cachesize=4096
  138. dnsforwardmax=4096
  139. nf_conntrack_max=65536
  140. elif test $memtotal -ge 65536; then
  141. # <= 128M
  142. cachesize=2048
  143. dnsforwardmax=2048
  144. nf_conntrack_max=32768
  145. else
  146. # < 64M
  147. cachesize=1024
  148. dnsforwardmax=1024
  149. nf_conntrack_max=16384
  150. fi
  151. test $version -lt 1 && {
  152. uci -q get dhcp.@dnsmasq[0] || uci -q add dhcp dnsmasq
  153. uci -q set dhcp.@dnsmasq[0].cachesize="$cachesize"
  154. uci -q set dhcp.@dnsmasq[0].dnsforwardmax="$dnsforwardmax"
  155. uci -q set dhcp.@dnsmasq[0].localservice='0'
  156. uci -q set dhcp.@dnsmasq[0].localise_queries='1'
  157. uci -q set dhcp.@dnsmasq[0].rebind_protection='0'
  158. uci -q set dhcp.@dnsmasq[0].rebind_localhost='1'
  159. uci commit dhcp
  160. uci -q set system.@system[0].zram_comp_algo='zstd'
  161. uci -q set system.@system[0].zram_size_mb="$(expr $memtotal / 1024 / 3)"
  162. uci commit system
  163. version=1
  164. }
  165. # sysctl overwrite
  166. SYSCTL_LOCAL=/etc/sysctl.d/50-local.conf
  167. mkdir -p /etc/sysctl.d
  168. echo -n >$SYSCTL_LOCAL
  169. echo net.nf_conntrack_max=$nf_conntrack_max >>$SYSCTL_LOCAL
  170. echo net.ipv4.ip_early_demux=0 >>$SYSCTL_LOCAL
  171. echo net.bridge.bridge-nf-call-iptables=0 >>$SYSCTL_LOCAL
  172. echo net.ipv4.fib_multipath_hash_policy=1 >>$SYSCTL_LOCAL
  173. echo net.ipv4.tcp_congestion_control=cubic >>$SYSCTL_LOCAL
  174. echo net.netfilter.nf_conntrack_helper=1 >>$SYSCTL_LOCAL
  175. echo kernel.msgmax = 65536 >>$SYSCTL_LOCAL
  176. echo kernel.msgmnb = 65536 >>$SYSCTL_LOCAL
  177. echo vm.swappiness=0 >>$SYSCTL_LOCAL
  178. cp -pR /www/cgi-bin/* /www/
  179. rm -rf /tmp/luci-*
  180. uci -q set base_config.@status[0].version=$version
  181. uci commit base_config