2015-07-13 15:59:05 +02:00
#!/bin/bash
2018-05-04 00:33:01 +02:00
#=================================================
2019-02-23 23:47:45 +01:00
# GENERIC START
2018-05-04 00:33:01 +02:00
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2015-07-24 19:09:56 +02:00
2018-05-04 00:33:01 +02:00
source _common.sh
source /usr/share/yunohost/helpers
2015-07-13 15:59:05 +02:00
2020-05-31 05:33:17 +02:00
upgrade_type=$(ynh_check_app_version_changed)
2019-02-23 23:47:45 +01:00
2021-05-22 11:53:07 +02:00
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
2021-10-18 01:39:24 +02:00
ynh_script_progression --message="Stopping the hotspot service ... (this may take some time)"
2023-10-05 20:34:32 +02:00
yunohost service stop $service_name
2021-05-22 11:53:07 +02:00
2019-02-23 23:47:45 +01:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2020-05-31 05:33:17 +02:00
ynh_script_progression --message="Ensuring downward compatibility..."
2019-02-23 23:47:45 +01:00
2019-03-10 23:39:25 +01:00
if [ -d /var/www/wifiadmin/ ]; then
2021-09-20 19:47:24 +02:00
ynh_secure_remove /var/www/wifiadmin/
2019-03-10 23:39:25 +01:00
fi
2023-10-05 19:08:51 +02:00
if [ -e /etc/dnsmasq.d/$app.conf ]; then
ynh_secure_remove /etc/dnsmasq.d/$app.conf
fi
2021-11-11 16:52:13 +01:00
2023-10-06 18:36:24 +02:00
if [ ${firmware_nonfree:-} = "yes" ]; then
2019-03-10 23:39:25 +01:00
firmware_nonfree=1
2020-06-02 23:50:44 +02:00
ynh_app_setting_set --app=$app --key=firmware_nonfree --value=$firmware_nonfree
2023-10-06 18:36:24 +02:00
elif [ ${firmware_nonfree:-} = "no" ]; then
2019-03-10 23:39:25 +01:00
firmware_nonfree=0
2020-06-02 23:50:44 +02:00
ynh_app_setting_set --app=$app --key=firmware_nonfree --value=$firmware_nonfree
2019-03-10 23:39:25 +01:00
fi
2023-10-06 18:36:24 +02:00
if [ -z ${service_name:-} ]; then
2023-08-21 18:43:20 +02:00
service_name="ynh-$app"
2020-06-02 23:50:44 +02:00
ynh_app_setting_set --app=$app --key=service_name --value=$service_name
2019-03-11 00:44:58 +01:00
fi
2023-10-06 18:36:24 +02:00
if [[ -n "${multissid:-}" ]] && [[ "${multissid}" -gt 1 ]]; then
2023-08-21 22:40:58 +02:00
wifi_ssid=$(cut -d'|' -f 1 <<< ${wifi_ssid})
wifi_secure=$(cut -d'|' -f 1 <<< ${wifi_secure})
wifi_passphrase=$(cut -d'|' -f 1 <<< ${wifi_passphrase})
2023-08-22 15:09:30 +02:00
advanced=$(cut -d'|' -f 1 <<< ${advanced})
2023-08-21 22:40:58 +02:00
ip4_nat_prefix=$(cut -d'|' -f 1 <<< ${ip4_nat_prefix})
ip6_net=$(cut -d'|' -f 1 <<< ${ip6_net})
ip6_firewall=$(cut -d'|' -f 1 <<< ${ip6_firewall})
dns=$(cut -d'|' -f 1 <<< ${dns})
2023-08-20 18:02:20 +02:00
ynh_app_setting_set --app=$app --key=wifi_ssid --value="${wifi_ssid}"
ynh_app_setting_set --app=$app --key=wifi_secure --value="${wifi_secure}"
ynh_app_setting_set --app=$app --key=wifi_passphrase --value="${wifi_passphrase}"
ynh_app_setting_set --app=$app --key=ip4_nat_prefix --value="${ip4_nat_prefix}"
ynh_app_setting_set --app=$app --key=ip6_net --value="${ip6_net}"
ynh_app_setting_set --app=$app --key=ip6_firewall --value="${ip6_firewall}"
fi
2023-10-06 18:36:24 +02:00
if [[ -n "${dns:-}" ]]; then
2023-08-20 17:14:13 +02:00
ip6_dns=""
ip4_dns=""
for ip in $(echo "${dns}" | tr ',' ' '); do
if [[ "$ip" == *":"* ]]; then
ip6_dns+="[$ip],"
else
ip4_dns+="$ip,"
fi
done
# Remove trailing ,
ip6_dns="${ip6_dns%%,}"
ip4_dns="${ip4_dns%%,}"
2023-10-06 18:36:24 +02:00
if [[ -z "$(ynh_app_setting_get --app=$app --key=ip6_dns)" ]]; then
2023-08-20 17:14:13 +02:00
ynh_app_setting_set --app=$app --key=ip6_dns --value="${ip6_dns}"
2023-08-20 18:35:02 +02:00
fi
2023-10-06 18:36:24 +02:00
if [[ -z "$(ynh_app_setting_get --app=$app --key=ip4_dns)" ]]; then
2023-08-20 17:14:13 +02:00
ynh_app_setting_set --app=$app --key=ip4_dns --value="${ip4_dns}"
2023-08-20 18:15:58 +02:00
fi
2023-08-20 17:14:13 +02:00
ynh_app_setting_delete $app dns
fi
2023-10-06 18:36:24 +02:00
if [[ -n "${multissid:-}" ]]; then
2023-08-20 18:02:20 +02:00
ynh_app_setting_delete --app=$app --key=multissid
2023-08-21 23:12:27 +02:00
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"
ynh_secure_remove --file="/etc/dnsmasq.dhcpd/"
fi
2023-08-21 16:17:22 +02:00
2023-10-06 18:36:24 +02:00
if [[ -z "${advanced:-}" ]]; then
2023-08-24 08:45:34 +02:00
ynh_app_setting_set --app=$app --key=advanced --value=0
2023-08-22 15:09:30 +02:00
fi
2021-10-13 01:22:32 +02:00
# Old stuff prior to 2.x
2023-10-06 18:36:24 +02:00
if [ "${ip6_net:-}" == "none" ]
2021-10-17 22:09:02 +02:00
then
ip6_net=""
ynh_app_setting_set --app=$app --key=ip6_net --value="$ip6_net"
fi
2021-10-13 01:22:32 +02:00
if [ -f /etc/nginx/conf.d/*.d/$app.conf ]; then
ynh_secure_remove /etc/nginx/conf.d/*.d/$app.conf
ynh_systemd_action --service_name=nginx --action=reload
fi
2021-11-11 16:52:13 +01:00
for php_path in $(ls /etc/php/*/fpm/pool.d/$app.conf 2> /dev/null); do
ynh_secure_remove $php_path
done
2021-10-13 01:22:32 +02:00
if [ -d /var/www/$app ]; then
ynh_secure_remove /var/www/$app
fi
2023-10-06 18:36:24 +02:00
[ -z "${domain:-}" ] || ynh_app_setting_delete $app domain
[ -z "${path:-}" ] || ynh_app_setting_delete $app path
[ -z "${install_dir:-}" ] || ynh_app_setting_delete $app install_dir
2021-10-13 01:22:32 +02:00
if [ -e "/etc/sudoers.d/${app}_ynh" ]; then
ynh_secure_remove "/etc/sudoers.d/${app}_ynh"
fi
2023-12-31 17:32:37 +01:00
if systemctl -q is-enabled hostapd
then
# Disable hostapd, we'll use hostapd@$app instead (for multissid support etc)
systemctl disable hostapd --quiet 2>&1
systemctl stop hostapd 2>&1
systemctl mask hostapd 2>&1
fi
2018-05-04 00:33:01 +02:00
#=================================================
# SPECIFIC UPGRADE
#=================================================
2020-05-31 05:33:17 +02:00
# COPY CONFIGS
#=================================================
ynh_script_progression --message="Copying configuration..."
2023-08-21 23:14:42 +02:00
hot_reload_usb_wifi_cards
2023-10-06 18:36:24 +02:00
2023-09-17 21:57:39 +02:00
if [[ -z "$wifi_device" ]] || ! grep -q -F "$wifi_device" <(unused_iw_devices); then
wifi_device="$(unused_iw_devices | head -n 1)"
2023-08-23 10:24:43 +02:00
ynh_app_setting_set --app=$app --key=wifi_device --value="${wifi_device}"
fi
2023-08-21 23:14:42 +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/
2020-05-31 05:33:17 +02:00
2023-10-06 18:36:24 +02:00
if [[ -n "${wifi_device:-}" ]]; then
2023-10-05 18:44:05 +02:00
configure_hostapd
configure_dhcp
2023-10-06 18:36:24 +02:00
ynh_app_setting_set --app=$app --key=service_enabled --value=1
else
ynh_app_setting_set --app=$app --key=service_enabled --value=0
wifi_device=""
2023-08-21 22:40:58 +02:00
fi
2020-05-31 05:33:17 +02: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-05-31 05:33:17 +02: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
2019-02-23 23:47:45 +01:00
#=================================================
# SETUP SYSTEMD
#=================================================
2020-05-31 05:33:17 +02:00
ynh_script_progression --message="Upgrading systemd configuration..."
2015-07-24 23:48:24 +02:00
2019-02-23 23:47:45 +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"
2015-07-24 23:48:24 +02:00
2023-10-05 18:49:17 +02:00
yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" --need_lock
2020-05-31 05:33:17 +02:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2021-10-18 01:39:24 +02:00
ynh_script_progression --message="Starting the hotspot service..."
2020-05-31 05:33:17 +02:00
# Start a systemd service if device is present
2021-09-20 19:47:24 +02:00
if [[ $wifi_device == "" ]]; then
2023-10-06 18:36:24 +02:00
echo "WARNING: Wifi Hotspot is not started because no wifi device was found (check the Hotspot configuration in the webadmin > Applications > Hotspot > the config panel)" >&2
2020-05-31 05:33:17 +02:00
else
2023-10-05 20:34:32 +02:00
yunohost service start $service_name
2020-05-31 05:33:17 +02:00
fi
2019-02-23 23:47:45 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2015-07-24 23:48:24 +02:00
2020-05-31 05:33:17 +02:00
ynh_script_progression --message="Upgrade of $app completed"