mirror of
https://github.com/sipeed/LicheeRV-Nano-Build.git
synced 2026-09-10 20:59:59 -05:00
49 lines
987 B
Bash
Executable File
49 lines
987 B
Bash
Executable File
#!/bin/sh
|
|
hex2mac() {
|
|
MAC=""
|
|
seq 2 2 12 | while read i
|
|
do
|
|
echo -n ${1} | head -c $i | tail -c 2
|
|
if [ $i != 12 ]
|
|
then
|
|
echo -n ':'
|
|
fi
|
|
done | tr '[:upper:]' '[:lower:]'
|
|
}
|
|
|
|
if [ "${1}" = start ]
|
|
then
|
|
prefix=licheervnano
|
|
if [ -e /boot/hostname.prefix ]
|
|
then
|
|
prefix=$(cat /boot/hostname.prefix)
|
|
fi
|
|
old_hostname=$(cat /etc/hostname)
|
|
new_hostname=${prefix}-$(sha512sum /device_key_legacy | head -c 4)
|
|
|
|
if [ -e /boot/hostname ]
|
|
then
|
|
new_hostname=$(cat /boot/hostname)
|
|
fi
|
|
|
|
if [ "${old_hostname}" != "${new_hostname}" ]
|
|
then
|
|
hostname ${new_hostname}
|
|
echo ${new_hostname} > /etc/hostname
|
|
sed -i -e "s/${old_hostname}/${new_hostname}/g" /etc/hosts
|
|
fi
|
|
echo "hostname: ${new_hostname}"
|
|
|
|
if [ -e /boot/eth.mac ]
|
|
then
|
|
new_ethmac=$(cat /boot/ethmac)
|
|
else
|
|
new_ethmac=$(hex2mac 48da356f$(sha512sum /device_key_legacy | head -c 4))
|
|
fi
|
|
|
|
ifconfig eth0 down
|
|
ip link set eth0 address ${new_ethmac}
|
|
ifconfig eth0 up
|
|
echo "ethernet mac address: ${new_ethmac}"
|
|
fi
|