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

Re: interfaces, mapping, etc



Anthony Towns wrote:
> I think you're misunderstanding the way mappings work. Basically
> they're totally scriptable, so "when the scheme changes" is, in general,
> undeterminable. There are a few reasonable ways (IMO) that you can do
> mappings:

> 	* scheme based -- setup a file /etc/network/scheme, and change it
> 	  by hand whenever you go somewhere else

No, I think I understand it. I'm only interested in this one right now,
and I want it to work as close to cardctl scheme as I can manage.

> It sounds kinda like you just want some utilities to support "scheme
> based" configuration easily. I don't think that should go into ifupdown
> proper (ie, it should just be some separate scripts), but it'd probably
> make more sense to put it in ifupdown.deb than anywhere else.

Yes that was my thought as well.

> Something like:
> 
> 	mapping eth0
> 		script network-scheme
> 	iface eth0-home inet static
> 		...
> 	iface eth0-work inet static
> 		...
> 
> should be able to be made work pretty easily, without any changes to
> /sbin/ifup.

Hmm, without any map lines? I must not understand this entirely, then.
Oh do the map lines just literally map script output to interface block
names? That makes sense.

Alright, rough draft attached.

-- 
see shy jo
#!/bin/sh -e

while [ ! -z "$1" ] ; do
	case "$1" in
		-s|--set)
			newscheme=$2
			shift
		;;
		-v|--verbose)
			verbose="-v"
		;;
		-*)
			echo "Usage: ifscheme [-v] [-s newscheme]" >&2
			exit 1
		;;
		*)
			iface=$1
		;;
	esac
	shift
done

if [ ! -z "$newscheme" ]; then
	if [ -e /etc/network/scheme ]; then
		oldscheme=$(cat /etc/network/scheme)
		if [ "$oldscheme" = "$newscheme" ]; then
			echo "Scheme unchanged."
			exit
		fi
	fi
	echo $newscheme > /etc/network/scheme
	echo "Scheme changed to $newscheme."

	if [ ! -z "$oldscheme" ] && [ -e /etc/network/ifstate ]; then
		for match in $(grep -- "-$oldscheme" /etc/network/ifstate | \
		               cut -d = -f 1); do
			printf "Reinitializing $match.."
			ifdown $verbose $match || echo "failed!"
			ifup $verbose $match || echo "failed!"
			echo "done."
		done
	fi
	exit 0
fi

if [ ! -e /etc/network/scheme ]; then
	echo $iface
else
	echo $iface-$(cat /etc/network/scheme)
	echo $iface-$(cat /etc/network/scheme) >&2
fi

Reply to: