#!/usr/bin/env bash

set -e

# Uninstall WiFi Access Point
sudo systemctl disable hostapd.service 2>/dev/null || true
sudo systemctl stop hostapd.service 2>/dev/null || true
sudo systemctl daemon-reload
if [ -f "/etc/network/interfaces.bak" ]; then
    sudo mv /etc/network/interfaces.bak /etc/network/interfaces
fi
if [ -f "/etc/sysctl.conf.bak" ]; then
    sudo mv /etc/sysctl.conf.bak /etc/sysctl.conf
fi
if [ -f "/etc/dnsmasq.conf.bak" ]; then
    sudo mv /etc/dnsmasq.conf.bak /etc/dnsmasq.conf
fi
if [ -f "/etc/dhcpcd.conf.bak" ]; then
    sudo mv /etc/dhcpcd.conf.bak /etc/dhcpcd.conf
fi
sudo rm -f /etc/radvd.conf
sudo rm -f /etc/hostapd/hostapd.conf
sudo rm -f /etc/hostapd/hostapd.eap_user
sudo rm -f /etc/hostapd/ca.pem
sudo rm -f /etc/hostapd/server.pem
sudo rm -f /etc/hostapd/nat.sh
sudo rm -f /etc/systemd/system/hostapd.service
