summaryrefslogtreecommitdiffstats
path: root/src/globals
blob: 616468c04015d8ae7228e49a05e6c15fecca6ef8 (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
##################################
##
#  /usr/lib/network/globals
##
##################################

# JP:rather than declare these in several library files, we just declare them
# once here, so they only need to be changed at a single point

# /etc/network.d/hooks directory
# any +x files in that directory will be sourced when this file is sourced
# they can override any of the utility functions defined here for custom behavior
# (such as logging error messages to syslog, as I like to do)
# 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/"
SUBR_DIR="/usr/lib/network/"
CONN_DIR="${SUBR_DIR}/connections/"
STATE_DIR="/var/run/network/"


### Logging/Error reporting
#

function report_err {
    echo "$*"
}

function report_warn {
    echo "$*"
}

function report_notify {
	true
}

function report_debug {
	[[ -n $NETCFG_DEBUG ]] && echo "DEBUG: $*"
}

function report_try {
    echo ":: $*"
    REPORT_TRYING=1
}

function report_fail {
    if [[ -n "$*" ]]; then
        if [[ -n "$REPORT_TRYING" ]]; then
            echo "- $*"
            REPORT_TRYING=
            echo "[fail]"
        else
            echo "$*"
        fi
    elif [[ -n "$REPORT_TRYING" ]]; then
        REPORT_TRYING=
        echo "[fail]"
    fi
}

function report_success {
    if [[ -n "$*" ]]; then
        echo "- $*"
    fi
    echo "[done]"
}

function at_interface_up {
	true
}
function at_interface_down {
	true
}

### 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; }

function load_hooks() {
	### Load any +x files in $HOOKS_DIR
	local hook
	for hook in $(find -L "$HOOKS_DIR/" -maxdepth 1 -type f -executable | sort); do
		source "$hook"
	done
}

load_hooks