#!/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 () { interfaces="`grep [0-9]=\\" /etc/conf.d/net | grep -v ^# | sed 's~.*_\([A-Za-z]*[0-9]\)=.*~\1~' | sort -u`" irestart= for i in $interfaces; do irestart="$irestart net.$i" done sudo eselect rc restart $irestart } Usage () { echo "Usage:" echo " net \$profile: selects network \$profile" echo " net new \$base \$profile: creates new \$profile based on \$base" echo " net edit: edit current active network profile" echo " net edit \$profile: edit network \$profile" echo " net view: view current active network profile" echo " net view \$profile: view network \$profile" echo " net rm \$profile: removes network \$profile" echo " net restart: restarts the network" echo echo "Profiles (*active):" active=`readlink /etc/conf.d/net | sed 's~^net\.~~'` for f in /etc/conf.d/net.*; do fn=`echo $f | sed 's~^/etc/conf.d/net\.~~'` [[ "$fn" == "$active" ]] && echo "* $fn" || echo " $fn" done } if [[ "$1" == "" ]]; then Usage elif [[ "$1" == "start" ]]; then __net_start elif [[ "$1" == "stop" ]]; then __net_stop elif [[ "$1" == "restart" ]]; then sudo eselect rc restart nscd __net_restart elif [[ "$1" == "edit" && "$2" == "" ]]; then sudo $EDITOR /etc/conf.d/net elif [[ "$1" == "edit" && "$2" != "" ]]; then sudo $EDITOR /etc/conf.d/net.$2 elif [[ "$1" == "rm" && "$2" != "" ]]; then sudo rm -f /etc/conf.d/net.$2 elif [[ "$1" == "view" && "$2" != "" ]]; then $PAGER /etc/conf.d/net.$2 elif [[ "$1" == "rm" && "$2" != "" ]]; then sudo rm -f /etc/conf.d/net.$2 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 __net_stop sudo rm -f /etc/conf.d/net && sudo ln -s net.$3 /etc/conf.d/net sudo eselect rc restart nscd __net_restart 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 eselect rc restart nscd __net_restart else Usage fi fi exit 0