1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/coin_ynh.git synced 2024-09-03 18:16:26 +02:00
coin_ynh/scripts/restore
2018-12-21 17:34:55 +01:00

85 lines
2.2 KiB
Bash

#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
# See comments in install script
app=$YNH_APP_INSTANCE_NAME
# Source YunoHost helpers
. /usr/share/yunohost/helpers
# Retrieve old app settings
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
admin=$(ynh_app_setting_get "$app" admin)
email=$(ynh_app_setting_get "$app" email)
isp_name=$(ynh_app_setting_get "$app" isp_name)
isp_site=$(ynh_app_setting_get "$app" isp_site)
secret=$(ynh_app_setting_get "$app" secret)
db_pwd=$(ynh_app_setting_get "$app" psqlpassword)
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a $app \
|| ynh_die "Path not available: ${domain}${path}"
final_path=/opt/$app
if [ -d $final_path ]; then
ynh_die "There is already a directory: $final_path "
fi
conf=/etc/nginx/conf.d/$domain.d/$app.conf
if [ -f $conf ]; then
ynh_die "There is already a nginx conf file at this path: $conf "
fi
gunicorn_path=/etc/systemd/system/$app.service
if [ -f $gunicorn_path ]; then
ynh_die "There is already a gunicorn service file at this path: $gunicorn_path "
fi
# Dependences
ynh_package_install python3-pip python3-virtualenv
# Restore sources & data
sudo cp -a ./sources $final_path
# Create user
useradd $app -d $final_path || echo "User already exists"
# Set permissions
sudo chown -R www-data:www-data $final_path
# Restore conf files
sudo cp -a ./nginx.conf $conf
sudo cp -a ./gunicorn.service $gunicorn_path
sudo chown root: $gunicorn_path
sudo chmod 644 $gunicorn_path
# Set Administrator
if ynh_user_exists $admin; then
sudo yunohost app addaccess $app -u $admin
fi
# Restore database
ynh_psql_test_if_first_run
db_name=$app
db_user=$app
ynh_psql_create_db $db_name $db_user $db_pwd
ynh_psql_execute_file_as_root "${YNH_CWD}/dump.sql" "$db_name"
# Log folder
sudo mkdir -p /var/log/$app
sudo chown -R $app /var/log/$app
sudo chgrp -R www-data /var/log/$app
# Reload Nginx
sudo service nginx reload
systemctl daemon-reload
sudo systemctl start $app
sudo systemctl enable $app
sudo yunohost service add $app -l /var/log/gunicorn/$app.log
ynh_app_setting_set "$app" skipped_uris "/"
sudo yunohost app ssowatconf