#!/bin/bash

yunohost_setting() {
  grep "^${1}:" "/etc/yunohost/apps/hotspot/settings.yml" | sed s/^[^:]\\+:\\s*[\"\']\\?// | sed s/\\s*[\"\']\$//
}

domain=$(yunohost_setting domain)
path=$(yunohost_setting path)
wifi_ssid=$(yunohost_setting wifi_ssid)
wifi_passphrase=$(yunohost_setting wifi_passphrase)

if dpkg -l firmware-linux-nonfree &> /dev/null; then
  firmware_nonfree=yes
else
  firmware_nonfree=no
fi

export HOTSPOT_UPGRADE=1
/etc/yunohost/apps/hotspot/scripts/remove
./install "${domain}" "${path}" "${wifi_ssid}" "${wifi_passphrase}" "${firmware_nonfree}"

sudo systemctl start ynh-hotspot

exit 0
