blob: c7a61e9d9d5fb1fb52e85c60661eb5deb93937db (
plain)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# /usr/lib/networks/globals
#
# any +x files in /usr/lib/network/hooks and /etc/network.d/hooks
# will be sourced when this file is.
# hook files can override any of the utility functions defined here for custom behavior
# (such as logging error messages to syslog)
# this lets us keep netcfg simple but gives it the flexibility for users
# to make modular use of it to do more complex things
### Globals
PROFILE_DIR="/etc/network.d/"
HOOKS_DIR="/usr/lib/network/hooks/"
USERHOOKS_DIR="$PROFILE_DIR/hooks/"
IFACE_DIR="$PROFILE/interfaces/"
SUBR_DIR="/usr/lib/network/"
CONN_DIR="${SUBR_DIR}/connections/"
STATE_DIR="/var/run/network/"
# Interface up/down hooks
#
function at_interface_up {
true
}
function at_interface_down {
true
}
### Logging/Error reporting
#
function report_err {
echo "$*"
}
function report_warn {
echo "$*"
}
function report_notify {
true
}
function report_debug {
checkyesno "$NETCFG_DEBUG" && echo "DEBUG: $*"
}
function report_try {
# JP: this needs -n option
echo -n ":: $*"
REPORT_TRYING=1
}
function report_fail {
if [[ -n "$*" ]]; then
if [[ -n "$REPORT_TRYING" ]]; then
# JP: this needs -n option
echo -n "- $*"
REPORT_TRYING=
echo "[fail]"
else
echo "$*"
fi
elif [[ -n "$REPORT_TRYING" ]]; then
REPORT_TRYING=
echo "[fail]"
fi
}
function report_success {
if [[ -n "$*" ]]; then
# JP: this needs -n option
echo -n "- $*"
REPORT_TRYING=
fi
echo "[done]"
}
### For calling scripts only; don't use in library functions
function exit_stderr { echo "$*" >&2; exit 1; }
function exit_err { report_err "$*"; exit 1; }
function exit_fail { report_fail "$*"; exit 1; }
### From FreeBSD's /etc/rc.subr
##
# checkyesno var
# Test $1 variable, and warn if not set to YES or NO.
# Return 0 if it's "yes" (et al), nonzero otherwise.
# to make default yes, do "checkyesno ${VAR:-yes}"
#
checkyesno()
{
local _value="$1"
#debug "checkyesno: $1 is set to $_value."
case "$_value" in
# "yes", "true", "on", or "1"
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
return 0
;;
# "no", "false", "off", or "0"
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
return 1
;;
*)
#warn "\$${1} is not set properly - see ${rcvar_manpage}."
return 1
;;
esac
}
function load_hooks() {
### Load any +x files in $HOOKS_DIR and $USERHOOKS_DIR
local hook
for hook in $(find -L "$HOOKS_DIR/" "$USERHOOKS_DIR/$hook" -maxdepth 1 -type f -executable -printf '%P\n' | sort -u); do
# if there's an executable hook of this name in USERHOOKS_DIR, we only load it
if [ -x "$USERHOOKS_DIR/$hook" ]; then
source "$USERHOOKS_DIR/$hook"
else
source "$HOOKS_DIR/$hook"
fi
done
}
load_hooks
|