mirror of
https://github.com/YunoHost-Apps/diaspora_ynh.git
synced 2024-09-03 18:26:13 +02:00
145 lines
5.1 KiB
Bash
145 lines
5.1 KiB
Bash
#!/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..."
|
|
|
|
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=5
|
|
|
|
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, RUBY AND NODE FOR CURRENT USER
|
|
#=================================================
|
|
ynh_script_progression --message="Reinstalling rbenv and ruby..." --weight=10
|
|
source ./install_ruby
|
|
ynh_script_progression --message="Reinstalling node" --weight=10
|
|
ynh_install_nodejs --nodejs_version=14
|
|
|
|
#=================================================
|
|
# 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=5
|
|
ynh_exec_warn_less 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=5
|
|
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=5
|
|
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=5
|
|
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)"
|
|
|
|
popd
|