#!/bin/bash #================================================= # GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS #================================================= final_path=$(ynh_app_setting_get $app final_path) #================================================= # SPECIFIC GETTERS FOR TOML SHORT KEY #================================================= get__no_antenna() { if [[ $(iw_devices) == "" ]] then echo "value: true" else echo "value: false" fi } get__status() { local service_enabled=$(ynh_app_setting_get $app service_enabled) if systemctl is-active hostapd -q then if [ $service_enabled -eq 1 ] then cat << EOF style: success ask: en: |- Your Hotspot is running :) EOF else cat << EOF style: warning ask: en: Your Hotspot is running, but it shouldn't ! EOF fi elif [ $service_enabled -eq 1 ] then cat << EOF style: danger ask: en: |- Your Hotspot is down ! Here are errors logged in the last 5 minutes \`\`\` $(journalctl -u hostapd -n10 -o cat | sed 's/^/ /g') \`\`\` EOF else cat << EOF style: info ask: en: Your Hotspot is down as expected. EOF fi } get__wifi_device() { if [[ $(iw_devices) == "" ]] then echo "choices: []" else cat << EOF choices: EOF for device in $(iw_devices | sed "s/|/ /g") do echo " $device: $device" done fi echo "value: '$(ynh_app_setting_get $app wifi_device)'" } get__dns() { ip6_dns=$(ynh_app_setting_get $app ip6_dns | tr -d '[' | tr -d ']') ip4_dns=$(ynh_app_setting_get $app ip4_dns) echo "value: ${ip4_dns},${ip6_dns}" } #================================================= # SPECIFIC VALIDATORS FOR TOML SHORT KEYS #================================================= validate__wifi_ssid() { if [[ -z "${wifi_ssid}" ]] then echo 'SSID required' fi } validate__wifi_passphrase() { if [[ "${wifi_secure}" == "1" ]] && [[ -z "${wifi_passphrase}" ]] then echo 'In WPA2 secure mode, you need to provide a passphrase' fi } validate__ip4_nat_prefix() { if [[ -z "${ip4_nat_prefix}" ]] then echo 'Private IPv4 nat prefix required' fi } validate__dns() { if ! echo "${dns}" | grep -q "\." then echo 'IPv4 DNS required' fi if [[ -n "${ip6_net}" ]] && ! echo "${dns}" | grep -q ":" then echo 'IPv6 DNS required' fi } #================================================= # SPECIFIC SETTERS FOR TOML SHORT KEYS #================================================= set__dns() { ip6_dns="" ip4_dns="" for ip in $(echo "${dns}" | tr ',' ' '); do if [[ "$ip" == *":"* ]]; then ip6_dns+="[$ip]," else ip4_dns+="$ip," fi done # Remove trailing , ip6_dns="${ip6_dns%%,}" ip4_dns="${ip4_dns%%,}" ynh_app_setting_set $app ip6_dns "${ip6_dns}" ynh_app_setting_set $app ip4_dns "${ip4_dns}" } #================================================= # OVERWRITING VALIDATE STEP #================================================= #================================================= # OVERWRITING APPLY STEP #================================================= ynh_app_config_apply() { # Stop vpn client ynh_print_info --message="Stopping hotspot in order to edit files" /usr/local/bin/ynh-hotspot stop _ynh_app_config_apply if [ "${wifi_secure}" -eq 1 ]; then local sec_comment="" else local sec_comment="#" fi ynh_add_config --template="/etc/hostapd/hostapd.base.conf" --destination="/etc/hostapd/hostapd-${wifi_device}.conf" ynh_add_config --template="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" --destination="/etc/dnsmasq.dhcpd/dhcpdv4-ssid-${wifi_device}.conf" if [[ -n "${ip6_net}" ]] && [[ "${ip6_net}" != "none" ]]; then ynh_add_config --template="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl" --destination="/etc/dnsmasq.dhcpd/dhcpdv6-ssid-${wifi_device}.conf" fi # Start vpn client ynh_print_info --message="Starting hotspot service if needed" /usr/local/bin/ynh-hotspot start } ynh_app_config_run $1