diff options
Diffstat (limited to 'recipes-core/net-persistent-mac/net-persistent-mac')
3 files changed, 44 insertions, 0 deletions
diff --git a/recipes-core/net-persistent-mac/net-persistent-mac/default b/recipes-core/net-persistent-mac/net-persistent-mac/default new file mode 100644 index 0000000..9086f7b --- /dev/null +++ b/recipes-core/net-persistent-mac/net-persistent-mac/default | |||
@@ -0,0 +1 @@ | |||
INTERFACES="" \ No newline at end of file | |||
diff --git a/recipes-core/net-persistent-mac/net-persistent-mac/imx233-olinuxino-maxi/default b/recipes-core/net-persistent-mac/net-persistent-mac/imx233-olinuxino-maxi/default new file mode 100644 index 0000000..fe4a054 --- /dev/null +++ b/recipes-core/net-persistent-mac/net-persistent-mac/imx233-olinuxino-maxi/default | |||
@@ -0,0 +1 @@ | |||
INTERFACES="usb0" | |||
diff --git a/recipes-core/net-persistent-mac/net-persistent-mac/init b/recipes-core/net-persistent-mac/net-persistent-mac/init new file mode 100644 index 0000000..a2e2863 --- /dev/null +++ b/recipes-core/net-persistent-mac/net-persistent-mac/init | |||
@@ -0,0 +1,42 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | ### BEGIN INIT INFO | ||
4 | # Provides: net-persistent-mac | ||
5 | # Required-Start: $local_fs | ||
6 | # Required-Stop: | ||
7 | # Default-Start: S | ||
8 | # Default-Stop: | ||
9 | # X-Start-Before: networking | ||
10 | # Short-Description: restore MAC during boot process | ||
11 | ### END INIT INFO | ||
12 | |||
13 | set -e | ||
14 | |||
15 | [ -f /etc/default/net-persistent-mac ] && . /etc/default/net-persistent-mac | ||
16 | |||
17 | MAC_DIR="/var/lib/net-persistent-mac" | ||
18 | |||
19 | for if in $INTERFACES; do | ||
20 | mkdir -p "$MAC_DIR" | ||
21 | IF_FILE="$MAC_DIR/$if.mac" | ||
22 | IF_MAC="/sys/class/net/$if/address" | ||
23 | |||
24 | # Store MAC for reuse | ||
25 | if [ ! -r "$IF_FILE" ]; then | ||
26 | if [ -e "$IF_MAC" ]; then | ||
27 | echo "Storing MAC for $if for future use." > /dev/stderr | ||
28 | cat "$IF_MAC" > "$IF_FILE" | ||
29 | else | ||
30 | echo "Failed to read MAC for $if; skiping device." | ||
31 | fi | ||
32 | fi | ||
33 | |||
34 | if [ -r "$IF_FILE" ]; then | ||
35 | # Restore MAC setting | ||
36 | WANTED_MAC=`cat $IF_FILE` | ||
37 | if [ "$WANTED_MAC" != "`cat $IF_MAC`" ]; then | ||
38 | echo "Setting MAC of $if to $WANTED_MAC." | ||
39 | ifconfig $if hw ether "$WANTED_MAC" | ||
40 | fi | ||
41 | fi | ||
42 | done | ||