diff options
author | Tom Grennan <tgrennan@io.vyatta.com> | 2007-12-13 18:35:20 -0800 |
---|---|---|
committer | Tom Grennan <tgrennan@io.vyatta.com> | 2007-12-13 18:35:20 -0800 |
commit | e6ed55f7593a0f4bc2700bc7b90903bb012e27f6 (patch) | |
tree | b0f2c082f34c8a134631e0cae21314e164720243 /scripts/vyatta_net_name | |
parent | 5ba8cf8393030d75c03a15551a57831f3f0908a4 (diff) | |
download | vyatta-cfg-quagga-e6ed55f7593a0f4bc2700bc7b90903bb012e27f6.tar.gz vyatta-cfg-quagga-e6ed55f7593a0f4bc2700bc7b90903bb012e27f6.zip |
process device persistence through udev rules rather than init script
Diffstat (limited to 'scripts/vyatta_net_name')
-rw-r--r-- | scripts/vyatta_net_name | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/scripts/vyatta_net_name b/scripts/vyatta_net_name new file mode 100644 index 00000000..d93dd288 --- /dev/null +++ b/scripts/vyatta_net_name @@ -0,0 +1,111 @@ +#!/bin/bash +# **** License **** +# Version: VPL 1.0 +# +# The contents of this file are subject to the Vyatta Public License +# Version 1.0 ("License"); you may not use this file except in +# compliance with the License. You may obtain a copy of the License at +# http://www.vyatta.com/vpl +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +# the License for the specific language governing rights and limitations +# under the License. +# +# This code was originally developed by Vyatta, Inc. +# Portions created by Vyatta are Copyright (C) 2007 Vyatta, Inc. +# All Rights Reserved. +# +# Author: Tom Grennan <tgrennan@vyatta.com> +# Description: search Vyatta config for interface name given address +# +# **** End License **** + +debug='' +attr_address=0:0:0:0:0:0 + +test -r /etc/default/vyatta && source /etc/default/vyatta + +# process command line variable overrides + +for arg ; do + case "$arg" in + --debug ) + debug=echo + ;; + --*=* ) + arg=${arg#--} + eval ${arg%=*}=\"${arg#*=}\" + ;; + *=* ) + eval ${arg%=*}=\"${arg#*=}\" + ;; + *:*:*:*:*:* ) + attr_address=$arg + ;; + * ) + kname=$arg + ;; + esac +done + +: ${vyatta_prefix:=/opt/vyatta} +: ${vyatta_sysconfdir:=${vyatta_prefix}/etc} +: ${BOOTFILE:=${vyatta_sysconfdir:-/opt/vyatta/etc}/config/config.boot} + +shopt -s extglob nullglob + +# load cfg_eth_hwid array from config file as follows +# interface { +# ... +# ethernet eth# { +# ... +# hw-id: XX:XX:XX:XX:XX:XX +# ... +# } +# } +# +# cfg_eth_hwid=( "eth#=xx:xx:xx:xx:xx:xx" ... ) + +declare -a cfg_net_hwid=( $( sed -ne ' + /^interfaces {/,/^}/ { + /^ *ethernet eth[0-9]* {/,/^ $/ { + /^ *ethernet/ { + s/.* eth\([0-9]\+\) {$/ eth\1=/ +# hold interface name + h + } + /^.*hw-id:/ { +# translate field name + s/.*hw-id: *// +# tolower hex mac address + y/ABCDEF/abcdef/ +# exchange hold and pattern space + x +# concatenate hold and pattern + G + s/\n//p + } + } + }' $BOOTFILE )) + +for name_hwid in ${cfg_net_hwid[@]} ; do + name=${name_hwid%=*} + hwid=${name_hwid#*=} + if [ "$hwid" == "$attr_address" ] ; then + echo $name + exit 0 + fi +done + +if [ -n "$kname" ] ; then + echo $kname + exit 0 +fi + +exit 1 + +# Local Variables: +# mode: shell-script +# sh-indentation: 4 +# End: |