2020-04-22 16:04:49 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-05-17 15:56:54 +02:00
|
|
|
## vars for remove script
|
|
|
|
can_remove_db=0
|
|
|
|
can_remove_home=0
|
|
|
|
can_remove_user=0
|
|
|
|
|
2020-04-22 16:04:49 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2020-05-17 15:56:54 +02:00
|
|
|
source ../settings/scripts/_common.sh
|
2020-04-22 16:04:49 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2020-05-17 15:56:54 +02:00
|
|
|
pushd $(readlink -f ../settings/scripts)
|
2020-04-22 16:04:49 +02:00
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Exit if an error occurs during the execution of the script
|
2020-07-05 19:14:29 +02:00
|
|
|
ynh_clean_setup() {
|
|
|
|
ynh_clean_check_starting
|
|
|
|
}
|
2020-04-22 16:04:49 +02:00
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2020-05-03 14:38:50 +02:00
|
|
|
ynh_script_progression --message="Loading settings..."
|
2020-04-22 16:04:49 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
#=================================================
|
2020-05-03 13:38:04 +02:00
|
|
|
ynh_script_progression --message="Validating restoration parameters..."
|
2020-04-22 16:04:49 +02:00
|
|
|
|
2020-05-17 15:56:54 +02:00
|
|
|
ynh_webpath_available --domain=$domain --path_url=/ \
|
|
|
|
|| ynh_die --message="Domain not available: ${domain}"
|
2020-04-22 16:04:49 +02:00
|
|
|
test ! -d $final_path \
|
|
|
|
|| ynh_die --message="There is already a directory: $final_path "
|
2020-05-17 15:56:54 +02:00
|
|
|
can_remove_home=1
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# Reinstall dependencies
|
|
|
|
#=================================================
|
2020-12-21 18:58:18 +01:00
|
|
|
ynh_script_progression --message="Reinstalling dependencies..." --weight=5
|
2020-12-18 22:56:28 +01:00
|
|
|
|
2020-05-17 15:56:54 +02:00
|
|
|
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
|
2020-12-18 22:56:28 +01:00
|
|
|
|
2020-05-17 15:56:54 +02:00
|
|
|
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
|
|
|
|
#=================================================
|
2020-12-21 18:58:18 +01:00
|
|
|
ynh_script_progression --message="Reinstalling rbenv and ruby..." --weight=10
|
2020-12-18 22:56:28 +01:00
|
|
|
|
2020-07-05 19:13:50 +02:00
|
|
|
source ./install_ruby
|
2020-05-17 15:56:54 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
# Download, check integrity, unucompress and patch the source from app.src
|
|
|
|
pushd $final_path
|
2020-12-21 18:58:18 +01:00
|
|
|
ynh_script_progression --message="Download the sources..." --weight=5
|
2020-07-05 19:14:29 +02:00
|
|
|
sudo -u $app git clone https://github.com/diaspora/diaspora.git -b $current_tag
|
2020-05-17 15:56:54 +02:00
|
|
|
popd
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# Restore files
|
|
|
|
#=================================================
|
2020-12-21 18:58:18 +01:00
|
|
|
ynh_script_progression --message="Restore the files" --weight=5
|
2020-05-17 15:56:54 +02:00
|
|
|
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
|
|
|
|
#=================================================
|
2020-12-21 18:58:18 +01:00
|
|
|
ynh_script_progression --message="Recreating and restoring database..." --weight=5
|
2020-05-17 15:56:54 +02:00
|
|
|
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
|
|
|
|
#=================================================
|
2020-12-21 18:58:18 +01:00
|
|
|
ynh_script_progression --message="Precompile assets..." --weight=5
|
2020-05-17 15:56:54 +02:00
|
|
|
source ./bundle_app
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# Restore nginx conf files
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Recreate nginx config from source"
|
2020-12-18 22:56:28 +01:00
|
|
|
|
2020-05-17 15:56:54 +02:00
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# Restore services
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Restore services..."
|
2020-12-18 22:56:28 +01:00
|
|
|
|
2020-05-17 15:56:54 +02:00
|
|
|
source ./create_services
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
|
|
|
#=================================================
|
2020-12-18 22:56:28 +01:00
|
|
|
|
2020-05-17 15:56:54 +02:00
|
|
|
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 "/"
|
2020-04-22 16:04:49 +02:00
|
|
|
|
2020-05-17 15:56:54 +02:00
|
|
|
popd
|