Commit 31b95461 authored by Jouke Witteveen's avatar Jouke Witteveen
Browse files

Minor code streamlining

parent a8f6fb14
......@@ -4,7 +4,7 @@
. /usr/lib/network/globals
PROFILE_FILE="$STATE_DIR/ifplugd_$1.profile"
PROFILE_FILE="$STATE_DIR/ifplugd-$1.profile"
case "$2" in
up)
......
......@@ -11,7 +11,7 @@ quote_word() {
}
mobile_ppp_up() {
local options_dir="$STATE_DIR/mobile_ppp.$Interface.$Profile"
local options_dir="$STATE_DIR/mobile_ppp-$Interface-$Profile"
network_ready
......@@ -83,7 +83,7 @@ EOF
mobile_ppp_down() {
local options_dir pidfile pid
options_dir="$STATE_DIR/mobile_ppp.$Interface.$Profile"
options_dir="$STATE_DIR/mobile_ppp-$Interface-$Profile"
pidfile="/var/run/ppp-$Profile.pid"
if [[ -r $pidfile ]]; then
......
......@@ -8,7 +8,7 @@ quote_word() {
}
pppoe_up() {
local options="$STATE_DIR/pppoe.$Interface.$Profile/options"
local options="$STATE_DIR/pppoe-$Interface-$Profile/options"
if ! is_interface "$Interface"; then
report_error "Interface '$Interface' does not exist"
......@@ -61,7 +61,7 @@ EOF
pppoe_down() {
local options pidfile pid
options="$STATE_DIR/pppoe.$Interface.$Profile/options"
options="$STATE_DIR/pppoe-$Interface-$Profile/options"
pidfile="/var/run/ppp-$Profile.pid"
if [[ -r $pidfile ]]; then
......
......@@ -8,7 +8,7 @@ dhclient_start() {
*) return 1;;
esac
[[ $2 == "noaddr" ]] && options+=" -S"
if ! do_debug do_readable dhclient -$1 -q -e "TIMEOUT=${TimeoutDHCP:-30}" -pf "$pidfile" $options "$Interface"; then
if ! do_debug do_readable dhclient "-$1" -q -e "TIMEOUT=${TimeoutDHCP:-30}" -pf "$pidfile" $options "$Interface"; then
report_error "DHCP IPv$1 lease attempt failed on interface '$Interface'"
return 1
fi
......@@ -18,7 +18,7 @@ dhclient_stop() {
local stop="-x" pidfile="/run/dhclient-$Interface-$1.pid"
if [[ -f $pidfile ]]; then
is_yes "${DHCPReleaseOnStop:-no}" && stop="-r"
do_debug dhclient -$1 -q $stop "$Interface" -pf "$pidfile" > /dev/null
do_debug dhclient "-$1" -q $stop "$Interface" -pf "$pidfile" > /dev/null
fi
}
......
......@@ -13,7 +13,7 @@ dhcpcd_start() {
fi
# If using own dns, tell dhcpcd to NOT replace resolv.conf
[[ $DNS ]] && options+=" -C resolv.conf"
if ! do_debug do_readable dhcpcd -$1 -q -t "${TimeoutDHCP:-30}" $options "$Interface"; then
if ! do_debug do_readable dhcpcd "-$1" -q -t "${TimeoutDHCP:-30}" $options "$Interface"; then
report_error "DHCP IPv$1 lease attempt failed on interface '$Interface'"
return 1
fi
......@@ -23,7 +23,7 @@ dhcpcd_stop() {
local stop="-x"
if [[ -f "/run/dhcpcd-$Interface-$1.pid" ]]; then
is_yes "${DHCPReleaseOnStop:-no}" && stop="-k"
do_debug dhcpcd -$1 -q $stop "$Interface" > /dev/null
do_debug dhcpcd "-$1" -q $stop "$Interface" > /dev/null
fi
}
......
......@@ -35,8 +35,8 @@ wpa_is_active() {
# $1: interface name
wpa_get_state() {
local state
state=$(wpa_call $1 status | grep -m1 "^wpa_state=") || return 1
echo ${state#wpa_state=}
state=$(wpa_call "$1" status | grep -m1 "^wpa_state=") || return 1
echo "${state#wpa_state=}"
}
## Waits until the wpa supplicant reaches a listed state
......@@ -64,28 +64,27 @@ wpa_wait_while_state() {
# $2: interface driver(s)
# $3: configuration file
wpa_start() {
local interface=$1 driver=$2 configuration=$3
local pidfile="/run/wpa_supplicant_$interface.pid"
local interface=$1 driver=$2 configuration
local pidfile="/run/wpa_supplicant-$interface.pid"
if [[ $3 ]]; then
configuration="-c$3"
else
WPA_CTRL_DIR="/run/wpa_supplicant"
configuration="-C$WPA_CTRL_DIR"
fi
if ! type wpa_supplicant &> /dev/null; then
report_error "You need to install 'wpa_supplicant'"
return 127
fi
if [[ $configuration ]]; then
configuration="-c$configuration"
else
WPA_CTRL_DIR="/run/wpa_supplicant"
configuration="-C$WPA_CTRL_DIR"
fi
do_debug wpa_supplicant -q -B -P "$pidfile" -i "$interface" -D "$driver" \
"$configuration" $WPAOptions >&2
# Wait up to one second for the pid file to appear
if ! timeout_wait 1 '[[ -f $pidfile ]]'; then
# Remove the configuration file if it was generated
configuration="$STATE_DIR/wpa_supplicant_$interface.conf"
configuration="$STATE_DIR/wpa_supplicant-$interface.conf"
[[ -f $configuration && -O $configuration ]] && rm -f "$configuration"
return 1
fi
......@@ -94,7 +93,8 @@ wpa_start() {
## Stop an instance of the wpa supplicant
# $1: interface name
wpa_stop() {
local interface=$1 config_file="$STATE_DIR/wpa_supplicant_$1.conf"
local interface=$1 config_file="$STATE_DIR/wpa_supplicant-$1.conf"
local pidfile="/run/wpa_supplicant-$interface.pid"
# We need this as long as wpa_cli has a different default than netctl
if [[ -z $WPA_CTRL_DIR && -z $WPAConfigFile ]]; then
WPA_CTRL_DIR="/run/wpa_supplicant"
......@@ -107,8 +107,8 @@ wpa_stop() {
[[ -f $config_file && -O $config_file ]] && rm -f "$config_file"
# Wait up to one second for the pid file to be removed
if ! timeout_wait 1 '[[ ! -f "/run/wpa_supplicant_$interface.pid" ]]'; then
kill "$(< "/run/wpa_supplicant_$interface.pid")" &> /dev/null
if ! timeout_wait 1 '[[ ! -f $pidfile ]]'; then
kill "$(< "$pidfile")" &> /dev/null
fi
}
......@@ -116,7 +116,7 @@ wpa_stop() {
# $1: interface name
# $2: fields of the wpa_supplicant scan_results
wpa_supplicant_scan() {
local interface=$1 fields=$2 spawned_wpa=0 essids
local interface=$1 fields=$2 spawned_wpa=no essids
# temp file used, as keeping ESSID's with spaces in their name in arrays
# is hard, obscure and kinda nasty. This is simpler and clearer.
......@@ -125,7 +125,7 @@ wpa_supplicant_scan() {
if ! wpa_is_active "$interface"; then
wpa_start "$interface" "${WPADriver:-nl80211,wext}" || return 1
spawned_wpa=1
spawned_wpa=yes
fi
wpa_call "$interface" scan > /dev/null
......@@ -147,7 +147,9 @@ wpa_supplicant_scan() {
# Re-sort by strength as the removal disorders the list
# Cut to the AP/essid fields only
(( spawned_wpa == 1 )) && wpa_stop "$interface"
if is_yes "$spawned_wpa"; then
wpa_stop "$interface"
fi
# File of 0 length: no ssid's
if [[ ! -s $essids ]]; then
......@@ -192,7 +194,7 @@ wpa_unquote() {
## Create a configuration file for wpa_supplicant without any network blocks
# $1: interface name
wpa_make_config_file() {
local config_file="$STATE_DIR/wpa_supplicant_$1.conf"
local config_file="$STATE_DIR/wpa_supplicant-$1.conf"
if [[ -e $config_file ]]; then
report_debug "The anticipated filename '$config_file' is not available"
......
......@@ -8,6 +8,7 @@
: ${ACTIOND:=wpa_actiond -p /run/wpa_supplicant}
: ${ACTION_SCRIPT:=$SUBR_DIR/auto.action}
usage() {
cat << END
Usage: netctl-auto {COMMAND} ...
......@@ -81,7 +82,7 @@ profile_enable_disable() {
local action="$1" profile="$2"
local id interfaces wpa_cmd
if [[ -n "$profile" ]]; then
if [[ $profile ]]; then
read -r interfaces id < <(get_wpa_network_id "$profile") || return 1
else
interfaces=$(list_netctl_auto_interfaces)
......@@ -197,7 +198,7 @@ list() {
# $1: interface
start() {
local interface="$1"
local pidfile="$STATE_DIR/wpa_actiond_$1.pid"
local pidfile="$STATE_DIR/wpa_actiond-$interface.pid"
if wpa_is_active "$interface"; then
exit_error "The interface ($interface) is already in use"
......@@ -247,7 +248,7 @@ start() {
# $1: interface
stop() {
local interface="$1"
local pidfile="$STATE_DIR/wpa_actiond_$1.pid"
local pidfile="$STATE_DIR/wpa_actiond-$interface.pid"
[[ -e "$pidfile" ]] && kill "$(< "$pidfile")"
if [[ -x "$PROFILE_DIR/interfaces/$interface" ]]; then
......@@ -259,6 +260,7 @@ stop() {
return 0
}
case $# in
1)
case $1 in
......@@ -292,4 +294,5 @@ case $# in
exit_error "$(usage)";;
esac
# vim: ft=sh ts=4 et sw=4:
......@@ -97,7 +97,7 @@ unit_enable() {
do_readable touch "$unit"
echo ".include @systemdsystemunitdir@/netctl@.service" > "$unit"
echo -e "\n[Unit]" >> "$unit"
[[ -n $Description ]] && echo "Description=$Description" >> "$unit"
[[ $Description ]] && echo "Description=$Description" >> "$unit"
declare -p BindsToInterfaces &> /dev/null || BindsToInterfaces=$Interface
if (( ${#BindsToInterfaces[@]} )); then
: ${InterfaceRoot=sys/subsystem/net/devices/}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment