blob: ad8993d4b1720ddd93736bafb321fa59f26d8910 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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
|