2014-11-09 22:49:07 +01:00
|
|
|
#wifiadmin!/bin/bash
|
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}
|
|
|
|
wifi_device=${5}
|
|
|
|
ip6_net=${6}
|
|
|
|
ip6_dns0=${7}
|
|
|
|
ip6_dns1=${8}
|
|
|
|
ip4_dns0=${9}
|
|
|
|
ip4_dns1=${10}
|
2014-11-02 21:30:56 +01:00
|
|
|
|
|
|
|
# Check arguments
|
|
|
|
# TODO
|
|
|
|
|
2014-11-09 22:49:07 +01:00
|
|
|
sudo yunohost app checkurl ${domain}${url_path} -a hotspot
|
|
|
|
if [ ! $? -eq 0 ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-11-02 21:30:56 +01:00
|
|
|
# Install packages
|
2014-11-04 23:00:04 +01:00
|
|
|
# TODO: Replace isc-dhcp-server by dnsmasq (currently negotiating with the YunoHost team to
|
|
|
|
# also replace bind9 by dnsmasq)
|
2014-11-09 22:49:07 +01:00
|
|
|
sudo apt-get --assume-yes --force-yes install hostapd radvd isc-dhcp-server iptables php5-fpm
|
2014-11-02 21:30:56 +01:00
|
|
|
|
|
|
|
# Install extra packages
|
|
|
|
sudo apt-get --assume-yes --force-yes install sipcalc
|
|
|
|
|
|
|
|
# Compute extra arguments
|
2014-11-09 00:40:40 +01:00
|
|
|
ip6_expanded_net=$(sipcalc "${ip6_net}" | grep Expanded | awk '{ print $NF; }')
|
|
|
|
ip6_net=$(sipcalc "${ip6_net}" | grep Compressed | awk '{ print $NF; }')
|
|
|
|
ip6_addr=$(echo "$(echo "${ip6_expanded_net}" | cut -d: -f1-7):1")
|
|
|
|
ip6_addr=$(sipcalc "${ip6_addr}" | grep Compressed | awk '{ print $NF; }')
|
2014-11-02 21:30:56 +01:00
|
|
|
ip4_nat_prefix=10.0.242
|
|
|
|
|
2014-11-09 22:49:07 +01:00
|
|
|
# Save arguments
|
2014-11-09 00:40:40 +01:00
|
|
|
sudo yunohost app setting hotspot wifi_ssid -v "${wifi_ssid}"
|
|
|
|
sudo yunohost app setting hotspot wifi_passphrase -v "${wifi_passphrase}"
|
|
|
|
sudo yunohost app setting hotspot wifi_device -v "${wifi_device}"
|
2014-11-09 22:49:07 +01:00
|
|
|
sudo yunohost app setting hotspot wifi_channel -v 6
|
2014-11-09 00:40:40 +01:00
|
|
|
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 "${ip6_dns0}"
|
|
|
|
sudo yunohost app setting hotspot ip6_dns1 -v "${ip6_dns1}"
|
|
|
|
sudo yunohost app setting hotspot ip4_dns0 -v "${ip4_dns0}"
|
|
|
|
sudo yunohost app setting hotspot ip4_dns1 -v "${ip4_dns1}"
|
|
|
|
sudo yunohost app setting hotspot ip4_nat_prefix -v "${ip4_nat_prefix}"
|
2014-11-04 23:00:04 +01:00
|
|
|
|
2014-11-02 21:30:56 +01:00
|
|
|
# Copy confs
|
2014-11-09 00:40:40 +01: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/radvd.conf.tpl /etc/
|
|
|
|
sudo install -b -o root -g root -m 0644 ../conf/dhcpd.conf.tpl /etc/dhcp/
|
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
|
|
|
# Create user for the web admin
|
|
|
|
sudo useradd -MUr wifiadmin
|
|
|
|
|
|
|
|
# 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
|
|
|
|
sudo sed 's|^;\?\s*max_execution_time.\+|max_execution_time = 600|' -i /etc/php5/fpm/php.ini
|
|
|
|
|
|
|
|
# Fix sources
|
|
|
|
sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i /var/www/wifiadmin/config.php
|
|
|
|
|
|
|
|
# Copy init script
|
|
|
|
sudo install -b -o root -g root -m 0755 ../conf/init_ynh-hotspot /etc/init.d/ynh-hotspot
|
|
|
|
|
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.
|
|
|
|
# All services are registred by yunohost in order to prevent conflicts after the uninstall.
|
|
|
|
sudo yunohost service add isc-dhcp-server
|
|
|
|
sudo yunohost service stop isc-dhcp-server
|
|
|
|
sudo yunohost service disable isc-dhcp-server
|
2014-11-09 22:49:07 +01:00
|
|
|
|
2014-11-02 21:30:56 +01:00
|
|
|
sudo yunohost service add radvd
|
|
|
|
sudo yunohost service stop radvd
|
|
|
|
sudo yunohost service disable radvd
|
2014-11-09 22:49:07 +01:00
|
|
|
|
2014-11-02 21:30:56 +01:00
|
|
|
sudo yunohost service add hostapd
|
|
|
|
sudo yunohost service stop hostapd
|
|
|
|
sudo yunohost service disable hostapd
|
|
|
|
|
2014-11-09 22:49:07 +01:00
|
|
|
sudo yunohost service add php5-fpm
|
|
|
|
sudo yunohost service enable php5-fpm
|
|
|
|
sudo yunohost service stop php5-fpm
|
|
|
|
sudo yunohost service start php5-fpm
|
|
|
|
|
|
|
|
sudo service nginx reload
|
|
|
|
|
2014-11-09 00:40:40 +01:00
|
|
|
# Remove IPv6 address set if there is a VPN installed
|
|
|
|
sudo ip -6 address show dev tun0 2> /dev/null | grep -q "${ip6_addr}/"
|
2014-11-05 23:41:51 +01:00
|
|
|
if [ "$?" -eq 0 ]; then
|
2014-11-09 00:40:40 +01:00
|
|
|
sudo ip address delete "${ip6_addr}/128" dev tun0 &> /dev/null
|
2014-11-05 23:41:51 +01:00
|
|
|
fi
|
|
|
|
|
2014-11-02 21:30:56 +01:00
|
|
|
sudo yunohost service add ynh-hotspot
|
|
|
|
sudo yunohost service enable ynh-hotspot
|
2014-11-09 22:49:07 +01:00
|
|
|
sudo service ynh-hotspot start
|
|
|
|
|
|
|
|
# Update SSO for wifiadmin
|
|
|
|
sudo yunohost app ssowatconf
|
2014-11-02 21:30:56 +01:00
|
|
|
|
|
|
|
exit 0
|