1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/hotspot_ynh.git synced 2024-09-03 19:25:53 +02:00

enable multi instance

This commit is contained in:
HgO 2023-08-21 18:43:20 +02:00
parent d6b5dc62c5
commit 538826b32e
11 changed files with 119 additions and 121 deletions

View file

@ -1,3 +1,3 @@
#!/bin/bash #!/bin/bash
systemctl restart ynh-hotspot systemctl restart __SERVICE_NAME__

View file

@ -6,8 +6,8 @@ After=network.target
[Service] [Service]
Type=oneshot Type=oneshot
User=root User=root
ExecStart=/usr/local/bin/ynh-hotspot start ExecStart=/usr/local/bin/__SERVICE_NAME__ start
ExecStop=/usr/local/bin/ynh-hotspot stop ExecStop=/usr/local/bin/__SERVICE_NAME__ stop
RemainAfterExit=yes RemainAfterExit=yes
[Install] [Install]

View file

@ -1,21 +1,12 @@
[Unit] [Unit]
Documentation=man:systemd-sysv-generator(8)
SourcePath=/etc/init.d/hostapd
Description=LSB: Advanced IEEE 802.11 management daemon Description=LSB: Advanced IEEE 802.11 management daemon
After=remote-fs.target After=remote-fs.target
After=network-online.target After=network-online.target
Wants=network-online.target Wants=network-online.target
[Service] [Service]
Type=forking Type=simple
Restart=no Restart=no
TimeoutSec=5min TimeoutSec=5min
IgnoreSIGPIPE=no ExecStart=/usr/sbin/hostapd /etc/hostapd/__APP__/hostapd.conf
KillMode=process ExecReload=/bin/kill -HEP $MAINPID
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

View file

@ -63,7 +63,13 @@ is_dhcpd4_running() {
} }
is_hostapd_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() { is_running() {
@ -206,7 +212,7 @@ stop_dhcpd() {
} }
stop_hostapd() { stop_hostapd() {
systemctl stop "hostapd@${wifi_device}" systemctl stop "hostapd@${app}"
} }
if [ "$1" != restart ]; then if [ "$1" != restart ]; then
@ -215,20 +221,21 @@ if [ "$1" != restart ]; then
echo -n "Retrieving Yunohost settings... " echo -n "Retrieving Yunohost settings... "
service_enabled=$(systemctl is-enabled ynh-hotspot) app=__APP__
wifi_device=$(ynh_app_setting_get hotspot wifi_device) service_enabled=$(ynh_app_setting_get --app=$app --key=service_enabled)
wifi_channel=$(ynh_app_setting_get hotspot wifi_channel) 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_ssid=$(ynh_app_setting_get --app=$app --key=wifi_ssid)
wifi_secure=$(ynh_app_setting_get hotspot wifi_secure) wifi_secure=$(ynh_app_setting_get --app=$app --key=wifi_secure)
wifi_passphrase=$(ynh_app_setting_get hotspot wifi_passphrase) wifi_passphrase=$(ynh_app_setting_get --app=$app --key=wifi_passphrase)
ip6_firewall=$(ynh_app_setting_get hotspot ip6_firewall) ip6_firewall=$(ynh_app_setting_get --app=$app --key=ip6_firewall)
ip6_dns=$(ynh_app_setting_get hotspot ip6_dns) ip6_dns=$(ynh_app_setting_get --app=$app --key=ip6_dns)
ip6_net=$(ynh_app_setting_get hotspot ip6_net) ip6_net=$(ynh_app_setting_get --app=$app --key=ip6_net)
ip4_dns=$(ynh_app_setting_get hotspot ip4_dns) ip4_dns=$(ynh_app_setting_get --app=$app --key=ip4_dns)
ip4_nat_prefix=$(ynh_app_setting_get hotspot ip4_nat_prefix) 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; }') new_gateway_interface=$(ip route get 1.2.3.4 | awk '{ print $5; }')
echo "OK" echo "OK"
@ -252,7 +259,7 @@ start)
fi fi
echo "[hotspot] Starting..." echo "[hotspot] Starting..."
touch /tmp/.ynh-hotspot-started touch /tmp/.${service_name}-started
# Check old state of the ipv4 NAT settings # 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 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 configure_hostapd
echo "Starting 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 journalctl -u hostapd -n 100 --no-hostname --no-pager
exit 1 exit 1
fi fi
@ -292,16 +299,18 @@ start)
;; ;;
stop) stop)
echo "[hotspot] Stopping..." 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 if ! is_other_hostapd_running; then
echo "Unset NAT" if [[ -n "${old_gateway_interface}" ]] && is_nat_set "${old_gateway_interface}"; then
unset_nat "${old_gateway_interface}" echo "Unset NAT"
unset_nat "${old_gateway_interface}"
fi
echo "Unset forwarding"
unset_forwarding
fi fi
echo "Unset forwarding"
unset_forwarding
unset_ipaddr unset_ipaddr
unset_ipfirewall unset_ipfirewall
stop_dhcpd stop_dhcpd

View file

@ -21,7 +21,7 @@
"requirements": { "requirements": {
"yunohost": ">= 4.3.2" "yunohost": ">= 4.3.2"
}, },
"multi_instance": false, "multi_instance": true,
"services": [], "services": [],
"arguments": { "arguments": {
"install" : [ "install" : [

View file

@ -30,7 +30,6 @@ app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree) firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree)
service_name=$(ynh_app_setting_get --app=$app --key=service_name) 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 # 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 # BACKUP THE APP MAIN DIR
#================================================= #=================================================
ynh_backup --src_path="/etc/hostapd/hostapd.conf.tpl" ynh_backup --src_path="/etc/hostapd/$app/hostapd.conf.tpl"
ynh_backup --src_path="/etc/hostapd/hostapd-${wifi_device}.conf" 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.$app/dhcpdv6.conf.tpl"
ynh_backup --src_path="/etc/dnsmasq.dhcpd/dhcpdv6-ssid-${wifi_device}.conf" 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.$app/dhcpdv4.conf.tpl"
ynh_backup --src_path="/etc/dnsmasq.dhcpd/dhcpdv4-ssid-${wifi_device}.conf" ynh_backup --src_path="/etc/dnsmasq.$app/dhcpdv4.conf"
ynh_backup --src_path="/usr/local/bin/$service_name" 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-up.d/90-$service_name"
ynh_backup --src_path="/etc/openvpn/scripts/route-down.d/90-hotspot" ynh_backup --src_path="/etc/openvpn/scripts/route-down.d/90-$service_name"
ynh_backup --src_path="/etc/init.d/hostapd"
#================================================= #=================================================
# SPECIFIC BACKUP # 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/$service_name.service"
ynh_backup --src_path="/etc/systemd/system/hostapd@$app.service"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT

View file

@ -181,11 +181,9 @@ set__dns() {
# OVERWRITING APPLY STEP # OVERWRITING APPLY STEP
#================================================= #=================================================
ynh_app_config_apply() { ynh_app_config_apply() {
old_wifi_device=$(ynh_app_setting_get $app wifi_device)
# Stop vpn client # Stop vpn client
ynh_print_info --message="Stopping hotspot in order to edit files" 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 _ynh_app_config_apply
@ -195,20 +193,16 @@ ynh_app_config_apply() {
local sec_comment="#" local sec_comment="#"
fi fi
ynh_secure_remove --file="/etc/hostapd/hostapd-${old_wifi_device}.conf" ynh_add_config --template="/etc/hostapd/$app/hostapd.conf.tpl" --destination="/etc/hostapd/$app/hostapd.conf"
ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv6-ssid-${old_wifi_device}.conf" ynh_add_config --template="/etc/dnsmasq.$app/dhcpdv4.conf.tpl" --destination="/etc/dnsmasq.$app/dhcpdv4.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"
if [[ -n "${ip6_net}" ]] && [[ "${ip6_net}" != "none" ]]; then 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 fi
# Start vpn client # Start hotspot
ynh_print_info --message="Starting hotspot service if needed" ynh_print_info --message="Starting hotspot service if needed"
/usr/local/bin/ynh-hotspot start /usr/local/bin/${service_name} start
} }

View file

@ -30,7 +30,7 @@ firmware_nonfree=$YNH_APP_ARG_FIRMWARE_NONFREE
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
# the service name must match the service template files # 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 # 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
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 hot_reload_usb_wifi_cards
wifi_device=$(iw_devices | awk -F\| '{ print $1 }') 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_firewall --value=1
ynh_app_setting_set --app=$app --key=ip6_dns --value="${ip6_dns}" 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=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_dns --value="${ip4_dns}"
ynh_app_setting_set --app=$app --key=ip4_nat_prefix --value=10.0.242 ynh_app_setting_set --app=$app --key=ip4_nat_prefix --value="${ip4_nat_prefix}"
if [[ -z $wifi_device ]]; then if [[ -z $wifi_device ]]; then
ynh_app_setting_set --app=$app --key=service_enabled --value=0 ynh_app_setting_set --app=$app --key=service_enabled --value=0
@ -155,32 +162,33 @@ fi
#================================================= #=================================================
ynh_script_progression --message="Copying configuration files..." ynh_script_progression --message="Copying configuration files..."
mkdir -pm 0755 /etc/dnsmasq.dhcpd/ mkdir -pm 0755 /etc/hostapd/$app/
chown root: /etc/dnsmasq.dhcpd/ chown root: /etc/hostapd/$app/
install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl /etc/hostapd/hostapd.conf.tpl mkdir -pm 0755 /etc/dnsmasq.$app/
install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl chown root: /etc/dnsmasq.$app/
install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl
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 # 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 # Copy openvpn scripts
mkdir -pm 0755 /etc/openvpn/scripts mkdir -pm 0755 /etc/openvpn/scripts
mkdir -pm 0755 /etc/openvpn/scripts/route-up.d mkdir -pm 0755 /etc/openvpn/scripts/route-up.d
mkdir -pm 0755 /etc/openvpn/scripts/route-down.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 ynh_add_config --template="../conf/openvpn_90-hotspot" --destination="/etc/openvpn/scripts/route-up.d/90-$service_name"
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-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 # CONFIGURE HOSTAPD
#================================================= #=================================================
ynh_script_progression --message="Configuring hostapd..." ynh_script_progression --message="Configuring hostapd..."
## hostapd
ynh_store_file_checksum --file="/etc/init.d/hostapd"
# Set default inits # Set default inits
# The boot order of these services are important, so they are disabled by default # The boot order of these services are important, so they are disabled by default
# and the ynh-hotspot service handles them. # and the ynh-hotspot service handles them.
@ -196,14 +204,14 @@ ynh_script_progression --message="Configuring a systemd service..."
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config --service=$service_name ynh_add_systemd_config --service=$service_name
# Create custom systemd config for hostapd to handle multiple wifi devices # 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 # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating 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 # START SYSTEMD SERVICE

View file

@ -18,7 +18,6 @@ app=$YNH_APP_INSTANCE_NAME
firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree) firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree)
service_name=$(ynh_app_setting_get --app=$app --key=service_name) service_name=$(ynh_app_setting_get --app=$app --key=service_name)
wifi_device=$(ynh_app_setting_get --app=$app --key=wifi_device)
#================================================= #=================================================
# STANDARD REMOVE # 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`) # 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 ynh_script_progression --message="Removing $app service"
then yunohost service stop $service_name
ynh_script_progression --message="Removing $app service" yunohost service remove $service_name
yunohost service stop $service_name
yunohost service remove $service_name
fi
#================================================= #=================================================
# STOP AND REMOVE SERVICE # STOP AND REMOVE SERVICE
@ -41,6 +37,7 @@ ynh_script_progression --message="Stopping and removing the systemd service..."
# Remove the dedicated systemd config # Remove the dedicated systemd config
ynh_remove_systemd_config --service=$service_name ynh_remove_systemd_config --service=$service_name
ynh_remove_systemd_config --service="hostapd@$app"
#================================================= #=================================================
# REMOVE DEPENDENCIES # REMOVE DEPENDENCIES
@ -55,26 +52,26 @@ ynh_remove_app_dependencies
#================================================= #=================================================
ynh_script_progression --message="Removing app main directory..." 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-up.d/90-${service_name}"
ynh_secure_remove --file="/etc/openvpn/scripts/route-down.d/90-hotspot" ynh_secure_remove --file="/etc/openvpn/scripts/route-down.d/90-${service_name}"
# Remove the app directory securely # Remove the app directory securely
ynh_secure_remove --file="/usr/local/bin/$service_name" 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 do
ynh_secure_remove --file="$FILE" ynh_secure_remove --file="$FILE"
done done
# Remove confs # Remove confs
ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl" ynh_secure_remove --file="/etc/dnsmasq.$app/dhcpdv6.conf.tpl"
ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv6-ssid-${wifi_device}.conf" 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.$app/dhcpdv4.conf.tpl"
ynh_secure_remove --file="/etc/dnsmasq.dhcpd/dhcpdv4-ssid-${wifi_device}.conf" ynh_secure_remove --file="/etc/dnsmasq.$app/dhcpdv4.conf"
ynh_secure_remove --file="/etc/hostapd/hostapd.conf.tpl" ynh_secure_remove --file="/etc/hostapd/$app/hostapd.conf.tpl"
ynh_secure_remove --file="/etc/hostapd/hostapd-${wifi_device}.conf" ynh_secure_remove --file="/etc/hostapd/$app/hostapd.conf"
#================================================= #=================================================
# CLOSE A PORT # CLOSE A PORT

View file

@ -29,7 +29,6 @@ app=$YNH_APP_INSTANCE_NAME
firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree) firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree)
service_name=$(ynh_app_setting_get --app=$app --key=service_name) 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 # CHECK IF THE APP CAN BE RESTORED
@ -62,21 +61,19 @@ else
pkg_dependencies="$pkg_dependencies $free_firmware_packages" pkg_dependencies="$pkg_dependencies $free_firmware_packages"
fi fi
ynh_restore_file --origin_path="/etc/hostapd/hostapd.conf.tpl" ynh_restore_file --origin_path="/etc/hostapd/$app/hostapd.conf.tpl"
ynh_restore_file --origin_path="/etc/hostapd/hostapd-${wifi_device}.conf" 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.$app/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" --not_mandatory
ynh_restore_file --origin_path="/etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl" ynh_restore_file --origin_path="/etc/dnsmasq.$app/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" --not_mandatory
ynh_restore_file --origin_path="/usr/local/bin/$service_name" 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-up.d/90-${service_name}"
ynh_restore_file --origin_path="/etc/openvpn/scripts/route-down.d/90-hotspot" ynh_restore_file --origin_path="/etc/openvpn/scripts/route-down.d/90-${service_name}"
ynh_restore_file --origin_path="/etc/init.d/hostapd"
#================================================= #=================================================
# SPECIFIC RESTORATION # SPECIFIC RESTORATION
@ -94,14 +91,14 @@ ynh_install_app_dependencies $pkg_dependencies
ynh_script_progression --message="Restoring the systemd configuration..." ynh_script_progression --message="Restoring the systemd configuration..."
ynh_restore_file --origin_path="/etc/systemd/system/$service_name.service" 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 # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating 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 # START SYSTEMD SERVICE

View file

@ -68,7 +68,7 @@ elif [ $firmware_nonfree = "no" ]; then
fi fi
if [ -z $service_name ]; then 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 ynh_app_setting_set --app=$app --key=service_name --value=$service_name
fi 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.base.conf"
ynh_secure_remove --file="/etc/hostapd/hostapd.accesspoint.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 for FILE in $(ls /etc/dnsmasq.dhcpd/*.conf 2>/dev/null); do
ynh_secure_remove --file="$FILE"
ynh_secure_remove --file="$FILE" ynh_secure_remove --file="$FILE"
done done
@ -188,22 +187,27 @@ ynh_install_app_dependencies $pkg_dependencies
#================================================= #=================================================
ynh_script_progression --message="Copying configuration..." ynh_script_progression --message="Copying configuration..."
mkdir -pm 0755 /etc/dnsmasq.dhcpd/ mkdir -pm 0755 /etc/hostapd/$app/
chown root: /etc/dnsmasq.dhcpd/ chown root: /etc/hostapd/$app/
install -b -o root -g root -m 0644 ../conf/hostapd.*.conf /etc/hostapd/ mkdir -pm 0755 /etc/dnsmasq.$app/
install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl chown root: /etc/dnsmasq.$app/
install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl
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 # 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 # Copy openvpn scripts
mkdir -pm 0755 /etc/openvpn/scripts mkdir -pm 0755 /etc/openvpn/scripts
mkdir -pm 0755 /etc/openvpn/scripts/route-up.d mkdir -pm 0755 /etc/openvpn/scripts/route-up.d
mkdir -pm 0755 /etc/openvpn/scripts/route-down.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 ynh_add_config --template="../conf/openvpn_90-hotspot" --destination="/etc/openvpn/scripts/route-up.d/90-$service_name"
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-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 # SETUP SYSTEMD
@ -213,7 +217,7 @@ ynh_script_progression --message="Upgrading systemd configuration..."
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config --service=$service_name ynh_add_systemd_config --service=$service_name
# Create custom systemd config for hostapd to handle multiple wifi devices # 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 # GENERIC FINALIZATION
@ -222,7 +226,7 @@ ynh_add_systemd_config --service="hostapd@.service" --template="../conf/systemd_
#================================================= #=================================================
ynh_script_progression --message="Integrating 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 # START SYSTEMD SERVICE