linkpi_firmware_history/rootfs/link/shell/setNetwork.sh

42 lines
1.1 KiB
Bash
Raw Permalink Normal View History

2024-02-15 22:07:35 +01:00
. /link/shell/util/func.sh
2024-02-15 22:07:30 +01:00
if [ -f /root/usb/local ];then
cp /root/usb/local /link/config/net.json
fi
cfg=/link/config/net.json
ip=`cat $cfg | grep -o '"ip":[0-9|.|"| ]*' | awk -F\" '{print $4}'`
if [ "$ip" == "" ]; then
cp /link/config/default/net.json /link/config/net.json
ip=`cat $cfg | grep -o '"ip":[0-9|.|"| ]*' | awk -F\" '{print $4}'`
fi
mask=`cat $cfg | grep -o '"mask":[0-9|.|"| ]*' | awk -F\" '{print $4}'`
gw=`cat $cfg | grep -o '"gateway":[0-9|.|"| ]*' | awk -F\" '{print $4}'`
dns=`cat $cfg | grep -o '"dns":[0-9|.|"| ]*' | awk -F\" '{print $4}'`
dhcp=`cat $cfg | grep -o '"dhcp":[^(,|})]*' | awk -F: '{print $2}'`
ifconfig lo 127.0.0.1
ifconfig eth0:0 192.168.88.88 netmask 255.255.255.0 up
echo $ip
echo $mask
ifconfig eth0 $ip netmask $mask up
echo $gw
route add default gw $gw
echo nameserver $dns > /etc/resolv.conf
echo $ip > /etc/hostname
hostname -F /etc/hostname
if [ ! -f /root/usb/local -a "$dhcp" == "true" ]; then
2024-02-15 22:07:35 +01:00
ifconfig eth0 up
if ! procExists udhcpc ;then
udhcpc -i eth0 -b -s /link/shell/dhcp.sh > /dev/null &
fi
else
pkill udhcpc
2024-02-15 22:07:30 +01:00
fi