99-custom.sh 2.58 KB
Newer Older
1
#!/bin/sh
2
3
4
5
# 99-custom.sh 就是immortalwrt固件首次启动时运行的脚本 位于固件内的/etc/uci-defaults/99-custom.sh
# Log file for debugging
LOGFILE="/tmp/uci-defaults-log.txt"
echo "Starting 99-custom.sh at $(date)" >> $LOGFILE
6
7
8
9
10
11
12
13
14
# 设置默认防火墙规则,方便虚拟机首次访问 WebUI
uci set firewall.@zone[1].input='ACCEPT'

# 设置主机名映射,解决安卓原生 TV 无法联网的问题
uci add dhcp domain
uci set "dhcp.@domain[-1].name=time.android.com"
uci set "dhcp.@domain[-1].ip=203.107.6.88"


15
# 计算网卡数量
16
17
18
19
20
21
22
23
24
count=0
for iface in /sys/class/net/*; do
  iface_name=$(basename "$iface")
  # 检查是否为物理网卡(排除回环设备和无线设备)
  if [ -e "$iface/device" ] && echo "$iface_name" | grep -Eq '^eth|^en'; then
    count=$((count + 1))
  fi
done

25
26
27
28
29
30
31
32
33
# 检查配置文件pppoe-settings是否存在 该文件由build.sh动态生成
SETTINGS_FILE="/etc/config/pppoe-settings"
if [ ! -f "$SETTINGS_FILE" ]; then
    echo "PPPoE settings file not found. Skipping." >> $LOGFILE
else
   # 读取pppoe信息($enable_pppoe、$pppoe_account、$pppoe_password)
   . "$SETTINGS_FILE"
fi

34
35
# 网络设置
if [ "$count" -eq 1 ]; then
36
37
38
   # 单网口设备 类似于NAS模式 动态获取ip模式 具体ip地址取决于上一级路由器给它分配的ip 也方便后续你使用web页面设置旁路由
   # 单网口设备 不支持修改ip 不要在此处修改ip 
   uci set network.lan.proto='dhcp'
39
elif [ "$count" -gt 1 ]; then
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
   # 多网口设备 支持修改为别的ip地址
   uci set network.lan.ipaddr='192.168.100.1'
   echo "set 192.168.100.1 at $(date)" >> $LOGFILE
   # 判断是否启用 PPPoE
   echo "print enable_pppoe value=== $enable_pppoe" >> $LOGFILE
   if [ "$enable_pppoe" = "yes" ]; then
      echo "PPPoE is enabled at $(date)" >> $LOGFILE
      # 设置宽带拨号信息
      uci set network.wan.proto='pppoe'                
      uci set network.wan.username=$pppoe_account     
      uci set network.wan.password=$pppoe_password     
      uci set network.wan.peerdns='1'                  
      uci set network.wan.auto='1' 
      echo "PPPoE configuration completed successfully." >> $LOGFILE
   else
      echo "PPPoE is not enabled. Skipping configuration." >> $LOGFILE
   fi
57
58
fi

wukongdaily's avatar
wukongdaily committed
59
60
61
# 设置所有网口可访问网页终端
uci delete ttyd.@ttyd[0].interface

wukongdaily's avatar
wukongdaily committed
62
63
64
# 设置所有网口可连接 SSH
uci set dropbear.@dropbear[0].Interface=''
uci commit
wukongdaily's avatar
wukongdaily committed
65

66
67
# 设置编译作者信息
FILE_PATH="/etc/openwrt_release"
wukongdaily's avatar
wukongdaily committed
68
NEW_DESCRIPTION="Compiled by wukongdaily"
69
70
71
sed -i "s/DISTRIB_DESCRIPTION='[^']*'/DISTRIB_DESCRIPTION='$NEW_DESCRIPTION'/" "$FILE_PATH"

exit 0