[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Mapping stanzas in interfaces file not working



On Tue, 2004-02-03 at 07:46, Adam Aube wrote:
> On Tuesday 03 February 2004 04:42 am, Chris Eisley wrote:
> > The problem is that when I put the mapping entry in, ifup gives the
> > error "Ignoring unknown interface eth0=eth0."
> 
> Have you tried manually running "ifup -v eth0"? If so, what was the 
> output?
> 

Did just now; What I get is:

Running mapping script /etc/network/show-role.sh -q -l on eth0
Ignoring unknown interface eth0=eth0.

> > The script I designate in the script line of the mapping stanza is never
> > being executed
> 
> How do you know?
> 

I put the following in the script as the first line of execution:

echo 1 > '/etc/network/blah'

And the test file wasn't created; it was if I ran the script myself. 
Here are the contents of the script, which has 755 perms and root:root
ownership:

#!/bin/sh

PATH="/bin:/sbin:/usr/bin:/usr/sbin"
OUTPUT=terminal
ROLE_FILE=/etc/network/roles

function print_usage() {
    if [ "$1" ]
        then
        echo $1
    fi
    cat <<EOF
Usage: role.sh -l IFACE
List or set the role of a single interface or all interfaces.

Options
  -l IFACE List the role data for interface IFACE.
           The special interface \`all' will show all interface
           data.
  -q       Used in conjunction with -l.
           Make only minimal output of a kind recognized by
           ifup/ifdown according to the mapping stanzas of
           the /etc/network/interfaces files.
  -h       Show this help document.

Currently list is the only action implemented.
The role file is located at $ROLE_FILE
EOF
exit 1
}

while getopts ":l:qh" ARG
  do
  if [ $ARG = '?' ]
      then
      print_usage "Invalid option: $OPTARG"
  elif [ $ARG = 'l' ]
      then
      ACTION=list
      IFACE="$OPTARG"
  elif [ $ARG = 'q' ]
      then
      OUTPUT=script
  elif [ $ARG = 'h' ]
      then
      print_usage
  fi
done

if [ "$OPTARG" = 'l' ]
    then
    print_usage "Interface argument for -l missing"
fi
if [ -z $ACTION ]
    then
    print_usage "You must specify an action"
fi
if [ $ACTION = 'list' ]
    then
    if ! [ -r $ROLE_FILE ]
        then
        echo "Error: Role file $ROLE_FILE doesn't exist or isn't
readable" >&2
        exit 1
    fi
    for l in `cat $ROLE_FILE`
      do
      CURRENT_IFACE=`echo "$l" | cut -d':' -f1`
      POSITION=`echo "$l" | cut -d':' -f2`
      NETWORK=`echo "$l" | cut -d':' -f3`
      if [ -z $CURRENT_IFACE ] || [ -z $POSITION ]
          then
          echo "Error: Unable to parse role file $ROLE_FILE" >&2
          exit 1
      elif [ $IFACE = 'all' ] || [ $CURRENT_IFACE = $IFACE ]
          then
          IFACE_FOUND=1
          if [ $OUTPUT = 'terminal' ]
              then
              echo -n "$CURRENT_IFACE: $POSITION interface"
              if [ $NETWORK ]
                  then
                  echo " for $NETWORK"
              fi
          else
              echo -n "$POSITION"
              if [ $NETWORK ]
                  then
                  echo -n "-$NETWORK"
              fi
          fi
      fi
    done
    if [ -z $IFACE_FOUND ]
        then
        echo "Error: No entry for interface "$IFACE" in role file
$ROLE_FILE" >&2
        exit 1
    fi
fi

The /etc/network/roles files contains:

eth0:INTERNAL:CEPHEUS
wlan0:EXTERNAL
ppp0:DISABLED

When I run the role script as /etc/network/show-roles.sh -q -l eth0",
"INTERNAL-CEPHEUS" is the output.

Thanks for taking a look.

-- 
Chris Eisley <chris@cepheus.net>



Reply to: