#!/sbin/openrc-run

description="Fallback Access Point"

depend() {
    need net
}

start() {
    ebegin "Starting fallback AP"

    # Zero 2 W braucht sanfteres Bringup
    if [ "0" -eq 1 ]; then
        echo "→ Zero 2 W Interface-Setup"
        ifconfig wlan0 192.168.50.1 netmask 255.255.255.0 up
    else
        echo "→ Standard Interface-Setup"
        ip link set wlan0 down
        ip addr flush dev wlan0
        ip addr add 192.168.50.1/24 dev wlan0
        ip link set wlan0 up
    fi

    start-stop-daemon --start --exec /usr/sbin/hostapd -- /etc/hostapd/hostapd.conf &
    start-stop-daemon --start --exec /usr/sbin/dnsmasq -- -C /etc/dnsmasq.conf
    eend $?
}

stop() {
    ebegin "Stopping fallback AP"

    start-stop-daemon --stop --exec /usr/sbin/hostapd
    start-stop-daemon --stop --exec /usr/sbin/dnsmasq

    ip link set wlan0 down
    eend $?
}
