diff options
author | Jim Pryor <profjim@jimpryor.net> | 2009-09-14 05:43:35 +0200 |
---|---|---|
committer | James Rayner <james@archlinux.org> | 2009-09-14 08:22:45 +0200 |
commit | 55a840edd32ac45b35c4d7c604bcfe00e0ee7fbc (patch) | |
tree | 3146bf6a577d43f91145674f397fca31064ba1a6 /src/network | |
parent | 67f1b8fae53ebe22ad1a0557c0d7a1371b96cb0b (diff) | |
download | netctl-55a840edd32ac45b35c4d7c604bcfe00e0ee7fbc.tar.gz netctl-55a840edd32ac45b35c4d7c604bcfe00e0ee7fbc.tar.xz |
tabs->spaces, vim modelines
Signed-off-by: Jim Pryor <profjim@jimpryor.net>
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network | 167 |
1 files changed, 84 insertions, 83 deletions
diff --git a/src/network b/src/network index 28250b4..f1f55cf 100644 --- a/src/network +++ b/src/network @@ -20,11 +20,11 @@ load_profile() report_fail "Profile missing an interface to configure" return 1 fi - if [[ -f "$IFACE_DIR/$INTERFACE" ]]; then - report_debug "Interface level configuration enabled: $IFACE_DIR/$INTERFACE" - . "$IFACE_DIR/$INTERFACE" - . "$PROFILE_DIR/$1" # we want profile settings to override, so need to source profile again - fi + if [[ -f "$IFACE_DIR/$INTERFACE" ]]; then + report_debug "Interface level configuration enabled: $IFACE_DIR/$INTERFACE" + . "$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 report_fail "$CONNECTION is not a valid connection, check spelling or look at examples" return 1 @@ -38,8 +38,8 @@ load_profile() all_down() { find "$STATE_DIR/profiles/" -maxdepth 1 -type f -printf '%f\n' \ - | while read prof; do - # the pipe to while read... creates a subshell + | while read prof; do + # the pipe to while read... creates a subshell profile_down "$prof" done } @@ -48,22 +48,22 @@ all_down() # store a list of running profiles and take them down (unless $2 is "no") interface_suspend() { - report_debug interface_suspend "$@" + report_debug interface_suspend "$@" [[ ! -d "$STATE_DIR" ]] && mkdir -p "$STATE_DIR"/{interfaces,profiles} [[ ! -d "$STATE_DIR/suspend" ]] && mkdir "$STATE_DIR/suspend" find "$STATE_DIR/profiles/" -maxdepth 1 -type f -printf '%f\n' \ - | while read prof; do + | while read prof; do # the pipe to "while read" will create a subshell, so sourced variables will already be in a sandbox # we just need to clear INTERFACE which is all we care about unset INTERFACE . "$STATE_DIR/profiles/$prof" if [[ "$1" == all || "$1" == "$INTERFACE" ]]; then report_notify "suspending interface $INTERFACE with profile $prof" - cp "$STATE_DIR/profiles/$prof" "$STATE_DIR/suspend/" + cp "$STATE_DIR/profiles/$prof" "$STATE_DIR/suspend/" if checkyesno "${2:-yes}"; then - profile_down "$prof" + profile_down "$prof" fi fi done @@ -79,16 +79,16 @@ all_suspend() { # optional arguments: interfaces not to resume (e.g., because they're disabled) all_resume() { - report_debug all_resume "$@" + report_debug all_resume "$@" find "$STATE_DIR/suspend/" -maxdepth 1 -type f -printf '%f\n' \ - | while read prof; do + | while read prof; do # the pipe to "while read" will create a subshell, so sourced variables will already be in a sandbox # we just need to clear INTERFACE which is all we care about unset INTERFACE . "$STATE_DIR/suspend/$prof" if [[ $# -eq 0 || ! " $* " =~ " $INTERFACE " ]]; then report_notify "resuming interface $INTERFACE with profile $prof" - profile_up "$prof" + profile_up "$prof" rm -f "$STATE_DIR/suspend/$prof" # if profile_up succeeds, it will have already removed this fi done @@ -104,14 +104,14 @@ profile_up() # exit 1 used in a subshell is effectively exiting a new process [[ ! -d "$STATE_DIR" ]] && mkdir -p "$STATE_DIR"/{interfaces,profiles,suspend} - local PROFILE="$1" # save PROFILE in a variable so that it's available to PRE_UP/POST_DOWN etc hooks + local PROFILE="$1" # save PROFILE in a variable so that it's available to PRE_UP/POST_DOWN etc hooks load_profile "$PROFILE" || exit 1 if check_profile "$PROFILE"; then - report_fail "$PROFILE already connected" - exit 1 - fi + report_fail "$PROFILE already connected" + exit 1 + fi # NETWORKS_EXCLUSIVE, rc.conf: Profiles are globally mutually exclusive # EXCLUSIVE, network.d/profile: Individual profile is mutually exclusive @@ -137,26 +137,26 @@ profile_up() ;; esac - if ! ( eval $PRE_UP ); then # JP: sandbox the eval so variables don't bleed into current function - report_debug profile_up "PRE_UP failed" - report_fail - exit 1 + if ! ( eval $PRE_UP ); then # JP: sandbox the eval so variables don't bleed into current function + report_debug profile_up "PRE_UP failed" + report_fail + exit 1 fi if ! "$CONN_DIR/$CONNECTION" up "$PROFILE" "$2"; then - report_debug profile_up "connect failed" + report_debug profile_up "connect failed" report_fail - # "$CONN_DIR/$CONNECTION" down "$PROFILE" "$2" # JP: should we do this to make sure? + # "$CONN_DIR/$CONNECTION" down "$PROFILE" "$2" # JP: should we do this to make sure? exit 1 fi - if ! ( eval $POST_UP ); then # JP: sandbox the eval - report_debug profile_up "POST_UP failed" - report_fail - # failing POST_UP will take interface down - "$CONN_DIR/$CONNECTION" down "$PROFILE" "$2" - exit 1 - fi + if ! ( eval $POST_UP ); then # JP: sandbox the eval + report_debug profile_up "POST_UP failed" + report_fail + # failing POST_UP will take interface down + "$CONN_DIR/$CONNECTION" down "$PROFILE" "$2" + exit 1 + fi set_profile up "$PROFILE" unset EXCLUSIVE @@ -164,7 +164,7 @@ profile_up() # Successfully running a new profile; erase any suspended profiles on this interface local iface="$INTERFACE" find "$STATE_DIR/suspend/" -maxdepth 1 -type f -printf '%f\n' \ - | while read prof; do + | while read prof; do # the pipe to "while read" will create a subshell, so sourced variables will already be in a sandbox # we just need to clear INTERFACE which is all we care about unset INTERFACE @@ -186,7 +186,7 @@ profile_down() ( [[ ! -d "$STATE_DIR" ]] && mkdir -p "$STATE_DIR"/{interfaces,profiles,suspend} - local PROFILE="$1" # save PROFILE in a variable so that it's available to PRE_UP/POST_DOWN etc hooks + local PROFILE="$1" # save PROFILE in a variable so that it's available to PRE_UP/POST_DOWN etc hooks load_profile "$PROFILE" || exit 1 @@ -201,24 +201,24 @@ profile_down() exit 1 fi - if ! ( eval $PRE_DOWN ); then # JP: sandbox the eval - report_debug profile_down "PRE_DOWN failed" - # true # JP: did we want failing PRE_DOWN to leave the profile active? - report_fail - exit 1 - fi + if ! ( eval $PRE_DOWN ); then # JP: sandbox the eval + report_debug profile_down "PRE_DOWN failed" + # true # JP: did we want failing PRE_DOWN to leave the profile active? + report_fail + exit 1 + fi if ! "$CONN_DIR/$CONNECTION" down "$PROFILE" "$2"; then - report_debug profile_up "disconnect failed" + report_debug profile_up "disconnect failed" report_fail exit 1 fi - if ! ( eval $POST_DOWN ); then # JP: sandbox the eval - report_debug profile_down "POST_DOWN failed" - report_fail - exit 1 - fi + if ! ( eval $POST_DOWN ); then # JP: sandbox the eval + report_debug profile_down "POST_DOWN failed" + report_fail + exit 1 + fi set_profile down "$PROFILE" report_success @@ -228,19 +228,19 @@ profile_down() # Check if variable is a member of an array inarray() { - local item search="$1" - shift - for item in "$@"; do - if [[ "$item" == "$search" ]]; then - return 0 - fi - done - return 1 + local item search="$1" + shift + for item in "$@"; do + if [[ "$item" == "$search" ]]; then + return 0 + fi + done + return 1 } quirk() { - inarray "$1" "${QUIRKS[@]}" - return $? + inarray "$1" "${QUIRKS[@]}" + return $? } # interface_down interface @@ -291,7 +291,7 @@ get_iface_prof() { # Outputs a list of all profiles list_profiles() { # JP: follow aliases with -L, also skip profiles that start with '.' or end with '~' or '.conf' (so profile.conf can be the wpa.conf file for profile) - find -L "$PROFILE_DIR/" -maxdepth 1 -type f -not -name '*~' -not -name '*.conf' -not -name '.*' -printf "%f\n" + find -L "$PROFILE_DIR/" -maxdepth 1 -type f -not -name '*~' -not -name '*.conf' -not -name '.*' -printf "%f\n" } # check_profile profile # Return 0 if profile registered as being up @@ -310,17 +310,17 @@ check_profile() { set_profile() { if [[ "$1" == "up" ]]; then ( # subshell creates sandbox for sourced variables - . "$PROFILE_DIR/$2" # we source profile in order to obtain INTERFACE + . "$PROFILE_DIR/$2" # we source profile in order to obtain INTERFACE 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" # we source profile in order to obtain INTERFACE + . "$STATE_DIR/profiles/$2" # we source profile in order to obtain INTERFACE rm "$STATE_DIR/profiles/$2" set_iface down "$INTERFACE" "$2" - ) + ) fi } @@ -343,32 +343,32 @@ set_interface() INTERFACE="$2" case "$1" in up|up-old) - if ! ( eval $IFACE_UP ); then - return 1 - fi - if [ "$1" = old ]; then - ifconfig "$INTERFACE" up - else - ip link set dev "$INTERFACE" up - fi + if ! ( eval $IFACE_UP ); then + return 1 + fi + if [ "$1" = old ]; then + ifconfig "$INTERFACE" up + else + ip link set dev "$INTERFACE" up + fi sleep "${UP_SLEEP:-2}" ;; down|forcedown|down-old|forcedown-old) - # should this be placed elsewhere? - if ! ( eval $IFACE_DOWN ); then - return 1 - fi - if [ "${1%-old}" != "$1" ]; then - ## ? - if ! quirk nodown || [ "$1" = forcedown-old ]; then - ifconfig "$INTERFACE" down - fi - else - ip addr flush dev "$INTERFACE" &>/dev/null - if ! quirk nodown || [ "$1" = forcedown ]; then - ip link set dev "$INTERFACE" down &>/dev/null - fi - fi + # should this be placed elsewhere? + if ! ( eval $IFACE_DOWN ); then + return 1 + fi + if [ "${1%-old}" != "$1" ]; then + ## ? + if ! quirk nodown || [ "$1" = forcedown-old ]; then + ifconfig "$INTERFACE" down + fi + else + ip addr flush dev "$INTERFACE" &>/dev/null + if ! quirk nodown || [ "$1" = forcedown ]; then + ip link set dev "$INTERFACE" down &>/dev/null + fi + fi ;; *) return 1 @@ -376,3 +376,4 @@ set_interface() esac } +# vim: ft=sh ts=4 et sw=4: |