meta-google: gbmc-mac-config: Fix setting MAC address

The gbmc-mac-config service is used to change the address to match the
value stored in the FRU by creating a config file for the interface.
However in commit 93433c165b38b1bbce6a679e43cf0188311551be of
phosphor-networkd, the default files for the interfaces are
consolidated into a single file for creating them. As a result, the
config generated by the service for eth1 isn't applied, and the
randomly generated MAC is used to obtain an IP address. Eventually, all
IP addresses are allocated to the randomly generated MAC addresses, and
the unit is unable to get a valid IP address. The MAC address is now
set using a different method.

Tested: Offline flashed a unit without the changes. Checked that MAC
address didn't match what is stored in the FRU. Flashed with the changes
and verified the MAC address matched the FRU.

Change-Id: Iaca14e86c93b5392def60d666b8b1aa6b03fd716
Signed-off-by: Kyle Nieman <kyle.nieman@fii-na.com>
diff --git a/meta-google/recipes-google/networking/files/gbmc-mac-config.sh.in b/meta-google/recipes-google/networking/files/gbmc-mac-config.sh.in
index 398445e..0466d0d 100644
--- a/meta-google/recipes-google/networking/files/gbmc-mac-config.sh.in
+++ b/meta-google/recipes-google/networking/files/gbmc-mac-config.sh.in
@@ -75,6 +75,13 @@
       mkdir -p "$override"
       printf '[NetDev]\nMACAddress=%s\n' "$macstr" >"$override"/50-mac.conf
     done
+    # In case we don't have any interface configs, set the MAC directly
+    # This is safe to apply, as systemd-networkd will always override this
+    # value based on written configs.
+    if ip link show $intf >/dev/null 2>&1 && \
+       ! ip link set dev $intf address $macstr; then
+      echo "Setting MAC($macstr) on $intf failed" >&2
+    fi
   done
   (( ++mac[5] ))
 done