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
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_script_progression --message="Loading installation settings..."
|
2018-05-04 00:33:01 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2020-05-31 05:33:17 +02:00
|
|
|
firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree)
|
|
|
|
service_name=$(ynh_app_setting_get --app=$app --key=service_name)
|
|
|
|
|
2023-08-23 10:24:43 +02:00
|
|
|
wifi_device=$(ynh_app_setting_get --app=$app --key=wifi_device)
|
2023-08-22 15:09:30 +02:00
|
|
|
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)
|
|
|
|
wifi_channel=$(ynh_app_setting_get --app=$app --key=wifi_channel)
|
|
|
|
advanced=$(ynh_app_setting_get --app=$app --key=advanced)
|
|
|
|
ip4_nat_prefix=$(ynh_app_setting_get --app=$app --key=ip4_nat_prefix)
|
|
|
|
ip6_net=$(ynh_app_setting_get --app=$app --key=ip6_net)
|
|
|
|
ip6_firewall=$(ynh_app_setting_get --app=$app --key=ip6_firewall)
|
|
|
|
dns=$(ynh_app_setting_get --app=$app --key=dns)
|
|
|
|
multissid=$(ynh_app_setting_get --app=$app --key=multissid)
|
|
|
|
|
2020-05-31 05:33:17 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Checking version..."
|
|
|
|
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
2019-02-23 23:47:45 +01:00
|
|
|
|
2021-05-22 11:53:07 +02:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
|
|
|
|
|
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
|
|
|
# Restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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)"
|
2021-05-22 11:53:07 +02:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$service_name --action="stop" --log_path=systemd #--line_match="Started YunoHost Wifi Hotspot"
|
|
|
|
|
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
|
|
|
|
|
2021-11-11 16:52:13 +01:00
|
|
|
|
2019-03-10 23:39:25 +01:00
|
|
|
if [ $firmware_nonfree = "yes" ]; then
|
|
|
|
firmware_nonfree=1
|
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
|
|
|
elif [ $firmware_nonfree = "no" ]; then
|
|
|
|
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
|
|
|
|
|
2019-03-11 00:44:58 +01: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-08-20 18:02:20 +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-08-20 17:14:13 +02:00
|
|
|
if [[ -n "${dns}" ]]; then
|
|
|
|
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%%,}"
|
|
|
|
|
|
|
|
if [[ -z "$(ynh_app_setting_get --app=$app --key=ip6_dns)" ]]; then
|
|
|
|
ynh_app_setting_set --app=$app --key=ip6_dns --value="${ip6_dns}"
|
2023-08-20 18:35:02 +02:00
|
|
|
fi
|
2023-08-20 17:14:13 +02:00
|
|
|
if [[ -z "$(ynh_app_setting_get --app=$app --key=ip4_dns)" ]]; then
|
|
|
|
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
|
2023-08-21 22:40:58 +02:00
|
|
|
else
|
|
|
|
ip6_dns=$(ynh_app_setting_get --app=$app --key=ip6_dns)
|
|
|
|
ip4_dns=$(ynh_app_setting_get --app=$app --key=ip4_dns)
|
2023-08-20 17:14:13 +02:00
|
|
|
fi
|
|
|
|
|
2023-08-20 18:02:20 +02:00
|
|
|
if [[ -n ${multissid} ]]; then
|
|
|
|
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-08-22 15:09:30 +02:00
|
|
|
if [[ -z ${advanced} ]]; then
|
|
|
|
ynh_app_setting_set --app=$app --key=adanced --value=0
|
|
|
|
fi
|
|
|
|
|
2021-10-13 01:22:32 +02:00
|
|
|
# Old stuff prior to 2.x
|
|
|
|
|
2021-10-17 22:09:02 +02:00
|
|
|
ip6_net=$(ynh_app_setting_get --app=$app --key=ip6_net)
|
|
|
|
if [ "$ip6_net" == "none" ]
|
|
|
|
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
|
|
|
|
|
|
|
|
[ -z "$(ynh_app_setting_get $app domain)" ] || ynh_app_setting_delete $app domain
|
|
|
|
[ -z "$(ynh_app_setting_get $app path)" ] || ynh_app_setting_delete $app path
|
|
|
|
[ -z "$(ynh_app_setting_get $app final_path)" ] || ynh_app_setting_delete $app final_path
|
|
|
|
|
|
|
|
if [ -e "/etc/sudoers.d/${app}_ynh" ]; then
|
|
|
|
ynh_secure_remove "/etc/sudoers.d/${app}_ynh"
|
|
|
|
fi
|
|
|
|
|
2021-05-15 20:52:43 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..."
|
|
|
|
|
|
|
|
# Create a dedicated user (if not existing)
|
2021-09-20 19:47:24 +02:00
|
|
|
ynh_system_user_create --username=$app
|
2019-02-23 23:47:45 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_script_progression --message="Upgrading dependencies..."
|
2019-02-23 23:47:45 +01:00
|
|
|
|
2019-02-26 01:27:39 +01:00
|
|
|
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-26 01:27:39 +01:00
|
|
|
else
|
2021-05-15 20:52:43 +02:00
|
|
|
pkg_dependencies="$pkg_dependencies $free_firmware_packages"
|
2019-02-26 01:27:39 +01:00
|
|
|
fi
|
|
|
|
|
2021-05-15 20:52:43 +02:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
2019-02-23 23:47:45 +01:00
|
|
|
|
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-08-23 10:24:43 +02:00
|
|
|
if [[ -z $wifi_device ]] || ! grep -q -F $wifi_device <(unused_iw_devices); then
|
|
|
|
wifi_device=$(unused_iw_devices | head -n 1)
|
|
|
|
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-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
|
2020-05-31 05:33:17 +02: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
|
|
|
|
|
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
|
|
|
|
2019-02-23 23:47:45 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
2020-05-31 05:33:17 +02:00
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
|
|
|
|
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
|
|
|
|
#=================================================
|
2021-10-18 01:39:24 +02:00
|
|
|
ynh_script_progression --message="Starting the hotspot service..."
|
2020-05-31 05:33:17 +02: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
|
2021-09-20 19:47:24 +02:00
|
|
|
wifi_device=""
|
2020-05-31 05:33:17 +02:00
|
|
|
else
|
2021-05-15 20:52:43 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=service_enabled --value=1
|
2020-05-31 05:33:17 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# 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
|
2020-05-31 05:33:17 +02:00
|
|
|
else
|
2021-05-15 20:52:43 +02:00
|
|
|
ynh_systemd_action --service_name=$service_name --action="start" --log_path=systemd #--line_match="Started YunoHost Wifi Hotspot"
|
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"
|