#!/bin/zsh -l
# Handle events from netplug or wpa_cli and mark interfaces as up or down accordingly

logger -t $0:t "${(qqq)@}"

usage() {
	logger -t $0:t "wrong arguments:" "${(qqq)@}"
	echo "$0:t: wrong arguments" >&2
	echo "Call with <interface> <in|out|probe|CONNECTED|DISCONNECTED>" >&2
	exit 1
}

(( $# == 2 )) || usage

mkdir -p /run/interfaces

case "$2" in
	(in) echo up >/run/interfaces/$1 ;;
	(CONNECTED) echo up >/run/interfaces/$1 ;;
	(out) echo down >/run/interfaces/$1 ;;
	(DISCONNECTED) echo down >/run/interfaces/$1 ;;
	(probe) ip link set dev $1 up ;;
	(*) usage ;;
esac

zsvgen