summaryrefslogtreecommitdiff
path: root/scripts/mod_bootfile_eth_hwid
blob: b913d121f19eb64bb76e15f56b258ba2c05e513b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash

# modify interface sub-block

shopt -s extglob

if [[ "$*" == *--help* ]] ; then
    echo ${0##*/} [test_]FILE INTERFACE HWID
    exit 0
fi

if [[ "$1" == test_* ]] ; then
    origfile=$1
    bootfile=/tmp/${1##*/}_$$
    cp $origfile $bootfile
    trap "diff -c $origfile $bootfile; rm -f $bootfile; exit 0" $?
else
    origfile=
    bootfile=$1
fi
eth=$2
hwid=$3

sed -i '/^interfaces {$/,/^}$/ {
	/^    ethernet '"$eth"' {$/ {
	    :join
	    /\n    }$/ {
		/hw-id: / s/\(hw-id:\) [0-9a-fA-F:]\+/\1 '"$hwid"'/
		/hw-id: /!	s/}$/    hw-id: '"$hwid"'\n    }/
		/link-detect/!	s/}$/    link-detect\n    }/
		b
	    }
	    N
	    b join
	}
}' $bootfile