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
fi
unset auto
fi
done
done
;;
stop)
if ck_daemon net-auto; then
......@@ -48,4 +48,4 @@ case "$1" in
exit_stderr "Usage: $0 {start|stop|restart}"
esac
# vim: set ts=4 et sw=4:
# vim: ft=sh ts=4 et sw=4:
......@@ -17,67 +17,67 @@ wifi_auto()
set_rf_state "$interface" up
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")
if [[ -z "$networks" ]]; then
set_interface forcedown "$interface"
set_interface forcedown "$interface"
exit_fail "- No networks available."
fi
# 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: also, make ESSIDs in wireless-dbus CONNECTIONS a regexp instead of a literal
# JP: add ability to use AP instead of ESSID
# JP: also, make ESSIDs in wireless-dbus CONNECTIONS a regexp instead of a literal
while read ap essid; do
while read network; do
(
unset CONNECTION INTERFACE AP ESSID
load_profile "$network"
case "$CONNECTION" in
wireless-old|wireless|wireless-dbus)
if [[ "$interface" = "$INTERFACE" ]]; then
if [[ "$ap" == "$AP" ]]; then
exit 2
elif [[ -z "$found_profile" ]]; then
if [[ "$CONNECTION" == wireless-dbus ]]; then
if expr match "$essid" "^$ESSID\$" 1>/dev/null; then
exit 1
fi
elif [[ "$essid" == "$ESSID" ]]; then
exit 1
fi
fi
fi
;;
esac
exit 0
)
case $? in
2) found_profile="$network"
found_essid="$essid"
break 2;;
1) found_profile="$network"
found_essid="$essid"
;;
esac
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
rm -f "$networks" # shouldn't we delete the tmp file?
while read network; do
(
unset CONNECTION INTERFACE AP ESSID
load_profile "$network"
case "$CONNECTION" in
wireless-old|wireless|wireless-dbus)
if [[ "$interface" = "$INTERFACE" ]]; then
if [[ "$ap" == "$AP" ]]; then
exit 2
elif [[ -z "$found_profile" ]]; then
if [[ "$CONNECTION" == wireless-dbus ]]; then
if expr match "$essid" "^$ESSID\$" 1>/dev/null; then
exit 1
fi
elif [[ "$essid" == "$ESSID" ]]; then
exit 1
fi
fi
fi
;;
esac
exit 0
)
case $? in
2) found_profile="$network"
found_essid="$essid"
break 2;;
1) found_profile="$network"
found_essid="$essid"
;;
esac
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
rm -f "$networks" # shouldn't we delete the tmp file?
if [[ -n "$found_profile" ]]; then
report_success
if profile_up "$found_profile" "$found_essid"; then # JP: now we pass literal essid to profile_up as $2
exit 0
else
set_interface forcedown "$interface"
exit_fail "Couldn't connect profile $found_profile."
fi
else
set_interface forcedown "$interface"
exit_fail "No profiles matched the local networks."
report_success
if profile_up "$found_profile" "$found_essid"; then # JP: now we pass literal essid to profile_up as $2
exit 0
else
set_interface forcedown "$interface"
exit_fail "Couldn't connect profile $found_profile."
fi
else
set_interface forcedown "$interface"
exit_fail "No profiles matched the local networks."
fi
}
......@@ -90,3 +90,4 @@ if [[ -z "$1" ]]; then
fi
wifi_auto "$1"
# vim: ft=sh ts=4 et sw=4:
......@@ -3,7 +3,7 @@
wpa_check()
{
local timeout=0 INTERFACE="$1" TIMEOUT="${2:-15}"
while [[ $timeout -lt "$TIMEOUT" ]]; do
( # Sometimes wpa_supplicant isn't ready so silence errors for 2s only to avoid hiding real errors
if [[ $timeout -lt 2 ]]; then
......@@ -11,7 +11,7 @@ wpa_check()
else
eval $(wpa_cli -i "$INTERFACE" status | fgrep "wpa_state=")
fi
[[ "$wpa_state" = "COMPLETED" ]]
[[ "$wpa_state" = "COMPLETED" ]]
) && return 0
sleep 1
let timeout++
......@@ -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
# termination should either be handled properly here, or by callers
stop_wpa "$INTERFACE"
return 1
return 1
}
start_wpa()
start_wpa()
{
local INTERFACE="$1" WPA_CONF="$2"
shift 2
......@@ -31,7 +31,7 @@ start_wpa()
wpa_supplicant -B -P "/var/run/wpa_supplicant_${INTERFACE}.pid" -i "$INTERFACE" -c "$WPA_CONF" $WPA_OPTS
sleep 1
if [[ ! -f "/var/run/wpa_supplicant_${INTERFACE}.pid" ]]; then
return 1
fi
......@@ -39,7 +39,7 @@ start_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...
# see <http://bbs.archlinux.org/viewtopic.php?pid=515667#p515667>
if [[ -f "/var/run/wpa_supplicant_$1.pid" ]]; then
......@@ -47,4 +47,4 @@ stop_wpa()
fi
}
# vim: set ts=4 et sw=4 ft=sh:
# vim: ft=sh ts=4 et sw=4:
......@@ -157,5 +157,5 @@ ethernet_status() {
ethernet_$1 "$2"
exit $?
# vim: set ts=4 et sw=4:
# vim: ft=sh ts=4 et sw=4:
......@@ -15,7 +15,7 @@ ethernet_up() {
if ! echo "$INTERFACE" | fgrep -q ":"; then
report_iproute "Interface $INTERFACE does not exist"
fi
fi
fi
report_debug ethernet_iproute_up ifup
set_interface up "$INTERFACE"
......@@ -24,8 +24,8 @@ ethernet_up() {
if ip link show dev "$INTERFACE" | fgrep -q "NO-CARRIER"; then
report_iproute "No connection"
fi
if checkyesno "${AUTH8021X:-no}"; then
if checkyesno "${AUTH8021X:-no}"; then
. "$SUBR_DIR/8021x"
[[ -z "$WPA_CONF" ]] && WPA_CONF="/etc/wpa_supplicant.conf"
[[ -z "$WPA_OPTS" ]] && WPA_OPTS="-Dwired"
......@@ -35,25 +35,25 @@ ethernet_up() {
report_fail "wpa_supplicant did not start, possible configuration error"
return 1
fi
if ! wpa_check "$INTERFACE"; then
# ignore quirk nodown---is that appropriate? or should we just use report_iproute?
# this adds a flush call as well---is that appropriate?
set_interface forcedown "$INTERFACE"
report_fail "WPA Authentication/Association Failed"
return 1
fi
fi
fi
case "$IP" in
dhcp)
# Clear remaining pid files.
# Clear remaining pid files.
rm -f "/var/run/dhcpcd-$INTERFACE".{pid,cache} >/dev/null 2>&1
# If using own dns, tell dhcpcd to NOT replace resolv.conf
[[ -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)"
if [[ "$PIPESTATUS" -ne 0 ]]; then
report_iproute "DHCP IP lease attempt failed"
......@@ -80,8 +80,8 @@ ethernet_up() {
if [[ -n "$IPCFG" ]]; then
for line in "${IPCFG[@]}"; do
report_debug ethernet_iproute_up ip "$line"
report_debug ethernet_iproute_up ip "$line"
if ! ip $line; then
report_iproute "Could not configure interface ($line)."
fi
......@@ -98,7 +98,7 @@ ethernet_up() {
# Generate a new resolv.conf
if [[ -n "$DNS" ]]; then
: >/etc/resolv.conf
: >/etc/resolv.conf
[[ -n "$DOMAIN" ]] && echo "domain $DOMAIN" >>/etc/resolv.conf
[[ -n "$SEARCH" ]] && echo "search $SEARCH" >>/etc/resolv.conf
......@@ -118,7 +118,7 @@ ethernet_down() {
dhcpcd -qx "$INTERFACE" &>/dev/null
fi
fi
report_debug ethernet_iproute_down if_down
# ignore quirk nodown---is that appropriate?
# this adds a flush call as well---is that appropriate?
......
......@@ -22,4 +22,5 @@ ppp_down() {
ppp_$1 "$2"
exit $?
# vim: set ts=4 et sw=4:
# vim: ft=sh ts=4 et sw=4:
......@@ -235,5 +235,5 @@ wireless_status() {
wireless_$1 "$2" "$3"
exit $?
# vim: set ts=4 et sw=4:
# vim: ft=sh ts=4 et sw=4:
......@@ -31,15 +31,15 @@ function report_warn {
}
function report_notify {
true
true
}
function report_debug {
checkyesno "$NETCFG_DEBUG" && echo "DEBUG: $*" >&2
checkyesno "$NETCFG_DEBUG" && echo "DEBUG: $*" >&2
}
function report_try {
# JP: this needs -n option
# JP: this needs -n option
echo -n ":: $*"
REPORT_TRYING=1
}
......@@ -47,7 +47,7 @@ function report_try {
function report_fail {
if [[ -n "$*" ]]; then
if [[ -n "$REPORT_TRYING" ]]; then
# JP: this needs -n option
# JP: this needs -n option
echo -n "- $*"
REPORT_TRYING=
echo "[fail]"
......@@ -62,9 +62,9 @@ function report_fail {
function report_success {
if [[ -n "$*" ]]; then
# JP: this needs -n option
# JP: this needs -n option
echo -n "- $*"
REPORT_TRYING=
REPORT_TRYING=
fi
echo "[done]"
}
......@@ -107,18 +107,18 @@ checkyesno()
function load_hooks() {
### Load any +x files in $HOOKS_DIR and $USERHOOKS_DIR
local hook
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 [ -x "$USERHOOKS_DIR/$hook" ]; then
source "$USERHOOKS_DIR/$hook"
else
source "$HOOKS_DIR/$hook"
fi
done
### Load any +x files in $HOOKS_DIR and $USERHOOKS_DIR
local hook
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 [ -x "$USERHOOKS_DIR/$hook" ]; then
source "$USERHOOKS_DIR/$hook"
else
source "$HOOKS_DIR/$hook"
fi
done
}
load_hooks
# vim: ft=sh ts=4 et sw=4:
......@@ -34,7 +34,9 @@ function report_fail {
function report_success {
if [[ -n "$*" ]]; then
stat_append "- $*"
REPORT_TRYING=
REPORT_TRYING=
fi
stat_done
}
# vim: ft=sh ts=4 et sw=4:
......@@ -18,8 +18,8 @@ case "$1" in
done
# $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 /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
......@@ -32,7 +32,7 @@ case "$1" in
add_daemon net-profiles
exit 0
fi
else
else
# No NET= passed at boot, go to NETWORKS=()
for network in "${NETWORKS[@]}"; do
case "$network" in
......@@ -55,7 +55,7 @@ case "$1" in
;;
esac
done
fi
fi
exit_err "No profile started." # JP: don't add_daemon unless we were successful (above)
;;
......@@ -79,4 +79,4 @@ case "$1" in
exit_stderr "Usage: $0 {start|stop|restart}"
esac
# vim: set ts=4 et sw=4:
# vim: ft=sh ts=4 et sw=4:
......@@ -22,4 +22,5 @@ case "$1" in
exit_stderr "Usage: $0 {start|stop|restart}"
;;
esac
# vim: set ts=4 et sw=4:
# vim: ft=sh ts=4 et sw=4:
......@@ -13,7 +13,7 @@ usage()
{
version
echo "Usage:"
echo " Start specified profile: netcfg profile "
echo " Start specified profile: netcfg profile "
echo " Other functions: netcfg argument profile"
echo "Arguments:"
echo " current Report currently running profiles"
......@@ -23,38 +23,38 @@ usage()
echo "-h, help This help message"
echo "-i, iface-down Take down profile active on specified interface"
echo "-l, list List all available profiles"
echo "-r, reconnect Disconnect and reconnect specified profile"
echo "-u, up Start specified profile"
echo "-r, reconnect Disconnect and reconnect specified profile"
echo "-u, up Start specified profile"
echo "-v, version Output version information and exit"
echo " all-resume Resume previously suspended profiles and reconnect 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
case "$1" in
--version|-v|version)
--version|-v|version)
version
exit 0;;
--help|-h|help)
exit 0;;
--help|-h|help)
usage;;
list|-l)
echo "Available Profiles"
echo "------------------"
list_profiles
exit 0;;
current)
if [[ -d "$STATE_DIR/profiles/" ]]; then
ls "$STATE_DIR/profiles/"
exit 0
else
exit_stderr "No active profiles."
fi;;
list|-l)
echo "Available Profiles"
echo "------------------"
list_profiles
exit 0;;
current)
if [[ -d "$STATE_DIR/profiles/" ]]; then
ls "$STATE_DIR/profiles/"
exit 0
else
exit_stderr "No active profiles."
fi;;
esac
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
case "$1" in
......@@ -63,35 +63,36 @@ case "$1" in
CHECK="YES"
profile_up "$2";;
clean)
rm "$STATE_DIR/interfaces"/* 2> /dev/null
rm "$STATE_DIR/profiles"/* 2> /dev/null
rm "$STATE_DIR/suspend"/* 2> /dev/null
rm "$STATE_DIR/last_profile" 2> /dev/null
rm "$STATE_DIR/interfaces"/* 2> /dev/null
rm "$STATE_DIR/profiles"/* 2> /dev/null
rm "$STATE_DIR/suspend"/* 2> /dev/null
rm "$STATE_DIR/last_profile" 2> /dev/null
killall wpa_supplicant 2> /dev/null
killall dhcpcd 2> /dev/null
;;
-d|down)
;;
-d|down)
profile_down "$2";;
-i|iface-down)
-i|iface-down)
interface_down "$2";;
-a|all-down)
all_down;;
-r|reconnect)
profile_down "$2"
profile_up "$2";;
-a|all-down)
all_down;;
-r|reconnect)
profile_down "$2"
profile_up "$2";;
all-resume)
all_resume;;
all-suspend)
all_suspend;;
-*|--*)
-*|--*)
usage;;
*)
*)
if [[ -n "$1" ]]; then
profile_up "$1"
else
usage
fi
;;
;;
esac
exit $?
# vim: set ts=2 noet:
# vim: ft=sh ts=4 et sw=4:
......@@ -41,24 +41,24 @@ dialog --timeout "$TIMEOUT" --default-item "$DEFAULT" \
13 50 6 "${profiles[@]}" 2> "$ANSWER"
ret=$?
case $ret in
1) ;; # Cancel - do nothing
255) # timeout - use default
255) # timeout - use default
profile_up "$DEFAULT" # JP: use profile_up and catch $?
ret=$?
if [[ $ret -eq 0 ]]; then echo "$DEFAULT" > "$STATE_DIR/menu"; fi
;;
;;
0) # User selection
profile_up "$(cat "$ANSWER")"
ret=$?
if [[ $ret -eq 0 ]]; then mv "$ANSWER" "$STATE_DIR/menu"; fi
;;
;;
*) # Shouldnt happen
exit_err "Abnormal ret code from dialog: $ret"
;;
;;
esac
rm -f "$ANSWER" # JP: add -f
exit $ret # JP: exit with caught $?
# vim: set ts=4 et sw=4:
# vim: ft=sh ts=4 et sw=4:
......@@ -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