#!/bin/sh
# iwd wifi service

# detect wireless interfaces
WLAN_IF=$(ip link show | awk -F: '/^[0-9]+: wl/ {print $2; exit}' | tr -d ' ')

if [ -z "$WLAN_IF" ]; then
	echo "error: no wireless interface found"
	echo "check that wireless drivers are loaded"
	exit 1
fi

echo "wifi: using interface $WLAN_IF"

# create iwd state directory
mkdir -p /var/lib/iwd

# start iwd daemon in foreground
# iwd will handle interface management, authentication, and dhcp
# configuration is in /var/lib/iwd/<SSID>.psk or /var/lib/iwd/<SSID>.open
exec iwd
