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

101 lines
3 KiB
Text
Raw Normal View History

2017-04-01 18:16:18 +02:00
#!/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)
ynh_package_update
ynh_package_install carton
2017-04-01 18:16:18 +02:00
# 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}/${app}.conf"
2017-04-01 18:16:18 +02:00
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/${app}.service"
if [ -f "${lufi_systemd}" ]; then
2017-04-01 18:19:41 +02:00
ynh_die "The LUFI SYSTEMD configuration already exists at '${lufi_systemd}'. You should safely delete it before restoring this app."
2017-04-01 18:16:18 +02:00
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
lufi_log="/var/log/${app}/production.log"
if [ -f "${lufi_log}" ]; then
ynh_die "The LUFI LOG configuration already exists at '${lufi_log}'. You should safely delete it before restoring this app."
fi
2017-04-01 18:16:18 +02:00
# 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 lufi configuration files
sudo cp -a ./lufi.conf "${lufi_conf}"
2017-04-01 18:19:41 +02:00
# Restore service
sudo cp -a ./systemd_lufi.service "${lufi_systemd}"
2017-04-01 18:16:18 +02:00
sudo cp -a ./cron_lufi "${lufi_cron}"
sudo cp -a ./logrotate_lufi "${lufi_logrotate}"
# Create log production
sudo mkdir "/var/log/${app}/"
sudo cp -a ./production.log "${lufi_log}"
# Delete symbolic link and restore
sudo rm -fr "${final_path}/log/production.log"
sudo ln -s "/var/log/${app}/production.log" "${final_path}/log/production.log"
# Reload lufi service
sudo systemctl daemon-reload
sudo systemctl start lufi.service
sudo systemctl enable lufi.service
2017-04-01 18:16:18 +02:00
# Set ssowat config
if [ "$is_public" = "No" ];
then
ynh_app_setting_delete $app skipped_uris
fi
# Reload services
sudo systemctl reload nginx
sudo yunohost app ssowatconf