<commit_before># Copyright 2007-2008 <NAME> <<EMAIL>>
# All rights reserved. Released under the 2-clause BSD license.

wpa_supplicant_depend()
{
	if [ -x /usr/sbin/wpa_supplicant ]; then
		program start /usr/sbin/wpa_supplicant
	else
		program start /sbin/wpa_supplicant
	fi
	after macnet plug
	before interface
	provide wireless

	# Prefer us over iwconfig
	after iwconfig
}

# Only set these functions if not set already
# IE, prefer to use iwconfig
if ! type _get_ssid >/dev/null 2>&1; then
_get_ssid()
{
	local timeout=5 ssid=

	while [ ${timeout} -gt 0 ]; do
		ssid=$(wpa_cli -i"${IFACE}" status | sed -n -e 's/^ssid=//p')
		if [ -n "${ssid}" ]; then
			echo "${ssid}"
			return 0
		fi
		sleep 1
		timeout=$((timeout - 1))
	done

	return 1
}

_get_ap_mac_address()
{
	wpa_cli -i"${IFACE}" status | sed -n -e 's/^bssid=\(.*\)$/\1/p' \
		| tr '[:lower:]' '[:upper:]'
}
fi

wpa_supplicant_pre_start()
{
	local opts= cfgfile= ctrl_dir= wireless=true
	local wpas=/usr/sbin/wpa_supplicant wpac=/usr/bin/wpa_cli
	local actfile=/etc/wpa_supplicant/wpa_cli.sh

	if [ ! -x "${wpas}" ]; then
		wpas=/sbin/wpa_supplicant
		wpac=/bin/wpa_cli
	fi
	[ "${RC_UNAME}" = "Linux" ] || unset wpac
	[ -e "${actfile}" ] || unset wpac

	eval opts=\$wpa_supplicant_${IFVAR}
	case " ${opts} " in
		*" -Dwired "*) wireless=false;;
		*) _is_wireless || return 0;;
	esac

	# We don't configure wireless if we're being called from
	# the background unless we're not currently running
	if yesno ${IN_BACKGROUND}; then
		if ${wireless} && \
		service_started_daemon "${RC_SVCNAME}" "${wpas}"; then
			SSID=$(_get_ssid "${IFACE}")
			SSIDVAR=$(shell_var "${SSID}")
			service_set_value "SSID" "${SSID}"
			metric=2000
		fi
		return 0
	fi

	service_set_value "SSID" ""
	ebegin "Starting wpa_supplicant on ${IFVAR}"

	if type iwconfig_defaults >/dev/null 2>&1; then
		iwconfig_defaults
		iwconfig_user_config
	fi

	cfgfile=${opts##* -c}
	if [ -n "${cfgfile}" -a "${cfgfile}" != "${opts}" ]; then
		case "${cfgfile}" in
			" "*) cfgfile=${cfgfile# *};;
		esac
		cfgfile=${cfgfile%% *}
	else
		# Support new and old style locations
		cfgfile="/etc/wpa_supplicant/wpa_supplicant-${IFACE}.conf"
		[ ! -e "${cfgfile}" ] \
			&& cfgfile="/etc/wpa_supplicant/wpa_supplicant.conf"
		[ ! -e ${cfgfile} ] \
			&& cfgfile="/etc/wpa_supplicant.conf"
		opts="${opts} -c ${cfgfile}"
	fi

	if [ ! -f ${cfgfile} ]; then
		eend 1 "/etc/wpa_supplicant/wpa_supplicant.conf not found"
		return 1
	fi

	# Work out where the ctrl_interface dir is if it's not specified
	local ctrl_dir=$(sed -e '/^ctrl_interface=/!d' \
				-e 's/^ctrl_interface=//' \
				-e 's/^ *//' \
				-e 's/^DIR=//' \
				-e 's/^ *//' \
				-e 's/GROUP=.*//' \
				"${cfgfile}")
	if [ -z "${ctrl_dir}" ]; then
		ctrl_dir=${opts##* -C}
		if [ -n "${ctrl_dir}" -a "${ctrl_dir}" != "${opts}" ]; then
			case "${ctrl_dir}" in
				" "*) ctrl_dir=${ctrl_dir# *};;
			esac
			ctrl_dir=${ctrl_dir%% *}
		else
			ctrl_dir="/var/run/wpa_supplicant"
			opts="${opts} -C ${ctrl_dir}"
		fi
	fi
	service_set_value ctrl_dir "${ctrl_dir}"

	if [ -n "${wpac}" ]; then
		opts="${opts} -W"
	elif service_started devd; then<commit_msg>Remove leading and trailing space on the ctrl_interface line.<commit_after># Copyright 2007-2008 <NAME> <<EMAIL>>
# All rights reserved. Released under the 2-clause BSD license.

wpa_supplicant_depend()
{
	if [ -x /usr/sbin/wpa_supplicant ]; then
		program start /usr/sbin/wpa_supplicant
	else
		program start /sbin/wpa_supplicant
	fi
	after macnet plug
	before interface
	provide wireless

	# Prefer us over iwconfig
	after iwconfig
}

# Only set these functions if not set already
# IE, prefer to use iwconfig
if ! type _get_ssid >/dev/null 2>&1; then
_get_ssid()
{
	local timeout=5 ssid=

	while [ ${timeout} -gt 0 ]; do
		ssid=$(wpa_cli -i"${IFACE}" status | sed -n -e 's/^ssid=//p')
		if [ -n "${ssid}" ]; then
			echo "${ssid}"
			return 0
		fi
		sleep 1
		timeout=$((timeout - 1))
	done

	return 1
}

_get_ap_mac_address()
{
	wpa_cli -i"${IFACE}" status | sed -n -e 's/^bssid=\(.*\)$/\1/p' \
		| tr '[:lower:]' '[:upper:]'
}
fi

wpa_supplicant_pre_start()
{
	local opts= cfgfile= ctrl_dir= wireless=true
	local wpas=/usr/sbin/wpa_supplicant wpac=/usr/bin/wpa_cli
	local actfile=/etc/wpa_supplicant/wpa_cli.sh

	if [ ! -x "${wpas}" ]; then
		wpas=/sbin/wpa_supplicant
		wpac=/bin/wpa_cli
	fi
	[ "${RC_UNAME}" = "Linux" ] || unset wpac
	[ -e "${actfile}" ] || unset wpac

	eval opts=\$wpa_supplicant_${IFVAR}
	case " ${opts} " in
		*" -Dwired "*) wireless=false;;
		*) _is_wireless || return 0;;
	esac

	# We don't configure wireless if we're being called from
	# the background unless we're not currently running
	if yesno ${IN_BACKGROUND}; then
		if ${wireless} && \
		service_started_daemon "${RC_SVCNAME}" "${wpas}"; then
			SSID=$(_get_ssid "${IFACE}")
			SSIDVAR=$(shell_var "${SSID}")
			service_set_value "SSID" "${SSID}"
			metric=2000
		fi
		return 0
	fi

	service_set_value "SSID" ""
	ebegin "Starting wpa_supplicant on ${IFVAR}"

	if type iwconfig_defaults >/dev/null 2>&1; then
		iwconfig_defaults
		iwconfig_user_config
	fi

	cfgfile=${opts##* -c}
	if [ -n "${cfgfile}" -a "${cfgfile}" != "${opts}" ]; then
		case "${cfgfile}" in
			" "*) cfgfile=${cfgfile# *};;
		esac
		cfgfile=${cfgfile%% *}
	else
		# Support new and old style locations
		cfgfile="/etc/wpa_supplicant/wpa_supplicant-${IFACE}.conf"
		[ ! -e "${cfgfile}" ] \
			&& cfgfile="/etc/wpa_supplicant/wpa_supplicant.conf"
		[ ! -e ${cfgfile} ] \
			&& cfgfile="/etc/wpa_supplicant.conf"
		opts="${opts} -c ${cfgfile}"
	fi

	if [ ! -f ${cfgfile} ]; then
		eend 1 "/etc/wpa_supplicant/wpa_supplicant.conf not found"
		return 1
	fi

	# Work out where the ctrl_interface dir is if it's not specified
	local ctrl_dir=$(sed -e 's/^ *//' \
				-e '/^ctrl_interface=/!d' \
				-e 's/^ctrl_interface=//' \
				-e 's/^ *//' \
				-e 's/^DIR=//' \
				-e 's/^ *//' \
				-e 's/GROUP=.*//' \
				-e 's/ *$//' \
				"${cfgfile}")
	if [ -z "${ctrl_dir}" ]; then
		ctrl_dir=${opts##* -C}
		if [ -n "${ctrl_dir}" -a "${ctrl_dir}" != "${opts}" ]; then
			case "${ctrl_dir}" in
				" "*) ctrl_dir=${ctrl_dir# *};;
			esac
			ctrl_dir=${ctrl_dir%% *}
		else
			ctrl_dir="/var/run/wpa_supplicant"
			opts="${opts} -C ${ctrl_dir}"
		fi
	fi
	service_set_value ctrl_dir "${ctrl_dir}"

	if [ -n "${wpac}" ]; then
		opts="${opts} -W"
	elif service_started devd; then
{'fraction_non_alphanumeric': 0.1857502359232463, 'fraction_numerical': 0.008807801195344448, 'mean_word_length': 3.3976486860304287, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4401179', 'n_tokens_mistral': 2851, 'n_tokens_neox': 2588, 'n_words': 619}