|
@@ -1,28 +1,19 @@
|
|
|
#!/bin/bash
|
|
|
-### BEGIN INIT INFO
|
|
|
-# Provides: ynh-hotspot
|
|
|
-# Required-Start: $network $remote_fs $syslog yunohost-api
|
|
|
-# Required-Stop: $network $remote_fs $syslog
|
|
|
-# Default-Start: 2 3 4 5
|
|
|
-# Default-Stop: 0 1 6
|
|
|
-# Short-Description: Set prerequisites for wifi hotspot.
|
|
|
-# Description: Set prerequisites for wifi hotspot.
|
|
|
-### END INIT INFO
|
|
|
-
|
|
|
-# Wifi Hotspot app for YunoHost
|
|
|
+#
|
|
|
+# Wifi Hotspot app for YunoHost
|
|
|
# Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
|
|
|
# Contribute at https://github.com/jvaubourg/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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
@@ -89,13 +80,13 @@ is_dhcpd4_running() {
|
|
|
}
|
|
|
|
|
|
is_hostapd_running() {
|
|
|
- service hostapd status &> /dev/null
|
|
|
+ systemctl is-active hostapd &> /dev/null
|
|
|
}
|
|
|
|
|
|
is_running() {
|
|
|
for i in $(seq 0 $((${ynh_multissid} - 1))); do
|
|
|
- ( has_ip6delegatedprefix ${i} && is_ip6addr_set ${i} || ! has_ip6delegatedprefix ${i} )\
|
|
|
- && is_ip4nataddr_set ${i} && is_dhcpd6_running ${i} && is_dhcpd4_running ${i}
|
|
|
+ ( has_ip6delegatedprefix ${i} && is_ip6addr_set ${i} && is_dhcpd6_running ${i} || ! has_ip6delegatedprefix ${i} )\
|
|
|
+ && is_ip4nataddr_set ${i} && is_dhcpd4_running ${i}
|
|
|
|
|
|
if [ ! $? -eq 0 ]; then
|
|
|
return 1
|
|
@@ -152,9 +143,7 @@ start_dhcpd6() {
|
|
|
dev="hotspot${i}"
|
|
|
fi
|
|
|
|
|
|
- rm -f /etc/dnsmasq.dhcpd/dhcpdv6-ssid*.conf
|
|
|
-
|
|
|
- cp /etc/dnsmasq.dhcp/dhcpdv6{.conf.tpl,-ssid${i}.conf}
|
|
|
+ cp /etc/dnsmasq.dhcpd/dhcpdv6{.conf.tpl,-ssid${i}.conf}
|
|
|
|
|
|
sed "s|<TPL:WIFI_DEVICE>|${dev}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf
|
|
|
sed "s|<TPL:IP6_NET>|${ynh_ip6_net[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf
|
|
@@ -173,8 +162,6 @@ start_dhcpd4() {
|
|
|
dev="hotspot${i}"
|
|
|
fi
|
|
|
|
|
|
- rm -f /etc/dnsmasq.dhcpd/dhcpdv4-ssid*.conf
|
|
|
-
|
|
|
cp /etc/dnsmasq.dhcpd/dhcpdv4{.conf.tpl,-ssid${i}.conf}
|
|
|
|
|
|
sed "s|<TPL:IP4_DNS0>|${ynh_ip4_dns0[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf
|
|
@@ -201,7 +188,7 @@ start_hostapd() {
|
|
|
sed "s|<TPL:WIFI_INTERFACE>|hotspot${i}|g" -i /etc/hostapd/hostapd.conf.tmp
|
|
|
sed "s|<TPL:WIFI_SSID>|${ynh_wifi_ssid[${i}]}|g" -i /etc/hostapd/hostapd.conf.tmp
|
|
|
sed "s|<TPL:WIFI_PASSPHRASE>|${ynh_wifi_passphrase[${i}]}|g" -i /etc/hostapd/hostapd.conf.tmp
|
|
|
-
|
|
|
+
|
|
|
if [ "${ynh_wifi_secure[${i}]}" -eq 1 ]; then
|
|
|
sed "s|<TPL:SEC_COMMENT>||g" -i /etc/hostapd/hostapd.conf.tmp
|
|
|
else
|
|
@@ -218,7 +205,7 @@ start_hostapd() {
|
|
|
rm /etc/hostapd/hostapd.conf.tmp
|
|
|
done
|
|
|
|
|
|
- service hostapd start
|
|
|
+ systemctl start hostapd
|
|
|
}
|
|
|
|
|
|
## Unsetters
|
|
@@ -269,33 +256,41 @@ stop_dhcpd4() {
|
|
|
}
|
|
|
|
|
|
stop_hostapd() {
|
|
|
- service hostapd stop
|
|
|
+ systemctl stop hostapd
|
|
|
}
|
|
|
|
|
|
## Tools
|
|
|
|
|
|
moulinette_get() {
|
|
|
var=${1}
|
|
|
+ gotcha=0
|
|
|
|
|
|
- value=$(yunohost app setting hotspot "${var}")
|
|
|
+ while [ "${gotcha}" -eq 0 ]; do
|
|
|
+ value=$(yunohost app setting hotspot "${var}")
|
|
|
|
|
|
- if [[ "${value}" =~ "An instance is already running" ]]; then
|
|
|
- echo "${value}" >&2
|
|
|
- exit 1
|
|
|
- fi
|
|
|
+ if [[ "${value}" =~ "An instance is already running" ]]; then
|
|
|
+ sleep $(($((RANDOM%5)) + 1))
|
|
|
+ else
|
|
|
+ gotcha=1
|
|
|
+ fi
|
|
|
+ done
|
|
|
|
|
|
echo "${value}"
|
|
|
-}
|
|
|
+}
|
|
|
|
|
|
moulinette_vpnclient_get() {
|
|
|
var=${1}
|
|
|
+ gotcha=0
|
|
|
|
|
|
- value=$(yunohost app setting vpnclient "${var}")
|
|
|
+ while [ "${gotcha}" -eq 0 ]; do
|
|
|
+ value=$(yunohost app setting vpnclient "${var}")
|
|
|
|
|
|
- if [[ "${value}" =~ "An instance is already running" ]]; then
|
|
|
- echo "${value}" >&2
|
|
|
- exit 1
|
|
|
- fi
|
|
|
+ if [[ "${value}" =~ "An instance is already running" ]]; then
|
|
|
+ sleep $(($((RANDOM%5)) + 1))
|
|
|
+ else
|
|
|
+ gotcha=1
|
|
|
+ fi
|
|
|
+ done
|
|
|
|
|
|
echo "${value}"
|
|
|
}
|
|
@@ -317,13 +312,13 @@ if [ "$1" != restart ]; then
|
|
|
# Restart php5-fpm at the first start (it needs to be restarted after the slapd start)
|
|
|
if [ ! -e /tmp/.ynh-hotspot-boot ]; then
|
|
|
touch /tmp/.ynh-hotspot-boot
|
|
|
- service php5-fpm restart
|
|
|
+ systemctl restart php5-fpm
|
|
|
fi
|
|
|
-
|
|
|
+
|
|
|
# Variables
|
|
|
-
|
|
|
+
|
|
|
echo -n "Retrieving Yunohost settings... "
|
|
|
-
|
|
|
+
|
|
|
ynh_service_enabled=$(moulinette_get service_enabled)
|
|
|
ynh_wifi_device=$(moulinette_get wifi_device)
|
|
|
ynh_wifi_channel=$(moulinette_get wifi_channel)
|
|
@@ -342,23 +337,23 @@ if [ "$1" != restart ]; then
|
|
|
|
|
|
old_internet_device=$(moulinette_get internet_device)
|
|
|
new_internet_device=$(ip route | awk '/default via/ { print $NF; }')
|
|
|
-
|
|
|
+
|
|
|
# Switch the NAT interface if there is a VPN
|
|
|
ip link show dev tun0 &> /dev/null
|
|
|
if [ "$?" -eq 0 ]; then
|
|
|
new_internet_device=tun0
|
|
|
fi
|
|
|
-
|
|
|
+
|
|
|
echo "OK"
|
|
|
-
|
|
|
+
|
|
|
# Check IPv6 delegated prefix from vpnclient
|
|
|
# vpnclient_ip6_net=$(moulinette_vpnclient_get ip6_net)
|
|
|
-#
|
|
|
+#
|
|
|
# if [ ! -z "${vpnclient_ip6_addr}" ]; then
|
|
|
# if [ "${ynh_ip6_net}" == none ]; then
|
|
|
# ynh_ip6_net=$vpnclient_ip6_net
|
|
|
# ynh_ip6_addr=$(moulinette_vpnclient_get ip6_addr)
|
|
|
-#
|
|
|
+#
|
|
|
# moulinette_set ip6_net "${ynh_ip6_net}"
|
|
|
# moulinette_set ip6_addr "${ynh_ip6_addr}"
|
|
|
# else
|
|
@@ -416,12 +411,16 @@ case "$1" in
|
|
|
exit 1
|
|
|
fi
|
|
|
|
|
|
- i=0; false || while [ $? -ne 0 ]; do
|
|
|
- sleep 1 && (( i++ ))
|
|
|
- [ ${i} -gt 20 ] && stop_hostapd
|
|
|
- [ ${i} -gt 20 ] && exit 1
|
|
|
- ip link show dev "mon.${ynh_wifi_device}" &> /dev/null
|
|
|
- done
|
|
|
+ if [ "${ynh_multissid}" -gt 1 ]; then
|
|
|
+ i=0; false || while [ $? -ne 0 ]; do
|
|
|
+ sleep 1 && (( i++ ))
|
|
|
+ [ ${i} -gt 20 ] && stop_hostapd
|
|
|
+ [ ${i} -gt 20 ] && exit 1
|
|
|
+ ip link show dev hotspot1 &> /dev/null
|
|
|
+ done
|
|
|
+ else
|
|
|
+ sleep 1
|
|
|
+ fi
|
|
|
fi
|
|
|
|
|
|
# For each registred ssid
|
|
@@ -432,13 +431,13 @@ case "$1" in
|
|
|
echo "hotspot${i}: Set IPv4 NAT address"
|
|
|
set_ip4nataddr ${i}
|
|
|
fi
|
|
|
-
|
|
|
+
|
|
|
# Set the ipv6 address
|
|
|
if has_ip6delegatedprefix ${i} && ! is_ip6addr_set ${i}; then
|
|
|
echo "hotspot${i}: Set IPv6 address"
|
|
|
set_ip6addr ${i}
|
|
|
fi
|
|
|
-
|
|
|
+
|
|
|
# Run DHCPv6 server
|
|
|
if has_ip6delegatedprefix ${i} && ! is_dhcpd6_running ${i}; then
|
|
|
echo "hotspot${i}: Start the NDP and DHCPv6 server (dnsmasq)"
|
|
@@ -480,8 +479,8 @@ case "$1" in
|
|
|
if has_ip6delegatedprefix ${i} && is_ip6addr_set ${i}; then
|
|
|
echo "hotspot${i}: Unset IPv6 address"
|
|
|
unset_ip6addr ${i}
|
|
|
- fi
|
|
|
-
|
|
|
+ fi
|
|
|
+
|
|
|
if is_dhcpd6_running ${i}; then
|
|
|
echo "hotspot${i}: Stop the NDP and DHCPv6 server (dnsmasq)"
|
|
|
stop_dhcpd6 ${i}
|
|
@@ -498,8 +497,9 @@ case "$1" in
|
|
|
stop_hostapd
|
|
|
fi
|
|
|
|
|
|
+ # Fix configuration
|
|
|
if has_vpnclient_app; then
|
|
|
- service ynh-vpnclient start
|
|
|
+ ynh-vpnclient start
|
|
|
fi
|
|
|
;;
|
|
|
restart)
|
|
@@ -541,7 +541,7 @@ case "$1" in
|
|
|
if has_ip6delegatedprefix ${i}; then
|
|
|
echo "[INFO] hotspot${i}: IPv6 delegated prefix found"
|
|
|
echo "[INFO] hotspot${i}: IPv6 address computed from the delegated prefix: ${ynh_ip6_addr}"
|
|
|
-
|
|
|
+
|
|
|
if is_ip6addr_set ${i}; then
|
|
|
echo "[OK] hotspot${i}: IPv6 address set"
|
|
|
else
|
|
@@ -558,14 +558,14 @@ case "$1" in
|
|
|
else
|
|
|
echo "[INFO] hotspot${i}: No IPv6 delegated prefix found"
|
|
|
fi
|
|
|
-
|
|
|
+
|
|
|
if is_dhcpd4_running ${i}; then
|
|
|
echo "[OK] hotspot${i}: DHCPv4 server (dnsmasq) is running"
|
|
|
else
|
|
|
echo "[ERR] hotspot${i}: NDP and DHCPv4 (dnsmasq) is not running"
|
|
|
exitcode=1
|
|
|
fi
|
|
|
-
|
|
|
+
|
|
|
if is_ip4nataddr_set ${i}; then
|
|
|
echo "[OK] hotspot${i}: IPv4 NAT address set"
|
|
|
else
|