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
|
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|
2021-05-15 20:52:43 +02:00
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_clean_check_starting
|
|
|
|
}
|
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
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
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
|
2023-08-21 18:43:20 +02:00
|
|
|
service_name=ynh-$app
|
2019-02-10 16:42:40 +01:00
|
|
|
|
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
|
|
|
|
|
|
|
# Check arguments
|
2021-10-13 01:22:32 +02:00
|
|
|
if [[ -z $wifi_ssid ]] || [[ -z $wifi_passphrase ]]; then
|
2021-05-15 20:52:43 +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
|
2021-10-13 01:22:32 +02:00
|
|
|
wifi_passphrase_length="$(wc -c <<< "${wifi_passphrase}")"
|
|
|
|
if [[ $wifi_passphrase_length -lt 8 ]] || [[ $wifi_passphrase_length -gt 63 ]]; then
|
2021-05-15 20:52:43 +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
|
2021-05-15 20:52:43 +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=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
|
|
|
|
|
2021-10-17 21:24:17 +02:00
|
|
|
# Meh idk where to put this ... On RPi, by default wlan is blocked
|
|
|
|
if test -e /usr/sbin/rfkill && rfkill | grep wlan | grep -q -w 'blocked'
|
|
|
|
then
|
|
|
|
ynh_print_info "Unblocking wlan interface..."
|
|
|
|
/usr/sbin/rfkill unblock wlan
|
|
|
|
fi
|
|
|
|
|
2019-02-23 00:46:33 +01:00
|
|
|
#=================================================
|
|
|
|
# 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-05-15 20:52:43 +02:00
|
|
|
check_armbian_nonfree_conflict
|
|
|
|
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-05-15 20:52:43 +02: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
|
|
|
|
#=================================================
|
2021-05-15 20:52:43 +02:00
|
|
|
ynh_script_progression --message="Installing dependencies..."
|
2019-02-23 00:46:33 +01:00
|
|
|
|
2021-05-15 20:52:43 +02: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
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
2021-10-13 01:22:32 +02:00
|
|
|
# SPECIFIC SETTINGS
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
2021-10-13 01:22:32 +02:00
|
|
|
ynh_script_progression --message="Configuring hotspot..."
|
2014-11-04 23:00:04 +01:00
|
|
|
|
2023-08-21 10:51:37 +02:00
|
|
|
ip6_net=""
|
|
|
|
ip6_dns=""
|
2019-02-23 00:56:02 +01:00
|
|
|
if [[ ! -v ip6_net ]]; then # if ip6_net not set
|
2021-05-15 20:52:43 +02:00
|
|
|
if [[ -e /tmp/.ynh-vpnclient-started ]]; then
|
|
|
|
vpnclient_ip6_net=$(ynh_app_setting_get vpnclient ip6_net 2>&1)
|
|
|
|
|
2021-10-18 00:04:34 +02:00
|
|
|
if [[ $vpnclient_ip6_net =~ :: ]]; then
|
2021-05-15 20:52:43 +02:00
|
|
|
ip6_net=${vpnclient_ip6_net}
|
2023-08-21 10:51:37 +02:00
|
|
|
ip6_dns="${ip6_net}1"
|
2021-05-15 20:52:43 +02:00
|
|
|
fi
|
|
|
|
fi
|
2019-02-23 00:56:02 +01:00
|
|
|
fi
|
|
|
|
|
2023-08-21 18:43:20 +02:00
|
|
|
ip4_nat_prefix_index=${app##*__}
|
|
|
|
if [[ "${ip4_nat_prefix_index}" == "${app}" ]]; then
|
|
|
|
ip4_nat_prefix_index=0
|
|
|
|
fi
|
|
|
|
ip4_nat_prefix="10.${ip4_nat_prefix_index}.242"
|
|
|
|
ip4_dns="${ip4_nat_prefix}.1"
|
|
|
|
|
2021-03-17 01:03:07 +01:00
|
|
|
hot_reload_usb_wifi_cards
|
2023-08-23 10:24:43 +02:00
|
|
|
wifi_device=$(unused_iw_devices | head -n 1)
|
2023-08-21 22:40:58 +02:00
|
|
|
wifi_secure=1
|
|
|
|
wifi_channel=6
|
2019-02-23 00:56:02 +01:00
|
|
|
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=wifi_ssid --value="${wifi_ssid}"
|
2023-08-21 22:40:58 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=wifi_secure --value="${wifi_secure}"
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=wifi_passphrase --value="${wifi_passphrase}"
|
|
|
|
ynh_app_setting_set --app=$app --key=wifi_device --value="${wifi_device}"
|
2023-08-21 22:40:58 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=wifi_channel --value="${wifi_channel}"
|
2023-08-22 09:28:36 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=advanced --value=0
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=ip6_firewall --value=1
|
2023-08-21 10:51:37 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=ip6_dns --value="${ip6_dns}"
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=ip6_net --value="${ip6_net}"
|
2023-08-21 18:43:20 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=ip4_dns --value="${ip4_dns}"
|
|
|
|
ynh_app_setting_set --app=$app --key=ip4_nat_prefix --value="${ip4_nat_prefix}"
|
2019-02-23 00:56:02 +01:00
|
|
|
|
|
|
|
if [[ -z $wifi_device ]]; then
|
2021-05-15 20:52:43 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=service_enabled --value=0
|
2019-02-23 00:56:02 +01:00
|
|
|
else
|
2021-05-15 20:52:43 +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
|
|
|
|
#=================================================
|
2021-10-13 01:22:32 +02:00
|
|
|
ynh_script_progression --message="Copying configuration files..."
|
2018-05-04 00:33:01 +02:00
|
|
|
|
2023-08-21 18:43:20 +02:00
|
|
|
mkdir -pm 0755 /etc/hostapd/$app/
|
|
|
|
chown root: /etc/hostapd/$app/
|
|
|
|
|
|
|
|
mkdir -pm 0755 /etc/dnsmasq.$app/
|
|
|
|
chown root: /etc/dnsmasq.$app/
|
2014-12-26 18:58:58 +01:00
|
|
|
|
2023-08-21 18:43:20 +02:00
|
|
|
install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl /etc/hostapd/$app/hostapd.conf.tpl
|
|
|
|
install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq.$app/dhcpdv6.conf.tpl
|
|
|
|
install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.$app/dhcpdv4.conf.tpl
|
2019-02-23 00:46:33 +01:00
|
|
|
|
|
|
|
# Copy init script
|
2023-08-21 18:43:20 +02:00
|
|
|
ynh_add_config --template="../conf/ynh-hotspot" --destination="/usr/local/bin/$service_name"
|
2023-08-21 19:19:24 +02:00
|
|
|
chmod 0755 "/usr/local/bin/$service_name"
|
2020-11-29 03:42:47 +01:00
|
|
|
|
2023-08-16 20:39:02 +02:00
|
|
|
# Copy openvpn scripts
|
|
|
|
mkdir -pm 0755 /etc/openvpn/scripts
|
|
|
|
mkdir -pm 0755 /etc/openvpn/scripts/route-up.d
|
|
|
|
mkdir -pm 0755 /etc/openvpn/scripts/route-down.d
|
2023-08-21 18:43:20 +02:00
|
|
|
ynh_add_config --template="../conf/openvpn_90-hotspot" --destination="/etc/openvpn/scripts/route-up.d/90-$service_name"
|
|
|
|
ynh_add_config --template="../conf/openvpn_90-hotspot" --destination="/etc/openvpn/scripts/route-down.d/90-$service_name"
|
|
|
|
chmod 0755 "/etc/openvpn/scripts/route-up.d/90-${service_name}"
|
|
|
|
chmod 0755 "/etc/openvpn/scripts/route-down.d/90-${service_name}"
|
2023-08-16 20:39:02 +02:00
|
|
|
|
2020-11-29 03:42:47 +01:00
|
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|
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.
|
2021-10-17 21:36:39 +02:00
|
|
|
systemctl disable hostapd --quiet 2>&1
|
|
|
|
systemctl stop hostapd 2>&1
|
|
|
|
systemctl unmask hostapd 2>&1 # On some system e.g. RPi, for some reason hostapd is masked after install ...
|
2020-11-29 03:42:47 +01:00
|
|
|
|
2023-08-21 22:40:58 +02:00
|
|
|
if [[ -n ${wifi_device} ]]; then
|
2023-08-22 14:51:13 +02:00
|
|
|
configure_hostapd
|
|
|
|
configure_dhcp
|
2023-08-21 22:40:58 +02:00
|
|
|
fi
|
|
|
|
|
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
|
2023-08-21 16:17:22 +02:00
|
|
|
# Create custom systemd config for hostapd to handle multiple wifi devices
|
2023-08-21 19:09:11 +02:00
|
|
|
ynh_add_systemd_config --service="hostapd@$app" --template="../conf/systemd_hostapd.service"
|
2014-11-09 22:49:07 +01:00
|
|
|
|
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
|
|
|
|
2023-08-23 15:46:15 +02:00
|
|
|
yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app"
|
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
|
2021-09-20 19:47:24 +02:00
|
|
|
if [[ $wifi_device == "" ]]; then
|
2021-05-15 20:52:43 +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
|
2023-08-21 22:40:58 +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"
|