PageRenderTime 53ms CodeModel.GetById 50ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/wpa_supplicant/action_wpa.sh

http://github.com/brinkman83/bashrc
Shell | 76 lines | 43 code | 15 blank | 18 comment | 8 complexity | 1dcca5080e42ea56d7be96d71214f57b MD5 | raw file
 1#!/bin/sh
 2
 3# Action script to enable/disable wpa-roam interfaces in reaction to
 4# pm-action or ifplugd events.
 5#
 6# Copyright: Copyright (c) 2008-2009, Kel Modderman <kel@otaku42.de>
 7# License:   GPL-2
 8#
 9
10PATH=/sbin:/usr/sbin:/bin:/usr/bin
11
12if [ ! -x /sbin/wpa_action ]; then
13	exit 0
14fi
15
16SELF=action_wpa
17COMMAND=
18IFPLUGD_IFACE=
19
20# pm-action(8) - <action> <suspend method>
21#
22# On suspend|hibernate, disconnect any wpa-roam managed interfaces,
23# reconnect it on resume.
24
25case "${1}" in
26        suspend|hibernate)
27                COMMAND=disconnect
28                ;;
29        resume|thaw)
30                COMMAND=reconnect
31                ;;
32esac
33
34if [ -z "$COMMAND" ]; then
35	# ifplugd(8) - <iface> <action>
36	#
37	# If an ifplugd managed interface is brought up, disconnect any
38	# wpa-roam managed interfaces so that only one "roaming" interface
39	# remains active on the system.
40
41	IFPLUGD_IFACE="${1}"
42
43	case "${2}" in
44		up)
45			COMMAND=disconnect
46			;;
47		down)
48			COMMAND=reconnect
49			;;
50		*)
51			echo "${SELF}: unknown $0 arguments: ${@}" >&2
52			exit 1
53			;;
54        esac
55fi
56
57if [ -z "$COMMAND" ]; then
58	echo "${SELF}: unknown arguments: ${@}" >&2
59	exit 1
60fi
61
62for CTRL in /var/run/wpa_supplicant/*; do
63	[ -S "${CTRL}" ] || continue
64
65	IFACE="${CTRL#/var/run/wpa_supplicant/}"
66
67	wpa_action "${IFACE}" check || continue
68
69	if [ "${IFPLUGD_IFACE}" ] && [ "${IFPLUGD_IFACE}" = "${IFACE}" ]; then
70		# if ifplugd is managing this interface (not likely but..)
71		# do nothing
72		continue
73	fi
74
75	wpa_cli -i "${IFACE}" "${COMMAND}"
76done