summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJouke Witteveen <j.witteveen@gmail.com>2012-03-01 01:33:12 +0100
committerJouke Witteveen <j.witteveen@gmail.com>2012-03-01 01:35:58 +0100
commiteed3f590c9db7cd9cd4d5fb4722fc7257a278ea6 (patch)
treed34406a8af61dccbb9655b899da30d04ce61a623
parent8d1c5e8ec6b637015e84bbb154ece9065c59f1c5 (diff)
downloadnetctl-eed3f590c9db7cd9cd4d5fb4722fc7257a278ea6.tar.gz
netctl-eed3f590c9db7cd9cd4d5fb4722fc7257a278ea6.tar.xz
Code quality upgrade
This is what you get when Dave Reisner points you at some bash anti-patterns. Also in this commit: - updated documentation - bugfix revision of the IPv6 SLAAC address/route bug
-rw-r--r--docs/netcfg-profiles.txt9
-rw-r--r--docs/netcfg.txt11
-rwxr-xr-xrc.d/net-auto-wired15
-rwxr-xr-xrc.d/net-auto-wireless8
-rwxr-xr-xrc.d/net-profiles4
-rw-r--r--scripts/ifplugd.action8
-rwxr-xr-xscripts/netcfg-menu12
-rwxr-xr-xscripts/netcfg-wpa_actiond10
-rwxr-xr-xscripts/wifi-menu73
-rw-r--r--src-wireless/net-auto4
-rw-r--r--src-wireless/netcfg-auto-wireless4
-rw-r--r--src-wireless/wireless-dbus26
-rw-r--r--src/8021x11
-rw-r--r--src/connections/bond6
-rw-r--r--src/connections/bridge28
-rw-r--r--src/connections/ethernet35
-rw-r--r--src/connections/pppoe4
-rw-r--r--src/connections/tunnel2
-rw-r--r--src/connections/tuntap4
-rw-r--r--src/connections/vlan10
-rw-r--r--src/connections/wireless4
-rw-r--r--src/rfkill2
22 files changed, 146 insertions, 144 deletions
diff --git a/docs/netcfg-profiles.txt b/docs/netcfg-profiles.txt
index 2aa7653..1c666bc 100644
--- a/docs/netcfg-profiles.txt
+++ b/docs/netcfg-profiles.txt
@@ -1,7 +1,8 @@
-% NETCFG-PROFILES(5) netcfg 2.6.8 | Arch Linux
-% Rémy Oudompheng <remy@archlinux.org>
+% NETCFG-PROFILES(5) netcfg 2.7 | Arch Linux
+% Jouke Witteveen <j.witteveen@gmail.com>
+ Rémy Oudompheng <remy@archlinux.org>
James Rayner <james@archlinux.org>
-% 14 August 2011
+% 29 February 2012
NAME
====
@@ -56,6 +57,8 @@ openvpn
: OpenVPN setup.
ppp
: PPP connections setup.
+pppoe
+: PPPoE connections setup.
The configuration variable for these connection types is described in the
following sections.
diff --git a/docs/netcfg.txt b/docs/netcfg.txt
index 0cb4408..499219f 100644
--- a/docs/netcfg.txt
+++ b/docs/netcfg.txt
@@ -1,7 +1,8 @@
-% NETCFG(8) netcfg 2.6.8 | Arch Linux
-% Rémy Oudompheng <remy@archlinux.org>
+% NETCFG(8) netcfg 2.7 | Arch Linux
+% Jouke Witteveen <j.witteveen@gmail.com>
+ Rémy Oudompheng <remy@archlinux.org>
James Rayner <james@archlinux.org>
-% 2011-08-14
+% 2012-02-29
NAME
====
@@ -37,12 +38,12 @@ current
: Report currently running profiles
`-c`, check-iface *profile*
: Start the specified profile, only if it's interface is not currently up.
-
`-u`, up *profile*
: Start the specified profile
`-r`, reconnect *profile*
: Disconnect and reconnect the specified profile
-
+`-R`, iface-recon *interface*
+: Reconnect profile active on specified interface
`-d`, down *profile*
: Stop the specified profile
`-i`, iface-down *interface*
diff --git a/rc.d/net-auto-wired b/rc.d/net-auto-wired
index 21f487d..859e57d 100755
--- a/rc.d/net-auto-wired
+++ b/rc.d/net-auto-wired
@@ -8,9 +8,9 @@
if [[ ! -x /usr/sbin/ifplugd ]]; then
echo "Please install 'ifplugd' to use net-auto-wired"
exit 1
-fi
+fi
-if [ -z "${WIRED_INTERFACE}" ]; then
+if [[ -z "${WIRED_INTERFACE}" ]]; then
echo "No interface name set. Add to /etc/conf.d/netcfg a line"
echo " WIRED_INTERFACE=\"your_interface\""
exit 1
@@ -19,7 +19,7 @@ fi
CFG=/etc/ifplugd/ifplugd.conf
ACTION=/etc/ifplugd/netcfg.action
PIDFILE=/var/run/ifplugd.$WIRED_INTERFACE.pid
-[[ -f $PIDFILE ]] && PID=$(cat $PIDFILE)
+[[ -f $PIDFILE ]] && read PID < $PIDFILE
# Source ifplugd configuration
[ -f $CFG ] && . $CFG
@@ -31,8 +31,8 @@ case "$1" in
fi
stat_busy "Starting netcfg auto-wired mode for interface ${WIRED_INTERFACE}"
A="`eval echo \$\{ARGS_${WIRED_INTERFACE}\}`"
- [ -z "$A" ] && A="$ARGS"
- [ -z "$PID" ] && /usr/sbin/ifplugd -i $WIRED_INTERFACE -r $ACTION $A
+ [[ "$A" ]] || A="$ARGS"
+ [[ "$PID" ]] || /usr/sbin/ifplugd -i $WIRED_INTERFACE -r $ACTION $A
# ifplugd may return non-zero, but still succeed if -w is passed, as default in upstream config.
sleep 1
if [[ -f $PIDFILE ]]; then
@@ -45,8 +45,7 @@ case "$1" in
stop)
if ! ck_daemon net-auto-wired; then
stat_busy "Stopping netcfg auto-wired mode for interface ${WIRED_INTERFACE}"
- [ -n "$PID" ] && /usr/sbin/ifplugd -k -i $WIRED_INTERFACE -r $ACTION
- if [ $? -eq 0 ]; then
+ if [[ "$PID" ]] && /usr/sbin/ifplugd -k -i $WIRED_INTERFACE -r $ACTION; then
rm_daemon net-auto-wired
stat_done
else
@@ -60,6 +59,6 @@ case "$1" in
"$0" start
;;
*)
- echo "Usage: $0 {start|stop|restart}"
+ echo "Usage: $0 {start|stop|restart}"
esac
exit 0
diff --git a/rc.d/net-auto-wireless b/rc.d/net-auto-wireless
index a03097b..79c43b0 100755
--- a/rc.d/net-auto-wireless
+++ b/rc.d/net-auto-wireless
@@ -10,7 +10,7 @@ if [[ ! -x /usr/sbin/wpa_actiond ]]; then
exit 1
fi
-if [ -z "${WIRELESS_INTERFACE}" ]; then
+if [[ -z "${WIRELESS_INTERFACE}" ]]; then
echo "No interface name set. Add to /etc/conf.d/netcfg a line"
echo " WIRELESS_INTERFACE=\"your_interface\""
exit 1
@@ -31,8 +31,7 @@ case "$1" in
done
stat_busy "Starting netcfg auto-wireless mode for interface ${WIRELESS_INTERFACE}"
- /usr/bin/netcfg-wpa_actiond "${WIRELESS_INTERFACE}" >/dev/null
- if [ $? -eq 0 ]; then
+ if /usr/bin/netcfg-wpa_actiond "${WIRELESS_INTERFACE}" >/dev/null; then
add_daemon net-auto-wireless
stat_done
else
@@ -42,8 +41,7 @@ case "$1" in
stop)
if ! ck_daemon net-auto-wireless; then
stat_busy "Stopping netcfg auto-wireless mode for interface ${WIRELESS_INTERFACE}"
- /usr/bin/netcfg-wpa_actiond stop "${WIRELESS_INTERFACE}" >/dev/null
- if [ $? -eq 0 ]; then
+ if /usr/bin/netcfg-wpa_actiond stop "${WIRELESS_INTERFACE}" >/dev/null; then
rm_daemon net-auto-wireless
stat_done
else
diff --git a/rc.d/net-profiles b/rc.d/net-profiles
index f7770ee..e8b8bc7 100755
--- a/rc.d/net-profiles
+++ b/rc.d/net-profiles
@@ -70,9 +70,9 @@ case "$1" in
# shutdown any profiles started by netcfg (or from NET_PROFILES in rc.conf)
# JP: only attempt to disconnect the profiles _this daemon_ was told to control
- for profile in $(cat "$STATE_DIR/net-profiles"); do
+ while read profile; do
/usr/bin/netcfg2 down "$profile"
- done
+ done < "$STATE_DIR/net-profiles"
rm -f "$STATE_DIR/net-profiles"
rm_daemon net-profiles
;;
diff --git a/scripts/ifplugd.action b/scripts/ifplugd.action
index 602e61a..573131d 100644
--- a/scripts/ifplugd.action
+++ b/scripts/ifplugd.action
@@ -1,6 +1,6 @@
#!/bin/bash
#
-# ifplugd.action script for netcfg
+# ifplugd.action script for netcfg
. /etc/rc.conf
. /etc/rc.d/functions
@@ -10,8 +10,8 @@ shopt -s extglob
case "$2" in
up)
# Look for a dhcp based profile to try first
- # dhcp can actually outright fail, whereas
- # it's difficult to tell if static succeeded
+ # dhcp can actually outright fail, whereas
+ # it's difficult to tell if static succeeded
# Also check profile is same iface and is right connection
echo "up"
declare -a preferred_profiles
@@ -49,6 +49,6 @@ case "$2" in
*)
echo "Wrong arguments" > /dev/stderr
;;
-esac
+esac
exit 1
diff --git a/scripts/netcfg-menu b/scripts/netcfg-menu
index ff57005..f7c9019 100755
--- a/scripts/netcfg-menu
+++ b/scripts/netcfg-menu
@@ -5,7 +5,7 @@
if [[ ! -x /usr/bin/dialog ]]; then
echo "Please install 'dialog' to use netcfg-menu"
exit 1
-fi
+fi
check_make_state_dir
@@ -18,10 +18,8 @@ i=0
while read prof; do
# if there is a profile called "main", Use as default
[[ "$prof" = "main" ]] && DEFAULT="main"
- profiles[$i]="$prof"
- let i++
- profiles[$i]=$(. "$PROFILE_DIR/$prof"; echo "$DESCRIPTION")
- let i++
+ profiles[i++]="$prof"
+ profiles[i++]=$(. "$PROFILE_DIR/$prof"; echo "$DESCRIPTION")
done < <(list_profiles | sort) # JP: re-use list_profiles instead of duplicating it; avoid subshell we'd get by piping it to the while read...
if [[ ${#profiles} -eq 0 ]]; then
@@ -52,12 +50,12 @@ case $ret in
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
+ (( ret == 0 )) && echo "$DEFAULT" > "$STATE_DIR/menu"
;;
0) # User selection
profile_up "$(cat "$ANSWER")"
ret=$?
- if [[ $ret -eq 0 ]]; then mv "$ANSWER" "$STATE_DIR/menu"; fi
+ (( ret == 0 )) && mv "$ANSWER" "$STATE_DIR/menu"
;;
*) # Shouldnt happen
exit_err "Abnormal ret code from dialog: $ret"
diff --git a/scripts/netcfg-wpa_actiond b/scripts/netcfg-wpa_actiond
index 2e402df..c8a2867 100755
--- a/scripts/netcfg-wpa_actiond
+++ b/scripts/netcfg-wpa_actiond
@@ -43,11 +43,11 @@ fi
[[ -f "$IFACE_DIR/$interface" ]] && source "$IFACE_DIR/$interface"
if [[ -f "$CONN_DIR/interfaces/$interface" ]]; then
- netcfg -i $interface
+ netcfg -i "$interface"
fi
if [[ -n "$RFKILL" ]]; then # Enable radio if necessary
- enable_rf $interface $RFKILL $RFKILL_NAME || exit $?
+ enable_rf "$interface" "$RFKILL" "$RFKILL_NAME" || exit $?
fi
WPA_CONF="$(make_wpa_config_file $interface)"
@@ -65,9 +65,9 @@ fi | while read profile; do
[[ $INTERFACE != $interface ]] && exit 1
# Exclude wpa-config, the wpa_conf is 'complete' and doesn't fit in this scheme
[[ -z "$SECURITY" ]] && SECURITY="none"
- [[ $SECURITY == "wpa-config" ]] && exit 1
-
- echo -e "network={ \n$(make_wpa_config) \nid_str=\"$profile\" \n}" >> $WPA_CONF
+ [[ $SECURITY == "wpa-config" ]] && exit 1
+
+ printf "%s\n" "network={" "$(make_wpa_config)" "id_str=\"$profile\"" "}" >> $WPA_CONF
)
done
diff --git a/scripts/wifi-menu b/scripts/wifi-menu
index fc21a9b..25ac87e 100755
--- a/scripts/wifi-menu
+++ b/scripts/wifi-menu
@@ -46,12 +46,12 @@ init_profiles()
)
case $? in
2)
- GENERATED[${#GENERATED[@]}]="$profile"
+ GENERATED+=("$profile")
;&
1)
- PROFILES[$i]="$profile"
- ESSIDS[$i]="$essid"
- let i++
+ PROFILES[i]=$profile
+ ESSIDS[i]=$essid
+ (( ++i ))
;;
esac
done
@@ -60,29 +60,29 @@ init_profiles()
# Builds ENTRIES as an argument list for dialog based on scan results in $1.
init_entries()
{
- local i=0 flags security signal ssid
+ local i=0 flags signal ssid
while IFS=$'\t' read signal flags ssid; do
- ENTRIES[$i]="--" # $ssid might look like an option to dialog.
- let i++
- ENTRIES[$i]="$ssid"
- let i++
+ ENTRIES[i++]="--" # $ssid might look like an option to dialog.
+ ENTRIES[i++]=$ssid
if inarray "$ssid" "${ESSIDS[@]}"; then
if inarray "$(ssid_to_profile "$ssid")" "${GENERATED[@]}"; then
- ENTRIES[$i]="+" # Automatically generated
+ ENTRIES[i]="+" # Automatically generated
else
- ENTRIES[$i]="*" # Handmade
+ ENTRIES[i]="*" # Handmade
fi
else
- ENTRIES[$i]="-" # Not present
+ ENTRIES[i]="-" # Not present
fi
if [[ "$ssid" = "$CONNECTION" ]]; then
- ENTRIES[$i]="!" # Currently connected
+ ENTRIES[i]="!" # Currently connected
fi
- security="$(expr match "$flags" ".*\(WPA2\|WPA\|WEP\)")"
- : ${security:="NONE"}
- ENTRIES[$i]+=":${security,,}"
- ENTRIES[$i]+=" :$signal"
- let i++
+ if [[ "$flags" =~ WPA2|WPA|WEP ]]; then
+ ENTRIES[i]+=":${BASH_REMATCH[0],,}"
+ else
+ ENTRIES[i]+=":none"
+ fi
+ ENTRIES[i]+=" :$signal"
+ (( ++i ))
done < "$1"
}
@@ -91,8 +91,8 @@ ssid_to_profile()
{
local i
for i in $(seq 0 $((${#ESSIDS[@]}-1))); do
- if [[ "$1" = "${ESSIDS[$i]}" ]]; then
- printf "%s" "${PROFILES[$i]}"
+ if [[ "$1" = "${ESSIDS[i]}" ]]; then
+ printf "%s" "${PROFILES[i]}"
return 0
fi
done
@@ -105,10 +105,13 @@ create_profile()
local flags key msg security
PROFILE="$INTERFACE-$1"
[[ -f "$PROFILE_DIR/$PROFILE" ]] && PROFILE+=".wifi-menu"
- flags="$(grep -m 1 $'\t'"$1\$" "$NETWORKS" | cut -f 2)"
- security="$(expr match "$flags" ".*\(WPA\|WEP\)")"
- : ${security:="NONE"}
- if [[ "$flags" =~ "PSK"|"WEP" ]]; then
+ flags=$(grep -m 1 $'\t'"$1\$" "$NETWORKS" | cut -f 2)
+ if [[ "$flags" =~ WPA|WEP ]]; then
+ security=${BASH_REMATCH[0],,}
+ else
+ security=none
+ fi
+ if [[ "$flags" =~ PSK|WEP ]]; then
msg="Enter $security security key for\n'$1'"
if [[ "$OBSCURE" ]]; then
key=$(wpa_passphrase "$1" "$(dialog --insecure --passwordbox \
@@ -120,13 +123,13 @@ create_profile()
key="KEY='$(dialog --inputbox "$msg" 10 40 --stdout)'"
RETURN=$?
fi
- [[ $RETURN -eq 0 ]] || return $RETURN
+ (( RETURN == 0 )) || return $RETURN
fi
cat << EOF > "$PROFILE_DIR/$PROFILE" || return 4
CONNECTION='wireless'
DESCRIPTION='Automatically generated profile by wifi-menu'
INTERFACE='$INTERFACE'
-SECURITY='${security,,}'
+SECURITY='$security'
ESSID='$1'
IP='dhcp'
$key
@@ -147,12 +150,12 @@ connect_to_ssid()
else
PROFILE=$(create_profile "$1")
RETURN=$?
- [[ $RETURN -eq 0 ]] || return $RETURN
+ (( RETURN == 0 )) || return $RETURN
SPAWNED_PROFILE=1
clear
fi
if ! profile_up "$PROFILE"; then
- if [[ "$SPAWNED_PROFILE" ]]; then
+ if (( SPAWNED_PROFILE )); then
msg=" CONNECTING FAILED
Do you want to keep the generated profile ('$PROFILE')?"
@@ -191,7 +194,7 @@ if [[ $(id -u) -ne 0 ]]; then
exit_stderr "This script needs to be run with root privileges"
fi
-INTERFACE="${1-$WIRELESS_INTERFACE}"
+INTERFACE=${1-$WIRELESS_INTERFACE}
if [[ -z "$INTERFACE" ]]; then
report_err "Missing interface specification"
usage
@@ -200,16 +203,16 @@ fi
cd / # We do not want to spawn anything that can block unmounting
is_interface "$INTERFACE" || exit_fail "No such interface: $INTERFACE"
-if [[ -z "$(ip link show up dev $INTERFACE)" ]]; then
+if [[ -z "$(ip link show up dev "$INTERFACE" 2> /dev/null)" ]]; then
[[ -f "$IFACE_DIR/$INTERFACE" ]] && . "$IFACE_DIR/$INTERFACE"
bring_interface up "$INTERFACE" || exit_fail "Interface unavailable"
SPAWNED_INTERFACE=1
fi
report_try "Scanning for networks"
-CONNECTION=$(expr substr \
- "$(wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" status \
- 2> /dev/null | grep "^ssid=")" 6 32)
+CONNECTION=$(wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" status 2> /dev/null \
+ | grep "^ssid=")
+CONNECTION=${CONNECTION#ssid=}
init_profiles "$INTERFACE"
NETWORKS=$(wpa_supplicant_scan_info "$INTERFACE" 3,4,5)
[[ $? -eq 0 ]] && init_entries "$NETWORKS"
@@ -227,7 +230,7 @@ Flags description:
CHOICE=$(dialog --column-separator : --menu "$MSG" 24 50 12 \
"${ENTRIES[@]}" --stdout)
RETURN=$?
- if [[ $RETURN -eq 0 ]]; then
+ if (( RETURN == 0 )); then
connect_to_ssid "$CHOICE"
RETURN=$?
fi
@@ -256,5 +259,5 @@ case $RETURN in
;;
esac
[[ -f "$NETWORKS" ]] && rm -f "$NETWORKS"
-[[ $RETURN -ne 0 && "$SPAWNED_INTERFACE" ]] && bring_interface down "$INTERFACE"
+(( RETURN && SPAWNED_INTERFACE )) && bring_interface down "$INTERFACE"
exit $RETURN
diff --git a/src-wireless/net-auto b/src-wireless/net-auto
index ca52b3e..5f972c3 100644
--- a/src-wireless/net-auto
+++ b/src-wireless/net-auto
@@ -35,9 +35,9 @@ case "$1" in
exit_stderr "net-auto not running"
fi
- for iface in $(cat "$STATE_DIR/net-auto"); do
+ while read iface; do
/usr/bin/netcfg2 iface-down "$iface"
- done
+ done < "$STATE_DIR/net-auto"
rm -f "$STATE_DIR/net-auto"
rm_daemon net-auto
;;
diff --git a/src-wireless/netcfg-auto-wireless b/src-wireless/netcfg-auto-wireless
index a3e3fb9..4d0a5e1 100644
--- a/src-wireless/netcfg-auto-wireless
+++ b/src-wireless/netcfg-auto-wireless
@@ -19,7 +19,7 @@ wifi_auto()
set_rf_state "$interface" up || exit $?
fi
- bring_interface up "$interface" # uses iproute methods---is it there any value to providing option to use ifconfig?
+ bring_interface up "$interface" # uses iproute methods - is there an option to use ifconfig?
networks=$(list_networks "$interface")
if [[ -z "$networks" ]]; then
@@ -31,7 +31,7 @@ wifi_auto()
local found_profile
- [ -z "$AUTO_PROFILES" ] && AUTO_PROFILES=$(list_profiles)
+ [[ "$AUTO_PROFILES" ]] || AUTO_PROFILES=$(list_profiles)
# JP: add ability to use AP instead of ESSID
while read ap essid; do
diff --git a/src-wireless/wireless-dbus b/src-wireless/wireless-dbus
index 0e219b6..f3773ee 100644
--- a/src-wireless/wireless-dbus
+++ b/src-wireless/wireless-dbus
@@ -35,7 +35,7 @@ def read_config(config):
def wep_hex2dec(key):
if len(key) not in [10, 26]:
fail("Bad key", report_type="err")
-
+
x=0
new_key=[]
while x<len(key):
@@ -76,7 +76,7 @@ def start(profile, essid):
# Base arguments
args=["wpa_supplicant", "-Bu", "-P/run/wpa_supplicant.pid"]
-
+
try:
args.append(profile['WPA_OPTS'])
except KeyError:
@@ -103,7 +103,7 @@ def start(profile, essid):
bus = dbus.SystemBus()
wpas_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_OPATH)
wpas = dbus.Interface(wpas_obj, WPAS_DBUS_INTERFACE)
-
+
# Add/Get interface path
try:
driver=profile["WPA_DRIVER"]
@@ -117,12 +117,12 @@ def start(profile, essid):
# Get interface object
if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
- iface = dbus.Interface(if_obj, WPAS_DBUS_INTERFACES_INTERFACE);
-
+ iface = dbus.Interface(if_obj, WPAS_DBUS_INTERFACES_INTERFACE);
+
# Add and select the network. Networks already specified for wpa-config
if profile['SECURITY'] in ['wpa','wep','none']:
report('debug', 'wireless_dbus', 'add and select network')
-
+
path = iface.addNetwork()
net_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
rnet = dbus.Interface(net_obj, WPAS_DBUS_NETWORKS_INTERFACE)
@@ -132,8 +132,8 @@ def start(profile, essid):
essid = profile["ESSID"]
if profile['SECURITY'] == "wpa":
- opts = dbus.Dictionary({"ssid": dbus.ByteArray(essid),
- "psk": dbus.String(profile['KEY'])},
+ opts = dbus.Dictionary({"ssid": dbus.ByteArray(essid),
+ "psk": dbus.String(profile['KEY'])},
signature="sv")
report('debug', 'wireless_dbus', 'connect to network with security=wpa')
rnet.set(opts)
@@ -141,7 +141,7 @@ def start(profile, essid):
key=profile['KEY']
if key[:2] == "s:": # String key prefixed by "s:"
keydbus=key[2:]
- else: # Hex key
+ else: # Hex key
key=wep_hex2dec(key)
keydbus = dbus.ByteArray()
for l in key:
@@ -155,11 +155,11 @@ def start(profile, essid):
report('debug', 'wireless_dbus', 'connect to network with security=wep')
rnet.set(opts)
elif profile['SECURITY'] == "none":
- opts = dbus.Dictionary({"ssid": dbus.ByteArray(essid)},
+ opts = dbus.Dictionary({"ssid": dbus.ByteArray(essid)},
signature="sv")
report('debug', 'wireless_dbus', 'connect to network with security=none')
rnet.set(opts)
-
+
# Determine timeout
try:
timeout = int(profile["TIMEOUT"])
@@ -174,7 +174,7 @@ def start(profile, essid):
state = iface.state()
if state == "COMPLETED":
break
-
+
if n == timeout:
fail("Association/Authentication failed:" + state)
@@ -184,7 +184,7 @@ def start(profile, essid):
except subprocess.CalledProcessError:
fail()
sys.exit(0)
-
+
def stop(profile):
ret = subprocess.call([ETHERNET_IPROUTE, "down", sys.argv[2]])
os.kill(int(open("/run/wpa_supplicant.pid").read()),SIGTERM)
diff --git a/src/8021x b/src/8021x
index 13c5b6e..560a44d 100644
--- a/src/8021x
+++ b/src/8021x
@@ -16,7 +16,7 @@ wpa_check()
[[ "$wpa_state" = "$CONDITION" ]]
) && return 0
sleep 1
- let timeout++
+ (( ++timeout ))
done
echo "$wpa_state"
# wpa_cli -i "$INTERFACE" terminate >/dev/null 2>&1 # callers sometimes called stop_wpa, which does more but seems redundant
@@ -178,9 +178,9 @@ make_wpa_config_file() {
# make empty tmp dir with correct permissions, rename it
check_make_state_dir
- # create symlink for old compatibility
+ # create symlink for old compatibility (Jouke: is this still needed?)
mkdir -p /run/wpa_supplicant
- if [ ! -e /var/run/wpa_supplicant ]; then
+ if [[ ! -e /var/run/wpa_supplicant ]]; then
ln -s /run/wpa_supplicant /var/run
fi
rm -rf "$WPA_CONF"
@@ -237,10 +237,11 @@ make_wpa_config() {
echo "key_mgmt=NONE"
;;
wpa)
+ echo "proto=RSN WPA"
if [[ "${#KEY}" -eq 64 ]]; then
- echo "proto=RSN WPA\npsk=$KEY"
+ echo "psk=$KEY"
else
- echo "proto=RSN WPA\npsk=\"$KEY\""
+ echo "psk=\"$KEY\""
fi
;;
esac
diff --git a/src/connections/bond b/src/connections/bond
index ea6af77..132225a 100644
--- a/src/connections/bond
+++ b/src/connections/bond
@@ -5,7 +5,7 @@ IFENSLAVE="/sbin/ifenslave"
bond_up() {
load_profile "$1"
- if [ -e /sys/class/net/$INTERFACE ]; then
+ if [[ -e "/sys/class/net/$INTERFACE" ]]; then
report_fail "Interface $INTERFACE already exists."
exit 1
else
@@ -31,12 +31,12 @@ bond_down() {
"$CONN_DIR/ethernet" down "$1"
bring_interface down "$INTERFACE"
- ip link delete $INTERFACE &>/dev/null
+ ip link delete "$INTERFACE" &> /dev/null
return 0
}
bond_status() {
- if [ -e /sys/class/net/$INTERFACE ]; then
+ if [[ -e "/sys/class/net/$INTERFACE" ]]; then
return 0
else
return 1
diff --git a/src/connections/bridge b/src/connections/bridge
index 3cf60c1..e134647 100644
--- a/src/connections/bridge
+++ b/src/connections/bridge
@@ -6,27 +6,23 @@ bridge_up() {
local bridge_interface
load_profile "$1"
- if [ -e "/sys/class/net/$INTERFACE" ]; then
- if [ ! -d "/sys/class/net/$INTERFACE/brif" ]; then
+ if [[ -e "/sys/class/net/$INTERFACE" ]]; then
+ if [[ ! -d "/sys/class/net/$INTERFACE/brif" ]]; then
report_fail "Interface $INTERFACE already exists and is not a bridge."
exit 1
fi
else
- $BRCTL addbr $INTERFACE
+ $BRCTL addbr "$INTERFACE"
fi
for bridge_client in $BRIDGE_INTERFACES; do
- ip link set $bridge_client promisc on up
- ip addr flush dev $bridge_client
- $BRCTL addif $INTERFACE $bridge_client
+ ip link set "$bridge_client" promisc on up
+ ip addr flush dev "$bridge_client"
+ $BRCTL addif "$INTERFACE" "$bridge_client"
done
# Set options
- if [ -n "$FWD_DELAY" ]; then
- $BRCTL setfd $INTERFACE "$FWD_DELAY"
- fi
- if [ -n "$MAX_AGE" ]; then
- $BRCTL setmaxage $INTERFACE "$MAX_AGE"
- fi
+ [[ "$FWD_DELAY" ]] && $BRCTL setfd "$INTERFACE" "$FWD_DELAY"
+ [[ "$MAX_AGE" ]] && $BRCTL setmaxage "$INTERFACE" "$MAX_AGE"
bring_interface up "$INTERFACE"
"$CONN_DIR/ethernet" up "$1"
@@ -38,14 +34,14 @@ bridge_down() {
load_profile "$1"
for bridge_client in $BRIDGE_INTERFACES; do
- ip link set $bridge_client promisc off down
- $BRCTL delif $INTERFACE $bridge_client
+ ip link set "$bridge_client" promisc off down
+ $BRCTL delif "$INTERFACE" "$bridge_client"
done
"$CONN_DIR/ethernet" down "$1"
bring_interface down "$INTERFACE"
- $BRCTL delbr $INTERFACE
- return 0
+ $BRCTL delbr "$INTERFACE"
+ return 0
}
# Returns status of profile - is it still functional?
diff --git a/src/connections/ethernet b/src/connections/ethernet
index 78f8240..8be3c6f 100644
--- a/src/connections/ethernet
+++ b/src/connections/ethernet
@@ -23,8 +23,8 @@ ethernet_up() {
fi
# Disable IPv6 before the interface to prevent SLAAC
- if [[ "$IP6" == "no"]]; then
- sysctl -q -w net.ipv6.conf.$INTERFACE.disable_ipv6=1
+ if [[ "$IP6" == "no" ]]; then
+ sysctl -q -w "net.ipv6.conf.$INTERFACE.disable_ipv6=1"
fi
report_debug ethernet_iproute_up ifup
@@ -32,7 +32,8 @@ ethernet_up() {
if ! checkyesno "${SKIPNOCARRIER:-no}" && ip link show dev "$INTERFACE" | fgrep -q "NO-CARRIER"; then
- sleep ${CARRIER_TIMEOUT:-2} # Some cards are plain slow to come up. Don't fail immediately.
+ # Some cards are plain slow to come up. Don't fail immediately.
+ sleep ${CARRIER_TIMEOUT:-2}
if ip link show dev "$INTERFACE" | fgrep -q "NO-CARRIER"; then
report_iproute "No connection"
fi
@@ -47,7 +48,7 @@ ethernet_up() {
if grep "^ *ctrl_interface=" "$WPA_CONF" &>/dev/null; then
WPA_CTRL_PATH=$(grep -m 1 "^ *ctrl_interface=" "$WPA_CONF" | tail -n 1 | cut -d= -f 2- | sed -r 's/DIR=(.*) +GROUP=.*/\1/')
fi
-
+
report_debug ethernet_iproute_up start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_DRIVER" "$WPA_OPTS"
if ! start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_DRIVER" "$WPA_OPTS"; then
report_fail "wpa_supplicant did not start, possible configuration error"
@@ -94,7 +95,7 @@ ethernet_up() {
static)
if [[ -n "$ADDR" ]]; then
[[ -z $NETMASK ]] && NETMASK=24
- report_debug ethernet_iproute_up ip addr add "$ADDR/$NETMASK" brd + dev "$INTERFACE"
+ report_debug ethernet_iproute_up ip addr add "$ADDR/$NETMASK" brd + dev "$INTERFACE"
if ! ip addr add "$ADDR/$NETMASK" brd + dev "$INTERFACE"; then
report_iproute "Could not configure interface"
fi
@@ -140,10 +141,12 @@ ethernet_up() {
# Load ipv6 module if necessary (FS#25530)
case "$IP6" in
dhcp*|stateless|static)
- [ -d "/proc/sys/net/ipv6" ] || modprobe ipv6
+ [[ -d "/proc/sys/net/ipv6" ]] || modprobe ipv6
;;
no)
- [ -d /proc/sys/net/ipv6 ] && sysctl -q -w net.ipv6.conf.$INTERFACE.accept_ra=0
+ [[ -d "/proc/sys/net/ipv6" ]] && sysctl -q -w "net.ipv6.conf.$INTERFACE.accept_ra=0"
+ ;;
+ "") # undefined IP6 does not prevent RA's from being received -> nop
;;
*)
report_iproute "IP6 must be 'dhcp', 'dhcp-noaddr', 'stateless', 'static' or 'no'"
@@ -153,12 +156,12 @@ ethernet_up() {
case "$IP6" in
dhcp*)
if [[ -x /usr/sbin/dhclient ]]; then
- _DHCLIENT_PIDFILE=/run/dhclient6-${INTERFACE}.pid
+ _DHCLIENT_PIDFILE="/run/dhclient6-${INTERFACE}.pid"
if [[ "$IP6" = "dhcp-noaddr" ]]; then
- sysctl -q -w net.ipv6.conf.$INTERFACE.accept_ra=1
+ sysctl -q -w "net.ipv6.conf.$INTERFACE.accept_ra=1"
DHCLIENT6_OPTIONS="-S ${DHCLIENT6_OPTIONS}"
else
- sysctl -q -w net.ipv6.conf.$INTERFACE.accept_ra=0
+ sysctl -q -w "net.ipv6.conf.$INTERFACE.accept_ra=0"
fi
rm -r ${_DHCLIENT_PIDFILE} &>/dev/null
report_debug ethernet_up dhclient -6 -q -e TIMEOUT="${DHCP_TIMEOUT:-10}" -pf ${_DHCLIENT_PIDFILE} "$INTERFACE"
@@ -172,10 +175,10 @@ ethernet_up() {
fi
;;
stateless)
- sysctl -q -w net.ipv6.conf.$INTERFACE.accept_ra=1
+ sysctl -q -w "net.ipv6.conf.$INTERFACE.accept_ra=1"
;;
static)
- sysctl -q -w net.ipv6.conf.$INTERFACE.accept_ra=0
+ sysctl -q -w "net.ipv6.conf.$INTERFACE.accept_ra=0"
if [[ -n "$ADDR6" ]]; then
for addr in "${ADDR6[@]}"; do
report_debug ethernet_iproute_up ip -6 addr add "$addr" dev "$INTERFACE"
@@ -194,8 +197,8 @@ ethernet_up() {
# Add static IPv6 routes
if [[ -n "$ROUTES6" ]]; then
for route in "${ROUTES6[@]}"; do
- report_debug ethernet_iproute_up ip -6 route add $route dev $INTERFACE
- if ! ip -6 route add $route dev $INTERFACE ; then
+ report_debug ethernet_iproute_up ip -6 route add "$route" dev "$INTERFACE"
+ if ! ip -6 route add "$route" dev "$INTERFACE"; then
report_iproute "Adding route '$route' failed"
fi
done
@@ -267,7 +270,7 @@ ethernet_down() {
else
bring_interface down "$INTERFACE"
fi
- return 0
+ return 0
}
# Returns status of profile - is it still functional?
@@ -277,7 +280,7 @@ ethernet_status() {
fi
}
-# Stop wpa_supplicant if neccessary
+# Stop wpa_supplicant if neccessary
stop_80211x() {
if checkyesno "${AUTH8021X:-no}"; then
. "$SUBR_DIR/8021x"
diff --git a/src/connections/pppoe b/src/connections/pppoe
index 07eb9ae..ba9f67a 100644
--- a/src/connections/pppoe
+++ b/src/connections/pppoe
@@ -61,8 +61,8 @@ pppoe_down() {
PIDFILE="/var/run/ppp-$1.pid"
if [[ -e $PIDFILE ]]; then
- PID=$(cat "$PIDFILE")
- [[ -n "$PID" ]] && kill "$PID"
+ read PID < "$PIDFILE"
+ [[ "$PID" ]] && kill "$PID"
fi
rm "${cfg}"
diff --git a/src/connections/tunnel b/src/connections/tunnel
index 613cc67..67c7d9d 100644
--- a/src/connections/tunnel
+++ b/src/connections/tunnel
@@ -4,7 +4,7 @@
tunnel_up() {
load_profile "$1"
- if [ -e "/sys/class/net/$INTERFACE" ]; then
+ if [[ -e "/sys/class/net/$INTERFACE" ]]; then
report_fail "Interface $INTERFACE already exists."
exit 1
else
diff --git a/src/connections/tuntap b/src/connections/tuntap
index 27641e4..84b3bce 100644
--- a/src/connections/tuntap
+++ b/src/connections/tuntap
@@ -4,7 +4,7 @@
tuntap_up() {
load_profile "$1"
- if [ -e /sys/class/net/$INTERFACE ]; then
+ if [[ -e /sys/class/net/$INTERFACE ]]; then
report_fail "Interface $INTERFACE already exists."
exit 1
else
@@ -26,7 +26,7 @@ tuntap_down() {
}
tuntap_status() {
- if [ -e /sys/class/net/$INTERFACE ]; then
+ if [[ -e "/sys/class/net/$INTERFACE" ]]; then
return 0
else
return 1
diff --git a/src/connections/vlan b/src/connections/vlan
index 7b81e7f..97147c7 100644
--- a/src/connections/vlan
+++ b/src/connections/vlan
@@ -5,12 +5,12 @@ vlan_up() {
local vlan_interface
load_profile "$1"
- if [ -e /sys/class/net/$INTERFACE ]; then
+ if [[ -e "/sys/class/net/$INTERFACE" ]]; then
report_fail "Interface $INTERFACE already exists."
exit 1
else
- ip link set $VLAN_PHYS_DEV up
- ip link add link $VLAN_PHYS_DEV name $INTERFACE type vlan id $VLAN_ID >/dev/null 2>&1
+ ip link set "$VLAN_PHYS_DEV" up
+ ip link add link "$VLAN_PHYS_DEV" name "$INTERFACE" type vlan id "$VLAN_ID" >/dev/null 2>&1
fi
bring_interface up "$INTERFACE"
"$CONN_DIR/ethernet" up "$1"
@@ -23,12 +23,12 @@ vlan_down() {
"$CONN_DIR/ethernet" down "$1"
bring_interface down "$INTERFACE"
- ip link delete $INTERFACE >/dev/null 2>&1
+ ip link delete "$INTERFACE" >/dev/null 2>&1
return 0
}
vlan_status() {
- if [ -e /sys/class/net/$INTERFACE ]; then
+ if [[ -e "/sys/class/net/$INTERFACE" ]]; then
return 0
else
return 1
diff --git a/src/connections/wireless b/src/connections/wireless
index b19afde..f08ba43 100644
--- a/src/connections/wireless
+++ b/src/connections/wireless
@@ -27,7 +27,7 @@ wireless_up() {
# Start wpa_supplicant
WPA_CTRL_PATH=/run/wpa_supplicant
- if [ "$SECURITY" = "wpa-config" ]; then
+ if [[ "$SECURITY" = "wpa-config" ]]; then
WPA_CONF="${WPA_CONF:-/etc/wpa_supplicant.conf}"
# Use defined control path (FS#24949)
if grep "^ *ctrl_interface=" "$WPA_CONF" &>/dev/null; then
@@ -74,7 +74,7 @@ wireless_up() {
wpa-config)
;;
none|wep|wpa|wpa-configsection)
- echo -e "network={ \n$(make_wpa_config) \n}" >> "$WPA_CONF"
+ printf "%s\n" "network={" "$(make_wpa_config)" "}" >> "$WPA_CONF"
report_debug wireless_up "Configuration generated at $WPA_CONF"
;;
*)
diff --git a/src/rfkill b/src/rfkill
index d61703d..4fbc34d 100644
--- a/src/rfkill
+++ b/src/rfkill
@@ -42,7 +42,7 @@ get_rf_state() {
local INTERFACE="$1" PROFILE="$2" path state
path=$(get_rf_path "$INTERFACE" "$RFKILL_NAME") || return 1
- state=$(cat "$path/state")
+ read state < "$path/state"
case "$state" in
0|2)