From 5e7becab2f678dfadbbf0d7633a6dba634f3d0a9 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Tue, 05 Aug 2014 15:05:03 -0400 Subject: Add network hook scripts --- (limited to 'ifupdown') 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 -- cgit v0.9.1