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

apply config during install and upgrade

This commit is contained in:
HgO 2023-08-21 22:40:58 +02:00
parent 9b6ba3ec5a
commit baf3dac35f
2 changed files with 54 additions and 13 deletions

View file

@ -139,12 +139,14 @@ ip4_dns="${ip4_nat_prefix}.1"
hot_reload_usb_wifi_cards
wifi_device=$(iw_devices | awk -F\| '{ print $1 }')
wifi_secure=1
wifi_channel=6
ynh_app_setting_set --app=$app --key=wifi_ssid --value="${wifi_ssid}"
ynh_app_setting_set --app=$app --key=wifi_secure --value=1
ynh_app_setting_set --app=$app --key=wifi_secure --value="${wifi_secure}"
ynh_app_setting_set --app=$app --key=wifi_passphrase --value="${wifi_passphrase}"
ynh_app_setting_set --app=$app --key=wifi_device --value="${wifi_device}"
ynh_app_setting_set --app=$app --key=wifi_channel --value=6
ynh_app_setting_set --app=$app --key=wifi_channel --value="${wifi_channel}"
ynh_app_setting_set --app=$app --key=ip6_firewall --value=1
ynh_app_setting_set --app=$app --key=ip6_dns --value="${ip6_dns}"
ynh_app_setting_set --app=$app --key=ip6_net --value="${ip6_net}"
@ -197,6 +199,21 @@ systemctl disable hostapd --quiet 2>&1
systemctl stop hostapd 2>&1
systemctl unmask hostapd 2>&1 # On some system e.g. RPi, for some reason hostapd is masked after install ...
if [[ -n ${wifi_device} ]]; then
if [ "${wifi_secure}" -eq 1 ]; then
local sec_comment=""
else
local sec_comment="#"
fi
ynh_add_config --template="/etc/hostapd/$app/hostapd.conf.tpl" --destination="/etc/hostapd/$app/hostapd.conf"
ynh_add_config --template="/etc/dnsmasq.$app/dhcpdv4.conf.tpl" --destination="/etc/dnsmasq.$app/dhcpdv4.conf"
if [[ -n "${ip6_net}" ]] && [[ "${ip6_net}" != "none" ]]; then
ynh_add_config --template="/etc/dnsmasq.$app/dhcpdv6.conf.tpl" --destination="/etc/dnsmasq.$app/dhcpdv6.conf"
fi
fi
#=================================================
# SETUP SYSTEMD
#=================================================
@ -223,8 +240,7 @@ ynh_script_progression --message="Starting a systemd service..."
if [[ $wifi_device == "" ]]; then
echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2
else
ynh_app_config_run apply
# ynh_systemd_action --service_name=$service_name --action="start" --log_path=systemd #--line_match="Started YunoHost Wifi Hotspot"
ynh_systemd_action --service_name=$service_name --action="start" --log_path=systemd #--line_match="Started YunoHost Wifi Hotspot"
fi
#=================================================

View file

@ -72,15 +72,24 @@ if [ -z $service_name ]; then
ynh_app_setting_set --app=$app --key=service_name --value=$service_name
fi
wifi_ssid=$(ynh_app_setting_get --app=$app --key=wifi_ssid)
wifi_secure=$(ynh_app_setting_get --app=$app --key=wifi_secure)
wifi_passphrase=$(ynh_app_setting_get --app=$app --key=wifi_passphrase)
wifi_channel=$(ynh_app_setting_get --app=$app --key=wifi_channel)
ip4_nat_prefix=$(ynh_app_setting_get --app=$app --key=ip4_nat_prefix)
ip6_net=$(ynh_app_setting_get --app=$app --key=ip6_net)
ip6_firewall=$(ynh_app_setting_get --app=$app --key=ip6_firewall)
dns=$(ynh_app_setting_get --app=$app --key=dns)
multissid=$(ynh_app_setting_get --app=$app --key=multissid)
if [[ -n ${multissid} ]] && [[ ${multissid} -gt 1 ]]; then
wifi_ssid=$(ynh_app_setting_get --app=$app --key=wifi_ssid | cut -d'|' -f 1)
wifi_secure=$(ynh_app_setting_get --app=$app --key=wifi_secure | cut -d'|' -f 1)
wifi_passphrase=$(ynh_app_setting_get --app=$app --key=wifi_passphrase | cut -d'|' -f 1)
ip4_nat_prefix=$(ynh_app_setting_get --app=$app --key=ip4_nat_prefix | cut -d'|' -f 1)
ip6_net=$(ynh_app_setting_get --app=$app --key=ip6_net | cut -d'|' -f 1)
ip6_firewall=$(ynh_app_setting_get --app=$app --key=ip6_firewall | cut -d'|' -f 1)
dns=$(ynh_app_setting_get --app=$app --key=dns | cut -d'|' -f 1)
wifi_ssid=$(cut -d'|' -f 1 <<< ${wifi_ssid})
wifi_secure=$(cut -d'|' -f 1 <<< ${wifi_secure})
wifi_passphrase=$(cut -d'|' -f 1 <<< ${wifi_passphrase})
ip4_nat_prefix=$(cut -d'|' -f 1 <<< ${ip4_nat_prefix})
ip6_net=$(cut -d'|' -f 1 <<< ${ip6_net})
ip6_firewall=$(cut -d'|' -f 1 <<< ${ip6_firewall})
dns=$(cut -d'|' -f 1 <<< ${dns})
ynh_app_setting_set --app=$app --key=wifi_ssid --value="${wifi_ssid}"
ynh_app_setting_set --app=$app --key=wifi_secure --value="${wifi_secure}"
@ -88,8 +97,6 @@ if [[ -n ${multissid} ]] && [[ ${multissid} -gt 1 ]]; then
ynh_app_setting_set --app=$app --key=ip4_nat_prefix --value="${ip4_nat_prefix}"
ynh_app_setting_set --app=$app --key=ip6_net --value="${ip6_net}"
ynh_app_setting_set --app=$app --key=ip6_firewall --value="${ip6_firewall}"
else
dns=$(ynh_app_setting_get --app=$app --key=dns)
fi
if [[ -n "${dns}" ]]; then
@ -114,6 +121,9 @@ if [[ -n "${dns}" ]]; then
fi
ynh_app_setting_delete $app dns
else
ip6_dns=$(ynh_app_setting_get --app=$app --key=ip6_dns)
ip4_dns=$(ynh_app_setting_get --app=$app --key=ip4_dns)
fi
if [[ -n ${multissid} ]]; then
@ -194,6 +204,21 @@ install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl /etc/hostapd/$app/ho
install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq.$app/dhcpdv6.conf.tpl
install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.$app/dhcpdv4.conf.tpl
if [[ -n ${wifi_device} ]]; then
if [ "${wifi_secure}" -eq 1 ]; then
local sec_comment=""
else
local sec_comment="#"
fi
ynh_add_config --template="/etc/hostapd/$app/hostapd.conf.tpl" --destination="/etc/hostapd/$app/hostapd.conf"
ynh_add_config --template="/etc/dnsmasq.$app/dhcpdv4.conf.tpl" --destination="/etc/dnsmasq.$app/dhcpdv4.conf"
if [[ -n "${ip6_net}" ]] && [[ "${ip6_net}" != "none" ]]; then
ynh_add_config --template="/etc/dnsmasq.$app/dhcpdv6.conf.tpl" --destination="/etc/dnsmasq.$app/dhcpdv6.conf"
fi
fi
# Copy init script
ynh_add_config --template="../conf/ynh-hotspot" --destination="/usr/local/bin/$service_name"
chmod 0755 "/usr/local/bin/$service_name"