Re: /etc/network/interfaces
Geoff Crompton wrote:
> Just out of interest, has anyone found a useful script to use with the
> map clause. When I fiddled with it, I found that the script has to
> output to stdout the name of the config to use. My script ended up
> being something like:
>
> #!/bin/sh
>
> echo "eth0-home"
> #echo "eth0-work"
>
> And I would just edit it to change it. It seemed to me that it would
> be difficult to write a script that dynamically worked out what
> network you were in. Either that or it would have to interupt the boot
> process to prompt the user for a location.
>
> What would a useful (for automation) script look like?
I don't do autodetection, but I find the following useful. If run with
-s it changes the scheme on the fly, rather like cardctl scheme does for
pcmcia.
#!/bin/sh -e
# /usr/local/bin/ifscheme
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.."
if ! ifdown $verbose $match || ! ifup $verbose $match ||
! grep -q "$match-" /etc/network/ifstate; then
echo "Failed!"
echo $oldscheme > /etc/network/scheme
printf "Going back to $oldscheme.."
ifdown $verbose $match 2>/dev/null || true
if ! ifup $verbose $match; then
echo "Er, that failed too! Giving up."
fi
echo "done."
exit 1
fi
echo "done."
done
fi
exit 0
fi
if [ -z "$iface" ]; then
if [ ! -e /etc/network/scheme ]; then
echo "Scheme not set."
else
echo "Current scheme is $(cat /etc/network/scheme)."
fi
exit 0
fi
if [ ! -e /etc/network/scheme ]; then
echo $iface
else
echo $iface-$(cat /etc/network/scheme)
fi
Reply to: