Commit 55a840ed authored by Jim Pryor's avatar Jim Pryor Committed by James Rayner
Browse files

tabs->spaces, vim modelines



Signed-off-by: default avatarJim Pryor <profjim@jimpryor.net>
parent 67f1b8fa
...@@ -28,7 +28,7 @@ case "$1" in ...@@ -28,7 +28,7 @@ case "$1" in
fi fi
unset auto unset auto
fi fi
done done
;; ;;
stop) stop)
if ck_daemon net-auto; then if ck_daemon net-auto; then
...@@ -48,4 +48,4 @@ case "$1" in ...@@ -48,4 +48,4 @@ case "$1" in
exit_stderr "Usage: $0 {start|stop|restart}" exit_stderr "Usage: $0 {start|stop|restart}"
esac esac
# vim: set ts=4 et sw=4: # vim: ft=sh ts=4 et sw=4:
...@@ -17,67 +17,67 @@ wifi_auto() ...@@ -17,67 +17,67 @@ wifi_auto()
set_rf_state "$interface" up set_rf_state "$interface" up
fi fi
set_interface up "$interface" # uses iproute methods---is it there any value to providing option to use ifconfig? set_interface up "$interface" # uses iproute methods---is it there any value to providing option to use ifconfig?
networks=$(list_networks "$interface") networks=$(list_networks "$interface")
if [[ -z "$networks" ]]; then if [[ -z "$networks" ]]; then
set_interface forcedown "$interface" set_interface forcedown "$interface"
exit_fail "- No networks available." exit_fail "- No networks available."
fi fi
# Loop through all the found essid's, then find a matching profile. # Loop through all the found essid's, then find a matching profile.
local found_profile found_essid local found_profile found_essid
# JP: add ability to use AP instead of ESSID # JP: add ability to use AP instead of ESSID
# JP: also, make ESSIDs in wireless-dbus CONNECTIONS a regexp instead of a literal # JP: also, make ESSIDs in wireless-dbus CONNECTIONS a regexp instead of a literal
while read ap essid; do while read ap essid; do
while read network; do while read network; do
( (
unset CONNECTION INTERFACE AP ESSID unset CONNECTION INTERFACE AP ESSID
load_profile "$network" load_profile "$network"
case "$CONNECTION" in case "$CONNECTION" in
wireless-old|wireless|wireless-dbus) wireless-old|wireless|wireless-dbus)
if [[ "$interface" = "$INTERFACE" ]]; then if [[ "$interface" = "$INTERFACE" ]]; then
if [[ "$ap" == "$AP" ]]; then if [[ "$ap" == "$AP" ]]; then
exit 2 exit 2
elif [[ -z "$found_profile" ]]; then elif [[ -z "$found_profile" ]]; then
if [[ "$CONNECTION" == wireless-dbus ]]; then if [[ "$CONNECTION" == wireless-dbus ]]; then
if expr match "$essid" "^$ESSID\$" 1>/dev/null; then if expr match "$essid" "^$ESSID\$" 1>/dev/null; then
exit 1 exit 1
fi fi
elif [[ "$essid" == "$ESSID" ]]; then elif [[ "$essid" == "$ESSID" ]]; then
exit 1 exit 1
fi fi
fi fi
fi fi
;; ;;
esac esac
exit 0 exit 0
) )
case $? in case $? in
2) found_profile="$network" 2) found_profile="$network"
found_essid="$essid" found_essid="$essid"
break 2;; break 2;;
1) found_profile="$network" 1) found_profile="$network"
found_essid="$essid" found_essid="$essid"
;; ;;
esac esac
done < <(list_profiles) # avoid subshell we'd get by piping list_profiles to while read done < <(list_profiles) # avoid subshell we'd get by piping list_profiles to while read
done < "$networks" # avoid subshell; list_networks returns name of a tmp file done < "$networks" # avoid subshell; list_networks returns name of a tmp file
rm -f "$networks" # shouldn't we delete the tmp file? rm -f "$networks" # shouldn't we delete the tmp file?
if [[ -n "$found_profile" ]]; then if [[ -n "$found_profile" ]]; then
report_success report_success
if profile_up "$found_profile" "$found_essid"; then # JP: now we pass literal essid to profile_up as $2 if profile_up "$found_profile" "$found_essid"; then # JP: now we pass literal essid to profile_up as $2
exit 0 exit 0
else else
set_interface forcedown "$interface" set_interface forcedown "$interface"
exit_fail "Couldn't connect profile $found_profile." exit_fail "Couldn't connect profile $found_profile."
fi fi
else else
set_interface forcedown "$interface" set_interface forcedown "$interface"
exit_fail "No profiles matched the local networks." exit_fail "No profiles matched the local networks."
fi fi
} }
...@@ -90,3 +90,4 @@ if [[ -z "$1" ]]; then ...@@ -90,3 +90,4 @@ if [[ -z "$1" ]]; then
fi fi
wifi_auto "$1" wifi_auto "$1"
# vim: ft=sh ts=4 et sw=4:
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
wpa_check() wpa_check()
{ {
local timeout=0 INTERFACE="$1" TIMEOUT="${2:-15}" local timeout=0 INTERFACE="$1" TIMEOUT="${2:-15}"
while [[ $timeout -lt "$TIMEOUT" ]]; do while [[ $timeout -lt "$TIMEOUT" ]]; do
( # Sometimes wpa_supplicant isn't ready so silence errors for 2s only to avoid hiding real errors ( # Sometimes wpa_supplicant isn't ready so silence errors for 2s only to avoid hiding real errors
if [[ $timeout -lt 2 ]]; then if [[ $timeout -lt 2 ]]; then
...@@ -11,7 +11,7 @@ wpa_check() ...@@ -11,7 +11,7 @@ wpa_check()
else else
eval $(wpa_cli -i "$INTERFACE" status | fgrep "wpa_state=") eval $(wpa_cli -i "$INTERFACE" status | fgrep "wpa_state=")
fi fi
[[ "$wpa_state" = "COMPLETED" ]] [[ "$wpa_state" = "COMPLETED" ]]
) && return 0 ) && return 0
sleep 1 sleep 1
let timeout++ let timeout++
...@@ -20,10 +20,10 @@ wpa_check() ...@@ -20,10 +20,10 @@ wpa_check()
# wpa_cli -i "$INTERFACE" terminate >/dev/null 2>&1 # callers sometimes called stop_wpa, which does more but seems redundant # wpa_cli -i "$INTERFACE" terminate >/dev/null 2>&1 # callers sometimes called stop_wpa, which does more but seems redundant
# termination should either be handled properly here, or by callers # termination should either be handled properly here, or by callers
stop_wpa "$INTERFACE" stop_wpa "$INTERFACE"
return 1 return 1
} }
start_wpa() start_wpa()
{ {
local INTERFACE="$1" WPA_CONF="$2" local INTERFACE="$1" WPA_CONF="$2"
shift 2 shift 2
...@@ -31,7 +31,7 @@ start_wpa() ...@@ -31,7 +31,7 @@ start_wpa()
wpa_supplicant -B -P "/var/run/wpa_supplicant_${INTERFACE}.pid" -i "$INTERFACE" -c "$WPA_CONF" $WPA_OPTS wpa_supplicant -B -P "/var/run/wpa_supplicant_${INTERFACE}.pid" -i "$INTERFACE" -c "$WPA_CONF" $WPA_OPTS
sleep 1 sleep 1
if [[ ! -f "/var/run/wpa_supplicant_${INTERFACE}.pid" ]]; then if [[ ! -f "/var/run/wpa_supplicant_${INTERFACE}.pid" ]]; then
return 1 return 1
fi fi
...@@ -39,7 +39,7 @@ start_wpa() ...@@ -39,7 +39,7 @@ start_wpa()
stop_wpa() stop_wpa()
{ {
wpa_cli -i "$1" terminate &> /dev/null wpa_cli -i "$1" terminate &> /dev/null
sleep 1 # JP: need this else the file tends to disappear after [[ -f ... ]] but before cat... sleep 1 # JP: need this else the file tends to disappear after [[ -f ... ]] but before cat...
# see <http://bbs.archlinux.org/viewtopic.php?pid=515667#p515667> # see <http://bbs.archlinux.org/viewtopic.php?pid=515667#p515667>
if [[ -f "/var/run/wpa_supplicant_$1.pid" ]]; then if [[ -f "/var/run/wpa_supplicant_$1.pid" ]]; then
...@@ -47,4 +47,4 @@ stop_wpa() ...@@ -47,4 +47,4 @@ stop_wpa()
fi fi
} }
# vim: set ts=4 et sw=4 ft=sh: # vim: ft=sh ts=4 et sw=4:
...@@ -157,5 +157,5 @@ ethernet_status() { ...@@ -157,5 +157,5 @@ ethernet_status() {
ethernet_$1 "$2" ethernet_$1 "$2"
exit $? exit $?
# vim: set ts=4 et sw=4:
# vim: ft=sh ts=4 et sw=4:
...@@ -15,7 +15,7 @@ ethernet_up() { ...@@ -15,7 +15,7 @@ ethernet_up() {
if ! echo "$INTERFACE" | fgrep -q ":"; then if ! echo "$INTERFACE" | fgrep -q ":"; then
report_iproute "Interface $INTERFACE does not exist" report_iproute "Interface $INTERFACE does not exist"
fi fi
fi fi
report_debug ethernet_iproute_up ifup report_debug ethernet_iproute_up ifup
set_interface up "$INTERFACE" set_interface up "$INTERFACE"
...@@ -24,8 +24,8 @@ ethernet_up() { ...@@ -24,8 +24,8 @@ ethernet_up() {
if ip link show dev "$INTERFACE" | fgrep -q "NO-CARRIER"; then if ip link show dev "$INTERFACE" | fgrep -q "NO-CARRIER"; then
report_iproute "No connection" report_iproute "No connection"
fi fi
if checkyesno "${AUTH8021X:-no}"; then if checkyesno "${AUTH8021X:-no}"; then
. "$SUBR_DIR/8021x" . "$SUBR_DIR/8021x"
[[ -z "$WPA_CONF" ]] && WPA_CONF="/etc/wpa_supplicant.conf" [[ -z "$WPA_CONF" ]] && WPA_CONF="/etc/wpa_supplicant.conf"
[[ -z "$WPA_OPTS" ]] && WPA_OPTS="-Dwired" [[ -z "$WPA_OPTS" ]] && WPA_OPTS="-Dwired"
...@@ -35,25 +35,25 @@ ethernet_up() { ...@@ -35,25 +35,25 @@ ethernet_up() {
report_fail "wpa_supplicant did not start, possible configuration error" report_fail "wpa_supplicant did not start, possible configuration error"
return 1 return 1
fi fi
if ! wpa_check "$INTERFACE"; then if ! wpa_check "$INTERFACE"; then
# ignore quirk nodown---is that appropriate? or should we just use report_iproute? # ignore quirk nodown---is that appropriate? or should we just use report_iproute?
# this adds a flush call as well---is that appropriate? # this adds a flush call as well---is that appropriate?
set_interface forcedown "$INTERFACE" set_interface forcedown "$INTERFACE"
report_fail "WPA Authentication/Association Failed" report_fail "WPA Authentication/Association Failed"
return 1 return 1
fi fi
fi fi
case "$IP" in case "$IP" in
dhcp) dhcp)
# Clear remaining pid files. # Clear remaining pid files.
rm -f "/var/run/dhcpcd-$INTERFACE".{pid,cache} >/dev/null 2>&1 rm -f "/var/run/dhcpcd-$INTERFACE".{pid,cache} >/dev/null 2>&1
# If using own dns, tell dhcpcd to NOT replace resolv.conf # If using own dns, tell dhcpcd to NOT replace resolv.conf
[[ -n "$DNS" ]] && DHCP_OPTIONS="-C resolv.conf $DHCP_OPTIONS" [[ -n "$DNS" ]] && DHCP_OPTIONS="-C resolv.conf $DHCP_OPTIONS"
report_debug ethernet_iproute_up dhcpcd -qL -t "${DHCP_TIMEOUT:-10}" $DHCP_OPTIONS "$INTERFACE" report_debug ethernet_iproute_up dhcpcd -qL -t "${DHCP_TIMEOUT:-10}" $DHCP_OPTIONS "$INTERFACE"
dhcpcd -qL -t "${DHCP_TIMEOUT:-10}" $DHCP_OPTIONS "$INTERFACE" 2>&1 | report_debug "$(cat)" dhcpcd -qL -t "${DHCP_TIMEOUT:-10}" $DHCP_OPTIONS "$INTERFACE" 2>&1 | report_debug "$(cat)"
if [[ "$PIPESTATUS" -ne 0 ]]; then if [[ "$PIPESTATUS" -ne 0 ]]; then
report_iproute "DHCP IP lease attempt failed" report_iproute "DHCP IP lease attempt failed"
...@@ -80,8 +80,8 @@ ethernet_up() { ...@@ -80,8 +80,8 @@ ethernet_up() {
if [[ -n "$IPCFG" ]]; then if [[ -n "$IPCFG" ]]; then
for line in "${IPCFG[@]}"; do for line in "${IPCFG[@]}"; do
report_debug ethernet_iproute_up ip "$line" report_debug ethernet_iproute_up ip "$line"
if ! ip $line; then if ! ip $line; then
report_iproute "Could not configure interface ($line)." report_iproute "Could not configure interface ($line)."
fi fi
...@@ -98,7 +98,7 @@ ethernet_up() { ...@@ -98,7 +98,7 @@ ethernet_up() {
# Generate a new resolv.conf # Generate a new resolv.conf
if [[ -n "$DNS" ]]; then if [[ -n "$DNS" ]]; then
: >/etc/resolv.conf : >/etc/resolv.conf
[[ -n "$DOMAIN" ]] && echo "domain $DOMAIN" >>/etc/resolv.conf [[ -n "$DOMAIN" ]] && echo "domain $DOMAIN" >>/etc/resolv.conf
[[ -n "$SEARCH" ]] && echo "search $SEARCH" >>/etc/resolv.conf [[ -n "$SEARCH" ]] && echo "search $SEARCH" >>/etc/resolv.conf
...@@ -118,7 +118,7 @@ ethernet_down() { ...@@ -118,7 +118,7 @@ ethernet_down() {
dhcpcd -qx "$INTERFACE" &>/dev/null dhcpcd -qx "$INTERFACE" &>/dev/null
fi fi
fi fi
report_debug ethernet_iproute_down if_down report_debug ethernet_iproute_down if_down
# ignore quirk nodown---is that appropriate? # ignore quirk nodown---is that appropriate?
# this adds a flush call as well---is that appropriate? # this adds a flush call as well---is that appropriate?
......
...@@ -22,4 +22,5 @@ ppp_down() { ...@@ -22,4 +22,5 @@ ppp_down() {
ppp_$1 "$2" ppp_$1 "$2"
exit $? exit $?
# vim: set ts=4 et sw=4:
# vim: ft=sh ts=4 et sw=4:
...@@ -235,5 +235,5 @@ wireless_status() { ...@@ -235,5 +235,5 @@ wireless_status() {
wireless_$1 "$2" "$3" wireless_$1 "$2" "$3"
exit $? exit $?
# vim: set ts=4 et sw=4:
# vim: ft=sh ts=4 et sw=4:
...@@ -31,15 +31,15 @@ function report_warn { ...@@ -31,15 +31,15 @@ function report_warn {
} }
function report_notify { function report_notify {
true true
} }
function report_debug { function report_debug {
checkyesno "$NETCFG_DEBUG" && echo "DEBUG: $*" >&2 checkyesno "$NETCFG_DEBUG" && echo "DEBUG: $*" >&2
} }
function report_try { function report_try {
# JP: this needs -n option # JP: this needs -n option
echo -n ":: $*" echo -n ":: $*"
REPORT_TRYING=1 REPORT_TRYING=1
} }
...@@ -47,7 +47,7 @@ function report_try { ...@@ -47,7 +47,7 @@ function report_try {
function report_fail { function report_fail {
if [[ -n "$*" ]]; then if [[ -n "$*" ]]; then
if [[ -n "$REPORT_TRYING" ]]; then if [[ -n "$REPORT_TRYING" ]]; then
# JP: this needs -n option # JP: this needs -n option
echo -n "- $*" echo -n "- $*"
REPORT_TRYING= REPORT_TRYING=
echo "[fail]" echo "[fail]"
...@@ -62,9 +62,9 @@ function report_fail { ...@@ -62,9 +62,9 @@ function report_fail {
function report_success { function report_success {
if [[ -n "$*" ]]; then if [[ -n "$*" ]]; then
# JP: this needs -n option # JP: this needs -n option
echo -n "- $*" echo -n "- $*"
REPORT_TRYING= REPORT_TRYING=
fi fi
echo "[done]" echo "[done]"
} }
...@@ -107,18 +107,18 @@ checkyesno() ...@@ -107,18 +107,18 @@ checkyesno()
function load_hooks() { function load_hooks() {
### Load any +x files in $HOOKS_DIR and $USERHOOKS_DIR ### Load any +x files in $HOOKS_DIR and $USERHOOKS_DIR
local hook local hook
for hook in $(find -L "$HOOKS_DIR/" "$USERHOOKS_DIR/$hook" -maxdepth 1 -type f -executable -printf '%P\n' | sort -u); do 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 there's an executable hook of this name in USERHOOKS_DIR, we only load it
if [ -x "$USERHOOKS_DIR/$hook" ]; then if [ -x "$USERHOOKS_DIR/$hook" ]; then
source "$USERHOOKS_DIR/$hook" source "$USERHOOKS_DIR/$hook"
else else
source "$HOOKS_DIR/$hook" source "$HOOKS_DIR/$hook"
fi fi
done done
} }
load_hooks load_hooks
# vim: ft=sh ts=4 et sw=4:
...@@ -34,7 +34,9 @@ function report_fail { ...@@ -34,7 +34,9 @@ function report_fail {
function report_success { function report_success {
if [[ -n "$*" ]]; then if [[ -n "$*" ]]; then
stat_append "- $*" stat_append "- $*"
REPORT_TRYING= REPORT_TRYING=
fi fi
stat_done stat_done
} }
# vim: ft=sh ts=4 et sw=4:
...@@ -18,8 +18,8 @@ case "$1" in ...@@ -18,8 +18,8 @@ case "$1" in
done done
# $NET env var is passed from the kernel boot line # $NET env var is passed from the kernel boot line
[[ -z "$NETWORKS_MENU_TIMEOUT" ]] && NETWORKS_MENU_TIMEOUT=5 [[ -z "$NETWORKS_MENU_TIMEOUT" ]] && NETWORKS_MENU_TIMEOUT=5
if [[ "$NET" = "menu" ]]; then if [[ "$NET" = "menu" ]]; then
if /usr/bin/netcfg-menu "$NETWORKS_MENU_TIMEOUT"; then if /usr/bin/netcfg-menu "$NETWORKS_MENU_TIMEOUT"; then
mv "$STATE_DIR"/{menu,net-profiles} # JP: user may want to disconnect profile by calling net-profiles stop mv "$STATE_DIR"/{menu,net-profiles} # JP: user may want to disconnect profile by calling net-profiles stop
...@@ -32,7 +32,7 @@ case "$1" in ...@@ -32,7 +32,7 @@ case "$1" in
add_daemon net-profiles add_daemon net-profiles
exit 0 exit 0
fi fi
else else
# No NET= passed at boot, go to NETWORKS=() # No NET= passed at boot, go to NETWORKS=()
for network in "${NETWORKS[@]}"; do for network in "${NETWORKS[@]}"; do
case "$network" in case "$network" in
...@@ -55,7 +55,7 @@ case "$1" in ...@@ -55,7 +55,7 @@ case "$1" in
;; ;;
esac esac
done done
fi fi
exit_err "No profile started." # JP: don't add_daemon unless we were successful (above) exit_err "No profile started." # JP: don't add_daemon unless we were successful (above)
;; ;;
...@@ -79,4 +79,4 @@ case "$1" in ...@@ -79,4 +79,4 @@ case "$1" in
exit_stderr "Usage: $0 {start|stop|restart}" exit_stderr "Usage: $0 {start|stop|restart}"
esac esac
# vim: set ts=4 et sw=4: # vim: ft=sh ts=4 et sw=4:
...@@ -22,4 +22,5 @@ case "$1" in ...@@ -22,4 +22,5 @@ case "$1" in
exit_stderr "Usage: $0 {start|stop|restart}" exit_stderr "Usage: $0 {start|stop|restart}"
;; ;;
esac esac
# vim: set ts=4 et sw=4:
# vim: ft=sh ts=4 et sw=4:
...@@ -13,7 +13,7 @@ usage() ...@@ -13,7 +13,7 @@ usage()
{ {
version version
echo "Usage:" echo "Usage:"
echo " Start specified profile: netcfg profile " echo " Start specified profile: netcfg profile "
echo " Other functions: netcfg argument profile" echo " Other functions: netcfg argument profile"
echo "Arguments:" echo "Arguments:"
echo " current Report currently running profiles" echo " current Report currently running profiles"
...@@ -23,38 +23,38 @@ usage() ...@@ -23,38 +23,38 @@ usage()
echo "-h, help This help message" echo "-h, help This help message"
echo "-i, iface-down Take down profile active on specified interface" echo "-i, iface-down Take down profile active on specified interface"
echo "-l, list List all available profiles" echo "-l, list List all available profiles"
echo "-r, reconnect Disconnect and reconnect specified profile" echo "-r, reconnect Disconnect and reconnect specified profile"
echo "-u, up Start specified profile" echo "-u, up Start specified profile"
echo "-v, version Output version information and exit" echo "-v, version Output version information and exit"
echo " all-resume Resume previously suspended profiles and reconnect them" echo " all-resume Resume previously suspended profiles and reconnect them"
echo " all-suspend Store a list of current running profiles and suspend them" echo " all-suspend Store a list of current running profiles and suspend them"
exit 1 exit 1
} }
# TODO: Re-add ROOT check and rewrite with getopts from BashFAQ # TODO: Re-add ROOT check and rewrite with getopts from BashFAQ
case "$1" in case "$1" in
--version|-v|version) --version|-v|version)
version version
exit 0;; exit 0;;
--help|-h|help) --help|-h|help)
usage;; usage;;
list|-l) list|-l)
echo "Available Profiles" echo "Available Profiles"
echo "------------------" echo "------------------"
list_profiles list_profiles
exit 0;; exit 0;;
current) current)
if [[ -d "$STATE_DIR/profiles/" ]]; then if [[ -d "$STATE_DIR/profiles/" ]]; then
ls "$STATE_DIR/profiles/" ls "$STATE_DIR/profiles/"
exit 0 exit 0
else else
exit_stderr "No active profiles." exit_stderr "No active profiles."
fi;; fi;;
esac esac
if [[ $(id -u) -gt 0 ]]; then if [[ $(id -u) -gt 0 ]]; then
exit_stderr "This script should be run as root." exit_stderr "This script should be run as root."
fi fi
case "$1" in case "$1" in
...@@ -63,35 +63,36 @@ case "$1" in ...@@ -63,35 +63,36 @@ case "$1" in
CHECK="YES" CHECK="YES"
profile_up "$2";; profile_up "$2";;