From 029fc89e0e1ddeb9adc757db50bcb1f73314c8f5 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Mon, 24 Dec 2018 11:15:52 +0100 Subject: [PATCH] Update Restore & Backup --- check_process | 2 +- scripts/backup | 11 +++++++---- scripts/install | 7 ++----- scripts/restore | 38 ++++++++++++++++++++++++++++++++++---- 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/check_process b/check_process index af2868d..a24cfed 100644 --- a/check_process +++ b/check_process @@ -8,7 +8,7 @@ language="en" is_public=0 (PUBLIC|public=1|private=0) upload=1 - password="password" + password="] jG?>j-@X}?A1u}DEA dZMKfQS]^r" # port="8083" (PORT) ; Checks pkg_linter=1 diff --git a/scripts/backup b/scripts/backup index 0871d96..04ba6cd 100755 --- a/scripts/backup +++ b/scripts/backup @@ -25,14 +25,19 @@ app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get $app final_path) path_url=$(ynh_app_setting_get $app path) domain=$(ynh_app_setting_get $app domain) -calibre_dir=$(ynh_app_setting_get $app calibre_dir) + +#Get settings from database in case it has been changed in the app +calibre_dir=$(sqlite3 $final_path/app.db "SELECT config_calibre_dir FROM settings WHERE ID=1") +#Save it in settings so that it can be used back afterward +calibre_dir=${calibre_dir%/} +ynh_app_setting_set $app calibre_dir $calibre_dir #================================================= # STANDARD BACKUP STEPS #================================================= # BACKUP THE APP MAIN DIR #================================================= - +#This will backup the app.db file at the same time ynh_backup "$final_path" #================================================= @@ -69,5 +74,3 @@ then else echo "Data dir will not be saved, because backup_core_only is set." >&2 fi - - diff --git a/scripts/install b/scripts/install index 9916a9e..7554613 100755 --- a/scripts/install +++ b/scripts/install @@ -37,8 +37,6 @@ upload=$7 # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= -### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app". -### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app" final_path=/var/www/$app test ! -e "$final_path" || ynh_die "This path already contains a folder" @@ -97,7 +95,7 @@ pip install --target $final_path/vendor -r $final_path/requirements.txt #================================================= # NGINX CONFIGURATION #================================================= -#Cannot use empty string for X-script-name +#Cannot use empty string for X-script-name, causes an issue in the python prg if [ $path_url = "/" ] ; then ynh_replace_string "X-Script-Name __PATH__;" "X-Script-Name /$app;" ../conf/nginx.conf fi @@ -112,7 +110,6 @@ ynh_add_nginx_config # Create a system user ynh_system_user_create $app - chown -R $app: $final_path #================================================= @@ -173,7 +170,7 @@ eval sqlite3 $final_path/app.db "$conf" #mise à jour du mot de passe (je ne sais pas pourquoi, je n'arrive pas à l'intégrer dans le fichier de conf, pb de " et ') ynh_print_OFF -#had to set it on two lines or package_linter cries... +#had to set it on two lines or package_linter cries like a baby... pass=$(python ../conf/generate_password_hash.py "$pass" $final_path/vendor) sqlite3 $final_path/app.db "UPDATE user SET password='$pass' WHERE ID=1" ynh_print_ON diff --git a/scripts/restore b/scripts/restore index 1ef17dc..74b1e07 100755 --- a/scripts/restore +++ b/scripts/restore @@ -26,6 +26,8 @@ domain=$(ynh_app_setting_get $app domain) path_url=$(ynh_app_setting_get $app path) final_path=$(ynh_app_setting_get $app final_path) calibre_dir=$(ynh_app_setting_get $app calibre_dir) +is_public=$(ynh_app_setting_get $app is_public) +port=$(ynh_app_setting_get $app port) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -41,22 +43,31 @@ test ! -d $final_path \ #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= - +ynh_print_info "Restore nginx settings" ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= -# RESTORE THE APP MAIN DIR +# REOPEN PORT #================================================= -ynh_restore_file "$final_path" +ynh_print_info "Reopening port $port" +yunohost firewall allow --no-upnp TCP $port 2>&1 +ynh_app_setting_set $app port $port #================================================= # RECREATE THE DEDICATED USER #================================================= +ynh_print_info "Restore user $app" # Create the dedicated user (if not existing) ynh_system_user_create $app +#================================================= +# RESTORE THE APP MAIN DIR +#================================================= +ynh_print_info "Restore app directory $final_path" +ynh_restore_file "$final_path" + #================================================= # RESTORE USER RIGHTS #================================================= @@ -71,7 +82,9 @@ chown -R $app: $final_path #================================================= # Define and install dependencies +ynh_print_info "Installing dependencies and pip packages" ynh_install_app_dependencies $pkg_dependencies +pip install --target $final_path/vendor -r $final_path/requirements.txt #================================================= # ADVERTISE SERVICE IN ADMIN PANEL @@ -118,11 +131,28 @@ fi # Remove the option backup_core_only if it's in the settings.yml file ynh_app_setting_delete $app backup_core_only +#================================================= +# SETUP SSOWAT +#================================================= + +# Make app public if necessary +if [ $is_public -eq 1 ] +then + # unprotected_uris allows SSO credentials to be passed anyway. + ynh_app_setting_set $app unprotected_uris "/" +fi + #================================================= # GENERIC FINALIZATION #================================================= # RELOAD NGINX #================================================= - +ynh_print_info "Reload nginx and start $app" systemctl reload nginx ynh_systemd_action -l "INFO in server: Starting Gevent server" + +#================================================= +# WARNING FOR READ ACCESS +#================================================= +ynh_print_warn "Please, give required access to $app user to the $calibre_dir folder." +