#!/bin/sh
# This script is called by ifup/down to load the network scheme specified by
# ifscheme.
#
# Arguments : on the command line, we have the name of the interface.
# If the mapping contains some "map" statements, we get them from stdin.

# Take care of users calling this program directly.
if [ -z "$1" ] ; then
	prog=$(basename $0)
	echo "$prog: This script is a utility for ifscheme." >&2
	echo "$prog: See the ifscheme(1) man page for more information." >&2
	exit 1
fi

# Figure out what the mapping should be
iface="$1"
mapping=""
if [ ! -e /etc/network/scheme ]; then
	mapping="$iface"
else
	mapping="$iface-$(cat /etc/network/scheme)"
fi

# Look at map statements passed by ifup for special cases
while read glob scheme; do
	# test if match globbing pattern (i.e. match '*' properly)
	case "$mapping" in
		$glob)
			mapping="$scheme"
			break
		;;
	esac
done

# Return to ifup
echo $mapping
