summaryrefslogtreecommitdiffstats
path: root/src-wireless/netcfg-auto-wireless
blob: 50d49be61aa4e911982d785e8b50d5e9c60e9151 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#! /bin/bash
# Originally contributed by Neuro: http://bbs.archlinux.org/viewtopic.php?pid=278148#p278148

. /usr/lib/network/network
. /usr/lib/network/wireless

# wifi_auto
#   autoconnect wireless interface
#   $1 - wireless interface
wifi_auto()
{
    interface=$1; 
    report_try "Scanning for networks"

    ifconfig $interface up
    networks="$(list_networks $interface)"

    if [[ ! "$networks" ]]; then
        exit_fail "- No networks available."
    fi

    # Loop through all the found essid's, then find a matching profile.
    while read essid; do
	for network in $(list_profiles); do
            load_profile $network
            case "$CONNECTION" in
                wireless-old|wireless|wireless-dbus)
                    if [[ "$essid" = "$ESSID" && "$interface" = "$INTERFACE" ]]; then
                        found=$network
                    fi
                    ;;
            esac
        done
    done < $networks
    
    if [[ "$found" ]]; then
        netcfg $found
	exit $?
    fi
    
    exit_fail "- No profiles matched the found networks"
}

if [[ $(id -u) -ne 0 ]]; then
    exit_stderr "This script needs to be run with root privileges"
fi
if [[ -z $1 ]]; then
    exit_stderr "Please supply an interface to connect"
fi
wifi_auto $1