#!/bin/bash

echo Moving /etc/hostapd/hostapd.conf in .back
mv /etc/hostapd/hostapd.conf /etc/hostapd/hostapd.conf.back || true

printf 'interface=wlan0
driver=nl80211
hw_mode=g
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
ieee80211n=1

ssid=UDOO hotspot
channel=1
wpa=2
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
wpa_passphrase=udooboard
' > /etc/hostapd/hostapd.conf

echo Configuring static IP address...
printf '

# Soft-AP mode for wlan0
auto wlan0
iface wlan0 inet static
address 192.168.100.1
netmask 255.255.255.0
' >> /etc/network/interfaces

echo Patching /usr/share/dbus-1/system-services/fi.w1.wpa_supplicant1.service to disable wpa_supplicant...
sed -i 's/Exec/#Exec/' /usr/share/dbus-1/system-services/fi.w1.wpa_supplicant1.service || true

