#!/bin/sh
set -eu

IFACE="ahcpdtest"

cleanup() {
    systemctl stop ahcpd.service 2>/dev/null || true
    ip link del "$IFACE" 2>/dev/null || true
    sed -i 's/^INTERFACES=.*/INTERFACES=""/' /etc/default/ahcpd
}
trap cleanup EXIT

ip link add "$IFACE" type dummy
ip link set "$IFACE" up

sed -i "s/^INTERFACES=.*/INTERFACES=\"$IFACE\"/" /etc/default/ahcpd

systemctl start ahcpd.service
systemctl is-active ahcpd.service

systemctl restart ahcpd.service
systemctl is-active ahcpd.service

systemctl stop ahcpd.service
! systemctl is-active ahcpd.service
