Commit 9c412668 authored by James Rayner's avatar James Rayner
Browse files

Read /etc/network.d/interfaces/ when loading profile

* profile is sourced again after doing so, so profile-level assignments
 can override
* folded validate_profile into load_profile: the extra source command in
 load_profile was redundant, so all that load_profile effectively did
 was just call validate_profile
parent d85c03f4
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
PROFILE_DIR="/etc/network.d/" PROFILE_DIR="/etc/network.d/"
HOOKS_DIR="/usr/lib/network/hooks/" HOOKS_DIR="/usr/lib/network/hooks/"
USERHOOKS_DIR="$PROFILE_DIR/hooks/" USERHOOKS_DIR="$PROFILE_DIR/hooks/"
IFACE_DIR="$PROFILE/interfaces/"
SUBR_DIR="/usr/lib/network/" SUBR_DIR="/usr/lib/network/"
CONN_DIR="${SUBR_DIR}/connections/" CONN_DIR="${SUBR_DIR}/connections/"
STATE_DIR="/var/run/network/" STATE_DIR="/var/run/network/"
......
...@@ -5,14 +5,8 @@ ...@@ -5,14 +5,8 @@
### Profile loading ### Profile loading
## ##
# load_profile profile # load_profile profile
# source the profile # source profile, checking whether it exists and is usable
load_profile() { load_profile()
validate_profile "$1" || return 1
. "$PROFILE_DIR/$1"
}
# validate_profile profile
# check whether profile exists and is usable
validate_profile()
{ {
[[ -z "$1" ]] && return 1 [[ -z "$1" ]] && return 1
if [[ ! -f "$PROFILE_DIR/$1" ]]; then if [[ ! -f "$PROFILE_DIR/$1" ]]; then
...@@ -24,6 +18,10 @@ validate_profile() ...@@ -24,6 +18,10 @@ validate_profile()
report_fail "Profile missing an interface to configure" report_fail "Profile missing an interface to configure"
return 1 return 1
fi fi
if [[ -f "$IFACE_DIR/$INTERFACE" ]]; then
. "$IFACE_DIR/$INTERFACE"
. "$PROFILE_DIR/$1" # we want profile settings to override, so need to source profile again
fi
if [[ ! -f "$CONN_DIR/$CONNECTION" ]]; then if [[ ! -f "$CONN_DIR/$CONNECTION" ]]; then
report_fail "$CONNECTION is not a valid connection, check spelling or look at examples" report_fail "$CONNECTION is not a valid connection, check spelling or look at examples"
return 1 return 1
...@@ -309,14 +307,14 @@ check_profile() { ...@@ -309,14 +307,14 @@ check_profile() {
set_profile() { set_profile() {
if [[ "$1" == "up" ]]; then if [[ "$1" == "up" ]]; then
( # subshell creates sandbox for sourced variables ( # subshell creates sandbox for sourced variables
. "$PROFILE_DIR/$2" . "$PROFILE_DIR/$2" # we source profile in order to obtain INTERFACE
cp "$PROFILE_DIR/$2" "$STATE_DIR/profiles/" cp "$PROFILE_DIR/$2" "$STATE_DIR/profiles/"
echo "$2" > "$STATE_DIR/last_profile" echo "$2" > "$STATE_DIR/last_profile"
set_iface up "$INTERFACE" "$2" set_iface up "$INTERFACE" "$2"
) )
elif [[ "$1" == "down" && -f "$STATE_DIR/profiles/$2" ]]; then # JP: skip if profile not already up elif [[ "$1" == "down" && -f "$STATE_DIR/profiles/$2" ]]; then # JP: skip if profile not already up
( # subshell ( # subshell
. "$STATE_DIR/profiles/$2" . "$STATE_DIR/profiles/$2" # we source profile in order to obtain INTERFACE
rm "$STATE_DIR/profiles/$2" rm "$STATE_DIR/profiles/$2"
set_iface down "$INTERFACE" "$2" set_iface down "$INTERFACE" "$2"
) )
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment