diff --git a/scripts/_common.sh b/scripts/_common.sh index 0687a14..a39ce75 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -48,6 +48,26 @@ function hot_reload_usb_wifi_cards() done } +function configure_hostapd() +{ + if [[ "${wifi_secure}" -eq 1 ]]; then + sec_comment="" + else + sec_comment="#" + fi + + ynh_add_config --template="/etc/hostapd/$app/hostapd.conf.tpl" --destination="/etc/hostapd/$app/hostapd.conf" +} + +function configure_dhcp() +{ + 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 +} + #================================================= # EXPERIMENTAL HELPERS #================================================= diff --git a/scripts/config b/scripts/config index 6ce9c2f..b0013ee 100644 --- a/scripts/config +++ b/scripts/config @@ -191,18 +191,8 @@ ynh_app_config_apply() { _ynh_app_config_apply - 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 + configure_hostapd + configure_dhcp # Start hotspot ynh_print_info --message="Starting hotspot service if needed" diff --git a/scripts/install b/scripts/install index 276885f..eec1e7a 100644 --- a/scripts/install +++ b/scripts/install @@ -201,18 +201,8 @@ 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 - sec_comment="" - else - 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 + configure_hostapd + configure_dhcp fi #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 670e77c..6ae4e2a 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -208,18 +208,8 @@ install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq 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 - sec_comment="" - else - 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 + configure_hostapd + configure_dhcp fi # Copy init script