1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/hotspot_ynh.git synced 2024-09-03 19:25:53 +02:00
hotspot_ynh/scripts/restore

86 lines
3.1 KiB
Text
Raw Normal View History

2015-07-25 16:33:38 +02:00
#!/bin/bash
#=================================================
# 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
source /usr/share/yunohost/helpers
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
# 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
2023-08-21 18:43:20 +02:00
ynh_restore_file --origin_path="/etc/hostapd/$app/hostapd.conf" --not_mandatory
ynh_restore_file --origin_path="/etc/dnsmasq.$app/dhcpdv6.conf" --not_mandatory
ynh_restore_file --origin_path="/etc/dnsmasq.$app/dhcpdv4.conf" --not_mandatory
2019-02-23 02:05:40 +01:00
2020-05-31 05:33:17 +02:00
ynh_restore_file --origin_path="/usr/local/bin/$service_name"
2019-02-23 02:05:40 +01:00
2023-08-21 18:43:20 +02:00
ynh_restore_file --origin_path="/etc/openvpn/scripts/route-up.d/90-${service_name}"
ynh_restore_file --origin_path="/etc/openvpn/scripts/route-down.d/90-${service_name}"
2019-02-23 02:05:40 +01:00
2020-05-31 05:33:17 +02:00
ynh_restore_file --origin_path="/etc/systemd/system/$service_name.service"
2023-08-21 18:43:20 +02:00
ynh_restore_file --origin_path="/etc/systemd/system/hostapd@$app.service"
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
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
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"