#!/bin/bash
{% if not network_enabled %}
echo -e "Networking role disabled\n"
echo -e "For details, see: https://github.com/iiab/iiab/pull/3302\n"
{% else %}
sed -i -e "s/^HOSTAPD_ENABLED.*/HOSTAPD_ENABLED=False/" {{ iiab_env_file }}
systemctl disable hostapd
systemctl stop hostapd
{% if wifi_up_down %}
systemctl disable iiab-clone-wifi.service
systemctl disable iiab-wifi-test.service
systemctl stop iiab-clone-wifi.service
echo " IIAB hotspot access point Disabled"
exit 0
{% else %}
{% if is_raspbian %}
# hotspot-off before ap0_updown
sed -i -e "s/^denyinterfaces/#denyinterfaces/" /etc/dhcpcd.conf
systemctl disable hostapd
systemctl stop hostapd
#systemctl disable dnsmasq
#systemctl stop dnsmasq
systemctl daemon-reload
systemctl restart dhcpcd
#systemctl restart networking 6/15/2019 TFM removed
# Temporary promiscuous-mode workaround for RPi's WiFi "10SEC disease"
# Set wlan0 to promiscuous when AP's OFF (for possible WiFi gateway)
# SEE ALSO iiab-hotspot-on + /usr/libexec/iiab-startup.sh
# https://github.com/iiab/iiab/issues/638#issuecomment-355455454
#if grep -qi raspbian /etc/*release; then
#    ip link set dev wlan0 promisc on
#fi
{% else %}
#ubuntu
if [ -f /etc/NetworkManager/conf.d/wifi-manage.conf ]; then
    sed -i -e "s|managed=0|managed=1|" /etc/NetworkManager/conf.d/wifi-manage.conf
fi
echo -e "\nPlease reboot to enable upstream WiFi access.\n"
exit 0
{% endif %}
#wifi_up_down
{% endif %}
{% endif %}
