2014-11-16 23:27:36 +01:00
|
|
|
#!/bin/bash
|
2014-11-02 21:30:56 +01:00
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
# Wifi Hotspot app for YunoHost
|
2014-12-26 20:18:03 +01:00
|
|
|
# Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
|
2015-07-22 23:54:56 +02:00
|
|
|
# Contribute at https://github.com/labriqueinternet/hotspot_ynh
|
2018-05-04 00:33:01 +02:00
|
|
|
#
|
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.
|
2018-05-04 00:33:01 +02:00
|
|
|
#
|
2014-12-26 20:18:03 +01:00
|
|
|
# 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.
|
2018-05-04 00:33:01 +02:00
|
|
|
#
|
2014-12-26 20:18:03 +01:00
|
|
|
# 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/>.
|
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2015-07-24 18:43:19 +02:00
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
2014-11-25 21:05:24 +01:00
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
2014-11-16 23:27:36 +01:00
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
2015-09-29 18:01:10 +02:00
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path_url=$YNH_APP_ARG_PATH
|
|
|
|
wifi_ssid=$YNH_APP_ARG_WIFI_SSID
|
|
|
|
wifi_passphrase=$YNH_APP_ARG_WIFI_PASSPHRASE
|
|
|
|
firmware_nonfree=$YNH_APP_ARG_FIRMWARE_NONFREE
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2019-02-10 16:42:40 +01:00
|
|
|
# the service name must match the service template files
|
|
|
|
service_name='ynh-hotspot'
|
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_script_progression --message="Validating installation parameters..."
|
2018-05-04 00:33:01 +02:00
|
|
|
|
2020-05-31 05:33:17 +02:00
|
|
|
final_path=/var/www/$app
|
|
|
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
2018-05-04 00:33:01 +02:00
|
|
|
|
|
|
|
# Register (book) web path
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
2018-05-04 00:33:01 +02:00
|
|
|
|
2019-03-19 21:33:16 +01:00
|
|
|
if [ $firmware_nonfree = "no" ]; then
|
|
|
|
firmware_nonfree=0
|
|
|
|
elif [ $firmware_nonfree = "yes" ]; then
|
|
|
|
firmware_nonfree=1
|
|
|
|
fi
|
2018-05-04 00:33:01 +02:00
|
|
|
|
|
|
|
# Check arguments
|
|
|
|
if [[ -z $wifi_ssid || -z $wifi_passphrase ]]; then
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_die --message="Your Wifi Hotspot needs a name and a password"
|
2018-05-04 00:33:01 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Check passphrase length
|
|
|
|
wifi_passphrase_length="$(echo -n "${wifi_passphrase}" | wc -c)"
|
|
|
|
if [[ $wifi_passphrase_length -lt 8 || $wifi_passphrase_length -gt 63 ]]; then
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_die --message="Your password must from 8 to 63 characters (WPA2 passphrase)"
|
2018-05-04 00:33:01 +02:00
|
|
|
fi
|
2014-11-16 23:27:36 +01:00
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
# Check no special characters are present in the passphrase
|
|
|
|
if [[ $wifi_passphrase =~ [^[:print:]] ]]; then
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_die --message="Only printable ASCII characters are permitted in your password (WPA2 passphrase)"
|
2014-11-09 22:49:07 +01:00
|
|
|
fi
|
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
2019-02-23 00:46:33 +01:00
|
|
|
# STORE SETTINGS FROM MANIFEST
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_script_progression --message="Storing installation settings..."
|
2019-02-23 00:46:33 +01:00
|
|
|
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=domain --value="$domain"
|
|
|
|
ynh_app_setting_set --app=$app --key=wifi_ssid --value="$wifi_ssid"
|
|
|
|
ynh_app_setting_set --app=$app --key=wifi_passphrase --value="$wifi_passphrase"
|
|
|
|
ynh_app_setting_set --app=$app --key=firmware_nonfree --value="$firmware_nonfree"
|
2020-11-29 03:42:47 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=service_name --value=$service_name
|
2018-05-04 00:33:01 +02:00
|
|
|
|
2019-02-10 19:51:12 +01:00
|
|
|
#=================================================
|
2019-02-23 00:46:33 +01:00
|
|
|
# STANDARD MODIFICATIONS
|
2019-02-10 19:51:12 +01:00
|
|
|
#=================================================
|
2019-02-23 00:46:33 +01:00
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
#=================================================
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_script_progression --message="Configuring firewall..."
|
2019-02-10 19:51:12 +01:00
|
|
|
|
2019-02-23 00:46:33 +01:00
|
|
|
# Update firewall for DHCP
|
|
|
|
ynh_exec_warn_less yunohost firewall allow --no-upnp --ipv6 UDP 547
|
|
|
|
ynh_exec_warn_less yunohost firewall allow --no-upnp UDP 67
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INSTALL NONFREE FIRWARE IF REQUESTED
|
|
|
|
#=================================================
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_script_progression --message="Installing firmware..."
|
2019-02-23 00:46:33 +01:00
|
|
|
|
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
|
|
|
|
# Packaged USB Wireless Device firmwares
|
|
|
|
# Based on https://wiki.debian.org/WiFi#USB_Devices
|
|
|
|
if [[ $firmware_nonfree -eq 1 ]]; then
|
2021-03-16 20:19:00 +01:00
|
|
|
check_armbian_nonfree_conflict
|
2021-03-20 20:51:34 +01:00
|
|
|
ynh_install_extra_app_dependencies --repo="deb http://deb.debian.org/debian $(ynh_get_debian_release) non-free" --package="$nonfree_firmware_packages"
|
2019-02-23 00:46:33 +01:00
|
|
|
else
|
2021-03-20 20:51:34 +01:00
|
|
|
pkg_dependencies="$pkg_dependencies $free_firmware_packages"
|
2019-02-10 19:51:12 +01:00
|
|
|
fi
|
|
|
|
|
2019-02-23 00:46:33 +01:00
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2020-11-02 19:54:21 +01:00
|
|
|
ynh_script_progression --message="Installing dependencies"
|
2019-02-23 00:46:33 +01:00
|
|
|
|
2021-03-20 20:51:34 +01:00
|
|
|
ynh_install_app_dependencies "$pkg_dependencies"
|
2019-02-23 00:46:33 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_script_progression --message="Configuring system user..."
|
2019-02-23 00:46:33 +01:00
|
|
|
|
|
|
|
# Create a system user
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_system_user_create --username=$app
|
2019-02-23 00:46:33 +01:00
|
|
|
|
2019-02-10 19:51:12 +01:00
|
|
|
# Ensure the system user has enough sudo permissions
|
|
|
|
install -b -o root -g root -m 0440 ../conf/sudoers.conf /etc/sudoers.d/${app}_ynh
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_replace_string --match_string="__HOTSPOT_SYSUSER__" --replace_string="${app}" --target_file="/etc/sudoers.d/${app}_ynh"
|
2019-02-23 00:46:33 +01:00
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
|
|
|
# INSTALL CUSTOM SCRIPTS
|
|
|
|
#=================================================
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_script_progression --message="Installing custom script..."
|
2018-05-04 00:33:01 +02:00
|
|
|
|
2019-02-09 12:42:19 +01:00
|
|
|
install -o root -g root -m 0755 ../conf/iw_multissid /usr/local/bin/
|
|
|
|
install -o root -g root -m 0755 ../conf/iw_devices /usr/local/bin/
|
|
|
|
install -o root -g root -m 0755 ../conf/iw_ssids /usr/local/bin/
|
|
|
|
install -o root -g root -m 0755 ../conf/ipv6_expanded /usr/local/bin/
|
|
|
|
install -o root -g root -m 0755 ../conf/ipv6_compressed /usr/local/bin/
|
2014-11-04 23:00:04 +01:00
|
|
|
|
2019-02-23 00:56:02 +01:00
|
|
|
if [[ ! -v ip6_net ]]; then # if ip6_net not set
|
|
|
|
ip6_net=none
|
|
|
|
ip6_addr=none
|
|
|
|
|
|
|
|
if [[ -e /tmp/.ynh-vpnclient-started ]]; then
|
|
|
|
vpnclient_ip6_net=$(ynh_app_setting_get vpnclient ip6_net 2>&1)
|
|
|
|
vpnclient_ip6_addr=$(ynh_app_setting_get vpnclient ip6_addr 2>&1)
|
|
|
|
|
|
|
|
if [[ $vpnclient_ip6_net =~ :: && $vpnclient_ip6_addr =~ :: ]]; then
|
|
|
|
ip6_net=${vpnclient_ip6_net}
|
|
|
|
ip6_addr=${vpnclient_ip6_addr}
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-03-17 01:03:07 +01:00
|
|
|
hot_reload_usb_wifi_cards
|
2019-02-23 01:01:18 +01:00
|
|
|
wifi_device=$(bash ../conf/iw_devices | awk -F\| '{ print $1 }')
|
2019-02-23 00:56:02 +01:00
|
|
|
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=multissid --value=1
|
|
|
|
ynh_app_setting_set --app=$app --key=wifi_ssid --value="${wifi_ssid}"
|
|
|
|
ynh_app_setting_set --app=$app --key=wifi_secure --value=1
|
|
|
|
ynh_app_setting_set --app=$app --key=wifi_passphrase --value="${wifi_passphrase}"
|
|
|
|
ynh_app_setting_set --app=$app --key=wifi_device --value="${wifi_device}"
|
|
|
|
ynh_app_setting_set --app=$app --key=wifi_channel --value=6
|
|
|
|
ynh_app_setting_set --app=$app --key=ip6_addr --value="${ip6_addr}"
|
|
|
|
ynh_app_setting_set --app=$app --key=ip6_firewall --value=1
|
|
|
|
ynh_app_setting_set --app=$app --key=ip6_net --value="${ip6_net}"
|
|
|
|
ynh_app_setting_set --app=$app --key=ip6_dns0 --value=2001:913::8
|
|
|
|
ynh_app_setting_set --app=$app --key=ip6_dns1 --value=2001:910:800::12
|
|
|
|
ynh_app_setting_set --app=$app --key=ip4_dns0 --value=80.67.188.188
|
|
|
|
ynh_app_setting_set --app=$app --key=ip4_dns1 --value=80.67.169.12
|
|
|
|
ynh_app_setting_set --app=$app --key=ip4_nat_prefix --value=10.0.242
|
|
|
|
ynh_app_setting_set --app=$app --key=vpnclient --value=no
|
2019-02-23 00:56:02 +01:00
|
|
|
|
|
|
|
if [[ -z $wifi_device ]]; then
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=service_enabled --value=0
|
2019-02-23 00:56:02 +01:00
|
|
|
wifi_device=none
|
|
|
|
else
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=service_enabled --value=1
|
2019-02-23 00:56:02 +01:00
|
|
|
fi
|
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
|
|
|
# COPY CONFIGS
|
|
|
|
#=================================================
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_script_progression --message="Copying configuration..."
|
2018-05-04 00:33:01 +02:00
|
|
|
|
2019-02-09 12:42:19 +01:00
|
|
|
mkdir -pm 0755 /etc/dnsmasq.dhcpd/
|
|
|
|
chown root: /etc/dnsmasq.dhcpd/
|
2014-12-26 18:58:58 +01:00
|
|
|
|
2019-02-09 12:42:19 +01:00
|
|
|
install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl? /etc/hostapd/
|
|
|
|
install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl
|
|
|
|
install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl
|
2019-02-23 00:46:33 +01:00
|
|
|
|
|
|
|
# Copy init script
|
|
|
|
install -o root -g root -m 0755 ../conf/$service_name /usr/local/bin/
|
2020-11-29 03:42:47 +01:00
|
|
|
ynh_replace_string --match_string="__PHPVERSION__" --replace_string="${YNH_PHP_VERSION}" --target_file="/usr/local/bin/$service_name"
|
2014-11-02 21:30:56 +01:00
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
|
|
|
# COPY WEB SOURCES
|
|
|
|
#=================================================
|
2020-11-29 03:42:47 +01:00
|
|
|
ynh_script_progression --message="Setting up source files..."
|
2018-05-04 00:33:01 +02:00
|
|
|
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
2019-02-23 00:46:33 +01:00
|
|
|
mkdir -pm 0755 ${final_path}/
|
|
|
|
cp -a ../sources/* ${final_path}/
|
2014-11-09 22:49:07 +01:00
|
|
|
|
2019-02-26 01:11:02 +01:00
|
|
|
chown -R $app: ${final_path}/
|
2019-02-23 00:46:33 +01:00
|
|
|
chmod -R 0644 ${final_path}/*
|
|
|
|
find ${final_path}/ -type d -exec chmod +x {} \;
|
2014-11-02 21:30:56 +01:00
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
2020-11-29 03:42:47 +01:00
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring nginx web server..."
|
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring php-fpm..."
|
|
|
|
|
|
|
|
# Create a dedicated php-fpm config
|
|
|
|
ynh_add_fpm_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CONFIGURE HOSTAPD
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
2020-11-29 03:42:47 +01:00
|
|
|
ynh_script_progression --message="Configuring hostapd..."
|
2018-05-04 00:33:01 +02:00
|
|
|
|
2014-11-02 21:30:56 +01:00
|
|
|
## hostapd
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_replace_string --match_string="^DAEMON_CONF=$" --replace_string="&/etc/hostapd/hostapd.conf" --target_file=/etc/init.d/hostapd
|
2019-03-14 02:39:00 +01:00
|
|
|
# We also need to put this in /etc/default/hostapd because on some setup
|
|
|
|
# like RPi, the version of hostapd is different and /etc/init.d/hostapd
|
|
|
|
# isnt used ... instead the service is "pure systemd" ...
|
|
|
|
echo "DAEMON_CONF=/etc/hostapd/hostapd.conf" > /etc/default/hostapd
|
2014-11-09 22:49:07 +01:00
|
|
|
|
2021-03-27 12:22:28 +01:00
|
|
|
# Apply configuration
|
|
|
|
ynh_add_config --template="config.php.tpl" --destination="$final_path/config.php"
|
2019-02-20 19:46:27 +01:00
|
|
|
|
2020-11-29 03:42:47 +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.
|
|
|
|
systemctl disable hostapd --quiet
|
|
|
|
systemctl stop hostapd
|
|
|
|
systemctl unmask hostapd # On some system e.g. RPi, for some reason hostapd is masked after install ...
|
|
|
|
|
2019-02-23 01:40:10 +01:00
|
|
|
#=================================================
|
|
|
|
# STORE THE CONFIG FILE CHECKSUM
|
|
|
|
#=================================================
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_script_progression --message="Storing the config file checksum..."
|
2019-02-23 01:40:10 +01:00
|
|
|
|
|
|
|
# Calculate and store the config file checksum into the app settings
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_store_file_checksum --file="/etc/init.d/hostapd"
|
2019-02-23 01:40:10 +01:00
|
|
|
|
2019-02-20 19:46:27 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_script_progression --message="Configuring a systemd service..."
|
2019-02-20 19:46:27 +01:00
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_add_systemd_config --service=$service_name
|
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
|
2018-05-04 00:33:01 +02:00
|
|
|
if [[ $ip6_addr != none ]]; then
|
2019-03-12 18:17:04 +01:00
|
|
|
if ip -6 address show dev tun0 2> /dev/null | grep -q "${ip6_addr}/"; then
|
2019-02-09 12:42:19 +01:00
|
|
|
ip address delete "${ip6_addr}/128" dev tun0 &> /dev/null
|
2014-11-10 22:27:59 +01:00
|
|
|
fi
|
2014-11-05 23:41:51 +01:00
|
|
|
fi
|
|
|
|
|
2020-05-31 05:33:17 +02:00
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
2015-07-24 19:20:19 +02:00
|
|
|
|
2021-03-29 11:20:25 +02:00
|
|
|
yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd"
|
2020-05-31 05:33:17 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
|
|
|
|
|
|
|
# Start a systemd service if device is present
|
2018-05-04 00:33:01 +02:00
|
|
|
if [[ $wifi_device == none ]]; then
|
2015-09-15 22:21:27 +02:00
|
|
|
echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2
|
2019-02-10 16:42:40 +01:00
|
|
|
else
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_systemd_action --service_name=$service_name --action="start" --log_path=systemd #--line_match="Started YunoHost Wifi Hotspot"
|
2015-09-15 22:21:27 +02:00
|
|
|
fi
|
|
|
|
|
2019-02-23 00:56:02 +01:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_script_progression --message="Installation of $app completed"
|