2021-09-18 12:00:30 +02:00
|
|
|
#!/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
|
|
|
|
#=================================================
|
|
|
|
|
2021-09-20 18:01:28 +02:00
|
|
|
get__no_antenna() {
|
2023-09-17 21:57:39 +02:00
|
|
|
if [[ "$(unused_iw_devices)" == "" ]]
|
2021-09-20 18:01:28 +02:00
|
|
|
then
|
2021-10-18 01:39:24 +02:00
|
|
|
echo "value: true"
|
2021-10-18 01:44:24 +02:00
|
|
|
else
|
|
|
|
echo "value: false"
|
2021-09-20 18:01:28 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-09-18 12:00:30 +02:00
|
|
|
get__status() {
|
|
|
|
local service_enabled=$(ynh_app_setting_get $app service_enabled)
|
2023-08-21 23:24:01 +02:00
|
|
|
if systemctl is-active hostapd@$app -q
|
2021-09-18 12:00:30 +02:00
|
|
|
then
|
2023-09-17 21:57:39 +02:00
|
|
|
if [[ "$service_enabled" -eq 1 ]]
|
2021-09-18 12:00:30 +02:00
|
|
|
then
|
|
|
|
cat << EOF
|
|
|
|
style: success
|
|
|
|
ask:
|
|
|
|
en: |-
|
2021-09-20 18:01:28 +02:00
|
|
|
Your Hotspot is running :)
|
2021-09-18 12:00:30 +02:00
|
|
|
EOF
|
|
|
|
else
|
|
|
|
cat << EOF
|
|
|
|
style: warning
|
|
|
|
ask:
|
2021-09-20 18:01:28 +02:00
|
|
|
en: Your Hotspot is running, but it shouldn't !
|
2021-09-18 12:00:30 +02:00
|
|
|
EOF
|
|
|
|
fi
|
2023-09-17 21:57:39 +02:00
|
|
|
elif [[ "$service_enabled" -eq 1 ]]
|
2021-09-18 12:00:30 +02:00
|
|
|
then
|
|
|
|
cat << EOF
|
|
|
|
style: danger
|
|
|
|
ask:
|
|
|
|
en: |-
|
2021-09-20 18:01:28 +02:00
|
|
|
Your Hotspot is down ! Here are errors logged in the last 5 minutes
|
2021-09-18 12:00:30 +02:00
|
|
|
\`\`\`
|
2023-08-21 23:24:01 +02:00
|
|
|
$(journalctl -u hostapd@$app -n10 -o cat | sed 's/^/ /g')
|
2021-09-18 12:00:30 +02:00
|
|
|
\`\`\`
|
|
|
|
EOF
|
|
|
|
else
|
|
|
|
cat << EOF
|
|
|
|
style: info
|
|
|
|
ask:
|
2021-09-20 19:19:01 +02:00
|
|
|
en: Your Hotspot is down as expected.
|
2021-09-18 12:00:30 +02:00
|
|
|
EOF
|
|
|
|
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-09-20 18:01:28 +02:00
|
|
|
get__wifi_device() {
|
2023-08-23 10:24:43 +02:00
|
|
|
local unused_wifi_devices=$(unused_iw_devices)
|
2023-09-17 21:57:39 +02:00
|
|
|
if [[ -z "${unused_wifi_devices}" ]]
|
2021-09-18 12:00:30 +02:00
|
|
|
then
|
2021-09-20 18:01:28 +02:00
|
|
|
echo "choices: []"
|
2021-09-18 12:00:30 +02:00
|
|
|
else
|
2021-09-20 18:01:28 +02:00
|
|
|
cat << EOF
|
|
|
|
choices:
|
|
|
|
EOF
|
2023-08-23 10:24:43 +02:00
|
|
|
for device in $unused_wifi_devices
|
2021-09-20 18:01:28 +02:00
|
|
|
do
|
|
|
|
echo " $device: $device"
|
|
|
|
done
|
2021-09-18 12:00:30 +02:00
|
|
|
fi
|
2021-10-18 01:39:24 +02:00
|
|
|
|
|
|
|
echo "value: '$(ynh_app_setting_get $app wifi_device)'"
|
2021-09-18 12:00:30 +02:00
|
|
|
}
|
|
|
|
|
2023-08-20 16:31:09 +02:00
|
|
|
get__dns() {
|
2023-08-21 21:59:27 +02:00
|
|
|
ip6_net=$(ynh_app_setting_get --app=$app --key=ip6_net)
|
|
|
|
ip6_dns=$(ynh_app_setting_get --app=$app --key=ip6_dns | tr -d '[]')
|
|
|
|
ip4_nat_prefix=$(ynh_app_setting_get --app=$app --key=ip4_nat_prefix)
|
|
|
|
ip4_dns=$(ynh_app_setting_get --app=$app --key=ip4_dns)
|
2023-08-21 10:51:37 +02:00
|
|
|
|
2023-09-17 21:57:39 +02:00
|
|
|
if [[ -n "${ip6_net}" ]] && [[ -z "${ip6_dns}" ]]; then
|
2023-08-21 10:51:37 +02:00
|
|
|
ip6_dns="${ip6_net}1"
|
|
|
|
fi
|
|
|
|
|
2023-09-17 21:57:39 +02:00
|
|
|
if [[ -n "${ip4_nat_prefix}" ]] && [[ -z "${ip4_dns}" ]]; then
|
2023-08-21 10:51:37 +02:00
|
|
|
ip4_dns="${ip4_nat_prefix}.1"
|
|
|
|
fi
|
|
|
|
|
2023-08-20 16:31:09 +02:00
|
|
|
echo "value: ${ip4_dns},${ip6_dns}"
|
|
|
|
}
|
|
|
|
|
2021-09-18 12:00:30 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC VALIDATORS FOR TOML SHORT KEYS
|
|
|
|
#=================================================
|
2023-08-20 15:22:11 +02:00
|
|
|
|
2021-09-20 18:01:28 +02:00
|
|
|
validate__wifi_ssid() {
|
2023-08-20 15:22:11 +02:00
|
|
|
if [[ -z "${wifi_ssid}" ]]
|
2021-09-20 18:01:28 +02:00
|
|
|
then
|
|
|
|
echo 'SSID required'
|
|
|
|
fi
|
|
|
|
}
|
2021-09-18 12:00:30 +02:00
|
|
|
|
2021-09-20 18:01:28 +02:00
|
|
|
validate__wifi_passphrase() {
|
2023-08-20 15:22:11 +02:00
|
|
|
if [[ "${wifi_secure}" == "1" ]] && [[ -z "${wifi_passphrase}" ]]
|
2021-09-18 12:00:30 +02:00
|
|
|
then
|
2021-09-20 18:01:28 +02:00
|
|
|
echo 'In WPA2 secure mode, you need to provide a passphrase'
|
2021-09-18 12:00:30 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-09-20 18:01:28 +02:00
|
|
|
validate__ip4_nat_prefix() {
|
2023-08-20 15:22:11 +02:00
|
|
|
if [[ -z "${ip4_nat_prefix}" ]]
|
2021-09-18 12:00:30 +02:00
|
|
|
then
|
2021-09-20 18:01:28 +02:00
|
|
|
echo 'Private IPv4 nat prefix required'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
validate__dns() {
|
2023-08-20 15:22:11 +02:00
|
|
|
if ! echo "${dns}" | grep -q "\."
|
2021-09-20 18:01:28 +02:00
|
|
|
then
|
|
|
|
echo 'IPv4 DNS required'
|
|
|
|
fi
|
2023-08-20 15:22:11 +02:00
|
|
|
if [[ -n "${ip6_net}" ]] && ! echo "${dns}" | grep -q ":"
|
2021-09-20 18:01:28 +02:00
|
|
|
then
|
|
|
|
echo 'IPv6 DNS required'
|
2021-09-18 12:00:30 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#=================================================
|
2021-09-20 18:01:28 +02:00
|
|
|
# SPECIFIC SETTERS FOR TOML SHORT KEYS
|
2021-09-18 12:00:30 +02:00
|
|
|
#=================================================
|
2021-09-20 18:01:28 +02:00
|
|
|
|
2023-08-20 16:20:20 +02:00
|
|
|
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%%,}"
|
|
|
|
|
2023-09-17 21:57:39 +02:00
|
|
|
if [[ -n "${ip6_net}" ]] && [[ -z "${ip6_dns}" ]]; then
|
2023-08-21 10:51:37 +02:00
|
|
|
ip6_dns="${ip6_net}1"
|
|
|
|
fi
|
|
|
|
|
2023-09-17 21:57:39 +02:00
|
|
|
if [[ -n "${ip4_nat_prefix}" ]] && [[ -z "${ip4_dns}" ]]; then
|
2023-08-21 10:51:37 +02:00
|
|
|
ip4_dns="${ip4_nat_prefix}.1"
|
|
|
|
fi
|
|
|
|
|
2023-08-20 16:20:20 +02:00
|
|
|
ynh_app_setting_set $app ip6_dns "${ip6_dns}"
|
|
|
|
ynh_app_setting_set $app ip4_dns "${ip4_dns}"
|
|
|
|
}
|
|
|
|
|
2021-09-20 18:01:28 +02:00
|
|
|
#=================================================
|
|
|
|
# OVERWRITING VALIDATE STEP
|
|
|
|
#=================================================
|
2021-09-18 12:00:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# OVERWRITING APPLY STEP
|
|
|
|
#=================================================
|
|
|
|
ynh_app_config_apply() {
|
2023-08-22 09:28:36 +02:00
|
|
|
service_name=$(ynh_app_setting_get --app=$app --key=service_name)
|
|
|
|
|
2021-09-18 12:00:30 +02:00
|
|
|
# Stop vpn client
|
2021-09-20 18:01:28 +02:00
|
|
|
ynh_print_info --message="Stopping hotspot in order to edit files"
|
2023-08-21 18:43:20 +02:00
|
|
|
/usr/local/bin/${service_name} stop
|
2021-09-18 12:00:30 +02:00
|
|
|
|
|
|
|
_ynh_app_config_apply
|
2023-08-20 15:22:11 +02:00
|
|
|
|
2023-08-22 14:51:13 +02:00
|
|
|
configure_hostapd
|
2023-09-22 17:33:14 +02:00
|
|
|
configure_dnsmasq
|
2023-08-22 14:51:13 +02:00
|
|
|
configure_dhcp
|
2023-08-20 15:22:11 +02:00
|
|
|
|
2023-08-21 18:43:20 +02:00
|
|
|
# Start hotspot
|
2021-09-20 18:01:28 +02:00
|
|
|
ynh_print_info --message="Starting hotspot service if needed"
|
2023-08-21 18:43:20 +02:00
|
|
|
/usr/local/bin/${service_name} start
|
2021-09-18 12:00:30 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ynh_app_config_run $1
|