diff options
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network | 61 |
1 files changed, 30 insertions, 31 deletions
diff --git a/src/network b/src/network index 12920de..8b1c088 100644 --- a/src/network +++ b/src/network @@ -7,24 +7,24 @@ # load_profile profile # source the profile load_profile() { - validate_profile $1 || return 1 - . $PROFILE_DIR/$1 + validate_profile "$1" || return 1 + . "$PROFILE_DIR/$1" } # validate_profile profile # check whether profile exists and is usable validate_profile() { [[ -z "$1" ]] && return 1 - if [[ ! -f $PROFILE_DIR/$1 ]]; then + if [[ ! -f "$PROFILE_DIR/$1" ]]; then report_fail "Profile \"$1\" does not exist" return 1 fi - . $PROFILE_DIR/$1 + . "$PROFILE_DIR/$1" if [[ -z "$INTERFACE" ]]; then report_fail "Profile missing an interface to configure" return 1 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" return 1 fi @@ -110,7 +110,7 @@ profile_up() # NETWORKS_EXCLUSIVE, rc.conf: Profiles are globally mutually exclusive # EXCLUSIVE, network.d/profile: Individual profile is mutually exclusive - if checkyesno $NETWORKS_EXCLUSIVE || checkyesno $EXCLUSIVE; then + if checkyesno "$NETWORKS_EXCLUSIVE" || checkyesno "$EXCLUSIVE"; then all_down fi @@ -123,7 +123,7 @@ profile_up() exit 1 else interface_down $INTERFACE || exit 1 - load_profile "$PROFILE" + load_profile "$PROFILE" fi ;; external) @@ -223,9 +223,9 @@ profile_down() # Check if variable is a member of an array inarray() { -search=$1 +search="$1" shift -for item in $*; do +for item in "$@"; do if [[ "$item" == "$search" ]]; then return 0 fi @@ -234,7 +234,7 @@ return 1 } quirk() { -inarray $1 ${QUIRKS[@]} +inarray "$1" "${QUIRKS[@]}" return $? } @@ -243,22 +243,21 @@ return $? # interface_down() { - local prof=$(get_iface_prof $1) - profile_down $prof + local prof=$(get_iface_prof "$1") + profile_down "$prof" return $? } -### Query functions ## # check_iface interface # Return 0 if interface up # Return 1 if interface down # check_iface() { - if [[ -f $STATE_DIR/interfaces/$1 ]]; then ( - . $STATE_DIR/interfaces/$1 - if [[ $PROFILE -eq external ]]; then + if [[ -f "$STATE_DIR/interfaces/$1" ]]; then ( + . "$STATE_DIR/interfaces/$1" + if [[ "$PROFILE" -eq external ]]; then echo "external" else echo "up" @@ -275,9 +274,9 @@ check_iface() { # Return 1 if down. # get_iface_prof() { - if check_iface $1; then - . $STATE_DIR/interfaces/$1 - echo $PROFILE + if check_iface "$1"; then + . "$STATE_DIR/interfaces/$1" + echo "$PROFILE" else return 1 fi @@ -294,7 +293,7 @@ list_profiles() { # Return 1 if profile not registered # check_profile() { - [[ -f $STATE_DIR/profiles/$1 && ! -f "$STATE_DIR/suspend/$1" ]] && return 0 + [[ -f "$STATE_DIR/profiles/$1" && ! -f "$STATE_DIR/suspend/$1" ]] && return 0 return 1 } @@ -306,16 +305,16 @@ check_profile() { set_profile() { if [[ "$1" == "up" ]]; then ( # subshell creates sandbox for sourced variables - . $PROFILE_DIR/$2 - cp $PROFILE_DIR/$2 $STATE_DIR/profiles/ - echo $2 > $STATE_DIR/last_profile - set_iface up $INTERFACE $2 + . "$PROFILE_DIR/$2" + cp "$PROFILE_DIR/$2" "$STATE_DIR/profiles/" + echo "$2" > "$STATE_DIR/last_profile" + set_iface up "$INTERFACE" "$2" ) elif [[ "$1" == "down" && -f "$STATE_DIR/profiles/$2" ]]; then # JP: skip if profile not already up ( # subshell - . $STATE_DIR/profiles/$2 - rm $STATE_DIR/profiles/$2 - set_iface down $INTERFACE $2 + . "$STATE_DIR/profiles/$2" + rm "$STATE_DIR/profiles/$2" + set_iface down "$INTERFACE" "$2" ) fi } @@ -325,10 +324,10 @@ set_profile() { # optionally link it to a profile. # set_iface() { - PROFILE=$3 + local PROFILE="$3" [[ -z "$PROFILE" ]] && PROFILE=external if [[ "$1" == "up" ]]; then - echo "PROFILE=$PROFILE" > $STATE_DIR/interfaces/$2 + echo "PROFILE=$PROFILE" > "$STATE_DIR/interfaces/$2" elif [[ "$1" == "down" ]]; then rm -f "$STATE_DIR/interfaces/$2" # JP: add -f so we don't complain if the interface isn't up fi @@ -376,9 +375,9 @@ set_interface() # checkyesno() { - _value=${1} + local _value="${1}" #debug "checkyesno: $1 is set to $_value." - case $_value in + case "$_value" in # "yes", "true", "on", or "1" [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) |