Unverified Commit d70180c8 authored by wukongdaily's avatar wukongdaily Committed by GitHub
Browse files

解决R5C和E20C网口顺序错误的问题

解决R5C和E20C网口顺序错误的问题
https://github.com/wukongdaily/AutoBuildImmortalWrt/discussions/336
parents be28eddf d355156a
......@@ -23,58 +23,76 @@ else
. "$SETTINGS_FILE"
fi
# 计算网卡数量
count=0
# 1. 先获取所有物理接口列表
ifnames=""
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))
ifnames="$ifnames $iface_name"
fi
done
# 删除多余空格
ifnames=$(echo "$ifnames" | awk '{$1=$1};1')
# 网络设置
count=$(echo "$ifnames" | wc -w)
echo "Detected physical interfaces: $ifnames" >>$LOGFILE
echo "Interface count: $count" >>$LOGFILE
# 2. 根据板子型号映射WAN和LAN接口
board_name=$(cat /tmp/sysinfo/board_name 2>/dev/null || echo "unknown")
echo "Board detected: $board_name" >>$LOGFILE
wan_ifname=""
lan_ifnames=""
# 此处特殊处理个别开发板网口顺序问题
case "$board_name" in
"radxa,e20c"|"friendlyarm,nanopi-r5c")
wan_ifname="eth1"
lan_ifnames="eth0"
echo "Using $board_name mapping: WAN=$wan_ifname LAN=$lan_ifnames" >>"$LOGFILE"
;;
*)
# 默认第一个接口为WAN,其余为LAN
wan_ifname=$(echo "$ifnames" | awk '{print $1}')
lan_ifnames=$(echo "$ifnames" | cut -d ' ' -f2-)
echo "Using default mapping: WAN=$wan_ifname LAN=$lan_ifnames" >>"$LOGFILE"
;;
esac
# 3. 配置网络
if [ "$count" -eq 1 ]; then
# 单网口设备 类似于NAS模式 动态获取ip模式 具体ip地址取决于上一级路由器给它分配的ip 也方便后续你使用web页面设置旁路由
# 单网口设备 不支持修改ip 不要在此处修改ip 单网口采用dhcp模式 删除默认的192.168.1.1
# 单网口设备,DHCP模式
uci set network.lan.proto='dhcp'
uci delete network.lan.ipaddr
uci delete network.lan.netmask
uci delete network.lan.gateway
uci delete network.lan.dns
uci delete network.lan.gateway
uci delete network.lan.dns
uci commit network
elif [ "$count" -gt 1 ]; then
# 提取第一个接口作为WAN
wan_ifname=$(echo "$ifnames" | awk '{print $1}')
# 剩余接口保留给LAN
lan_ifnames=$(echo "$ifnames" | cut -d ' ' -f2-)
# 设置WAN接口基础配置
# 多网口设备配置
# 配置WAN
uci set network.wan=interface
# 提取第一个接口作为WAN
uci set network.wan.device="$wan_ifname"
# WAN接口默认DHCP
uci set network.wan.proto='dhcp'
# 设置WAN6绑定网口eth0
# 配置WAN6
uci set network.wan6=interface
uci set network.wan6.device="$wan_ifname"
# 更新LAN接口成员
# 查找对应设备的section名称
uci set network.wan6.proto='dhcpv6'
# 查找 br-lan 设备 section
section=$(uci show network | awk -F '[.=]' '/\.@?device\[\d+\]\.name=.br-lan.$/ {print $2; exit}')
if [ -z "$section" ]; then
echo "error:cannot find device 'br-lan'." >>$LOGFILE
else
# 删除原来的ports列表
# 删除原ports
uci -q delete "network.$section.ports"
# 添加新的ports列表
# 添加LAN接口端口
for port in $lan_ifnames; do
uci add_list "network.$section.ports"="$port"
done
echo "ports of device 'br-lan' are update." >>$LOGFILE
echo "Updated br-lan ports: $lan_ifnames" >>$LOGFILE
fi
# LAN口设置静态IP
uci set network.lan.proto='static'
# 多网口设备 支持修改为别的管理后台地址 在Github Action 的UI上自行输入即可
......@@ -91,23 +109,22 @@ elif [ "$count" -gt 1 ]; then
echo "default router ip is 192.168.100.1" >> $LOGFILE
fi
# 判断是否启用 PPPoE
echo "print enable_pppoe value=== $enable_pppoe" >>$LOGFILE
# PPPoE设置
echo "enable_pppoe value: $enable_pppoe" >>$LOGFILE
if [ "$enable_pppoe" = "yes" ]; then
echo "PPPoE is enabled at $(date)" >>$LOGFILE
# 设置ipv4宽带拨号信息
echo "PPPoE enabled, configuring..." >>$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.username="$pppoe_account"
uci set network.wan.password="$pppoe_password"
uci set network.wan.peerdns='1'
uci set network.wan.auto='1'
# 设置ipv6 默认不配置协议
uci set network.wan6.proto='none'
echo "PPPoE configuration completed successfully." >>$LOGFILE
echo "PPPoE config done." >>$LOGFILE
else
echo "PPPoE is not enabled. Skipping configuration." >>$LOGFILE
echo "PPPoE not enabled." >>$LOGFILE
fi
uci commit network
fi
# 若安装了dockerd 则设置docker的防火墙规则
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment