2015-07-25 16:33:38 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2021-05-15 20:52:43 +02:00
|
|
|
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
2019-02-23 02:05:40 +01:00
|
|
|
source ../settings/scripts/_common.sh
|
2018-05-04 00:33:01 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2023-12-31 17:32:37 +01:00
|
|
|
if systemctl -q is-enabled hostapd
|
|
|
|
then
|
|
|
|
# Disable hostapd, we'll use hostapd@$app instead (for multissid support etc)
|
|
|
|
systemctl disable hostapd --quiet 2>&1
|
|
|
|
systemctl stop hostapd 2>&1
|
|
|
|
systemctl mask hostapd 2>&1
|
|
|
|
fi
|
|
|
|
|
2023-09-22 18:12:20 +02:00
|
|
|
#=================================================
|
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring firewall..."
|
|
|
|
|
|
|
|
# Update firewall for DHCP
|
|
|
|
ynh_exec_warn_less yunohost firewall allow --no-upnp --ipv6 UDP 547
|
|
|
|
ynh_exec_warn_less yunohost firewall allow --no-upnp UDP 67
|
|
|
|
|
2021-10-17 21:24:17 +02:00
|
|
|
# Meh idk where to put this ... On RPi, by default wlan is blocked
|
|
|
|
if test -e /usr/sbin/rfkill && rfkill | grep wlan | grep -q -w 'blocked'
|
|
|
|
then
|
|
|
|
ynh_print_info "Unblocking wlan interface..."
|
|
|
|
/usr/sbin/rfkill unblock wlan
|
|
|
|
fi
|
2019-02-23 02:05:40 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD RESTORATION STEPS
|
|
|
|
#=================================================
|
2021-06-07 18:32:16 +02:00
|
|
|
|
2023-10-06 18:36:24 +02:00
|
|
|
ynh_script_progression --message="Restoring configurations ..."
|
2019-02-23 02:05:40 +01:00
|
|
|
|
2024-01-02 10:59:14 +01:00
|
|
|
ynh_restore
|
2019-02-23 02:05:40 +01:00
|
|
|
|
2023-10-06 18:36:24 +02:00
|
|
|
yunohost service add "$service_name" --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" --need_lock
|
2020-05-31 05:33:17 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2023-10-06 18:36:24 +02:00
|
|
|
ynh_script_progression --message="Starting the hotspot service..."
|
2020-05-31 05:33:17 +02:00
|
|
|
|
2021-03-17 01:03:07 +01:00
|
|
|
hot_reload_usb_wifi_cards
|
2023-10-06 18:36:24 +02:00
|
|
|
if [[ -z "${wifi_device:-}" ]] || ! grep -q -F "$wifi_device" <(unused_iw_devices); then
|
2023-08-23 10:24:43 +02:00
|
|
|
wifi_device=$(unused_iw_devices | head -n 1)
|
|
|
|
ynh_app_setting_set --app=$app --key=wifi_device --value="${wifi_device}"
|
|
|
|
fi
|
2020-05-31 05:33:17 +02:00
|
|
|
|
2023-10-06 18:36:24 +02:00
|
|
|
if [[ -z "${wifi_device:-}" ]]; then
|
2021-05-15 20:52:43 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=service_enabled --value=0
|
2020-05-31 05:33:17 +02:00
|
|
|
else
|
2021-05-15 20:52:43 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=service_enabled --value=1
|
2020-05-31 05:33:17 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Start a systemd service if device is present
|
2023-10-06 18:36:24 +02:00
|
|
|
if [[ "${wifi_device:-}" == "" ]]; then
|
2021-05-15 20:52:43 +02:00
|
|
|
echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2
|
2020-05-31 05:33:17 +02:00
|
|
|
else
|
2023-10-05 20:34:32 +02:00
|
|
|
yunohost service start $service_name
|
2020-05-31 05:33:17 +02:00
|
|
|
fi
|
2019-02-23 02:05:40 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
2015-07-25 16:33:38 +02:00
|
|
|
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_script_progression --message="Restoration completed for $app"
|