#! /bin/bash . /usr/lib/network/globals . "$SUBR_DIR/8021x" . "$SUBR_DIR/rfkill" AUTOWIFI="/usr/sbin/wpa_actiond -p /run/wpa_supplicant" ACTION_SCRIPT="/usr/lib/network/auto.action" if [[ $# != 2 || $1 != @(start|stop) ]]; then exit_error "Usage: netctl-auto [start|stop] " fi INTERFACE=$2 PIDFILE="$STATE_DIR/wpa_actiond_$INTERFACE.pid" PROFILE_FILE="$STATE_DIR/wpa_actiond_$INTERFACE.profile" shift 2 case $1 in start) if [[ -e "/run/wpa_supplicant_$INTERFACE.pid" ]]; then exit_error "The interface ($INTERFACE) is already in use" fi if [[ -x "$PROFILE_DIR/interfaces/$INTERFACE" ]]; then source "$PROFILE_DIR/interfaces/$INTERFACE" fi [[ $RFKill ]] && enable_rf "$INTERFACE" "$RFKill" || exit 1 WPA_CONF=$(wpa_make_config_file "$INTERFACE") list_profiles | while read -r profile; do report_notice "$profile" ( source "$PROFILE_DIR/$profile" is_yes "${ExcludeAuto:-no}"&& exit 1 : ${Security:=none} [[ $Interface != "$INTERFACE" ]] && exit 1 [[ $Connection != "wireless" ]] && exit 1 # Exclude wpa-config, the wpa_conf is 'complete' and doesn't fit in this scheme [[ $Security == "wpa-config" ]] && exit 1 printf "%s\n" "network={" "$(wpa_make_config_block)" "id_str=\"$profile\"" "}" >> "$WPA_CONF" ) done # Kill any lingering WPA supplicants WPAConfigFile= wpa_stop "$INTERFACE" &> /dev/null # Start the WPA supplicant : ${WPADriver:=nl80211,wext} WPAOptions+=" -W" if wpa_start "$INTERFACE" "$WPADriver" "$WPA_CONF"; then if $AUTOWIFI -i "$INTERFACE" -P "$PIDFILE" -a "$ACTION_SCRIPT" "$@"; then exit 0 fi fi exit 1 ;; stop) if [[ -e $PROFILE_FILE ]]; then "$SUBR_DIR/network" stop "$(< "$PROFILE_FILE")" && rm -f "$PROFILE_FILE" else if [[ -x "$PROFILE_DIR/interfaces/$INTERFACE" ]]; then source "$PROFILE_DIR/interfaces/$INTERFACE" fi wpa_stop "$INTERFACE" ip link set dev "$INTERFACE" down [[ $RFKill ]] && disable_rf "$INTERFACE" "$RFKill" fi timeout_wait 1 '[[ ! -f "$PIDFILE" ]]' || kill "$(< "$PIDFILE")" ;; esac # vim: ft=sh ts=4 et sw=4: