default-settings 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #!/bin/sh
  2. version=`uci get base_config.@status[0].version 2>/dev/null`
  3. . /etc/openwrt_release
  4. test -n "${DISTRIB_ID}" || DISTRIB_ID=OpenWrt
  5. DISTRIB_ID=`echo -n $DISTRIB_ID | tr a-z A-Z`
  6. MACADDR=""
  7. test -e /usr/share/natcapd/board_mac.lua && MACADDR=`lua /usr/share/natcapd/board_mac.lua`
  8. test -n "$MACADDR" || MACADDR=`cat /etc/board.json | grep macaddr | tr a-f A-F | grep -o "[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]" | head -n1`
  9. test -n "$MACADDR" || MACADDR=`cat /sys/class/net/eth0/address | tr a-z A-Z`
  10. test -n "$MACADDR" || MACADDR=`cat /sys/class/net/eth1/address | tr a-z A-Z`
  11. test -n "$MACADDR" || MACADDR=`head -c6 /dev/urandom | hexdump -e '/1 "%02X:"' | head -c17`
  12. test -n "$MACADDR" || MACADDR=`head -c6 /dev/random | hexdump -e '/1 "%02X:"' | head -c17`
  13. sed -i '/profile.d/d' /lib/upgrade/keep.d/base-files
  14. sed -i '/openwrt_custom/d' /etc/opkg/distfeeds.conf
  15. sed -i 's/downloads.openwrt.org/op.supes.top/g' /etc/opkg/distfeeds.conf
  16. echo $(uci 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. ln -s /sbin/poweroff /sbin/shutdown
  22. sed -i '/S99opkg/d' /etc/crontabs/root
  23. echo "0 4 * * * sh /etc/rc.d/S99opkg >/tmp/opkgupdate.log 2>&1" >> /etc/crontabs/root
  24. cpuinfo=`/sbin/cpuinfo 2>/dev/null`
  25. test -n "$cpuinfo" || sed -i "s/_('CPU Info'),cpuinfo.cpufreq,//" /www/luci-static/resources/view/status/include/10_system.js
  26. test $version -lt 1 && {
  27. uci set luci.main.lang='auto'
  28. uci set luci.main.mediaurlbase=/luci-static/edge
  29. uci commit luci
  30. uci get system.@system[0] >/dev/null 2>&1 && {
  31. uci set system.@system[0].hostname="${DISTRIB_ID}"
  32. uci set system.@system[0].zonename='Asia/Shanghai'
  33. uci set system.@system[0].timezone='CST-8'
  34. uci del system.ntp.server
  35. uci add_list system.ntp.server='ntp.aliyun.com'
  36. uci add_list system.ntp.server='0.openwrt.pool.ntp.org'
  37. uci set system.@system[0].autoupgrade_pkg='1'
  38. uci set system.@system[0].autoupgrade_fm='1'
  39. uci commit system
  40. }
  41. uci set uhttpd.main.rfc1918_filter=0
  42. uci set uhttpd.main.redirect_https=0
  43. uci commit uhttpd
  44. SUBFIX=`echo -n $MACADDR | sed 's/://g' | tr a-z A-Z | tail -c4`
  45. SSID=${DISTRIB_ID}_${SUBFIX}
  46. SSID_PASSWD=88888888
  47. uci set base_config.@status[0].SSID=${SSID}
  48. # uci set base_config.@status[0].SSID_PASSWD=${SSID_PASSWD}
  49. uci set upnpd.config.enabled='1'
  50. uci commit upnpd
  51. grep -q log-facility /etc/dnsmasq.conf ||
  52. echo "log-facility=/dev/null" >> /etc/dnsmasq.conf
  53. grep -q /etc/dnsmasq.d /etc/dnsmasq.conf ||
  54. echo "conf-dir=/etc/dnsmasq.d" >> /etc/dnsmasq.conf
  55. uci set turboacc.config.sfe_ipv6='1'
  56. uci commit turboacc
  57. uci set fstab.@global[0].anon_mount=1
  58. uci commit fstab
  59. test ! -f /etc/config/placeholder && {
  60. sed -i 's/root:.*/root:$1$tTPCBw1t$ldzfp37h5lSpO9VXk4uUE\/:18336:0:99999:7:::/g' /etc/shadow
  61. uci set network.lan.ipaddr="10.0.0.1"
  62. uci set network.@globals[0].packet_steering=1
  63. uci commit network
  64. }
  65. uci set dhcp.@dnsmasq[0].dns_redirect='1'
  66. uci set dhcp.dnsmasq[0].allservers='1'
  67. uci set dhcp.lan.force='1'
  68. uci set dhcp.@dnsmasq[0].cachesize='1500'
  69. uci set dhcp.@dnsmasq[0].min_ttl='3600'
  70. uci set dhcp.lan.ra='hybrid'
  71. uci set dhcp.lan.ndp='hybrid'
  72. uci set dhcp.lan.dhcpv6='hybrid'
  73. uci set dhcp.lan.force='1'
  74. uci commit dhcp
  75. uci set nft-qos.default.limit_enable='0'
  76. uci commit nft-qos
  77. }
  78. # kB
  79. memtotal=`grep MemTotal /proc/meminfo | awk '{print $2}'`
  80. cachesize=2048
  81. dnsforwardmax=2048
  82. nf_conntrack_max=16384
  83. if test $memtotal -ge 1048576; then
  84. # > 1024M
  85. cachesize=10000
  86. dnsforwardmax=10000
  87. nf_conntrack_max=262144
  88. elif test $memtotal -ge 524288; then
  89. # <= 1024M
  90. cachesize=10000
  91. dnsforwardmax=10000
  92. nf_conntrack_max=131072
  93. elif test $memtotal -ge 262144; then
  94. # <= 512M
  95. cachesize=8192
  96. dnsforwardmax=8192
  97. nf_conntrack_max=65536
  98. elif test $memtotal -ge 131072; then
  99. # <= 256M
  100. cachesize=4096
  101. dnsforwardmax=4096
  102. nf_conntrack_max=65536
  103. elif test $memtotal -ge 65536; then
  104. # <= 128M
  105. cachesize=2048
  106. dnsforwardmax=2048
  107. nf_conntrack_max=32768
  108. else
  109. # < 64M
  110. cachesize=1024
  111. dnsforwardmax=1024
  112. nf_conntrack_max=16384
  113. fi
  114. test $version -lt 1 && {
  115. uci -q get dhcp.@dnsmasq[0] || uci add dhcp dnsmasq
  116. uci set dhcp.@dnsmasq[0].cachesize="$cachesize"
  117. uci set dhcp.@dnsmasq[0].dnsforwardmax="$dnsforwardmax"
  118. uci set dhcp.@dnsmasq[0].localservice='0'
  119. uci set dhcp.@dnsmasq[0].localise_queries='1'
  120. uci set dhcp.@dnsmasq[0].rebind_protection='0'
  121. uci set dhcp.@dnsmasq[0].rebind_localhost='1'
  122. uci commit dhcp
  123. version=1
  124. }
  125. # sysctl overwrite
  126. SYSCTL_LOCAL=/etc/sysctl.d/50-local.conf
  127. mkdir -p /etc/sysctl.d
  128. echo -n >$SYSCTL_LOCAL
  129. echo net.nf_conntrack_max=$nf_conntrack_max >>$SYSCTL_LOCAL
  130. echo net.ipv4.ip_early_demux=0 >>$SYSCTL_LOCAL
  131. echo net.bridge.bridge-nf-call-iptables=0 >>$SYSCTL_LOCAL
  132. echo net.ipv4.fib_multipath_hash_policy=1 >>$SYSCTL_LOCAL
  133. echo net.ipv4.tcp_congestion_control=cubic >>$SYSCTL_LOCAL
  134. echo net.netfilter.nf_conntrack_helper=1 >>$SYSCTL_LOCAL
  135. echo kernel.msgmax = 65536 >>$SYSCTL_LOCAL
  136. echo kernel.msgmnb = 65536 >>$SYSCTL_LOCAL
  137. echo vm.swappiness=0 >>$SYSCTL_LOCAL
  138. rm -rf /tmp/luci-*