default-settings 6.7 KB

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