#! /bin/bash
#
# Copyright (c) 2002-2003 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, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA
#
# Authors: Michal Svec <msvec@suse.cz>
#          Christian Zoz <zoz@suse.de>
#
# $Id: ifup-skel 1135 2004-12-08 08:50:41Z zoz $
#

# 
# USE THIS AS A SKELETON FOR ADDITIONAL if{up,down,status}-* SCRIPTS
#

usage () {
	echo $@
	echo "Usage: if{up,down}-skel [<config>] <hwdesc> [-o <options>]"
	echo "  hwdesc may be the interface nmae or any valid descriptions"
	echo "  of the corresponding device, for details see ifup(8)."
	echo
	echo "Options are: option    : explanation"
	echo "All other or wrong options are silently ignored."
	echo
	echo "      This is just a skeleton."
	echo "  !!! PLEASE MODIFY THESE LINES !!!"
	exit $R_USAGE
}

######################################################################
# change the working direcory and source some common files
#
R_INTERNAL=1      # internal error, e.g. no config or missing scripts
cd /etc/sysconfig/network || exit $R_INTERNAL
test -f scripts/functions && . scripts/functions || exit $R_INTERNAL
test -f ./config && . ./config

######################################################################
# check arguments and how we are called (in case of links)
#
SCRIPTNAME=${0##*/}
debug $*
ACTION=${SCRIPTNAME#if}
ACTION=${ACTION%%-skel}  # <--- adapt it to the scriptname !!!!!!!!!!!
case "${ACTION}" in
	up|status|down|check) ;;
	*) usage
esac
INTERFACE=$1
case "$INTERFACE" in ""|-h|*help*) usage; esac
shift
if [ -n "$1" -a "$1" != "-o" ] ; then
	CONFIG=$INTERFACE
	INTERFACE=$1
fi
shift
test "$1" = "-o" && shift
OPTIONS="$@"
MODE=manual
while [ $# -gt 0 ]; do
	case $1 in
		boot|onboot) MODE=auto ;;
		hotplug)     MODE=auto ;;
		auto)        MODE=auto ;;
		quiet)       BE_QUIET=yes ;;
		debug)       BE_QUIET=no
		             DEBUG=yes ;;
		*)           debug unknown option $1 ;;
	esac
	shift
done

######################################################################
# get the interface and check if it is available or up
#
# If your script needs a base interface upon which the new interface resides
# (e.g. for tunnels) then pay attention to the following:
# Imagine you have a variable BASE_DEVICE in your configuration which you expect
# to contain the interface name of the base interface. This variable may contain
# any valid description of the base device and need not to be an interface name.
# Moreover it is recommended to prefer an device description to the interface
# name, because interface names are not always persistent the may change. See
# man ifup for valid device descriptions. You will get the current interface
# name to this device with /sbin/getcfg-interface:
#
# BASE_INTERFACE=`/sbin/getcfg-interface -- $BASE_DEVICE`
#
# if ! is_iface_available  $INTERFACE ; then
# 	logerror "interface ${INTERFACE} is not available"
# 	exit $R_NODEV
# fi
# if ! is_iface_up $INTERFACE ; then
# 	logerror "interface ${INTERFACE} is not up"
# 	exit $R_NOTRUNNING
# fi

######################################################################
# check presence of configuration file and source it
#
if [ -f ifcfg-$CONFIG ] ; then
	. ifcfg-$CONFIG
else
	message "could not find configuration file ifcfg-$CONFIG"
fi

######################################################################
# now do what has to be done
#
case $ACTION in
	up)
		: do ifup job
		;;
	down)
		: do ifdown job
		;;
	status)
		: do status job
		;;
	check)
		: do check job
		;;
esac
