diff --git a/conf/hostapd.conf.tpl2 b/conf/hostapd.accesspoint.conf similarity index 100% rename from conf/hostapd.conf.tpl2 rename to conf/hostapd.accesspoint.conf diff --git a/conf/hostapd.base.conf b/conf/hostapd.base.conf new file mode 100644 index 0000000..8ea3d7d --- /dev/null +++ b/conf/hostapd.base.conf @@ -0,0 +1,8 @@ +interface=__WIFI_DEVICE__ +hw_mode=g +__N_COMMENT__ieee80211n=1 +__N_COMMENT__wmm_enabled=1 +macaddr_acl=0 +auth_algs=1 +ignore_broadcast_ssid=0 +channel=__WIFI_CHANNEL__ diff --git a/conf/hostapd.conf.tpl1 b/conf/hostapd.conf.tpl1 deleted file mode 100644 index 897e93f..0000000 --- a/conf/hostapd.conf.tpl1 +++ /dev/null @@ -1,26 +0,0 @@ -# Wifi Hotspot app for YunoHost -# Copyright (C) 2015 Julien Vaubourg -# Contribute at https://github.com/labriqueinternet/hotspot_ynh -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -interface=__WIFI_DEVICE__ -hw_mode=g -__N_COMMENT__ieee80211n=1 -__N_COMMENT__wmm_enabled=1 -macaddr_acl=0 -auth_algs=1 -ignore_broadcast_ssid=0 -channel=__WIFI_CHANNEL__ - diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index d2ba1f3..6087e43 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -164,40 +164,32 @@ start_dhcpd4() { dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf -p0 } -start_hostapd() { - cp /etc/hostapd/hostapd.conf{.tpl1,} +configure_hostapd() { ethaddr=$(ip link show dev "${ynh_wifi_device}" | grep link/ether | awk -F: '{ printf "02:%s:%s:%s:%s:00", $2, $3, $4, $5 }') ip link set addr "${ethaddr}" dev "${ynh_wifi_device}" + cp /etc/hostapd/hostapd.base.conf /etc/hostapd/hostapd.conf sed "s|__WIFI_DEVICE__|${ynh_wifi_device}|g" -i /etc/hostapd/hostapd.conf sed "s|__WIFI_CHANNEL__|${ynh_wifi_channel}|g" -i /etc/hostapd/hostapd.conf sed "s|__N_COMMENT__||g" -i /etc/hostapd/hostapd.conf for i in $(seq 0 $((${ynh_multissid} - 1))); do - cp /etc/hostapd/hostapd.conf{.tpl2,.tmp} + + [ "${ynh_wifi_secure[${i}]}" -eq 1 ] && local sec_comment="" || local sec_comment="#" + [ "${i}" -eq 0 ] && local bss_comment="#" || local bss_comment="" + + cp /etc/hostapd/hostapd.accesspoint.conf /etc/hostapd/hostapd.conf.tmp sed "s|__WIFI_INTERFACE__|hotspot${i}|g" -i /etc/hostapd/hostapd.conf.tmp sed "s|__WIFI_SSID__|${ynh_wifi_ssid[${i}]}|g" -i /etc/hostapd/hostapd.conf.tmp sed "s|__WIFI_PASSPHRASE__|${ynh_wifi_passphrase[${i}]}|g" -i /etc/hostapd/hostapd.conf.tmp - - if [ "${ynh_wifi_secure[${i}]}" -eq 1 ]; then - sed "s|__SEC_COMMENT__||g" -i /etc/hostapd/hostapd.conf.tmp - else - sed "s|__SEC_COMMENT__|#|g" -i /etc/hostapd/hostapd.conf.tmp - fi - - if [ "${i}" -eq 0 ]; then - sed "s|__BSS_COMMENT__|#|g" -i /etc/hostapd/hostapd.conf.tmp - else - sed "s|__BSS_COMMENT__||g" -i /etc/hostapd/hostapd.conf.tmp - fi + sed "s|__SEC_COMMENT__|${sec_comment}|g" -i /etc/hostapd/hostapd.conf.tmp + sed "s|__BSS_COMMENT__|${bss_comment}|g" -i /etc/hostapd/hostapd.conf.tmp cat /etc/hostapd/hostapd.conf.tmp >> /etc/hostapd/hostapd.conf rm /etc/hostapd/hostapd.conf.tmp done - - systemctl start hostapd } ## Unsetters