contrib/meshwizard: Fix getting of mac address when the interface is not up yet,...
[project/luci.git] / contrib / package / meshwizard / files / usr / bin / meshwizard / helpers / gen_auto-ipv6-dhcpv6-ip.sh
index e10677c..114c8f9 100755 (executable)
@@ -1,7 +1,16 @@
 #!/bin/sh
+netrenamed=$1
+
 local PREFIX="$(echo $profile_ipv6_prefix| cut -d "/" -f 1| sed 's/::/:/')"
-local MAC="$(ifconfig $1 |grep HWaddr | awk '{ print $5 '})"
-local IPV6_UNIQ="$(echo $MAC | awk -F: '{ print $1$2":"$3$4":"$5$6 }')"
+
+# Get the devices mac address
+local device="$(uci -p/var/state -q get network.$1.ifname)"
+if [ -n "$device" ]; then
+       local MAC="$(ifconfig $netrenamed |grep HWaddr | awk '{ print $5 '})"
+else 
+       local MAC="$(cat /sys/class/net/$1/address)"
+       local IPV6_UNIQ="$(echo $MAC | awk -F: '{ print $1$2":"$3$4":"$5$6 }')"
+fi
 
 echo "${PREFIX}${IPV6_UNIQ}:1"