mirror of
https://github.com/YunoHost-Apps/diaspora_ynh.git
synced 2024-09-03 18:26:13 +02:00
Add a restore script
This commit is contained in:
parent
6dfcadf003
commit
6666747c29
2 changed files with 110 additions and 6 deletions
|
@ -10,11 +10,11 @@
|
||||||
setup_root=1
|
setup_root=1
|
||||||
setup_nourl=0
|
setup_nourl=0
|
||||||
upgrade=1
|
upgrade=1
|
||||||
# upgrade=1 from_commit=CommitHash
|
upgrade=1 from_commit=0.7.13.0-ynh1
|
||||||
backup_restore=0
|
backup_restore=1
|
||||||
multi_instance=1
|
multi_instance=1
|
||||||
port_already_use=0
|
port_already_use=0
|
||||||
change_url=0
|
change_url=0 # not supported upstream
|
||||||
;;; Levels
|
;;; Levels
|
||||||
# If the level 5 (Package linter) is forced to 1. Please add justifications here.
|
# If the level 5 (Package linter) is forced to 1. Please add justifications here.
|
||||||
Level 5=auto
|
Level 5=auto
|
||||||
|
|
110
scripts/restore
110
scripts/restore
|
@ -1,13 +1,19 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
## vars for remove script
|
||||||
|
can_remove_db=0
|
||||||
|
can_remove_home=0
|
||||||
|
can_remove_user=0
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC START
|
# GENERIC START
|
||||||
#=================================================
|
#=================================================
|
||||||
# IMPORT GENERIC HELPERS
|
# IMPORT GENERIC HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
source ../settings/scripts/_common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
pushd $(readlink -f ../settings/scripts)
|
||||||
#=================================================
|
#=================================================
|
||||||
# MANAGE SCRIPT FAILURE
|
# MANAGE SCRIPT FAILURE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -32,8 +38,106 @@ db_user=$db_name
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Validating restoration parameters..."
|
ynh_script_progression --message="Validating restoration parameters..."
|
||||||
|
|
||||||
ynh_webpath_available --domain=$domain --path_url=$path_url \
|
ynh_webpath_available --domain=$domain --path_url=/ \
|
||||||
|| ynh_die --message="Path not available: ${domain}${path_url}"
|
|| ynh_die --message="Domain not available: ${domain}"
|
||||||
test ! -d $final_path \
|
test ! -d $final_path \
|
||||||
|| ynh_die --message="There is already a directory: $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_rvm_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 v0.7.13.0
|
||||||
|
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=200
|
||||||
|
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
|
||||||
|
|
Loading…
Reference in a new issue