diff options
Diffstat (limited to 'openbsd_net.sh')
| -rwxr-xr-x | openbsd_net.sh | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/openbsd_net.sh b/openbsd_net.sh new file mode 100755 index 0000000..ad8993d --- /dev/null +++ b/openbsd_net.sh @@ -0,0 +1,83 @@ +#!/bin/sh +set -e + +# No trailing slash +conf_dir="/etc/net" +interface="iwn0" + +help(){ +cat <<EOF +Usage: $0 [option] + +$0 Allows you to set, edit, or display saved interface configurations placed +in "$conf_dir". + +Configurations are in the standard hostname.if(5) format. + +Where option is: + -l List all of the available network names. + -s "\$name" Sets the network name + -e "\$name" Edit the configuration file of "\$name" + -d "\$name" Display the configuration file of "\$name" + -i "\$interface" Override the interface ($interface) set in the script. + -D Set the interface down and remove all IP addresses +EOF +if ! [ -z "$1" ] ; then + exit "$1" +else + exit 0 +fi +} + +list() { + find "$conf_dir" -type f | sed -e"s@$conf_dir/@@g" +} + +edit_net() { + if [ -z "$1" ] ; then + echo "Please pass in a file name!" + exit 1 + fi + _f="$1"; shift + "$EDITOR" "${conf_dir}/$_f" +} + +display_net() { + if [ -z "$1" ] ; then + echo "Please pass in a file name!" + exit 1 + fi + _f="$1"; shift + cat "${conf_dir}/$_f" +} + +set_net() { + if [ -z "$1" ] ; then + echo "Please pass in a file name!" + exit 1 + fi + _f="$1"; shift + + if [ -L "/etc/hostname.${interface}" ] ; then + rm "/etc/hostname.${interface}" + fi + ln -s "${conf_dir}/$_f" "/etc/hostname.${interface}" + sh /etc/netstart +} + +down_net() { + ifconfig "$interface" down -inet -inet6 +} + +if [ -z "$1" ] ; then + help +fi +while [ $# -gt 0 ] ; do case $1 in + -i) interface="$2"; shift; shift ;; + -l) shift; list ; break ;; + -s) shift; set_net "$@" ; break ;; + -d) shift; display_net "$@" ; break ;; + -e) shift; edit_net "$@" ; break ;; + -D) shift; down_net "$@" ; break ;; + *) help 1;; +esac ; done |
