summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2014-08-05 15:05:03 (EDT)
committer P. J. McDermott <pj@pehjota.net>2014-08-05 15:05:03 (EDT)
commit5e7becab2f678dfadbbf0d7633a6dba634f3d0a9 (patch)
tree1c4626e391b180c219b02e80296fc30cf07cf9d9
parente1f7888d31f6bbaa5844a4a494488d6e0169419e (diff)
Add network hook scripts
-rwxr-xr-xbuild4
-rwxr-xr-xifupdown/if-down10
-rwxr-xr-xifupdown/if-pre-up82
-rw-r--r--wpa-supplicant.pkg/files1
4 files changed, 97 insertions, 0 deletions
diff --git a/build b/build
index ec6f626..9951572 100755
--- a/build
+++ b/build
@@ -14,6 +14,10 @@ install: build
oh-autoinstall -B src/wpa_supplicant/ -- \
LIBDIR=/usr/lib/$(OPK_HOST_ARCH) \
BINDIR=/usr/sbin
+ set -e; for f in ../ifupdown/*; do \
+ install -d -m 0755 "dest/etc/network/$${f##*/}.d"; \
+ install -m 0755 "$${f}" "dest/etc/network/$${f##*/}.d/wpa"; \
+ done
oh-fixperms
oh-strip
oh-installfiles
diff --git a/ifupdown/if-down b/ifupdown/if-down
new file mode 100755
index 0000000..6915ade
--- /dev/null
+++ b/ifupdown/if-down
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+set -eu
+
+if [ "x${IFACE#wlan}" != "x${IFACE}" ]; then
+ if [ -f "/var/run/wpa_supplicant.${IFACE}.conf" ]; then
+ wpa_cli -p/var/run/wpa_supplicant -i${IFACE} terminate
+ rm "/var/run/wpa_supplicant.${IFACE}.conf"
+ fi
+fi
diff --git a/ifupdown/if-pre-up b/ifupdown/if-pre-up
new file mode 100755
index 0000000..97d091f
--- /dev/null
+++ b/ifupdown/if-pre-up
@@ -0,0 +1,82 @@
+#!/bin/sh
+
+set -eu
+
+get_iface_opts()
+{
+ local opts_start_cb="${1}"
+ local opt_cb="${2}"
+ local opts_end_cb="${3}"
+ local script=
+ local opts=
+ local opt=
+
+ script="$(printf '
+ /^iface[ \t][ \t]*%s/,/^[^ \t]/{
+ /^$/q;
+ s/^[ \t][ \t]*%s-//p;
+ }
+ ' "${IFACE}" "${0##*/}")"
+
+ opts="$(sed -n "${script}" /var/run/net-ifaces)"
+ if [ "x${opts}" = 'x' ]; then
+ return 0
+ fi
+
+ ${opts_start_cb}
+ while read -r opt; do
+ ${opt_cb} ${opt}
+ done <<-EOF
+ ${opts}
+ EOF
+ ${opts_end_cb}
+
+ return 0
+}
+
+wpa_opts_start_cb()
+{
+ exec 3>"/var/run/wpa_supplicant.${IFACE}.conf"
+ printf 'ctrl_interface=DIR=/var/run/wpa_supplicant\ncountry=US\n\n' >&3
+ printf 'network={\n' >&3
+}
+
+wpa_opt_cb()
+{
+ local field="${1}"
+ shift 1
+ local value="${*}"
+
+ field="$(printf '%s\n' "${field}" | tr '-' '_')"
+ case "${field}" in
+ ssid)
+ if printf '%s\n' "${value}" | grep -q '[^0-9A-Fa-f:]'
+ then
+ if [ "x${value#\"}" = "x${value}" ]; then
+ value="\"${value}\""
+ fi
+ fi
+ ;;
+ psk)
+ if printf '%s\n' "${value}" | grep -q '[^0-9A-Fa-f]'
+ then
+ if [ "x${value#\"}" = "x${value}" ]; then
+ value="\"${value}\""
+ fi
+ fi
+ ;;
+ esac
+ printf '\t%s=%s\n' "${field}" "${value}" >&3
+}
+
+wpa_opts_end_cb()
+{
+ printf '}\n' >&3
+ exec &3>-
+ wpa_supplicant -B -s -Dnl80211 -i"${IFACE}" \
+ -c"/var/run/wpa_supplicant.${IFACE}.conf"
+}
+
+if [ "x${IFACE#wlan}" != "x${IFACE}" ]; then
+ get_iface_opts wpa_opts_start_cb wpa_opt_cb wpa_opts_end
+fi
diff --git a/wpa-supplicant.pkg/files b/wpa-supplicant.pkg/files
index 73bbf01..cda6718 100644
--- a/wpa-supplicant.pkg/files
+++ b/wpa-supplicant.pkg/files
@@ -1 +1,2 @@
+/etc/network
/usr/sbin