网络脚本优化
This commit is contained in:
parent
3dac60d370
commit
13d9d9ed21
|
@ -18,7 +18,7 @@ static version versions[] = {
|
|||
{"V1.07 20240425", "1.继承SDK1.3版本; 2. rtsp-server 更新; 3. 有线网卡脚本优化;"},
|
||||
{"V1.08 20240430", "修复485+RTC"},
|
||||
{"V1.09 20240508", "1.添加 i2c-tools、can-utils、ifmetric、network-manager等测试工具包; 2.解决QT界面程序编译报错问题"},
|
||||
{"V1.10 20240510", "重写网络控制脚本"},
|
||||
{"V1.10 20240514", "重写网络控制脚本"},
|
||||
};
|
||||
|
||||
/* 获取版本信息说明 */
|
||||
|
|
|
@ -9,9 +9,7 @@ do_package_qa[noexec] = "1"
|
|||
|
||||
do_install() {
|
||||
install -d ${D}/opt/algmode
|
||||
# install -m 0755 ${WORKDIR}/algmode ${D}/opt/algmode
|
||||
cp -rf ${WORKDIR}/algmode/* ${D}/opt/algmode/
|
||||
# cp -rf ${WORKDIR}/algmode/adas_detect.bin ${D}/opt/algmode/adas_detect.bin
|
||||
}
|
||||
|
||||
INSANE_SKIP:${PN} += "already-stripped"
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
[Unit]
|
||||
Description=network-manager-service
|
||||
SourcePath=/usr/bin/network-manager.sh
|
||||
After=pcie1scan.service
|
||||
|
||||
[Service]
|
||||
Restart=no
|
||||
RemainAfterExit=yes
|
||||
ExecStartPre=/bin/sleep 10
|
||||
ExecStart=/usr/bin/network-manager.sh
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
|
@ -1,41 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
eth0_dhcp=false
|
||||
eth0_address="192.168.10.12/24"
|
||||
eth0_gateway="192.168.10.1"
|
||||
eth0_dns="192.168.10.1"
|
||||
|
||||
enP1p17s0_dhcp=false
|
||||
enP1p17s0_address="192.168.1.249/24"
|
||||
enP1p17s0_gateway="192.168.1.1"
|
||||
enP1p17s0_dns="192.168.1.1"
|
||||
|
||||
# 禁用DHCP服务
|
||||
systemctl stop dhcpcd.service
|
||||
systemctl disable dhcpcd.service
|
||||
|
||||
# 删除默认配置
|
||||
nmcli connection delete "Wired connection 1"
|
||||
nmcli connection delete "Wired connection 2"
|
||||
nmcli connection delete eth0
|
||||
nmcli connection delete enP1p17s0
|
||||
|
||||
if $eth0_dhcp ;then
|
||||
nmcli connection add type ethernet con-name eth0 ifname eth0
|
||||
else
|
||||
nmcli connection add type ethernet con-name eth0 ifname eth0 ipv4.addresses $eth0_address ipv4.gateway $eth0_gateway ipv4.dns $eth0_dns ipv4.method manual
|
||||
fi
|
||||
|
||||
if $enP1p17s0_dhcp ;then
|
||||
nmcli connection add type ethernet con-name enP1p17s0 ifname enP1p17s0
|
||||
else
|
||||
nmcli connection add type ethernet con-name enP1p17s0 ifname enP1p17s0 ipv4.addresses $enP1p17s0_address ipv4.gateway $enP1p17s0_gateway ipv4.dns $enP1p17s0_dns ipv4.method manual
|
||||
fi
|
||||
|
||||
# 启动
|
||||
nmcli connection up eth0
|
||||
nmcli connection up enP1p17s0
|
||||
|
||||
# 设置优先级
|
||||
ifmetric eth0 2100
|
||||
ifmetric enP1p17s0 2000
|
|
@ -1,26 +0,0 @@
|
|||
DESCRIPTION = "Install network manager application"
|
||||
SECTION = "network-manager"
|
||||
DEPENDS = ""
|
||||
LICENSE = "CLOSED"
|
||||
|
||||
SRC_URI += "file://network-manager.sh"
|
||||
SRC_URI += "file://network-manager.service"
|
||||
|
||||
S = "${WORKDIR}"
|
||||
|
||||
## prebuilt library don't need following steps
|
||||
do_configure[noexec] = "1"
|
||||
do_compile[noexec] = "1"
|
||||
do_package_qa[noexec] = "1"
|
||||
|
||||
do_install() {
|
||||
install -d ${D}${bindir}
|
||||
install -m 0755 ${WORKDIR}/network-manager.sh ${D}${bindir}
|
||||
|
||||
install -d ${D}/etc/systemd/system/
|
||||
install -d ${D}/etc/systemd/system/multi-user.target.wants/
|
||||
install -m 0644 ${WORKDIR}/network-manager.service -D ${D}/etc/systemd/system/network-manager.service
|
||||
ln -sf /etc/systemd/system/network-manager.service ${D}/etc/systemd/system/multi-user.target.wants/network-manager.service
|
||||
}
|
||||
|
||||
FILES_${PN} += "/etc/*"
|
|
@ -0,0 +1,80 @@
|
|||
#!/bin/bash
|
||||
|
||||
INTERFACE=$1 # 状态发生变化的网络接口
|
||||
STATUS=$2 # 网络接口的新状态:up, down, vpn-up, vpn-down
|
||||
|
||||
echo "INTERFACE=$INTERFACE STATUS=$STATUS"
|
||||
|
||||
if [ $STATUS = "up" ]; then
|
||||
# 禁用DHCP服务
|
||||
systemctl stop dhcpcd.service
|
||||
systemctl disable dhcpcd.service
|
||||
|
||||
# 删除默认配置
|
||||
if test ! -z "$(nmcli connection | grep 'Wired connection 1')"; then
|
||||
nmcli connection delete "Wired connection 1"
|
||||
fi
|
||||
|
||||
if test ! -z "$(nmcli connection | grep 'Wired connection 1')"; then
|
||||
nmcli connection delete "Wired connection 2"
|
||||
fi
|
||||
|
||||
dhcp=false
|
||||
metric=2000
|
||||
address=""
|
||||
|
||||
# 判断是哪一张网卡
|
||||
if [ $INTERFACE = "eth0" ]; then
|
||||
dhcp=`cat /etc/networkd-configuration/eth0.dhcp`
|
||||
metric=`cat /etc/networkd-configuration/eth0.metric`
|
||||
address=`cat /etc/networkd-configuration/eth0.address`
|
||||
elif [ $INTERFACE = "enP1p17s0" ]; then
|
||||
dhcp=`cat /etc/networkd-configuration/enP1p17s0.dhcp`
|
||||
metric=`cat /etc/networkd-configuration/enP1p17s0.metric`
|
||||
address=`cat /etc/networkd-configuration/enP1p17s0.address`
|
||||
fi
|
||||
|
||||
gateway=${address/${address##*.}/"1"}
|
||||
|
||||
echo "dhcp=$dhcp address=$address gateway=$gateway dns=$gateway"
|
||||
|
||||
# 地址为空, 不是eth0/enP1p17s0网卡
|
||||
if test -z "$address"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 如果不存在网卡配置
|
||||
if test -z "$(nmcli connection | grep $INTERFACE)"; then
|
||||
# 创建网卡配置
|
||||
if $dhcp ; then
|
||||
nmcli connection add type ethernet con-name $INTERFACE ifname $INTERFACE
|
||||
else
|
||||
nmcli connection add type ethernet con-name $INTERFACE ifname $INTERFACE ipv4.addresses $address/24 ipv4.gateway $gateway ipv4.dns $gateway ipv4.method manual
|
||||
fi
|
||||
else
|
||||
# 动态分配IP的情况下
|
||||
if $dhcp ; then
|
||||
# 检查 ipv4.method 配置是否一致,不一致需要重新设置并重启网卡
|
||||
str=`nmcli connection show $INTERFACE | grep ipv4.method`
|
||||
if [${str##*:} != "auto" ]; then
|
||||
nmcli connection modify $INTERFACE ipv4.addresses "" ipv4.gateway "" ipv4.dns "" ipv4.method auto
|
||||
echo "nmcli connection modify $INTERFACE ipv4.addresses ipv4.gateway ipv4.dns ipv4.method auto"
|
||||
# 启动网卡
|
||||
nmcli connection up $INTERFACE
|
||||
fi
|
||||
else
|
||||
# 检查 ipv4.address 配置是否一致,不一致需要重新设置并重启网卡
|
||||
str1=`nmcli connection show $INTERFACE | grep ipv4.method`
|
||||
str2=`nmcli connection show $INTERFACE | grep ipv4.addresses`
|
||||
if [${str1##*:} != "manual" ] || [${str2##*:} != $address ]; then
|
||||
nmcli connection modify $INTERFACE ipv4.addresses $address/24 ipv4.gateway $gateway ipv4.dns $gateway ipv4.method manual
|
||||
echo "nmcli connection modify $INTERFACE ipv4.addresses $address/24 ipv4.gateway $gateway ipv4.dns $gateway ipv4.method manual"
|
||||
# 启动网卡
|
||||
nmcli connection up $INTERFACE
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# 设置优先级
|
||||
ifmetric $INTERFACE $metric
|
||||
fi
|
|
@ -0,0 +1 @@
|
|||
192.168.1.249
|
|
@ -0,0 +1 @@
|
|||
false
|
|
@ -0,0 +1 @@
|
|||
2000
|
|
@ -0,0 +1 @@
|
|||
192.168.10.22
|
|
@ -0,0 +1 @@
|
|||
false
|
|
@ -0,0 +1 @@
|
|||
2100
|
|
@ -0,0 +1,24 @@
|
|||
DESCRIPTION = "Install network configuration"
|
||||
SECTION = "network-configuration-tvis"
|
||||
DEPENDS = ""
|
||||
LICENSE = "CLOSED"
|
||||
|
||||
SRC_URI += "file://networkd-configuration"
|
||||
SRC_URI += "file://networkd-configuration.sh"
|
||||
|
||||
S = "${WORKDIR}"
|
||||
|
||||
## prebuilt library don't need following steps
|
||||
do_configure[noexec] = "1"
|
||||
do_compile[noexec] = "1"
|
||||
do_package_qa[noexec] = "1"
|
||||
|
||||
do_install() {
|
||||
install -d ${D}/etc/networkd-configuration
|
||||
cp -rf ${WORKDIR}/networkd-configuration/* ${D}/etc/networkd-configuration/
|
||||
|
||||
install -d ${D}/etc/NetworkManager/dispatcher.d/
|
||||
install -m 0755 ${WORKDIR}/networkd-configuration.sh -D ${D}/etc/NetworkManager/dispatcher.d/10-networkd-configuration.sh
|
||||
}
|
||||
|
||||
FILES_${PN} += "/etc/*"
|
|
@ -10,6 +10,6 @@ RDEPENDS:${PN} = "\
|
|||
motovis-tvis \
|
||||
netcore-tvis \
|
||||
opencv-tvis \
|
||||
network-manager-tvis \
|
||||
networkd-configuration-tvis \
|
||||
rtsp-server-tvis \
|
||||
"
|
Loading…
Reference in New Issue
Block a user