1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/lufi_ynh.git synced 2024-09-03 19:36:28 +02:00
lufi_ynh/scripts/restore
2017-04-01 18:19:41 +02:00

85 lines
No EOL
2.6 KiB
Bash

#!/bin/bash
# This restore script is adapted to Yunohost >=2.4
# Exit on command errors and treat unset variables as an error
set -eu
# Source app helpers
source /usr/share/yunohost/helpers
# The parameter $app is the id of the app instance ex: ynhexample__2
app=$YNH_APP_INSTANCE_NAME
# Get old parameter of the app
domain=$(ynh_app_setting_get $app domain)
path=$(ynh_app_setting_get $app path)
is_public=$(ynh_app_setting_get $app is_public)
# Check domain/path availability
sudo yunohost app checkurl "${domain}${path}" -a "${app}" \
|| ynh_die "Path not available: ${domain}${path}"
# Check $final_path
final_path="/var/www/${app}"
if [ -d "${final_path}" ]; then
ynh_die "There is already a directory: ${final_path}"
fi
# Check configuration files nginx
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
if [ -f "${nginx_conf}" ]; then
ynh_die "The NGINX configuration already exists at '${nginx_conf}'. You should safely delete it before restoring this app."
fi
# Check configuration files lufi
lufi_conf="${final_path}/lufi.conf"
if [ -f "${lufi_conf}" ]; then
ynh_die "The LUFI CONF configuration already exists at '${lufi_conf}'. You should safely delete it before restoring this app."
fi
lufi_systemd="/etc/systemd/system/lufi.service"
if [ -f "${lufi_default}" ]; then
ynh_die "The LUFI SYSTEMD configuration already exists at '${lufi_systemd}'. You should safely delete it before restoring this app."
fi
lufi_cron="/etc/cron.d/${app}"
if [ -f "${lufi_cron}" ]; then
ynh_die "The LUFI CRONTAB configuration already exists at '${lufi_cron}'. You should safely delete it before restoring this app."
fi
lufi_logrotate="/etc/logrotate.d/${app}"
if [ -f "${lufi_logrotate}" ]; then
ynh_die "The LUFI LOGROTATE configuration already exists at '${lufi_logrotate}'. You should safely delete it before restoring this app."
fi
# Restore sources & data
sudo cp -a ./sources "${final_path}"
# Set permissions
sudo chown -R www-data: "${final_path}"
# Restore nginx configuration files
sudo cp -a ./nginx.conf "${nginx_conf}"
# Restore php-fpm configuration files
sudo cp -a ./php-fpm.conf "${phpfpm_conf}"
sudo cp -a ./php-fpm.ini "${phpfpm_ini}"
# Restore lufi configuration files
sudo cp -a ./lufi.conf "${lufi_conf}"
# Restore service
sudo cp -a ./systemd_lufi.service "${lufi_systemd}"
sudo cp -a ./cron_lufi "${lufi_cron}"
sudo cp -a ./logrotate_lufi "${lufi_logrotate}"
# Set ssowat config
if [ "$is_public" = "No" ];
then
ynh_app_setting_delete $app skipped_uris
fi
# Reload services
sudo systemctl reload php5-fpm
sudo systemctl reload nginx
sudo yunohost app ssowatconf