1*4882a593Smuzhiyun#!/bin/sh 2*4882a593Smuzhiyun# 3*4882a593Smuzhiyun# netplug - policy agent for netplugd 4*4882a593Smuzhiyun# 5*4882a593Smuzhiyun# Copyright 2003 Key Research, Inc. 6*4882a593Smuzhiyun# 7*4882a593Smuzhiyun# This program is free software; you can redistribute it and/or modify 8*4882a593Smuzhiyun# it under the terms of the GNU General Public License, version 2, as 9*4882a593Smuzhiyun# published by the Free Software Foundation. You are forbidden from 10*4882a593Smuzhiyun# redistributing or modifying it under the terms of any other license, 11*4882a593Smuzhiyun# including other versions of the GNU General Public License. 12*4882a593Smuzhiyun# 13*4882a593Smuzhiyun# This program is distributed in the hope that it will be useful, but 14*4882a593Smuzhiyun# WITHOUT ANY WARRANTY; without even the implied warranty of 15*4882a593Smuzhiyun# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16*4882a593Smuzhiyun# General Public License for more details. 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun 19*4882a593SmuzhiyunPATH=/usr/bin:/bin:/usr/sbin:/sbin 20*4882a593Smuzhiyunexport PATH 21*4882a593Smuzhiyun 22*4882a593Smuzhiyundev="$1" 23*4882a593Smuzhiyunaction="$2" 24*4882a593Smuzhiyun 25*4882a593Smuzhiyuncase "$action" in 26*4882a593Smuzhiyunin) 27*4882a593Smuzhiyun if [ -x /sbin/ifup ]; then 28*4882a593Smuzhiyun exec /sbin/ifup $dev 29*4882a593Smuzhiyun else 30*4882a593Smuzhiyun echo "Please teach me how to plug in an interface!" 1>&2 31*4882a593Smuzhiyun exit 1 32*4882a593Smuzhiyun fi 33*4882a593Smuzhiyun ;; 34*4882a593Smuzhiyunout) 35*4882a593Smuzhiyun if [ -x /sbin/ifdown ]; then 36*4882a593Smuzhiyun # At least on Fedora Core 1, the call to ip addr flush infloops 37*4882a593Smuzhiyun # /sbin/ifdown $dev && exec /sbin/ip addr flush $dev 38*4882a593Smuzhiyun exec /sbin/ifdown $dev 39*4882a593Smuzhiyun else 40*4882a593Smuzhiyun echo "Please teach me how to unplug an interface!" 1>&2 41*4882a593Smuzhiyun exit 1 42*4882a593Smuzhiyun fi 43*4882a593Smuzhiyun ;; 44*4882a593Smuzhiyunprobe) 45*4882a593Smuzhiyun # exec /sbin/ip link set $dev up >/dev/null 2>&1 46*4882a593Smuzhiyun if [ -x /sbin/ifconfig ]; then 47*4882a593Smuzhiyun exec /sbin/ifconfig $dev up >/dev/null 2>&1 48*4882a593Smuzhiyun else 49*4882a593Smuzhiyun echo "Failed to probe an interface!" 1>&2 50*4882a593Smuzhiyun exit 1 51*4882a593Smuzhiyun fi 52*4882a593Smuzhiyun ;; 53*4882a593Smuzhiyun*) 54*4882a593Smuzhiyun echo "I have been called with a funny action of '%s'!" 1>&2 55*4882a593Smuzhiyun exit 1 56*4882a593Smuzhiyun ;; 57*4882a593Smuzhiyunesac 58