summaryrefslogtreecommitdiffstats
path: root/meta-sys940x/recipes-bsp/genmac
diff options
context:
space:
mode:
Diffstat (limited to 'meta-sys940x/recipes-bsp/genmac')
-rw-r--r--meta-sys940x/recipes-bsp/genmac/files/genmac46
-rw-r--r--meta-sys940x/recipes-bsp/genmac/genmac.bb30
2 files changed, 76 insertions, 0 deletions
diff --git a/meta-sys940x/recipes-bsp/genmac/files/genmac b/meta-sys940x/recipes-bsp/genmac/files/genmac
new file mode 100644
index 00000000..1899e95f
--- /dev/null
+++ b/meta-sys940x/recipes-bsp/genmac/files/genmac
@@ -0,0 +1,46 @@
1#!/bin/sh
2### BEGIN INIT INFO
3# Provides: Random MAC address generator
4# Required-Start: $syslog
5# Required-Stop: $syslog
6# Default-Start: 2 3 4 5
7# Default-Stop: 0 1 6
8# Short-Description: Set a random MAC for tagged interfaces
9# Description: Set a random MAC for interfaces with RANDOM_MAC
10### END INIT INFO
11
12# Author: Darren Hart <dvhart@linux.intel.com>
13# Based on /etc/init.d/skeleton
14
15PATH=/sbin:/usr/sbin:/bin:/usr/bin
16DESC="Set a random MAC for tagged interfaces"
17NAME=genmac
18RANPWD=`which ranpwd`
19SCRIPTNAME=/etc/init.d/$NAME
20
21# Exit if ranpwd is not installed
22[ -x "$RANPWD" ] || exit 0
23
24do_start() {
25 # Replace every occurence of RANDOM_MAC with a unique locally
26 # administered, unicast, randomly generated MAC address.
27 while grep -q RANDOM_MAC /etc/network/interfaces; do
28 sed -i "1,/RANDOM_MAC/s/RANDOM_MAC/$($RANPWD -m)/" /etc/network/interfaces
29 done
30}
31
32case "$1" in
33start)
34 echo "$NAME: Setting random MAC addresses"
35 do_start
36 ;;
37stop)
38 ;;
39*)
40 echo "Usage: $SCRIPTNAME {start|stop}" >&2
41 exit 3
42 ;;
43esac
44
45exit 0
46
diff --git a/meta-sys940x/recipes-bsp/genmac/genmac.bb b/meta-sys940x/recipes-bsp/genmac/genmac.bb
new file mode 100644
index 00000000..56849b46
--- /dev/null
+++ b/meta-sys940x/recipes-bsp/genmac/genmac.bb
@@ -0,0 +1,30 @@
1SUMMARY = "Provide a basic init script to generate a random MAC"
2DESCRIPTION = "Set the MAC from the config file."
3SECTION = "base"
4LICENSE = "MIT"
5LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=3f40d7994397109285ec7b81fdeb3b58"
6
7PR = "r0"
8
9inherit update-rc.d
10
11RDEPENDS_${PN} = "ranpwd"
12
13SRC_URI = "file://genmac"
14
15INITSCRIPT_NAME = "genmac"
16# Run as early as possible to ensure we are before the networking scripts
17INITSCRIPT_PARAMS = "start 39 S ."
18
19do_install() {
20 install -d ${D}${sysconfdir} \
21 ${D}${sysconfdir}/init.d
22 install -m 0755 ${WORKDIR}/${INITSCRIPT_NAME} ${D}${sysconfdir}/init.d
23 cat ${WORKDIR}/${INITSCRIPT_NAME} | \
24 sed -e 's,/etc,${sysconfdir},g' \
25 -e 's,/usr/sbin,${sbindir},g' \
26 -e 's,/var,${localstatedir},g' \
27 -e 's,/usr/bin,${bindir},g' \
28 -e 's,/usr,${prefix},g' > ${D}${sysconfdir}/init.d/${INITSCRIPT_NAME}
29 chmod 755 ${D}${sysconfdir}/init.d/${INITSCRIPT_NAME}
30}