#!/bin/bash #================================================= # GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= ynh_print_info "Loading installation settings..." app=$YNH_APP_INSTANCE_NAME dns_method=$(ynh_app_setting_get $app dns_method) nameservers=$(ynh_app_setting_get $app nameservers) #================================================= # SPECIAL UPGRADE FOR VERSIONS < 1.2.0 #================================================= # Removing configuration files with naming that occured in versions < 1.2.0 ("vpnadmin" instead off "$app") if [ -d /var/www/vpnadmin ]; then ynh_secure_remove /var/www/vpnadmin fi #================================================= # SPECIAL UPGRADE FOR VERSIONS < 2.0 #================================================= # Old stuff 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 if [ -f /etc/php/*/fpm/pool.d/$app.conf ]; then ynh_secure_remove /etc/php/*/fpm/pool.d/$app.conf ynh_systemd_action --service_name=php$YNH_DEFAULT_PHP_VERSION-fpm --action=reload fi 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 is_public)" ] || ynh_app_setting_delete $app is_public [ -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 # New stuff if [ -z "$dns_method" ]; then ynh_app_setting_set --app=$app --key=dns_method --value=custom fi if [ -z "$nameservers" ]; then nameservers="$(grep -o -P '\s*nameserver\s+\K[abcdefabcdef\d.:]+' /etc/resolv.dnsmasq.conf | sort | uniq | paste -s -d, -)" ynh_app_setting_set --app=$app --key=nameservers --value="$nameservers" fi ##================================================= ## BACKUP BEFORE UPGRADE THEN ACTIVE TRAP ##================================================= # Not done because vpnclient backup ain't so relevant I guess ? #================================================= # DO UPGRADE #================================================= # INSTALL DEPENDENCIES #================================================= ynh_print_info "Installing dependencies..." ynh_install_app_dependencies "$pkg_dependencies" #================================================= # DEPLOY FILES FROM PACKAGE #================================================= # Keep a copy of existing config files before overwriting them tmpdir=$(mktemp -d /tmp/vpnclient-upgrade-XXX) cp -r /etc/openvpn/client* ${tmpdir} # Deploy files from package vpnclient_deploy_files_and_services # Restore previously existing config files cp -r ${tmpdir}/client* /etc/openvpn/ ynh_secure_remove ${tmpdir} #================================================= # SERVICE INTEGRATION IN YUNOHOST #================================================= ### Make sure that the yunohost services have a description and need-lock enabled # main service yunohost service add $service_name --description "Tunnels the internet traffic through a VPN" --need_lock --test_status="systemctl is-active openvpn@client.service" --log "/var/log/ynh-vpnclient.log" # checker service (this service was previously integrated in yunohost but we do not do this anymore) if ynh_exec_warn_less yunohost service status $service_checker_name >/dev/null then yunohost service remove $service_checker_name fi #================================================= # RESTART RELEVANT SERVICES #================================================= ynh_print_info "Restart services..." # this is meant to propagate the new files and configs systemctl -q is-active $service_name && yunohost service restart $service_name # Not sure if these are really necessary ... systemctl -q is-active $service_checker_name && systemctl restart $service_checker_name systemctl -q is-active $service_checker_name.timer && systemctl restart $service_checker_name.timer #================================================= # END OF SCRIPT #================================================= ynh_print_info "Upgrade of $app completed"