90 lines
3.0 KiB
Bash

#!/bin/bash
ynh_setting() {
app=${1}
setting=${2}
sudo grep "^${setting}:" "/etc/yunohost/apps/${app}/settings.yml" | sed s/^[^:]\\+:\\s*[\"\']\\?// | sed s/\\s*[\"\']\$//
}
#=================================================
# LOAD 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)
#=================================================
# 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
sudo sed "s|/var/www/vpnadmin/|/var/www/${app}/|g" -i "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
sudo sed "s|vpnadmin.sock|${app}.sock|g" -i "/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
sudo sed "s|/var/www/vpnadmin/|/var/www/${app}/|g" -i /etc/php5/fpm/pool.d/vpnadmin.conf
sudo sed "s|vpnadmin.sock|${app}.sock|g" -i /etc/php5/fpm/pool.d/vpnadmin.conf
mv /etc/php5/fpm/pool.d/vpnadmin.conf /etc/php5/fpm/pool.d/${app}.conf
fi
test -d /var/www/vpnadmin && mv /var/www/vpnadmin /var/www/${app}
## 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_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)
sudo cp -r /etc/openvpn/client* ${tmpdir}
# Deploy files from package
vpnclient_deploy_files_and_services "${domain}" "${app}"
# Restore previously existing config files
sudo cp -r ${tmpdir}/client* /etc/openvpn/
sudo rm -rf ${tmpdir}
#=================================================
# RELOAD RELEVANT SERVICES
#=================================================
ynh_systemctl reload php5-fpm
ynh_systemctl reload nginx
ynh_systemctl restart ynh-vpnclient
exit 0