#!/bin/bash #================================================= # GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= ynh_print_info "Loading installation settings..." app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) path_url=$(ynh_app_setting_get $app path) is_public=$(ynh_app_setting_get $app is_public) final_path=$(ynh_app_setting_get $app final_path) server_name=$(ynh_app_setting_get $app server_name) service_name=$(ynh_app_setting_get $app service_name) service_checker_name=$service_name"-checker" #================================================= # SPECIAL UPGRADE FOR VERSIONS < 1.2.0 #================================================= # Apply renaming that occured in v1.2.0 ("vpnadmin" -> "${app}") if [ -f /etc/nginx/conf.d/${domain}.d/vpnadmin.conf ]; then ynh_replace_string "/var/www/vpnadmin/" "/var/www/${app}/" "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf" ynh_replace_string "vpnadmin.sock" "${app}.sock" "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf" mv /etc/nginx/conf.d/${domain}.d/vpnadmin.conf /etc/nginx/conf.d/${domain}.d/${app}.conf fi if [ -f /etc/php5/fpm/pool.d/vpnadmin.conf ]; then ynh_replace_string "/var/www/vpnadmin/" "/var/www/${app}/" /etc/php/7.0/fpm/pool.d/vpnadmin.conf ynh_replace_string "vpnadmin.sock" "${app}.sock" /etc/php/7.0/fpm/pool.d/vpnadmin.conf mv /etc/php5/fpm/pool.d/vpnadmin.conf /etc/php/7.0/fpm/pool.d/${app}.conf fi test -d /var/www/vpnadmin && mv /var/www/vpnadmin /var/www/${app} if [ -z $service_name ]; then service_name="ynh-vpnclient" service_checker_name=$service_name"-checker" ynh_app_setting_set "$app" service_name "$service_name" fi ## Versions known to have a buggy backup script #buggy_versions="1.0.0 1.0.1 1.1.0" #curr_version=$(read_manifest version) #if echo $buggy_versions | grep -w $curr_version > /dev/null; then # echo "Your current version of ${app} is very old: ${curr_version}. Please ignore the next warning." >&2 #fi # ##================================================= ## BACKUP BEFORE UPGRADE THEN ACTIVE TRAP ##================================================= # #ynh_backup_before_upgrade #ynh_clean_setup () { # ynh_restore_upgradebackup #} ## Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # 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 "${domain}" "${app}" "${service_name}" # Restore previously existing config files cp -r ${tmpdir}/client* /etc/openvpn/ ynh_secure_remove ${tmpdir} #================================================= # RELOAD RELEVANT SERVICES #================================================= ynh_print_info "Reload services..." systemctl reload php7.0-fpm systemctl reload nginx ### Make sure that the yunohost services have a description and need-lock enabled # main service if service_is_managed_by_yunohost $service_name then yunohost service remove $service_name fi yunohost service add $service_name --description "Tunnels the internet traffic through a VPN" --need_lock # checker service if service_is_managed_by_yunohost $service_checker_name then yunohost service remove $service_checker_name fi yunohost service add $service_checker_name --description "Makes sure that the VPN service is running" --need_lock # Reload systemd configuration systemctl daemon-reload ### Restart services # restart main service if needed if systemctl is-active $service_name >/dev/null; then yunohost service restart $service_name fi # restart checker service if needed if systemctl is-active $service_checker_name >/dev/null; then yunohost service restart $service_checker_name fi # restart checker service timer if systemctl is-active $service_name.timer >/dev/null; then yunohost service restart $service_checker_name.timer fi #================================================= # END OF SCRIPT #================================================= ynh_print_info "Upgrade of $app completed"