stop unused interfaces

This commit is contained in:
Kolan Sh 2012-06-06 13:46:20 +04:00
parent 34b3e1e4ca
commit 1500b26562
1 changed files with 43 additions and 7 deletions

View File

@ -1,5 +1,25 @@
#!/bin/bash #!/bin/bash
__net_start ()
{
interfaces="`grep [0-9]=\\" /etc/conf.d/net | grep -v ^# | sed 's~.*_\([A-Za-z]*[0-9]\)=.*~\1~' | sort -u`"
istart=
for i in $interfaces; do
istart="$istart net.$i"
done
sudo eselect rc start $istart
}
__net_stop ()
{
interfaces="`grep [0-9]=\\" /etc/conf.d/net | grep -v ^# | sed 's~.*_\([A-Za-z]*[0-9]\)=.*~\1~' | sort -u`"
istop=
for i in $interfaces; do
istop="$istop net.$i"
done
sudo eselect rc stop $istop
}
__net_restart () __net_restart ()
{ {
interfaces="`grep [0-9]=\\" /etc/conf.d/net | grep -v ^# | sed 's~.*_\([A-Za-z]*[0-9]\)=.*~\1~' | sort -u`" interfaces="`grep [0-9]=\\" /etc/conf.d/net | grep -v ^# | sed 's~.*_\([A-Za-z]*[0-9]\)=.*~\1~' | sort -u`"
@ -10,7 +30,8 @@ __net_restart ()
sudo eselect rc restart $irestart sudo eselect rc restart $irestart
} }
if [[ "$1" == "" ]]; then Usage ()
{
echo "Usage:" echo "Usage:"
echo " net \$profile: selects network \$profile" echo " net \$profile: selects network \$profile"
echo " net new \$base \$profile: creates new \$profile based on \$base" echo " net new \$base \$profile: creates new \$profile based on \$base"
@ -27,8 +48,19 @@ if [[ "$1" == "" ]]; then
fn=`echo $f | sed 's~^/etc/conf.d/net\.~~'` fn=`echo $f | sed 's~^/etc/conf.d/net\.~~'`
[[ "$fn" == "$active" ]] && echo "* $fn" || echo " $fn" [[ "$fn" == "$active" ]] && echo "* $fn" || echo " $fn"
done done
}
if [[ "$1" == "" ]]; then
Usage
elif [[ "$1" == "start" ]]; then
__net_start
elif [[ "$1" == "stop" ]]; then
__net_stop
elif [[ "$1" == "restart" ]]; then elif [[ "$1" == "restart" ]]; then
sudo eselect nscd restart
__net_restart __net_restart
elif [[ "$1" == "edit" && "$2" == "" ]]; then elif [[ "$1" == "edit" && "$2" == "" ]]; then
@ -40,9 +72,6 @@ elif [[ "$1" == "edit" && "$2" != "" ]]; then
elif [[ "$1" == "rm" && "$2" != "" ]]; then elif [[ "$1" == "rm" && "$2" != "" ]]; then
sudo rm -f /etc/conf.d/net.$2 sudo rm -f /etc/conf.d/net.$2
elif [[ "$1" == "view" && "$2" == "" ]]; then
$PAGER /etc/conf.d/net
elif [[ "$1" == "view" && "$2" != "" ]]; then elif [[ "$1" == "view" && "$2" != "" ]]; then
$PAGER /etc/conf.d/net.$2 $PAGER /etc/conf.d/net.$2
@ -51,13 +80,20 @@ elif [[ "$1" == "rm" && "$2" != "" ]]; then
elif [[ "$1" == "new" && "$2" != "" && "$3" != "" ]]; then elif [[ "$1" == "new" && "$2" != "" && "$3" != "" ]]; then
sudo cp -f /etc/conf.d/net.$2 /etc/conf.d/net.$3 && sudo $EDITOR /etc/conf.d/net.$3 sudo cp -f /etc/conf.d/net.$2 /etc/conf.d/net.$3 && sudo $EDITOR /etc/conf.d/net.$3
__net_stop
sudo rm -f /etc/conf.d/net && sudo ln -s net.$3 /etc/conf.d/net sudo rm -f /etc/conf.d/net && sudo ln -s net.$3 /etc/conf.d/net
sudo eselect nscd restart
__net_restart __net_restart
else else
if [ -f /etc/conf.d/net.$1 ]; then
__net_stop
sudo rm -f /etc/conf.d/net && sudo ln -s net.$1 /etc/conf.d/net sudo rm -f /etc/conf.d/net && sudo ln -s net.$1 /etc/conf.d/net
sudo eselect nscd restart
__net_restart __net_restart
else
Usage
fi
fi fi
exit 0 exit 0