2014-11-16 23:27:36 +01:00
|
|
|
#!/bin/bash
|
2014-11-02 21:30:56 +01:00
|
|
|
|
2014-12-26 20:18:03 +01:00
|
|
|
# Wifi Hotspot app for YunoHost
|
|
|
|
# Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
|
2015-07-22 23:54:56 +02:00
|
|
|
# Contribute at https://github.com/labriqueinternet/hotspot_ynh
|
2014-12-26 20:18:03 +01:00
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
|
2015-07-24 18:43:19 +02:00
|
|
|
# This is an upgrade?
|
|
|
|
upgrade=$([ "$HOTSPOT_UPGRADE" == 1 ] && echo true || echo false)
|
|
|
|
|
2014-11-02 21:30:56 +01:00
|
|
|
# Retrieve arguments
|
2014-11-09 22:49:07 +01:00
|
|
|
domain=${1}
|
|
|
|
url_path=${2}
|
|
|
|
wifi_ssid=${3}
|
|
|
|
wifi_passphrase=${4}
|
2015-03-14 15:44:48 +01:00
|
|
|
firmware_nonfree=${5}
|
2014-11-25 21:05:24 +01:00
|
|
|
|
2015-07-24 18:43:19 +02:00
|
|
|
if ! $upgrade; then
|
2014-11-16 23:27:36 +01:00
|
|
|
|
2015-07-24 18:43:19 +02:00
|
|
|
# Check YunoHost version
|
|
|
|
ynh_version=$(sudo dpkg -l yunohost | grep ii | awk '{ print $3 }' | sed 's/\.//g')
|
|
|
|
|
|
|
|
if [ "${ynh_version}" -lt 220 ]; then
|
|
|
|
echo "ERROR: You need a YunoHost version equals or greater than 2.2.0"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
sudo systemctl is-active dnsmasq &> /dev/null
|
|
|
|
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "ERROR: You need to enable dnsmasq instead of bind9 (apt-get remove bind9 && systemctl start dnsmasq)"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check arguments
|
|
|
|
if [ -z "${wifi_ssid}" -o -z "${wifi_passphrase}" ]; then
|
|
|
|
echo "ERROR: Your Wifi Hotspot needs a name and a password" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
wifi_passphrase_length="$(echo -n "${wifi_passphrase}" | wc -c)"
|
|
|
|
if [ "${wifi_passphrase_length}" -lt 8 -o "${wifi_passphrase_length}" -gt 63 ]; then
|
|
|
|
echo "ERROR: Your password must from 8 to 63 characters (WPA2 passphrase)" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "${wifi_passphrase}" | grep -qP '[^[:print:]]'
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "ERROR: Only printable ASCII characters are permitted in your password (WPA2 passphrase)" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check domain/path availability
|
|
|
|
sudo yunohost app checkurl ${domain}${url_path} -a hotspot
|
|
|
|
if [ ! $? -eq 0 ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
2014-11-16 23:27:36 +01:00
|
|
|
|
2014-11-09 22:49:07 +01:00
|
|
|
fi
|
|
|
|
|
2014-11-02 21:30:56 +01:00
|
|
|
# Install packages
|
2015-05-02 14:54:08 +02:00
|
|
|
packages='php5-fpm sipcalc hostapd iptables iw dnsmasq'
|
2015-03-17 00:35:34 +01:00
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
2014-12-28 15:38:05 +01:00
|
|
|
|
|
|
|
# Packaged USB Wireless Device firmwares
|
|
|
|
# Based on https://wiki.debian.org/WiFi#USB_Devices
|
2015-03-14 15:44:48 +01:00
|
|
|
if [ "${firmware_nonfree}" == yes ]; then
|
|
|
|
packages="$packages firmware-atheros atmel-firmware firmware-linux-free firmware-linux-nonfree firmware-realtek firmware-ralink firmware-libertas zd1211-firmware"
|
|
|
|
else
|
|
|
|
packages="$packages firmware-linux-free"
|
2015-07-22 19:44:11 +02:00
|
|
|
|
|
|
|
# Extract from http://packages.trisquel.info/toutatis-updates/open-ath9k-htc-firmware
|
|
|
|
# https://www.fsf.org/news/ryf-certification-thinkpenguin-usb-with-atheros-chip
|
|
|
|
# https://wiki.debian.org/ath9k_htc/open_firmware
|
|
|
|
sudo install -b -o root -g root -m 0644 ../conf/firmware_htc-7010.fw /lib/firmware/htc_7010.fw
|
|
|
|
sudo install -b -o root -g root -m 0644 ../conf/firmware_htc-9271.fw /lib/firmware/htc_9271.fw
|
2015-03-14 15:44:48 +01:00
|
|
|
fi
|
2014-12-28 15:38:05 +01:00
|
|
|
|
2014-11-25 21:05:24 +01:00
|
|
|
sudo apt-get --assume-yes --force-yes install ${packages}
|
2014-11-02 21:30:56 +01:00
|
|
|
|
2014-11-25 21:05:24 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
sudo apt-get update
|
|
|
|
sudo apt-get --assume-yes --force-yes install ${packages}
|
|
|
|
fi
|
2014-11-02 21:30:56 +01:00
|
|
|
|
2015-07-24 18:43:19 +02:00
|
|
|
if ! $upgrade; then
|
|
|
|
|
|
|
|
# Compute extra arguments
|
|
|
|
if [ -z "${ip6_net}" ]; then
|
|
|
|
ip6_net=none
|
|
|
|
ip6_addr=none
|
|
|
|
|
|
|
|
if [ -e /tmp/.ynh-vpnclient-started ]; then
|
|
|
|
vpnclient_ip6_net=$(sudo yunohost app setting vpnclient ip6_net 2>&1)
|
|
|
|
vpnclient_ip6_addr=$(sudo yunohost app setting vpnclient ip6_addr 2>&1)
|
|
|
|
|
|
|
|
if [[ "${vpnclient_ip6_net}" =~ :: && "${vpnclient_ip6_addr}" =~ :: ]]; then
|
|
|
|
ip6_net=${vpnclient_ip6_net}
|
|
|
|
ip6_addr=${vpnclient_ip6_addr}
|
|
|
|
fi
|
2014-12-29 01:18:31 +01:00
|
|
|
fi
|
|
|
|
fi
|
2015-07-24 18:43:19 +02:00
|
|
|
|
|
|
|
wifi_device=$(sudo bash ../conf/iw_devices | awk -F\| '{ print $1 }')
|
|
|
|
|
|
|
|
if [ -z "${wifi_device}" ]; then
|
|
|
|
echo "ERROR: No wifi interface found" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Save arguments
|
|
|
|
sudo yunohost app setting hotspot service_enabled -v 1
|
|
|
|
sudo yunohost app setting hotspot multissid -v 1
|
|
|
|
sudo yunohost app setting hotspot wifi_ssid -v "${wifi_ssid}"
|
|
|
|
sudo yunohost app setting hotspot wifi_secure -v 1
|
|
|
|
sudo yunohost app setting hotspot wifi_passphrase -v "${wifi_passphrase}"
|
|
|
|
sudo yunohost app setting hotspot wifi_device -v "${wifi_device}"
|
|
|
|
sudo yunohost app setting hotspot wifi_channel -v 6
|
|
|
|
sudo yunohost app setting hotspot ip6_addr -v "${ip6_addr}"
|
|
|
|
sudo yunohost app setting hotspot ip6_net -v "${ip6_net}"
|
|
|
|
sudo yunohost app setting hotspot ip6_dns0 -v 2001:913::8
|
|
|
|
sudo yunohost app setting hotspot ip6_dns1 -v 2001:910:800::12
|
|
|
|
sudo yunohost app setting hotspot ip4_dns0 -v 80.67.188.188
|
|
|
|
sudo yunohost app setting hotspot ip4_dns1 -v 80.67.169.12
|
|
|
|
sudo yunohost app setting hotspot ip4_nat_prefix -v 10.0.242
|
|
|
|
sudo yunohost app setting hotspot vpnclient -v no
|
2014-11-16 23:27:36 +01:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
2015-05-02 14:54:08 +02:00
|
|
|
# Install custom scripts
|
|
|
|
sudo install -o root -g root -m 0755 ../conf/iw_multissid /usr/local/bin/
|
|
|
|
sudo install -o root -g root -m 0755 ../conf/iw_devices /usr/local/bin/
|
|
|
|
sudo install -o root -g root -m 0755 ../conf/iw_ssids /usr/local/bin/
|
2014-11-16 23:27:36 +01:00
|
|
|
sudo install -o root -g root -m 0755 ../conf/ipv6_expanded /usr/local/bin/
|
|
|
|
sudo install -o root -g root -m 0755 ../conf/ipv6_compressed /usr/local/bin/
|
2014-11-04 23:00:04 +01:00
|
|
|
|
2014-11-02 21:30:56 +01:00
|
|
|
# Copy confs
|
2015-03-17 01:03:19 +01:00
|
|
|
sudo mkdir -pm 0755 /var/log/nginx/
|
2015-04-26 21:34:11 +02:00
|
|
|
sudo mkdir -pm 0755 /etc/dnsmasq.dhcpd/
|
|
|
|
sudo chown root: /etc/dnsmasq.dhcpd/
|
2014-12-26 18:58:58 +01:00
|
|
|
|
2015-04-26 21:34:11 +02:00
|
|
|
sudo install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl? /etc/hostapd/
|
|
|
|
sudo install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl
|
|
|
|
sudo install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl
|
2014-11-09 22:49:07 +01:00
|
|
|
sudo install -b -o root -g root -m 0644 ../conf/nginx_wifiadmin.conf "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf"
|
|
|
|
sudo install -b -o root -g root -m 0644 ../conf/phpfpm_wifiadmin.conf /etc/php5/fpm/pool.d/wifiadmin.conf
|
2014-11-02 21:30:56 +01:00
|
|
|
|
2014-11-09 22:49:07 +01:00
|
|
|
# Copy web sources
|
|
|
|
sudo mkdir -pm 0755 /var/www/wifiadmin/
|
|
|
|
sudo cp -a ../sources/* /var/www/wifiadmin/
|
|
|
|
|
|
|
|
sudo chown -R root: /var/www/wifiadmin/
|
|
|
|
sudo chmod -R 0644 /var/www/wifiadmin/*
|
|
|
|
sudo find /var/www/wifiadmin/ -type d -exec chmod +x {} \;
|
2014-11-02 21:30:56 +01:00
|
|
|
|
2014-11-09 22:49:07 +01:00
|
|
|
# Fix confs
|
2014-11-02 21:30:56 +01:00
|
|
|
## hostapd
|
|
|
|
sudo sed 's|^DAEMON_CONF=$|&/etc/hostapd/hostapd.conf|' -i /etc/init.d/hostapd
|
|
|
|
|
2014-11-09 22:49:07 +01:00
|
|
|
## nginx
|
|
|
|
sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf"
|
|
|
|
sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/wifiadmin/|g' -i "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf"
|
|
|
|
sudo sed 's|<TPL:PHP_NAME>|wifiadmin|g' -i "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf"
|
|
|
|
|
|
|
|
## php-fpm
|
|
|
|
sudo sed 's|<TPL:PHP_NAME>|wifiadmin|g' -i /etc/php5/fpm/pool.d/wifiadmin.conf
|
|
|
|
sudo sed 's|<TPL:PHP_USER>|admin|g' -i /etc/php5/fpm/pool.d/wifiadmin.conf
|
|
|
|
sudo sed 's|<TPL:PHP_GROUP>|admins|g' -i /etc/php5/fpm/pool.d/wifiadmin.conf
|
|
|
|
sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/wifiadmin/|g' -i /etc/php5/fpm/pool.d/wifiadmin.conf
|
|
|
|
|
|
|
|
# Fix sources
|
|
|
|
sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i /var/www/wifiadmin/config.php
|
|
|
|
|
|
|
|
# Copy init script
|
2015-05-25 02:23:28 +02:00
|
|
|
sudo install -o root -g root -m 0755 ../conf/ynh-hotspot /usr/local/bin/
|
|
|
|
sudo install -o root -g root -m 0644 ../conf/ynh-hotspot.service /etc/systemd/system/
|
2014-11-09 22:49:07 +01:00
|
|
|
|
2014-12-26 18:58:58 +01:00
|
|
|
# Update firewall for DHCP
|
|
|
|
sudo yunohost firewall allow --no-upnp --ipv6 UDP 547
|
|
|
|
sudo yunohost firewall allow --no-upnp UDP 67
|
|
|
|
|
2014-11-02 21:30:56 +01:00
|
|
|
# Set default inits
|
|
|
|
# The boot order of these services are important, so they are disabled by default
|
|
|
|
# and the ynh-hotspot service handles them.
|
2015-05-25 02:23:28 +02:00
|
|
|
sudo systemctl disable hostapd
|
|
|
|
sudo systemctl stop hostapd
|
|
|
|
sudo systemctl enable php5-fpm
|
|
|
|
sudo systemctl restart php5-fpm
|
|
|
|
sudo systemctl reload nginx
|
2014-11-09 22:49:07 +01:00
|
|
|
|
2014-11-09 00:40:40 +01:00
|
|
|
# Remove IPv6 address set if there is a VPN installed
|
2014-11-10 22:27:59 +01:00
|
|
|
if [ "${ip6_addr}" != none ]; then
|
|
|
|
sudo ip -6 address show dev tun0 2> /dev/null | grep -q "${ip6_addr}/"
|
|
|
|
if [ "$?" -eq 0 ]; then
|
|
|
|
sudo ip address delete "${ip6_addr}/128" dev tun0 &> /dev/null
|
|
|
|
fi
|
2014-11-05 23:41:51 +01:00
|
|
|
fi
|
|
|
|
|
2015-07-24 18:43:19 +02:00
|
|
|
if ! $upgrade; then
|
|
|
|
sudo systemctl enable ynh-hotspot
|
|
|
|
sudo systemctl start ynh-hotspot
|
2014-11-09 22:49:07 +01:00
|
|
|
|
2015-07-24 18:43:19 +02:00
|
|
|
sudo yunohost service add ynh-hotspot
|
|
|
|
sudo yunohost app ssowatconf
|
|
|
|
fi
|
2014-11-02 21:30:56 +01:00
|
|
|
|
|
|
|
exit 0
|