1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/redmine_ynh.git synced 2024-09-03 20:16:16 +02:00

Update restore

This commit is contained in:
liberodark 2019-03-22 16:36:55 +01:00 committed by GitHub
parent c0d54efbc5
commit d9f9207e27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,52 +1,100 @@
#!/bin/bash #!/bin/bash
# Note: each files and directories you've saved using the ynh_backup helper #=================================================
# will be located in the current directory, regarding the last argument. # GENERIC START
#=================================================
# Exit on command errors and treat unset variables as an error # IMPORT GENERIC HELPERS
set -eu #=================================================
source _common.sh
# See comments in install script
app=$YNH_APP_INSTANCE_NAME
# Source YunoHost helpers
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
# Retrieve old app settings #=================================================
domain=$(ynh_app_setting_get "$app" domain) # MANAGE SCRIPT FAILURE
path_url=$(ynh_app_setting_get "$app" path_url) #=================================================
# Check domain/path availability ynh_clean_setup () {
sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \ #### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app psql_db)
db_pwd=$(ynh_app_setting_get $app psqlpwd)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}" || ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
# Restore sources & data #=================================================
src_path="/var/www/${app}" # STANDARD RESTORATION STEPS
sudo cp -a ./sources "$src_path" #=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
# Restore permissions to app files ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
# you may need to make some file and/or directory writeable by www-data (nginx user)
sudo chown -R root: "$src_path"
### MySQL (remove if not used) ### #=================================================
# If a MySQL database is used: # RESTORE THE APP MAIN DIR
# # Create and restore the database #=================================================
# dbname=$app var_root=/home/yunohost.app/$app
# dbuser=$app ynh_restore_file "$final_path"
# dbpass=$(ynh_app_setting_get "$app" mysqlpwd) ynh_restore_file "$var_root"
# ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
# ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./dump.sql
### MySQL end ###
# Restore NGINX configuration #=================================================
sudo cp -a ./nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf" # RESTORE THE psql DATABASE
#=================================================
ynh_psql_test_if_first_run
ynh_psql_create_user $app $db_pwd
ynh_psql_execute_as_root \
"CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $app;"
ynh_psql_execute_file_as_root ./db.sql "$db_name"
### PHP (remove if not used) ### #=================================================
# If a dedicated php-fpm process is used: # RECREATE THE DEDICATED USER
# # Copy PHP-FPM pool configuration and reload the service #=================================================
# sudo cp -a ./php-fpm.conf "/etc/php5/fpm/pool.d/${app}.conf"
# sudo service php5-fpm reload
### PHP end ###
# Restart webserver # Create the dedicated user (if not existing)
sudo service nginx reload ynh_system_user_create $app
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
chown -R $app: $final_path
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
# Define and install dependencies
ynh_install_app_dependencies postgresql ruby-dev zlib1g-dev libpq-dev
ynh_print_info "Installing Rails & Bunlder..."
gem install rails:5.2.2 bundler:2.0.1
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx