2016-06-28 16:29:58 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Exit on command errors and treat unset variables as an error
|
2017-02-21 23:23:45 +01:00
|
|
|
set -eu
|
2016-06-28 16:29:58 +02:00
|
|
|
|
|
|
|
# Get multi-instances specific variables
|
2016-12-18 01:13:17 +01:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2016-06-28 16:29:58 +02:00
|
|
|
|
|
|
|
# Source app helpers
|
2017-02-21 23:23:45 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
2016-06-28 16:29:58 +02:00
|
|
|
|
|
|
|
# Retrieve old app settings
|
2016-12-18 01:13:17 +01:00
|
|
|
domain=$(ynh_app_setting_get "$app" domain)
|
|
|
|
path=$(ynh_app_setting_get "$app" path)
|
|
|
|
dbname=$app
|
|
|
|
dbuser=$app
|
|
|
|
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
2016-06-28 16:29:58 +02:00
|
|
|
|
|
|
|
# Check domain/path availability
|
2016-12-18 01:13:17 +01:00
|
|
|
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
|
|
|
|| exit 1
|
2016-06-28 16:29:58 +02:00
|
|
|
|
|
|
|
# Check destination directory
|
2016-12-18 01:13:17 +01:00
|
|
|
DESTDIR="/var/www/$app"
|
|
|
|
[[ -d $DESTDIR ]] && ynh_die \
|
|
|
|
"The destination directory '$DESTDIR' already exists.\
|
|
|
|
You should safely delete it before restoring this app."
|
2016-06-28 16:29:58 +02:00
|
|
|
|
|
|
|
# Check configuration files
|
2016-12-18 01:13:17 +01:00
|
|
|
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
|
|
|
[[ -f $nginx_conf ]] && ynh_die \
|
|
|
|
"The NGINX configuration already exists at '${nginx_conf}'.
|
|
|
|
You should safely delete it before restoring this app."
|
|
|
|
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
|
|
|
|
[[ -f $phpfpm_conf ]] && ynh_die \
|
|
|
|
"The PHP FPM configuration already exists at '${phpfpm_conf}'.
|
|
|
|
You should safely delete it before restoring this app."
|
2016-06-28 16:29:58 +02:00
|
|
|
|
|
|
|
# Restore the app files
|
2016-12-18 01:13:17 +01:00
|
|
|
sudo cp -a ./sources "$DESTDIR"
|
2016-06-28 16:29:58 +02:00
|
|
|
|
|
|
|
# Create and restore the database
|
2016-12-18 01:13:17 +01:00
|
|
|
ynh_mysql_create_db $dbname $dbuser $dbpass
|
|
|
|
ynh_mysql_connect_as $dbuser $dbpass $dbname < ./dump.sql
|
2016-06-28 16:29:58 +02:00
|
|
|
|
|
|
|
# Fix installation directories and permissions
|
2016-12-18 01:13:17 +01:00
|
|
|
sudo mkdir -p "${DESTDIR}/logs" "${DESTDIR}/temp"
|
|
|
|
sudo chown -R www-data: "$DESTDIR"
|
2016-06-28 16:29:58 +02:00
|
|
|
|
|
|
|
# Restore configuration files
|
2016-12-18 01:13:17 +01:00
|
|
|
sudo cp -a ./nginx.conf "$nginx_conf"
|
|
|
|
sudo cp -a ./php-fpm.conf "$phpfpm_conf"
|
2016-06-28 16:29:58 +02:00
|
|
|
|
|
|
|
# Reload services
|
2017-02-21 23:23:45 +01:00
|
|
|
sudo service php5-fpm reload || true
|
2016-12-18 01:13:17 +01:00
|
|
|
sudo service nginx reload || true
|