#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= ynh_clean_setup () { ynh_clean_check_starting } # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # 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 # the service name must match the service template files service_name='ynh-hotspot' #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= ynh_script_progression --message="Validating installation parameters..." # Check arguments if [[ -z $wifi_ssid ]] || [[ -z $wifi_passphrase ]]; then ynh_die --message="Your Wifi Hotspot needs a name and a password" fi # Check passphrase length wifi_passphrase_length="$(wc -c <<< "${wifi_passphrase}")" if [[ $wifi_passphrase_length -lt 8 ]] || [[ $wifi_passphrase_length -gt 63 ]]; then ynh_die --message="Your password must from 8 to 63 characters (WPA2 passphrase)" fi # Check no special characters are present in the passphrase if [[ $wifi_passphrase =~ [^[:print:]] ]]; then ynh_die --message="Only printable ASCII characters are permitted in your password (WPA2 passphrase)" fi #================================================= # STORE SETTINGS FROM MANIFEST #================================================= ynh_script_progression --message="Storing installation settings..." 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" ynh_app_setting_set --app=$app --key=service_name --value=$service_name #================================================= # STANDARD MODIFICATIONS #================================================= # FIND AND OPEN A PORT #================================================= ynh_script_progression --message="Configuring firewall..." # 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 # 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 #================================================= # INSTALL NONFREE FIRWARE IF REQUESTED #================================================= ynh_script_progression --message="Installing firmware..." export DEBIAN_FRONTEND=noninteractive # Packaged USB Wireless Device firmwares # Based on https://wiki.debian.org/WiFi#USB_Devices if [[ $firmware_nonfree -eq 1 ]]; then 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" else pkg_dependencies="$pkg_dependencies $free_firmware_packages" fi #================================================= # INSTALL DEPENDENCIES #================================================= ynh_script_progression --message="Installing dependencies..." ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE DEDICATED USER #================================================= ynh_script_progression --message="Configuring system user..." # Create a system user ynh_system_user_create --username=$app #================================================= # SPECIFIC SETTINGS #================================================= ynh_script_progression --message="Configuring hotspot..." if [[ ! -v ip6_net ]]; then # if ip6_net not set ip6_net="" if [[ -e /tmp/.ynh-vpnclient-started ]]; then vpnclient_ip6_net=$(ynh_app_setting_get vpnclient ip6_net 2>&1) if [[ $vpnclient_ip6_net =~ :: ]]; then ip6_net=${vpnclient_ip6_net} fi fi fi hot_reload_usb_wifi_cards wifi_device=$(iw_devices | awk -F\| '{ print $1 }') ynh_app_setting_set --app=$app --key=multissid --value=1 ynh_app_setting_set --app=$app --key=ssid_nb --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_firewall --value=1 ynh_app_setting_set --app=$app --key=ip6_net --value="${ip6_net}" ynh_app_setting_set --app=$app --key=dns --value="10.0.242.1" ynh_app_setting_set --app=$app --key=ip4_nat_prefix --value=10.0.242 if [[ -z $wifi_device ]]; then ynh_app_setting_set --app=$app --key=service_enabled --value=0 else ynh_app_setting_set --app=$app --key=service_enabled --value=1 fi #================================================= # COPY CONFIGS #================================================= ynh_script_progression --message="Copying configuration files..." mkdir -pm 0755 /etc/dnsmasq.dhcpd/ chown root: /etc/dnsmasq.dhcpd/ install -b -o root -g root -m 0644 ../conf/hostapd.*.conf /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 # Copy init script install -o root -g root -m 0755 ../conf/$service_name /usr/local/bin/ # 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 install -o root -g root -m 0755 ../conf/openvpn_90-hotspot /etc/openvpn/scripts/route-up.d/90-hotspot install -o root -g root -m 0755 ../conf/openvpn_90-hotspot /etc/openvpn/scripts/route-down.d/90-hotspot #================================================= # CONFIGURE HOSTAPD #================================================= ynh_script_progression --message="Configuring hostapd..." ## hostapd ynh_replace_string --match_string="^DAEMON_CONF=$" --replace_string="&/etc/hostapd/hostapd.conf" --target_file=/etc/init.d/hostapd ynh_store_file_checksum --file="/etc/init.d/hostapd" # 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 # 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 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 ... #================================================= # SETUP SYSTEMD #================================================= ynh_script_progression --message="Configuring a systemd service..." # Create a dedicated systemd config ynh_add_systemd_config --service=$service_name #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." # Start a systemd service if device is present if [[ $wifi_device == "" ]]; then echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2 else ynh_systemd_action --service_name=$service_name --action="start" --log_path=systemd #--line_match="Started YunoHost Wifi Hotspot" fi #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed"