From patchwork Fri Mar 3 18:23:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via arch-projects X-Patchwork-Id: 53 Return-Path: Delivered-To: patchwork@archlinux.org Received: from nymeria.archlinux.org by nymeria.archlinux.org (Dovecot) with LMTP id pQwIDMq0uVj2JAAAtiB/HQ for ; Fri, 03 Mar 2017 19:24:10 +0100 Received: from nymeria.archlinux.org (localhost.localdomain [127.0.0.1]) by nymeria.archlinux.org (Postfix) with ESMTP id CEFA240916; Fri, 3 Mar 2017 19:24:08 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on nymeria.archlinux.org X-Spam-Level: X-Spam-Status: No, score=-4.3 required=2.5 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_MED shortcircuit=no autolearn=unavailable autolearn_force=no version=3.4.1 Received: from luna.archlinux.org (luna.archlinux.org [IPv6:2a01:4f8:160:3033::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by nymeria.archlinux.org (Postfix) with ESMTPS; Fri, 3 Mar 2017 19:24:08 +0100 (CET) Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 695132CCB4; Fri, 3 Mar 2017 18:24:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=luna2; t=1488565448; bh=glxjU+Ggw3JDXgQIj6S7Au1g+EB/SKFLacFk9hMCseM=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc; b=ZeERaMc6ri0k3X5P3C5V5BuCM5JCBvIaN/jhcvQRBgNMfye91pz5WKmR88/IAs2HE 4MgtS2O9fXw8lsJpqk1dRtRsqLI6ZvN5ka4vfVeqpUe2GwwF+a9NmUotxea/moD8zw nP40wfhckBUu+rbRcIqoWnD3AZhKBzX5nkDQoPV3cNnOAiISOwOMUY836CYYJzsAnc sTUBDQ4ONqo42DnwtpKhszgmDpsPZ095+mAnGVj3FbtIcsbPxvfm1lpG7M6bxPksZg F3JPHknv9VAkUEhFHd8EgU4irpOScM5MmvP/nam84k7V5D82E9jpXwdtrF1GyMI0po Qwn9zIsWYCndkXH2VHf/yibaTtvrrYx8SAN3C0nLzarIfz9QtnMNDC8caR4e5ZyIHd IotkDAzcXgics7zqU1lcjxxbDUIAGQ96ygNja3FYnZuBpoDsmaCssnWzNeEW42nKGc uIn2EZ6VAlL711HgpBy0C2YLNw1xJXqP5sF53GyAqzEPBUPIfceq2fqeRUAC6AIL7g 6qpS4iGq6b+CoDAbhLyf2uNLD1rinYJhP2So5Wor2CUbMPQNLXYiKwyB49WUWfyjBF BHr9i7LufsbU79axh6X6febiFiQNk6Ffat0Qj5Cf6yiVzhVEJJOTTeLZtCaUpxH3O7 4spqdWSjHsJ43ioy2n/xDByw= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 863EC2CCA3 for ; Fri, 3 Mar 2017 18:24:05 +0000 (UTC) Received: from nymeria.archlinux.org (nymeria.archlinux.org [IPv6:2a00:1828:2000:547::2]) by luna.archlinux.org (Postfix) with ESMTPS for ; Fri, 3 Mar 2017 18:24:05 +0000 (UTC) Received: from nymeria.archlinux.org (localhost.localdomain [127.0.0.1]) by nymeria.archlinux.org (Postfix) with ESMTP id 1F45E408DD for ; Fri, 3 Mar 2017 19:24:03 +0100 (CET) Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by nymeria.archlinux.org (Postfix) with ESMTPS for ; Fri, 3 Mar 2017 19:24:02 +0100 (CET) Received: by mail-wm0-x242.google.com with SMTP id m70so4372944wma.1 for ; Fri, 03 Mar 2017 10:24:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=PDd4+HhycmOL6WHrM+JIX0zAagdwwFk1qLkLpw7HvfU=; b=TqByiQFq3RRcXy5NRRVwKuf/eUpIDIdT9/3cyYyGF9AFkbcNf9o71/IGlC6K4QSBYP MxKXX6Tr5hjbetVKKPmqejnk43HJbzvL6+GFDKsSx/65C2Vl5P8plAVFEpoFLeu9yfbR QQDhEgIC6fUT1a5Bw3B5Mocd5zInaetD9F4J7SqmQbY2RU4clUFATP1306FSxiiaZ2b8 L/eC2TksAB430JKAJeHciVdiIO6BrQX7WCDumaqXeElwkZFFgSTYwtw5fCEisTjR1f10 zfuBjPNi9kr71OJaepVxwnOOVgBKfF73kI+K78Wv7rmdU7/eDrjUjeNl2hK5PMliFxTm 60lw== X-Gm-Message-State: AMke39k0XvcuLDatVDjnxvui6SFCwELQwskawsdqPkSCTTGqh6VcftKQD1OV6ScG0b20hQ== X-Received: by 10.28.196.68 with SMTP id u65mr4076996wmf.8.1488565441754; Fri, 03 Mar 2017 10:24:01 -0800 (PST) Received: from Mindship-03 (ip5653397a.direct-adsl.nl. [86.83.57.122]) by smtp.gmail.com with ESMTPSA id 10sm16127551wrw.13.2017.03.03.10.24.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Mar 2017 10:24:00 -0800 (PST) Date: Fri, 3 Mar 2017 19:23:54 +0100 To: arch-projects@archlinux.org Message-ID: <20170303182354.GA5475@Mindship-03> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.8.0 (2017-02-23) Subject: [arch-projects] [netctl][PATCH 1/3] Minor code streamlining X-BeenThere: arch-projects@archlinux.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Arch Linux projects development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Jouke Witteveen via arch-projects Reply-To: Arch Linux projects development discussion Cc: Jouke Witteveen Errors-To: arch-projects-bounces@archlinux.org Sender: "arch-projects" X-UID: 126 Status: X-Keywords: Content-Length: 8856 --- src/ifplugd.action | 2 +- src/lib/connections/mobile_ppp | 4 ++-- src/lib/connections/pppoe | 4 ++-- src/lib/dhcp/dhclient | 4 ++-- src/lib/dhcp/dhcpcd | 4 ++-- src/lib/wpa | 25 +++++++++++++------------ src/netctl-auto | 9 ++++++--- src/netctl.in | 2 +- 8 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/ifplugd.action b/src/ifplugd.action index 42d1c5a..a1c8dee 100755 --- a/src/ifplugd.action +++ b/src/ifplugd.action @@ -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) diff --git a/src/lib/connections/mobile_ppp b/src/lib/connections/mobile_ppp index 0890373..11cb41e 100644 --- a/src/lib/connections/mobile_ppp +++ b/src/lib/connections/mobile_ppp @@ -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 diff --git a/src/lib/connections/pppoe b/src/lib/connections/pppoe index 15e4db5..96cda80 100644 --- a/src/lib/connections/pppoe +++ b/src/lib/connections/pppoe @@ -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 diff --git a/src/lib/dhcp/dhclient b/src/lib/dhcp/dhclient index 87e9a92..397adda 100644 --- a/src/lib/dhcp/dhclient +++ b/src/lib/dhcp/dhclient @@ -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 } diff --git a/src/lib/dhcp/dhcpcd b/src/lib/dhcp/dhcpcd index c88047f..ef1245d 100644 --- a/src/lib/dhcp/dhcpcd +++ b/src/lib/dhcp/dhcpcd @@ -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 } diff --git a/src/lib/wpa b/src/lib/wpa index b61f93b..e7d873d 100644 --- a/src/lib/wpa +++ b/src/lib/wpa @@ -64,29 +64,29 @@ 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 config_file=$3 + local pidfile="/run/wpa_supplicant-$interface.pid" if ! type wpa_supplicant &> /dev/null; then report_error "You need to install 'wpa_supplicant'" return 127 fi - if [[ $configuration ]]; then - configuration="-c$configuration" + if [[ $config_file ]]; then + config_file="-c$config_file" else WPA_CTRL_DIR="/run/wpa_supplicant" - configuration="-C$WPA_CTRL_DIR" + config_file="-C$WPA_CTRL_DIR" fi do_debug wpa_supplicant -q -B -P "$pidfile" -i "$interface" -D "$driver" \ - "$configuration" $WPAOptions >&2 + "$config_file" $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" - [[ -f $configuration && -O $configuration ]] && rm -f "$configuration" + config_file="$STATE_DIR/wpa_supplicant-$interface.conf" + [[ -f $config_file && -O $config_file ]] && rm -f "$config_file" return 1 fi } @@ -94,7 +94,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 +108,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 } @@ -192,7 +193,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" diff --git a/src/netctl-auto b/src/netctl-auto index b25d258..f78efe3 100755 --- a/src/netctl-auto +++ b/src/netctl-auto @@ -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: diff --git a/src/netctl.in b/src/netctl.in index ea1c9aa..37c095c 100644 --- a/src/netctl.in +++ b/src/netctl.in @@ -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/} From patchwork Fri Mar 3 18:24:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via arch-projects X-Patchwork-Id: 54 Return-Path: Delivered-To: patchwork@archlinux.org Received: from nymeria.archlinux.org by nymeria.archlinux.org (Dovecot) with LMTP id KdTXNee0uVjzJAAAtiB/HQ for ; Fri, 03 Mar 2017 19:24:39 +0100 Received: from nymeria.archlinux.org (localhost.localdomain [127.0.0.1]) by nymeria.archlinux.org (Postfix) with ESMTP id C879540924; Fri, 3 Mar 2017 19:24:38 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on nymeria.archlinux.org X-Spam-Level: X-Spam-Status: No, score=-4.3 required=2.5 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_MED shortcircuit=no autolearn=unavailable autolearn_force=no version=3.4.1 Received: from luna.archlinux.org (luna.archlinux.org [5.9.250.164]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by nymeria.archlinux.org (Postfix) with ESMTPS; Fri, 3 Mar 2017 19:24:38 +0100 (CET) Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 7D3812CCC0; Fri, 3 Mar 2017 18:24:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=luna2; t=1488565478; bh=qX77fV5PldrO9w1Cqzvo+VnX/c8+FXtFrV3wysF97Qw=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc; b=kxQCDU5xxTm/db2lcFcDz/bSq8R/eeOtiHgKP6TfGlC5qBGX/yf2e4h4GDSzLCWit x4gJv/rbno/CjVKolOXrc4/fL+EaowoojQ3TygYdoIHlvl7Fb2xfJPo7iz/UPTjONw 04R6J0Ax/lyNEtA1IyCTWGQw2V1ByPF8ntsBM5mTiyE8Snd+0IqkEi83yaWy2WRYNB laFsh4IOZ0D6if6W94W0CFEONbozkBBHNLvN65cMTEAq5yNPP4ITM4xuD3PfDlNbzU w8J8nG3e0TXJiEmSZJLZ+bP/QP0l2d3Si/UIP51Pyu/1VslUwvIX9rWrNxreAy8zhN E5fTyq2HvFMPe2ER3FkK7fJR9kIvJ/UUfyLIvgyrpnTEKfKbCEhfcPvBosDUnlSQ6H eGLQnYiCONNNf3vkHugbMfjh9nz5bfcZUu7DyiOFlMnHHB7PMrfHuSSBpLUpiqRnwQ Q7Ji1ptaDYeLd9dAWS8aSs7WWI0sqy9Ybwavv55+aq79wHR3BaPMT4+sv6wnj2x/Oe RnNBjFb4+ffFJ4DZ0epPaGclMnQwkMlk42f8EU+GcMMpOLHsn2FR1QJkEIugl1vFrc hxhXLAShvfXZcemJfhixR64CnTd+D2rVPy7qtWUlkhpcrXXrNl1Of1h+hGzNbLlxWA riBiiYztCSEuECQXi8L6HmZc= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 3AEC62CCBD for ; Fri, 3 Mar 2017 18:24:35 +0000 (UTC) Received: from nymeria.archlinux.org (nymeria.archlinux.org [IPv6:2a00:1828:2000:547::2]) by luna.archlinux.org (Postfix) with ESMTPS for ; Fri, 3 Mar 2017 18:24:35 +0000 (UTC) Received: from nymeria.archlinux.org (localhost.localdomain [127.0.0.1]) by nymeria.archlinux.org (Postfix) with ESMTP id A121A40918 for ; Fri, 3 Mar 2017 19:24:33 +0100 (CET) Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by nymeria.archlinux.org (Postfix) with ESMTPS for ; Fri, 3 Mar 2017 19:24:33 +0100 (CET) Received: by mail-wm0-x242.google.com with SMTP id v190so4376665wme.3 for ; Fri, 03 Mar 2017 10:24:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=BB660sD5Xd6fBZNt5+6nc9/0hPN8nuQIHg5OeQg/sD8=; b=eHXvPledixikZ+w2+0S59lsE87nUzmqiSKixF65bKAIdxoqk8ioPjy1OqcHt+hvmj5 DlA8GCSnRyUr80amw1axbb6/3f3EUOga27Aqpc4UIhCbYQQiR2agnxU/QhC3XjLleUwE /qwF8EPwddA7oyKnqdBIrGk0Z4XvnhgRaZm3LrKf0/5LPKoVR+AzhjVD/BL74ubkRSwp YOElzGD6g6xYBs2+C1meIh2GG5UubVLVZDFOog8koVNkoXV628odNXnjSzgRIBekgQXB SnsexbSC5HTCmZ1kRx2F4l5oqAjivb5lf+zMQ3YjZPm+dt7b1Y52/BGhPOshcm/KNd5B PIPg== X-Gm-Message-State: AMke39ksJ2eAt/SZlpv6H4mG0Mxzx9qtve89IE13lWJQDJV2ezTeUlLLUDag+Sx6eGVc0Q== X-Received: by 10.28.109.147 with SMTP id b19mr4353696wmi.69.1488565472670; Fri, 03 Mar 2017 10:24:32 -0800 (PST) Received: from Mindship-03 (ip5653397a.direct-adsl.nl. [86.83.57.122]) by smtp.gmail.com with ESMTPSA id j74sm1072935wrj.21.2017.03.03.10.24.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Mar 2017 10:24:32 -0800 (PST) Date: Fri, 3 Mar 2017 19:24:27 +0100 To: arch-projects@archlinux.org Message-ID: <20170303182411.GA5486@Mindship-03> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.8.0 (2017-02-23) Subject: [arch-projects] [netctl][PATCH 2/3] Move from /usr/lib/network to /usr/lib/netctl X-BeenThere: arch-projects@archlinux.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Arch Linux projects development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Jouke Witteveen via arch-projects Reply-To: Arch Linux projects development discussion Cc: Jouke Witteveen Errors-To: arch-projects-bounces@archlinux.org Sender: "arch-projects" X-UID: 127 Status: X-Keywords: Content-Length: 7663 --- Makefile | 10 +++++----- services/netctl-wait-online.service | 2 +- services/netctl@.service | 4 ++-- src/ifplugd.action | 2 +- src/lib/auto.action | 2 +- src/lib/connections/README | 8 ++++---- src/lib/dhcp/README | 8 ++++---- src/lib/globals | 4 ++-- src/lib/ip | 2 +- src/lib/network | 2 +- src/lib/rfkill | 2 +- src/lib/wpa | 2 +- src/netctl-auto | 2 +- src/netctl.in | 2 +- src/wifi-menu | 2 +- 15 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 157ecfd..e9f7fa8 100644 --- a/Makefile +++ b/Makefile @@ -15,11 +15,11 @@ install: install -d $(DESTDIR)/etc/netctl/{examples,hooks,interfaces} install -m644 docs/examples/* $(DESTDIR)/etc/netctl/examples/ # Libs - install -d $(DESTDIR)/usr/lib/network/{connections,dhcp} - install -m644 src/lib/{globals,ip,rfkill,wpa} $(DESTDIR)/usr/lib/network/ - install -m644 src/lib/connections/* $(DESTDIR)/usr/lib/network/connections/ - install -m644 src/lib/dhcp/* $(DESTDIR)/usr/lib/network/dhcp/ - install -m755 src/lib/{auto.action,network} $(DESTDIR)/usr/lib/network/ + install -d $(DESTDIR)/usr/lib/netctl/{connections,dhcp} + install -m644 src/lib/{globals,ip,rfkill,wpa} $(DESTDIR)/usr/lib/netctl/ + install -m644 src/lib/connections/* $(DESTDIR)/usr/lib/netctl/connections/ + install -m644 src/lib/dhcp/* $(DESTDIR)/usr/lib/netctl/dhcp/ + install -m755 src/lib/{auto.action,network} $(DESTDIR)/usr/lib/netctl/ # Scripts install -d $(DESTDIR)/usr/bin sed -e "s|@systemdsystemconfdir@|$(systemdsystemconfdir)|g" \ diff --git a/services/netctl-wait-online.service b/services/netctl-wait-online.service index 64ca06d..86329aa 100644 --- a/services/netctl-wait-online.service +++ b/services/netctl-wait-online.service @@ -7,7 +7,7 @@ Before=network-online.target [Service] Type=oneshot RemainAfterExit=yes -ExecStart=/usr/lib/network/network wait-online +ExecStart=/usr/lib/netctl/network wait-online [Install] WantedBy=network-online.target diff --git a/services/netctl@.service b/services/netctl@.service index 3bb4129..77415d8 100644 --- a/services/netctl@.service +++ b/services/netctl@.service @@ -9,5 +9,5 @@ Wants=network.target Type=notify NotifyAccess=exec RemainAfterExit=yes -ExecStart=/usr/lib/network/network start %I -ExecStop=/usr/lib/network/network stop %I +ExecStart=/usr/lib/netctl/network start %I +ExecStop=/usr/lib/netctl/network stop %I diff --git a/src/ifplugd.action b/src/ifplugd.action index a1c8dee..fa0321e 100755 --- a/src/ifplugd.action +++ b/src/ifplugd.action @@ -2,7 +2,7 @@ # # ifplugd.action script for netctl -. /usr/lib/network/globals +. /usr/lib/netctl/globals PROFILE_FILE="$STATE_DIR/ifplugd-$1.profile" diff --git a/src/lib/auto.action b/src/lib/auto.action index 5b770c2..66d13b0 100755 --- a/src/lib/auto.action +++ b/src/lib/auto.action @@ -1,6 +1,6 @@ #! /bin/bash -. /usr/lib/network/globals +. /usr/lib/netctl/globals . "$SUBR_DIR/ip" export INTERFACE="$1" diff --git a/src/lib/connections/README b/src/lib/connections/README index 2dd4b7b..10282fe 100644 --- a/src/lib/connections/README +++ b/src/lib/connections/README @@ -1,11 +1,11 @@ Support for connection types is implemented by connection files in - /usr/lib/network/connections/ + /usr/lib/netctl/connections/ The file name determines the name of the connection type, so support for the aviancarrier connection type will be provided by the file: - /usr/lib/network/connections/aviancarrier + /usr/lib/netctl/connections/aviancarrier Files that implement support for a connection type should NOT be executable. Such files should contain valid Bash code, among which two @@ -20,8 +20,8 @@ respectively. When the functions are called, three bash files are already sourced, so all functions and variables in those files are available. The readily sourced files are: - /usr/lib/network/network - /usr/lib/network/globals + /usr/lib/netctl/network + /usr/lib/netctl/globals /etc/netctl/ Here, is the profile file specifying the desired network diff --git a/src/lib/dhcp/README b/src/lib/dhcp/README index df17d5a..87a0669 100644 --- a/src/lib/dhcp/README +++ b/src/lib/dhcp/README @@ -1,11 +1,11 @@ Support for dhcp clients is implemented by files in - /usr/lib/network/dhcp/ + /usr/lib/netctl/dhcp/ The file name determines the name of the client for the profile, so support for a client named dhcpcd is provided by the file: - /usr/lib/network/dhcp/dhcpcd + /usr/lib/netctl/dhcp/dhcpcd Files that implement support for a connection type should NOT be executable. Such files should contain valid Bash code, among which two @@ -20,8 +20,8 @@ client. When the functions are called, three bash files are already sourced, so all functions and variables in those files are available. The readily sourced files are: - /usr/lib/network/network - /usr/lib/network/globals + /usr/lib/netctl/network + /usr/lib/netctl/globals /etc/netctl/ Here, is the profile file specifying the desired network diff --git a/src/lib/globals b/src/lib/globals index f4e64a3..ac3ae66 100644 --- a/src/lib/globals +++ b/src/lib/globals @@ -1,7 +1,7 @@ NETCTL_VERSION="notpackaged" PROFILE_DIR="/etc/netctl" -SUBR_DIR="/usr/lib/network" -STATE_DIR="/run/network" +SUBR_DIR="/usr/lib/netctl" +STATE_DIR="/run/netctl" STATE_FILE="${NETCTL_STATE_FILE:-/var/lib/netctl/netctl.state}" diff --git a/src/lib/ip b/src/lib/ip index 71c7fa2..47253e4 100644 --- a/src/lib/ip +++ b/src/lib/ip @@ -1,4 +1,4 @@ -## /usr/lib/network/globals needs to be sourced before this file +## /usr/lib/netctl/globals needs to be sourced before this file ## Interface a DHCP client diff --git a/src/lib/network b/src/lib/network index 81a4234..e068bc8 100755 --- a/src/lib/network +++ b/src/lib/network @@ -1,6 +1,6 @@ #! /bin/bash -. /usr/lib/network/globals +. /usr/lib/netctl/globals ## Check if a string represents a network interface diff --git a/src/lib/rfkill b/src/lib/rfkill index 05c1382..959ff28 100644 --- a/src/lib/rfkill +++ b/src/lib/rfkill @@ -1,4 +1,4 @@ -## /usr/lib/network/globals needs to be sourced before this file +## /usr/lib/netctl/globals needs to be sourced before this file ## Determine the system interface of an rfkill device diff --git a/src/lib/wpa b/src/lib/wpa index e7d873d..b696229 100644 --- a/src/lib/wpa +++ b/src/lib/wpa @@ -1,4 +1,4 @@ -## /usr/lib/network/globals needs to be sourced before this file +## /usr/lib/netctl/globals needs to be sourced before this file ## Wrapper around wpa_cli to deal with supplicant configurations that set a diff --git a/src/netctl-auto b/src/netctl-auto index f78efe3..ff017b0 100755 --- a/src/netctl-auto +++ b/src/netctl-auto @@ -1,7 +1,7 @@ #! /bin/bash # Contributed by: Sebastian Wicki -. /usr/lib/network/globals +. /usr/lib/netctl/globals . "$SUBR_DIR/wpa" . "$SUBR_DIR/rfkill" diff --git a/src/netctl.in b/src/netctl.in index 37c095c..f5c5459 100644 --- a/src/netctl.in +++ b/src/netctl.in @@ -1,6 +1,6 @@ #! /bin/bash -. /usr/lib/network/globals +. /usr/lib/netctl/globals usage() { diff --git a/src/wifi-menu b/src/wifi-menu index c13c35b..bafefc4 100755 --- a/src/wifi-menu +++ b/src/wifi-menu @@ -1,6 +1,6 @@ #! /bin/bash -. /usr/lib/network/globals +. /usr/lib/netctl/globals . "$SUBR_DIR/wpa" . "$SUBR_DIR/rfkill" From patchwork Fri Mar 3 18:24:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via arch-projects X-Patchwork-Id: 55 Return-Path: Delivered-To: patchwork@archlinux.org Received: from nymeria.archlinux.org by nymeria.archlinux.org (Dovecot) with LMTP id +eLUHfG0uVjsJAAAtiB/HQ for ; Fri, 03 Mar 2017 19:24:49 +0100 Received: from nymeria.archlinux.org (localhost.localdomain [127.0.0.1]) by nymeria.archlinux.org (Postfix) with ESMTP id 690D640924; Fri, 3 Mar 2017 19:24:48 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on nymeria.archlinux.org X-Spam-Level: X-Spam-Status: No, score=-4.3 required=2.5 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_MED shortcircuit=no autolearn=unavailable autolearn_force=no version=3.4.1 Received: from luna.archlinux.org (luna.archlinux.org [IPv6:2a01:4f8:160:3033::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by nymeria.archlinux.org (Postfix) with ESMTPS; Fri, 3 Mar 2017 19:24:48 +0100 (CET) Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 2467E2CCCE; Fri, 3 Mar 2017 18:24:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=luna2; t=1488565488; bh=mv9yr6zfIfLaoOCLQuCDdoJitVUgjuVNdhO148ARYRY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc; b=Ek4nKh+bMBULSgQYVdCY0+kBES8qCXxkMoi9AT8vHCelWHB9ak+qyF6mSAjowlEtp PC3RtkzuYkvW8t7XWlfo7UjjvXQF1jIRFj3D+rBV1ExfqF522YR8j8R3EL+MbN1VDK CRWNPNWYyarwWQAMPvwpAaVuCQPL4DAL8tdMNJb5JL7CXcY8pMs0JeyZe4b4EndpwR SihyJh1sYwzgaPsAFaUxAXgtn6hl0WIoMz8iUiXVLIARyiLvYvAk399+FwOIrUarh+ KhSAwq5kalcrq0MfyZ/Hl7RzLHCEiaF7CGbL9xCPmsvwLlNORjZOtY/VtwyrYF9n0l m1Qu5tBGHcsfHwc8zIeL1uaugZKyxmnWBPgGEJcE7tCxSWLLLzttJpaPaCCxqblLZZ 8hKzZLqxvIYYCH9wKjfK25CmHTr/JF5tnkhmwC2/jJX7QPLJ4muj+BEw8RKQMLgeFx DcNn0vtQ9P6G2Z2qG0T2vBJJAhAHYi5OaXxXTRMGL8go/Wa2qoEw7yhMqvNJ5LEO0l 9JpEwFAeGJA8Hpw+Is/8uR+SszRed+uDBasEKJ256joR34pbm7toazYXtPutKXHgSZ mmxV//CZ0ZpOm1NR8m0MN1alkvtjbkcIx9AELjbxX5N/7+awNbjglwLb6ckLvAW/rg CtSUhpDtazRAg5Keoxvv6ONM= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 7E8C32CCBD for ; Fri, 3 Mar 2017 18:24:46 +0000 (UTC) Received: from nymeria.archlinux.org (nymeria.archlinux.org [IPv6:2a00:1828:2000:547::2]) by luna.archlinux.org (Postfix) with ESMTPS for ; Fri, 3 Mar 2017 18:24:46 +0000 (UTC) Received: from nymeria.archlinux.org (localhost.localdomain [127.0.0.1]) by nymeria.archlinux.org (Postfix) with ESMTP id 002A74091E for ; Fri, 3 Mar 2017 19:24:45 +0100 (CET) Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by nymeria.archlinux.org (Postfix) with ESMTPS for ; Fri, 3 Mar 2017 19:24:44 +0100 (CET) Received: by mail-wm0-x242.google.com with SMTP id m70so4375462wma.1 for ; Fri, 03 Mar 2017 10:24:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=25ZEFAVO3VEThdZusgfIh6A2MJc0jkostKLZKzVP/3U=; b=UkNTDo8TJrLSk+Xz0ecj2jKwyRP/RE2j+0nugHwt+I68Rp231/y72BN4FwV/lELteo BNN2w2xi51r/AUDYlx+g9dsVXarvrYwNpVu2hgXWN70vsPfYmARXHIpA5zYe3rQ68i4z w7uus8H9RGw+XCgwICcDPaZ6T9GWnYSqKyr7mAZvm6WLqeKtVF1tiuRcWNJAfw3WX7VZ lL529C+JlQ4IJvbyFs2TvP0sxLIEvk1FfDXsv6Y65pATq/nlTKwmcFgrz87Q3kb8zJz/ qhN6Mz+vLqCPQgqBBriEpXfIjhewi/JSTPFXhFz36mMv0EQ1H35NgpcFeAwra5ZZqbDb /RMQ== X-Gm-Message-State: AMke39mqDu5qZ5q/TDjOgAfYcpbnHVYwOvBy3V2v11J13z+loMz64MVcDwlA8Ad8EbpbSA== X-Received: by 10.28.29.138 with SMTP id d132mr4075050wmd.40.1488565483917; Fri, 03 Mar 2017 10:24:43 -0800 (PST) Received: from Mindship-03 (ip5653397a.direct-adsl.nl. [86.83.57.122]) by smtp.gmail.com with ESMTPSA id m139sm7029307wma.2.2017.03.03.10.24.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Mar 2017 10:24:43 -0800 (PST) Date: Fri, 3 Mar 2017 19:24:37 +0100 To: arch-projects@archlinux.org Message-ID: <20170303182437.GA5498@Mindship-03> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.8.0 (2017-02-23) Subject: [arch-projects] [netctl][PATCH 3/3] Factor out network interface utilities X-BeenThere: arch-projects@archlinux.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Arch Linux projects development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Jouke Witteveen via arch-projects Reply-To: Arch Linux projects development discussion Cc: Jouke Witteveen Errors-To: arch-projects-bounces@archlinux.org Sender: "arch-projects" X-UID: 128 Status: X-Keywords: Content-Length: 10057 --- Makefile | 2 +- src/lib/auto.action | 2 ++ src/lib/connections/README | 1 + src/lib/dhcp/README | 1 + src/lib/globals | 5 +--- src/lib/interface | 65 ++++++++++++++++++++++++++++++++++++++++++++++ src/lib/network | 55 ++------------------------------------- src/netctl-auto | 17 +++++------- src/wifi-menu | 12 ++++----- 9 files changed, 85 insertions(+), 75 deletions(-) create mode 100644 src/lib/interface diff --git a/Makefile b/Makefile index e9f7fa8..34d3956 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ install: install -m644 docs/examples/* $(DESTDIR)/etc/netctl/examples/ # Libs install -d $(DESTDIR)/usr/lib/netctl/{connections,dhcp} - install -m644 src/lib/{globals,ip,rfkill,wpa} $(DESTDIR)/usr/lib/netctl/ + install -m644 src/lib/{globals,interface,ip,rfkill,wpa} $(DESTDIR)/usr/lib/netctl/ install -m644 src/lib/connections/* $(DESTDIR)/usr/lib/netctl/connections/ install -m644 src/lib/dhcp/* $(DESTDIR)/usr/lib/netctl/dhcp/ install -m755 src/lib/{auto.action,network} $(DESTDIR)/usr/lib/netctl/ diff --git a/src/lib/auto.action b/src/lib/auto.action index 66d13b0..31e089f 100755 --- a/src/lib/auto.action +++ b/src/lib/auto.action @@ -1,6 +1,7 @@ #! /bin/bash . /usr/lib/netctl/globals +. "$SUBR_DIR/interface" . "$SUBR_DIR/ip" export INTERFACE="$1" @@ -10,6 +11,7 @@ Profile="$3" export ACTION="$4" load_profile "$Profile" +load_interface_config "$INTERFACE" case $ACTION in CONNECT) diff --git a/src/lib/connections/README b/src/lib/connections/README index 10282fe..eb2c29f 100644 --- a/src/lib/connections/README +++ b/src/lib/connections/README @@ -22,6 +22,7 @@ available. The readily sourced files are: /usr/lib/netctl/network /usr/lib/netctl/globals + /usr/lib/netctl/interface /etc/netctl/ Here, is the profile file specifying the desired network diff --git a/src/lib/dhcp/README b/src/lib/dhcp/README index 87a0669..e231b46 100644 --- a/src/lib/dhcp/README +++ b/src/lib/dhcp/README @@ -22,6 +22,7 @@ The readily sourced files are: /usr/lib/netctl/network /usr/lib/netctl/globals + /usr/lib/netctl/interface /etc/netctl/ Here, is the profile file specifying the desired network diff --git a/src/lib/globals b/src/lib/globals index ac3ae66..3caae2f 100644 --- a/src/lib/globals +++ b/src/lib/globals @@ -109,7 +109,7 @@ list_profiles() { find -L "$PROFILE_DIR/" -maxdepth 1 -type f -not -name '.*' -not -name '*~' -not -name $'*\n*' -not -name '*.action' -not -name '*.conf' -not -name '*.service' -printf "%f\n" } -## Sources all hooks, a profile and any interface hook +## Sources all hooks and a profile (but no interface configuration) # $1: profile name load_profile() { local hook @@ -126,9 +126,6 @@ load_profile() { if [[ ! -r "${Connection:+$SUBR_DIR/connections/$Connection}" ]]; then exit_error "Profile '$1' does not specify a valid connection" fi - if [[ -x "$PROFILE_DIR/interfaces/$Interface" ]]; then - source "$PROFILE_DIR/interfaces/$Interface" - fi source "$SUBR_DIR/connections/$Connection" } diff --git a/src/lib/interface b/src/lib/interface new file mode 100644 index 0000000..2ebf81e --- /dev/null +++ b/src/lib/interface @@ -0,0 +1,65 @@ +## /usr/lib/netctl/globals needs to be sourced before this file + + +## Load interface configuration, if present +# $1: interface name +load_interface_config() { + local config_file="$PROFILE_DIR/interfaces/$1" + if [[ -x $config_file ]]; then + source "$config_file" + fi +} + +## Check if a string represents a network interface +# $1: potential interface name +is_interface() { + # Strip any old school alias specifier + [[ -d "/sys/class/net/${1%%:?*}" ]] +} + +## Add an interface +# $1: interface type +# $2: interface name +# $3: interface link (optional) +# $4...: additional arguments +interface_add() { + local type="$1" name="$2" link="$3" + do_debug ip link add ${link:+link "$link"} name "$name" type "$type" "${@:4}" $LinkOptions || return + load_interface_config "$name" +} + +## Delete an interface +# $1: interface name +interface_delete() { + bring_interface_down "$1" + ip link delete "$1" +} + +## Check if an interface is up +# $1: interface name +interface_is_up() { + local flags + read flags < "/sys/class/net/${1%%:?*}/flags" + # IFF_UP is defined as 0x1 in linux/if.h + (( flags & 0x1 )) +} + +## Activate an interface +# $1: interface name +bring_interface_up() { + local interface=$1 + ip link set dev "$interface" up &>/dev/null + timeout_wait "${TimeoutUp:-5}" 'interface_is_up "$interface"' +} + +## Deactivate an interface +# $1: interface name +bring_interface_down() { + local interface=$1 + ip link set dev "$interface" down &>/dev/null + # We reuse the up timeout (down normally is faster) + timeout_wait "${TimeoutUp:-5}" '! interface_is_up "$interface"' +} + + +# vim: ft=sh ts=4 et sw=4: diff --git a/src/lib/network b/src/lib/network index e068bc8..9c88c9c 100755 --- a/src/lib/network +++ b/src/lib/network @@ -1,61 +1,9 @@ #! /bin/bash . /usr/lib/netctl/globals +. "$SUBR_DIR/interface" -## Check if a string represents a network interface -# $1: potential interface name -is_interface() { - # Strip any old school alias specifier - [[ -d "/sys/class/net/${1%%:?*}" ]] -} - -## Add an interface -# $1: interface type -# $2: interface name -# $3: interface link (optional) -# $4...: additional arguments -interface_add() { - local type="$1" name="$2" link="$3" - do_debug ip link add ${link:+link "$link"} name "$name" type "$type" "${@:4}" $LinkOptions || return - if [[ -x "$PROFILE_DIR/interfaces/$name" ]]; then - source "$PROFILE_DIR/interfaces/$name" - fi -} - -## Delete an interface -# $1: interface name -interface_delete() { - bring_interface_down "$1" - ip link delete "$1" -} - -## Check if an interface is up -# $1: interface name -interface_is_up() { - local flags - read flags < "/sys/class/net/${1%%:?*}/flags" - # IFF_UP is defined as 0x1 in linux/if.h - (( flags & 0x1 )) -} - -## Activate an interface -# $1: interface name -bring_interface_up() { - local interface=$1 - ip link set dev "$interface" up &>/dev/null - timeout_wait "${TimeoutUp:-5}" 'interface_is_up "$interface"' -} - -## Deactivate an interface -# $1: interface name -bring_interface_down() { - local interface=$1 - ip link set dev "$interface" down &>/dev/null - # We reuse the up timeout (down normally is faster) - timeout_wait "${TimeoutUp:-5}" '! interface_is_up "$interface"' -} - ## Indicate that the network stack for the profile is up network_ready() { if ! is_yes "${WaitOnline:-no}" && ! is_yes "${NETWORK_READY:-no}"; then @@ -82,6 +30,7 @@ if [[ $# -eq 2 && $1 == @(start|stop) ]]; then # Expose the profile name Profile=$2 load_profile "$Profile" + load_interface_config "$Interface" elif [[ $# -ne 1 || $1 != "wait-online" ]]; then exit_error "Usage: $0 {start|stop|wait-online} [profile]" fi diff --git a/src/netctl-auto b/src/netctl-auto index ff017b0..f49273b 100755 --- a/src/netctl-auto +++ b/src/netctl-auto @@ -2,8 +2,9 @@ # Contributed by: Sebastian Wicki . /usr/lib/netctl/globals -. "$SUBR_DIR/wpa" +. "$SUBR_DIR/interface" . "$SUBR_DIR/rfkill" +. "$SUBR_DIR/wpa" : ${ACTIOND:=wpa_actiond -p /run/wpa_supplicant} : ${ACTION_SCRIPT:=$SUBR_DIR/auto.action} @@ -200,11 +201,8 @@ start() { local interface="$1" local pidfile="$STATE_DIR/wpa_actiond-$interface.pid" - if wpa_is_active "$interface"; then - exit_error "The interface ($interface) is already in use" - fi - if [[ -x "$PROFILE_DIR/interfaces/$interface" ]]; then - source "$PROFILE_DIR/interfaces/$interface" + if interface_is_up "$interface"; then + exit_error "The interface '$interface' is already up" fi if [[ $RFKill ]]; then rf_enable "$interface" "$RFKill" || return 1 @@ -240,6 +238,7 @@ start() { return 0 fi wpa_stop "$interface" + bring_interface_down "$interface" fi return 1 } @@ -251,11 +250,8 @@ stop() { local pidfile="$STATE_DIR/wpa_actiond-$interface.pid" [[ -e "$pidfile" ]] && kill "$(< "$pidfile")" - if [[ -x "$PROFILE_DIR/interfaces/$interface" ]]; then - source "$PROFILE_DIR/interfaces/$interface" - fi timeout_wait 1 '! wpa_is_active "$interface"' || wpa_stop "$interface" - ip link set dev "$interface" down + bring_interface_down "$interface" [[ $RFKill ]] && rf_disable "$interface" "$RFKill" return 0 } @@ -286,6 +282,7 @@ case $# in exit_error "Use 'systemctl $1 netctl-auto@$2' to $1 netctl-auto." fi ensure_root "$(basename "$0")" + load_interface_config "$2" "$1" "$2";; *) exit_error "$(usage)";; diff --git a/src/wifi-menu b/src/wifi-menu index bafefc4..65fddd6 100755 --- a/src/wifi-menu +++ b/src/wifi-menu @@ -1,8 +1,9 @@ #! /bin/bash . /usr/lib/netctl/globals -. "$SUBR_DIR/wpa" +. "$SUBR_DIR/interface" . "$SUBR_DIR/rfkill" +. "$SUBR_DIR/wpa" usage() { @@ -231,15 +232,12 @@ if [[ -z "$INTERFACE" ]]; then fi INTERFACE=${INTERFACE:15:-10} report_debug "Using interface '$INTERFACE'" +elif ! is_interface "$INTERFACE"; then + exit_error "No such interface: $INTERFACE" fi -if [[ -x "$PROFILE_DIR/interfaces/$INTERFACE" ]]; then - source "$PROFILE_DIR/interfaces/$INTERFACE" -fi +load_interface_config "$INTERFACE" cd / # We do not want to spawn anything that can block unmounting -if [[ ! -d "/sys/class/net/$INTERFACE" ]]; then - exit_error "No such interface: $INTERFACE" -fi if [[ "$RFKill" && "$(rf_status "$INTERFACE" "$RFKill")" ]]; then if ! rf_enable "$INTERFACE" "$RFKill"; then exit_error "Could not unblock transmission on interface '$INTERFACE'"