#!/bin/bash ## vars for remove script can_remove_db=0 can_remove_home=0 can_remove_user=0 #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers pushd $(readlink -f ../settings/scripts) #================================================= # MANAGE SCRIPT FAILURE #================================================= # Exit if an error occurs during the execution of the script ynh_clean_setup() { ynh_clean_check_starting } ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= ynh_script_progression --message="Loading settings..." app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) final_path=$(ynh_app_setting_get --app=$app --key=final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= ynh_script_progression --message="Validating restoration parameters..." ynh_webpath_available --domain=$domain --path_url=/ \ || ynh_die --message="Domain not available: ${domain}" test ! -d $final_path \ || ynh_die --message="There is already a directory: $final_path " can_remove_home=1 #================================================= # Reinstall dependencies #================================================= ynh_script_progression --message="Reinstalling dependencies..." --weight=27 ynh_install_app_dependencies $pkg_dependencies $ruby_build_dependencies # now that we have psql for sure, test db existence ynh_script_progression --message="Checking DB availability" --weight=1 ynh_psql_database_exists --database $app && ynh_die --message="There is already a database: $app" can_remove_db=1 #================================================= # Restoring dedicated USER #================================================= ynh_script_progression --message="Restoring user..." --weight=1 ynh_system_user_create --username=$app --home_dir=$final_path --use_shell can_remove_user=1 mkdir -p $final_path chmod 0750 $final_path -R chown $app:www-data $final_path #================================================= # INSTALL RVM AND RUBY FOR CURRENT USER #================================================= ynh_script_progression --message="Reinstalling rvm and ruby..." --weight=50 source ./install_ruby #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= # Download, check integrity, unucompress and patch the source from app.src pushd $final_path ynh_script_progression --message="Download the sources..." --weight=16 sudo -u $app git clone https://github.com/diaspora/diaspora.git -b $current_tag popd #================================================= # Restore files #================================================= ynh_script_progression --message="Restore the files" --weight=16 ynh_restore_file --origin_path=/var/www/diaspora/diaspora/config/database.yml ynh_restore_file --origin_path=/var/www/diaspora/diaspora/config/diaspora.yml ynh_restore_file --not_mandatory --origin_path=/var/www/diaspora/diaspora/public/uploads/ # restoring somewhere postgres can read ynh_restore_file --origin_path=/var/www/diaspora/backup/diaspora.dump --dest_path=/tmp/diaspora.dump #================================================= # Restore database #================================================= ynh_script_progression --message="Recreating and restoring database..." --weight=16 db_name=$(ynh_sanitize_dbid $app) ynh_psql_test_if_first_run db_pass=$(ynh_app_setting_get --app=$app --key=psqlpwd) ynh_psql_setup_db --db_user=$db_name --db_name=$db_name --db_pwd=$db_pass ynh_script_progression --message="Restoring database..." sudo -u postgres pg_restore \ --single-transaction \ --dbname=$app \ /tmp/diaspora.dump ynh_secure_remove --file=/tmp/diaspora.dump #================================================= # Bundle the ruby app #================================================= ynh_script_progression --message="Precompile assets..." --weight=20 source ./bundle_app #================================================= # Restore nginx conf files #================================================= ynh_script_progression --message="Recreate nginx config from source" ynh_add_nginx_config #================================================= # Restore services #================================================= ynh_script_progression --message="Restore services..." source ./create_services #================================================= # ADVERTISE SERVICE IN ADMIN PANEL #================================================= yunohost service add $app.target\ --log $final_path/diaspora/log/production.log \ $final_path/diaspora/log/unicorn-stderr.log\ $final_path/diaspora/log/unicorn-stdout.log\ $final_path/diaspora/log/sidekiq.log\ --description "Diaspora service (unicorn web and sidekiq)" #================================================= # SETUP SSOWAT #================================================= # unprotected_uris allows SSO credentials to be passed anyway. ynh_app_setting_set $app unprotected_uris "/" popd