#! /bin/bash
#
# Copyright (c) 2002-2006 SuSE Linux AG Nuernberg, Germany.
# All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Author: Christian Zoz <zoz@suse.de>
#
# $Id: $
#
# Description:
# This scripts starts or stops services which have start/stop links in
# /etc/sysconfig/network/ifservices[-<interface>[-<essid>]]. See manpage
# ifservices.5 for details.
# Note that services are stopped always _after_ the interface is down. Stopping
# services earlier would require a change in NetworkManager itself.

cd /etc/sysconfig/network/ || exit 0
test -r ./config && . ./config
test -r scripts/functions && . scripts/functions

# Check if there is a script for the action
test -x "scripts/if${2}-services" || exit 0

E=`iwconfig "${1}" 2>/dev/null | \
	sed -n 's/^.*ESSID:\"\([^\"]*\)\".*$/\1/p' | \
	sed -e 's/[^abcdefghijklmnopqrstuvwxyz0123456789=._-]/_/gi'`
info_mesg "calling 'if${2}-services ${1}${E:+-$E}'"
scripts/if${2}-services "${1}${E:+-$E}"
