default-settings 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. sed -i '/profile.d/d' /lib/upgrade/keep.d/base-files
  12. test ! -f /etc/nginx/uci.conf && {
  13. ln -sf /var/lib/nginx/uci.conf /etc/nginx/uci.conf
  14. }
  15. sed -i 's/\(custom.*\)\/custom/\1/' /etc/opkg/distfeeds.conf
  16. sed -i 's?\(src/gz openwrt_core\)?#\1?' /etc/opkg/distfeeds.conf
  17. echo $(uci -q get uhttpd.main.index_page) | grep -q "cgi-bin/luci" ||
  18. uci -q add_list uhttpd.main.index_page='cgi-bin/luci' && uci commit uhttpd
  19. [ -f /usr/bin/wget ] &&
  20. ln -s /usr/bin/wget /usr/bin/wget-ssl
  21. sed -i "s/git-.*-\(.*\)/git-\1/g" /usr/lib/lua/luci/version.lua
  22. ln -s /sbin/poweroff /sbin/shutdown
  23. sed -i '/S99opkg/d' /etc/crontabs/root
  24. sec="$(grep -m1 -ao '[0-6][0-9]' /dev/urandom | head -n1)"
  25. echo "$sec 4 * * * sh /etc/rc.d/S99opkg >/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 -q set system.@system[0].autoupgrade_pkg='1'
  44. uci -q set system.@system[0].autoupgrade_fm='1'
  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. SSID=${DISTRIB_ID}
  52. SSID_PASSWD=88888888
  53. uci -q set base_config.@status[0].SSID=${SSID}
  54. # uci set base_config.@status[0].SSID_PASSWD=${SSID_PASSWD}
  55. uci -q set upnpd.config.enabled='1'
  56. uci commit upnpd
  57. grep -q log-facility /etc/dnsmasq.conf ||
  58. echo "log-facility=/dev/null" >> /etc/dnsmasq.conf
  59. grep -q /etc/dnsmasq.d /etc/dnsmasq.conf ||
  60. echo "conf-dir=/etc/dnsmasq.d" >> /etc/dnsmasq.conf
  61. uci -q set turboacc.config.sfe_flow='0'
  62. uci commit turboacc
  63. uci -q set fstab.@global[0].anon_mount=1
  64. uci commit fstab
  65. test ! -f /etc/config/placeholder && {
  66. uci -q set network.lan.ipaddr="10.0.0.1"
  67. uci -q set network.@globals[0].packet_steering=1
  68. uci commit network
  69. }
  70. uci -q set dhcp.@dnsmasq[0].dns_redirect='1'
  71. uci -q set dhcp.dnsmasq[0].allservers='1'
  72. uci -q set dhcp.lan.force='1'
  73. uci -q set dhcp.@dnsmasq[0].cachesize='1500'
  74. uci -q set dhcp.@dnsmasq[0].min_ttl='3600'
  75. uci -q set dhcp.lan.ra='hybrid'
  76. uci -q set dhcp.lan.ndp='hybrid'
  77. uci -q set dhcp.lan.dhcpv6='hybrid'
  78. uci -q set dhcp.lan.force='1'
  79. uci commit dhcp
  80. uci -q set nft-qos.default.limit_enable='0'
  81. uci commit nft-qos
  82. uci -q set system.@system[0].conloglevel='4'
  83. uci -q set system.@system[0].cronloglevel='8'
  84. uci commit system
  85. }
  86. # kB
  87. memtotal=`grep MemTotal /proc/meminfo | awk '{print $2}'`
  88. if test $memtotal -ge 1048576; then
  89. # > 1024M
  90. cachesize=10000
  91. dnsforwardmax=10000
  92. nf_conntrack_max=262144
  93. elif test $memtotal -ge 524288; then
  94. # <= 1024M
  95. cachesize=10000
  96. dnsforwardmax=10000
  97. nf_conntrack_max=131072
  98. elif test $memtotal -ge 262144; then
  99. # <= 512M
  100. cachesize=8192
  101. dnsforwardmax=8192
  102. nf_conntrack_max=65536
  103. elif test $memtotal -ge 131072; then
  104. # <= 256M
  105. cachesize=4096
  106. dnsforwardmax=4096
  107. nf_conntrack_max=65536
  108. elif test $memtotal -ge 65536; then
  109. # <= 128M
  110. cachesize=2048
  111. dnsforwardmax=2048
  112. nf_conntrack_max=32768
  113. else
  114. # < 64M
  115. cachesize=1024
  116. dnsforwardmax=1024
  117. nf_conntrack_max=16384
  118. fi
  119. test $version -lt 1 && {
  120. uci -q get dhcp.@dnsmasq[0] || uci -q add dhcp dnsmasq
  121. uci -q set dhcp.@dnsmasq[0].cachesize="$cachesize"
  122. uci -q set dhcp.@dnsmasq[0].dnsforwardmax="$dnsforwardmax"
  123. uci -q set dhcp.@dnsmasq[0].localservice='0'
  124. uci -q set dhcp.@dnsmasq[0].localise_queries='1'
  125. uci -q set dhcp.@dnsmasq[0].rebind_protection='0'
  126. uci -q set dhcp.@dnsmasq[0].rebind_localhost='1'
  127. uci commit dhcp
  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