1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/roundcube_ynh.git synced 2024-09-03 20:16:28 +02:00
roundcube_ynh/scripts/restore
Jérôme Lebleu eb43d2e8c5 [enh] Initial commit for new app based on Kloadut/roundcube_ynh
Since sources where included in the last YunoHost app package, this
rebase is intended to have a lighter git repository.
2016-05-19 19:49:47 +02:00

63 lines
1.8 KiB
Bash

#!/bin/bash
# Retrieve arguments
backup_dir=$1
app=$2
# TODO: Put a simple die function in app helpers, redeclare it since
# _common.sh cannot be easily sourced
die() {
printf "%s" "$1" 1>&2
exit "${2:-1}"
}
# Set app specific variables
dbname=$app
dbuser=$app
# Source app helpers
. /usr/share/yunohost/helpers
# Retrieve old app settings
domain=$(ynh_app_setting_get $app domain)
path=$(ynh_app_setting_get $app path)
dbpass=$(ynh_app_setting_get $app mysqlpwd)
# TODO: Check domain/path availability with app helper
sudo yunohost app checkurl $domain$path -a $app \
|| die "The path ${domain}${path} is not available for app installation."
# Check destination directory
DESTDIR="/var/www/$app"
[[ -d $DESTDIR ]] && die \
"The destination directory '$DESTDIR' already exists.\
You should safely delete it before restoring this app."
# Check configuration files
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
[[ -f $nginx_conf ]] && 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 ]] && die \
"The PHP FPM configuration already exists at '${phpfpm_conf}'.
You should safely delete it before restoring this app."
# Restore the app files
sudo cp -a ./sources "$DESTDIR"
# Create and restore the database
ynh_mysql_create_db $dbname $dbuser $dbpass
ynh_mysql_connect_as $dbuser $dbpass $dbname < ./dump.sql
# Fix installation directories and permissions
sudo mkdir -p "${DESTDIR}/logs" "${DESTDIR}/temp"
sudo chown -R www-data: "$DESTDIR"
# Restore configuration files
sudo cp -a ./nginx.conf "$nginx_conf"
sudo cp -a ./php-fpm.conf "$phpfpm_conf"
# Reload services
sudo service php5-fpm restart || true
sudo service nginx reload || true