From 538826b32e88ab3f448e0d8f5df6e7e957dd0e12 Mon Sep 17 00:00:00 2001 From: HgO Date: Mon, 21 Aug 2023 18:43:20 +0200 Subject: [PATCH] enable multi instance --- conf/openvpn_90-hotspot | 2 +- conf/systemd.service | 4 +-- conf/systemd_hostapd.service | 15 ++-------- conf/ynh-hotspot | 55 +++++++++++++++++++++--------------- manifest.json | 2 +- scripts/backup | 20 ++++++------- scripts/config | 18 ++++-------- scripts/install | 42 ++++++++++++++++----------- scripts/remove | 29 +++++++++---------- scripts/restore | 23 +++++++-------- scripts/upgrade | 30 +++++++++++--------- 11 files changed, 119 insertions(+), 121 deletions(-) diff --git a/conf/openvpn_90-hotspot b/conf/openvpn_90-hotspot index 5964ef2..98bb699 100644 --- a/conf/openvpn_90-hotspot +++ b/conf/openvpn_90-hotspot @@ -1,3 +1,3 @@ #!/bin/bash -systemctl restart ynh-hotspot +systemctl restart __SERVICE_NAME__ diff --git a/conf/systemd.service b/conf/systemd.service index 6268e69..1537aca 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -6,8 +6,8 @@ After=network.target [Service] Type=oneshot User=root -ExecStart=/usr/local/bin/ynh-hotspot start -ExecStop=/usr/local/bin/ynh-hotspot stop +ExecStart=/usr/local/bin/__SERVICE_NAME__ start +ExecStop=/usr/local/bin/__SERVICE_NAME__ stop RemainAfterExit=yes [Install] diff --git a/conf/systemd_hostapd.service b/conf/systemd_hostapd.service index c2b3146..14ad3eb 100644 --- a/conf/systemd_hostapd.service +++ b/conf/systemd_hostapd.service @@ -1,21 +1,12 @@ [Unit] -Documentation=man:systemd-sysv-generator(8) -SourcePath=/etc/init.d/hostapd Description=LSB: Advanced IEEE 802.11 management daemon After=remote-fs.target After=network-online.target Wants=network-online.target [Service] -Type=forking +Type=simple Restart=no TimeoutSec=5min -IgnoreSIGPIPE=no -KillMode=process -GuessMainPID=no -RemainAfterExit=yes -SuccessExitStatus=5 6 -Environment=DAEMON_CONF=/etc/hostapd/hostapd-%i.conf -ExecStart=/etc/init.d/hostapd start -ExecStop=/etc/init.d/hostapd stop -ExecReload=/etc/init.d/hostapd reload +ExecStart=/usr/sbin/hostapd /etc/hostapd/__APP__/hostapd.conf +ExecReload=/bin/kill -HEP $MAINPID diff --git a/conf/ynh-hotspot b/conf/ynh-hotspot index adf5194..5f3428f 100644 --- a/conf/ynh-hotspot +++ b/conf/ynh-hotspot @@ -63,7 +63,13 @@ is_dhcpd4_running() { } is_hostapd_running() { - systemctl is-active "hostapd@${wifi_device}" &>/dev/null + systemctl is-active "hostapd@${app}" &>/dev/null +} + +is_other_hostapd_running() { + other_hostapd_services=$(systemctl list-units --state=running hostapd@*.service | grep -v "^hostapd@$app.service") + + [[ -n "${other_hostapd_service}" ]] } is_running() { @@ -206,7 +212,7 @@ stop_dhcpd() { } stop_hostapd() { - systemctl stop "hostapd@${wifi_device}" + systemctl stop "hostapd@${app}" } if [ "$1" != restart ]; then @@ -215,20 +221,21 @@ if [ "$1" != restart ]; then echo -n "Retrieving Yunohost settings... " - service_enabled=$(systemctl is-enabled ynh-hotspot) - wifi_device=$(ynh_app_setting_get hotspot wifi_device) - wifi_channel=$(ynh_app_setting_get hotspot wifi_channel) + app=__APP__ + service_enabled=$(ynh_app_setting_get --app=$app --key=service_enabled) + wifi_device=$(ynh_app_setting_get --app=$app --key=wifi_device) + wifi_channel=$(ynh_app_setting_get --app=$app --key=wifi_channel) - wifi_ssid=$(ynh_app_setting_get hotspot wifi_ssid) - wifi_secure=$(ynh_app_setting_get hotspot wifi_secure) - wifi_passphrase=$(ynh_app_setting_get hotspot wifi_passphrase) - ip6_firewall=$(ynh_app_setting_get hotspot ip6_firewall) - ip6_dns=$(ynh_app_setting_get hotspot ip6_dns) - ip6_net=$(ynh_app_setting_get hotspot ip6_net) - ip4_dns=$(ynh_app_setting_get hotspot ip4_dns) - ip4_nat_prefix=$(ynh_app_setting_get hotspot ip4_nat_prefix) + wifi_ssid=$(ynh_app_setting_get --app=$app --key=wifi_ssid) + wifi_secure=$(ynh_app_setting_get --app=$app --key=wifi_secure) + wifi_passphrase=$(ynh_app_setting_get --app=$app --key=wifi_passphrase) + ip6_firewall=$(ynh_app_setting_get --app=$app --key=ip6_firewall) + ip6_dns=$(ynh_app_setting_get --app=$app --key=ip6_dns) + ip6_net=$(ynh_app_setting_get --app=$app --key=ip6_net) + ip4_dns=$(ynh_app_setting_get --app=$app --key=ip4_dns) + ip4_nat_prefix=$(ynh_app_setting_get --app=$app --key=ip4_nat_prefix) - old_gateway_interface=$(ynh_app_setting_get hotspot gateway_interface) + old_gateway_interface=$(ynh_app_setting_get --app=$app --key=gateway_interface) new_gateway_interface=$(ip route get 1.2.3.4 | awk '{ print $5; }') echo "OK" @@ -252,7 +259,7 @@ start) fi echo "[hotspot] Starting..." - touch /tmp/.ynh-hotspot-started + touch /tmp/.${service_name}-started # Check old state of the ipv4 NAT settings if [[ -n "${old_gateway_interface}" ]] && [[ "${new_gateway_interface}" != "${old_gateway_interface}" ]] && is_nat_set "${old_gateway_interface}"; then @@ -275,7 +282,7 @@ start) configure_hostapd echo "Starting hostapd..." - if ! systemctl start "hostapd@${wifi_device}"; then + if ! systemctl start "hostapd@${app}"; then journalctl -u hostapd -n 100 --no-hostname --no-pager exit 1 fi @@ -292,16 +299,18 @@ start) ;; stop) echo "[hotspot] Stopping..." - rm -f /tmp/.ynh-hotspot-started + rm -f /tmp/.${service_name}-started - if [[ -n "${old_gateway_interface}" ]] && is_nat_set "${old_gateway_interface}"; then - echo "Unset NAT" - unset_nat "${old_gateway_interface}" + if ! is_other_hostapd_running; then + if [[ -n "${old_gateway_interface}" ]] && is_nat_set "${old_gateway_interface}"; then + echo "Unset NAT" + unset_nat "${old_gateway_interface}" + fi + + echo "Unset forwarding" + unset_forwarding fi - echo "Unset forwarding" - unset_forwarding - unset_ipaddr unset_ipfirewall stop_dhcpd diff --git a/manifest.json b/manifest.json index f2ecc47..efcda4f 100644 --- a/manifest.json +++ b/manifest.json @@ -21,7 +21,7 @@ "requirements": { "yunohost": ">= 4.3.2" }, - "multi_instance": false, + "multi_instance": true, "services": [], "arguments": { "install" : [ diff --git a/scripts/backup b/scripts/backup index ba2defc..cbf88e1 100644 --- a/scripts/backup +++ b/scripts/backup @@ -30,7 +30,6 @@ app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get --app=$app --key=final_path) firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree) service_name=$(ynh_app_setting_get --app=$app --key=service_name) -wifi_device=$(ynh_app_setting_get --app=$app --key=wifi_device) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -41,21 +40,19 @@ ynh_print_info --message="Declaring files to be backed up..." # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="/etc/hostapd/hostapd.conf.tpl" -ynh_backup --src_path="/etc/hostapd/hostapd-${wifi_device}.conf" +ynh_backup --src_path="/etc/hostapd/$app/hostapd.conf.tpl" +ynh_backup --src_path="/etc/hostapd/$app/hostapd.conf" -ynh_backup --src_path="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl" -ynh_backup --src_path="/etc/dnsmasq.dhcpd/dhcpdv6-ssid-${wifi_device}.conf" +ynh_backup --src_path="/etc/dnsmasq.$app/dhcpdv6.conf.tpl" +ynh_backup --src_path="/etc/dnsmasq.$app/dhcpdv6.conf" -ynh_backup --src_path="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" -ynh_backup --src_path="/etc/dnsmasq.dhcpd/dhcpdv4-ssid-${wifi_device}.conf" +ynh_backup --src_path="/etc/dnsmasq.$app/dhcpdv4.conf.tpl" +ynh_backup --src_path="/etc/dnsmasq.$app/dhcpdv4.conf" ynh_backup --src_path="/usr/local/bin/$service_name" -ynh_backup --src_path="/etc/openvpn/scripts/route-up.d/90-hotspot" -ynh_backup --src_path="/etc/openvpn/scripts/route-down.d/90-hotspot" - -ynh_backup --src_path="/etc/init.d/hostapd" +ynh_backup --src_path="/etc/openvpn/scripts/route-up.d/90-$service_name" +ynh_backup --src_path="/etc/openvpn/scripts/route-down.d/90-$service_name" #================================================= # SPECIFIC BACKUP @@ -64,6 +61,7 @@ ynh_backup --src_path="/etc/init.d/hostapd" #================================================= ynh_backup --src_path="/etc/systemd/system/$service_name.service" +ynh_backup --src_path="/etc/systemd/system/hostapd@$app.service" #================================================= # END OF SCRIPT diff --git a/scripts/config b/scripts/config index 34f5794..4c7c40c 100644 --- a/scripts/config +++ b/scripts/config @@ -181,11 +181,9 @@ set__dns() { # OVERWRITING APPLY STEP #================================================= ynh_app_config_apply() { - old_wifi_device=$(ynh_app_setting_get $app wifi_device) - # Stop vpn client ynh_print_info --message="Stopping hotspot in order to edit files" - /usr/local/bin/ynh-hotspot stop + /usr/local/bin/${service_name} stop _ynh_app_config_apply @@ -195,20 +193,16 @@ ynh_app_config_apply() { local sec_comment="#" fi - ynh_secure_remove --file="/etc/hostapd/hostapd-${old_wifi_device}.conf" - ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv6-ssid-${old_wifi_device}.conf" - ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv4-ssid-${old_wifi_device}.conf" - - ynh_add_config --template="/etc/hostapd/hostapd.conf.tpl" --destination="/etc/hostapd/hostapd-${wifi_device}.conf" - ynh_add_config --template="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" --destination="/etc/dnsmasq.dhcpd/dhcpdv4-ssid-${wifi_device}.conf" + ynh_add_config --template="/etc/hostapd/$app/hostapd.conf.tpl" --destination="/etc/hostapd/$app/hostapd.conf" + ynh_add_config --template="/etc/dnsmasq.$app/dhcpdv4.conf.tpl" --destination="/etc/dnsmasq.$app/dhcpdv4.conf" if [[ -n "${ip6_net}" ]] && [[ "${ip6_net}" != "none" ]]; then - ynh_add_config --template="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl" --destination="/etc/dnsmasq.dhcpd/dhcpdv6-ssid-${wifi_device}.conf" + ynh_add_config --template="/etc/dnsmasq.$app/dhcpdv6.conf.tpl" --destination="/etc/dnsmasq.$app/dhcpdv6.conf" fi - # Start vpn client + # Start hotspot ynh_print_info --message="Starting hotspot service if needed" - /usr/local/bin/ynh-hotspot start + /usr/local/bin/${service_name} start } diff --git a/scripts/install b/scripts/install index 1e9504c..725312f 100644 --- a/scripts/install +++ b/scripts/install @@ -30,7 +30,7 @@ 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' +service_name=ynh-$app #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS @@ -130,6 +130,13 @@ if [[ ! -v ip6_net ]]; then # if ip6_net not set fi fi +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" + hot_reload_usb_wifi_cards wifi_device=$(iw_devices | awk -F\| '{ print $1 }') @@ -141,8 +148,8 @@ 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_dns --value="${ip6_dns}" ynh_app_setting_set --app=$app --key=ip6_net --value="${ip6_net}" -ynh_app_setting_set --app=$app --key=ip4_dns --value="10.0.242.1" -ynh_app_setting_set --app=$app --key=ip4_nat_prefix --value=10.0.242 +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}" if [[ -z $wifi_device ]]; then ynh_app_setting_set --app=$app --key=service_enabled --value=0 @@ -155,32 +162,33 @@ fi #================================================= ynh_script_progression --message="Copying configuration files..." -mkdir -pm 0755 /etc/dnsmasq.dhcpd/ -chown root: /etc/dnsmasq.dhcpd/ +mkdir -pm 0755 /etc/hostapd/$app/ +chown root: /etc/hostapd/$app/ -install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl /etc/hostapd/hostapd.conf.tpl -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 +mkdir -pm 0755 /etc/dnsmasq.$app/ +chown root: /etc/dnsmasq.$app/ + +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 # Copy init script -install -o root -g root -m 0755 ../conf/$service_name /usr/local/bin/ +ynh_add_config --template="../conf/ynh-hotspot" --destination="/usr/local/bin/$service_name" # 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 - +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}" #================================================= # CONFIGURE HOSTAPD #================================================= ynh_script_progression --message="Configuring hostapd..." -## hostapd -ynh_store_file_checksum --file="/etc/init.d/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. @@ -196,14 +204,14 @@ ynh_script_progression --message="Configuring a systemd service..." # Create a dedicated systemd config ynh_add_systemd_config --service=$service_name # Create custom systemd config for hostapd to handle multiple wifi devices -ynh_add_systemd_config --service="hostapd@.service" --template="../conf/systemd_hostapd.service" +ynh_add_systemd_config --service="hostapd@$app.service" --template="../conf/systemd_hostapd.service" #================================================= # 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" +yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/remove b/scripts/remove index 408f31a..d3acaa9 100644 --- a/scripts/remove +++ b/scripts/remove @@ -18,7 +18,6 @@ app=$YNH_APP_INSTANCE_NAME firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree) service_name=$(ynh_app_setting_get --app=$app --key=service_name) -wifi_device=$(ynh_app_setting_get --app=$app --key=wifi_device) #================================================= # STANDARD REMOVE @@ -27,12 +26,9 @@ wifi_device=$(ynh_app_setting_get --app=$app --key=wifi_device) #================================================= # Remove the service from the list of services known by Yunohost (added from `yunohost service add`) -if yunohost service status $service_name >/dev/null 2>&1 -then - ynh_script_progression --message="Removing $app service" - yunohost service stop $service_name - yunohost service remove $service_name -fi +ynh_script_progression --message="Removing $app service" +yunohost service stop $service_name +yunohost service remove $service_name #================================================= # STOP AND REMOVE SERVICE @@ -41,6 +37,7 @@ ynh_script_progression --message="Stopping and removing the systemd service..." # Remove the dedicated systemd config ynh_remove_systemd_config --service=$service_name +ynh_remove_systemd_config --service="hostapd@$app" #================================================= # REMOVE DEPENDENCIES @@ -55,26 +52,26 @@ ynh_remove_app_dependencies #================================================= ynh_script_progression --message="Removing app main directory..." -ynh_secure_remove --file="/etc/openvpn/scripts/route-up.d/90-hotspot" -ynh_secure_remove --file="/etc/openvpn/scripts/route-down.d/90-hotspot" +ynh_secure_remove --file="/etc/openvpn/scripts/route-up.d/90-${service_name}" +ynh_secure_remove --file="/etc/openvpn/scripts/route-down.d/90-${service_name}" # Remove the app directory securely ynh_secure_remove --file="/usr/local/bin/$service_name" -for FILE in $(ls /tmp/.ynh-hotspot-* 2>/dev/null) +for FILE in $(ls /tmp/.${service_name}-* 2>/dev/null) do ynh_secure_remove --file="$FILE" done # Remove confs -ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl" -ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv6-ssid-${wifi_device}.conf" +ynh_secure_remove --file="/etc/dnsmasq.$app/dhcpdv6.conf.tpl" +ynh_secure_remove --file="/etc/dnsmasq.$app/dhcpdv6.conf" -ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" -ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv4-ssid-${wifi_device}.conf" +ynh_secure_remove --file="/etc/dnsmasq.$app/dhcpdv4.conf.tpl" +ynh_secure_remove --file="/etc/dnsmasq.$app/dhcpdv4.conf" -ynh_secure_remove --file="/etc/hostapd/hostapd.conf.tpl" -ynh_secure_remove --file="/etc/hostapd/hostapd-${wifi_device}.conf" +ynh_secure_remove --file="/etc/hostapd/$app/hostapd.conf.tpl" +ynh_secure_remove --file="/etc/hostapd/$app/hostapd.conf" #================================================= # CLOSE A PORT diff --git a/scripts/restore b/scripts/restore index e4d982b..0fc6027 100644 --- a/scripts/restore +++ b/scripts/restore @@ -29,7 +29,6 @@ app=$YNH_APP_INSTANCE_NAME firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree) service_name=$(ynh_app_setting_get --app=$app --key=service_name) -wifi_device=$(ynh_app_setting_get --app=$app --key=wifi_device) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -62,21 +61,19 @@ else pkg_dependencies="$pkg_dependencies $free_firmware_packages" fi -ynh_restore_file --origin_path="/etc/hostapd/hostapd.conf.tpl" -ynh_restore_file --origin_path="/etc/hostapd/hostapd-${wifi_device}.conf" +ynh_restore_file --origin_path="/etc/hostapd/$app/hostapd.conf.tpl" +ynh_restore_file --origin_path="/etc/hostapd/$app/hostapd.conf" --not_mandatory -ynh_restore_file --origin_path="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl" -ynh_restore_file --origin_path="/etc/dnsmasq.dhcpd/dhcpdv6-ssid-${wifi_device}.conf" +ynh_restore_file --origin_path="/etc/dnsmasq.$app/dhcpdv6.conf.tpl" +ynh_restore_file --origin_path="/etc/dnsmasq.$app/dhcpdv6.conf" --not_mandatory -ynh_restore_file --origin_path="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" -ynh_restore_file --origin_path="/etc/dnsmasq.dhcpd/dhcpdv4-ssid-${wifi_device}.conf" +ynh_restore_file --origin_path="/etc/dnsmasq.$app/dhcpdv4.conf.tpl" +ynh_restore_file --origin_path="/etc/dnsmasq.$app/dhcpdv4.conf" --not_mandatory ynh_restore_file --origin_path="/usr/local/bin/$service_name" -ynh_restore_file --origin_path="/etc/openvpn/scripts/route-up.d/90-hotspot" -ynh_restore_file --origin_path="/etc/openvpn/scripts/route-down.d/90-hotspot" - -ynh_restore_file --origin_path="/etc/init.d/hostapd" +ynh_restore_file --origin_path="/etc/openvpn/scripts/route-up.d/90-${service_name}" +ynh_restore_file --origin_path="/etc/openvpn/scripts/route-down.d/90-${service_name}" #================================================= # SPECIFIC RESTORATION @@ -94,14 +91,14 @@ ynh_install_app_dependencies $pkg_dependencies ynh_script_progression --message="Restoring the systemd configuration..." ynh_restore_file --origin_path="/etc/systemd/system/$service_name.service" -systemctl enable $service_name.service --quiet +ynh_restore_file --origin_path="/etc/systemd/system/hostapd@$app.service" #================================================= # 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" +yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/upgrade b/scripts/upgrade index 9ef90ed..6a9ce48 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -68,7 +68,7 @@ elif [ $firmware_nonfree = "no" ]; then fi if [ -z $service_name ]; then - service_name="ynh-hotspot" + service_name="ynh-$app" ynh_app_setting_set --app=$app --key=service_name --value=$service_name fi @@ -124,8 +124,7 @@ ynh_secure_remove --file="/etc/hostapd/hostapd.conf" ynh_secure_remove --file="/etc/hostapd/hostapd.base.conf" ynh_secure_remove --file="/etc/hostapd/hostapd.accesspoint.conf" -for FILE in $(ls /etc/dnsmasq.dhcpd/dhcpdv{4,6}-ssid{0..3}.conf 2>/dev/null); do - ynh_secure_remove --file="$FILE" +for FILE in $(ls /etc/dnsmasq.dhcpd/*.conf 2>/dev/null); do ynh_secure_remove --file="$FILE" done @@ -188,22 +187,27 @@ ynh_install_app_dependencies $pkg_dependencies #================================================= ynh_script_progression --message="Copying configuration..." -mkdir -pm 0755 /etc/dnsmasq.dhcpd/ -chown root: /etc/dnsmasq.dhcpd/ +mkdir -pm 0755 /etc/hostapd/$app/ +chown root: /etc/hostapd/$app/ -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 +mkdir -pm 0755 /etc/dnsmasq.$app/ +chown root: /etc/dnsmasq.$app/ + +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 # Copy init script -install -o root -g root -m 0755 ../conf/$service_name /usr/local/bin/ +ynh_add_config --template="../conf/ynh-hotspot" --destination="/usr/local/bin/$service_name" # 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 +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}" #================================================= # SETUP SYSTEMD @@ -213,7 +217,7 @@ ynh_script_progression --message="Upgrading systemd configuration..." # Create a dedicated systemd config ynh_add_systemd_config --service=$service_name # Create custom systemd config for hostapd to handle multiple wifi devices -ynh_add_systemd_config --service="hostapd@.service" --template="../conf/systemd_hostapd.service" +ynh_add_systemd_config --service="hostapd@$app.service" --template="../conf/systemd_hostapd.service" #================================================= # GENERIC FINALIZATION @@ -222,7 +226,7 @@ ynh_add_systemd_config --service="hostapd@.service" --template="../conf/systemd_ #================================================= 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" +yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" #================================================= # START SYSTEMD SERVICE