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

85 lines
3.1 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
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
#=================================================
# 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
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
ynh_script_progression --message="Restoring configurations ..."
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
ynh_restore_file --origin_path="/usr/local/bin/$service_name"
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}"
ynh_restore_file --origin_path="/etc/systemd/system/$service_name.service"
ynh_restore_file --origin_path="/etc/systemd/system/hostapd@$app.service"
yunohost service add "$service_name" --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" --need_lock
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting the hotspot service..."
hot_reload_usb_wifi_cards
if [[ -z "${wifi_device:-}" ]] || ! grep -q -F "$wifi_device" <(unused_iw_devices); then
wifi_device=$(unused_iw_devices | head -n 1)
ynh_app_setting_set --app=$app --key=wifi_device --value="${wifi_device}"
fi
if [[ -z "${wifi_device:-}" ]]; then
ynh_app_setting_set --app=$app --key=service_enabled --value=0
else
ynh_app_setting_set --app=$app --key=service_enabled --value=1
fi
# Start a systemd service if device is present
if [[ "${wifi_device:-}" == "" ]]; then
echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2
else
yunohost service start $service_name
fi
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app"