1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/bozon_ynh.git synced 2024-09-03 18:16:09 +02:00
bozon_ynh/scripts/restore

65 lines
2.1 KiB
Text
Raw Normal View History

#!/bin/bash
2016-03-23 19:30:43 +01:00
2016-10-13 06:51:38 +02:00
# Exit on command errors and treat unset variables as an error
set -eu
2016-04-04 22:35:43 +02:00
2016-10-13 06:51:38 +02:00
# Source YunoHost helpers
source /usr/share/yunohost/helpers
2016-05-23 21:40:55 +02:00
#retrieve arguments
2016-10-13 06:51:38 +02:00
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get "$app" domain)
2017-01-07 14:26:26 +01:00
path=$(ynh_app_setting_get "$app" path)
2016-05-23 21:40:55 +02:00
2016-04-04 20:01:54 +02:00
# definie useful vars
parent_path=/var/www
2016-10-13 06:51:38 +02:00
final_path="$parent_path"/"$app"
data_path=/home/yunohost.app/"$app"
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
# check domain/path availability with app helper
sudo yunohost app checkurl $domain$path -a $app \
|| ynh_die "The path ${domain}${path} is not available for app installation."
# check directories availability
[[ -d $final_path ]] && ynh_die \
"The path '${final_path}' already exists.
You should safely delete it before restoring this app."
[[ -d $data_path ]] && ynh_die \
"The path '${data_path}' already exists.
You should safely delete it before restoring this app."
# check configuration files
[[ -f $nginx_conf ]] && ynh_die \
"The NGINX configuration already exists at '${nginx_conf}'.
You should safely delete it before restoring this app."
[[ -f $phpfpm_conf ]] && ynh_die \
"The PHP FPM configuration already exists at '${phpfpm_conf}'.
You should safely delete it before restoring this app."
# add required packages
ynh_package_is_installed "php5-curl" || ynh_package_install "php5-curl"
ynh_package_is_installed "php5-gd" || ynh_package_install "php5-gd"
2016-04-04 20:01:54 +02:00
2016-04-05 20:03:26 +02:00
# restore sources & data
2016-10-13 06:51:38 +02:00
sudo cp -a ./www "$final_path"
sudo mkdir -p "$data_path"
sudo cp -a ./data/. "$data_path"
2016-04-04 20:01:54 +02:00
# restore permissions
2016-10-13 06:51:38 +02:00
sudo chown -R root: "$final_path"
sudo find "$final_path" -type f | xargs sudo chmod 644
sudo find "$final_path" -type d | xargs sudo chmod 755
sudo chown -R www-data: "$final_path"/private
sudo chown -R www-data: "$data_path"/uploads
sudo chown -R www-data: "$data_path"/thumbs
# restore Nginx & php-fpm
sudo cp -a ./conf/nginx.conf "$nginx_conf"
sudo cp -a ./conf/php-fpm.conf "$phpfpm_conf"
2016-05-23 20:59:08 +02:00
# Restart services
sudo service php5-fpm restart || true
sudo service nginx restart || true