restore 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/bash
  2. source /usr/share/yunohost/helpers
  3. source ../settings/scripts/_common.sh
  4. # reinstall couchdb
  5. ynh_script_progression --message="Reinstalling couchdb..." --weight=40
  6. flohmarkt_ynh_up_inst_couchdb
  7. # add couchdb configuration
  8. if ! [[ -e /opt/couchdb/etc/local.d/05-flohmarkt.ini ]]; then
  9. ynh_script_progression --message="Adding a configuration file..." --weight=2
  10. flohmarkt_ynh_stop_couchdb
  11. ynh_restore_file --origin_path="/opt/couchdb/etc/local.d/05-flohmarkt.ini"
  12. chown root:couchdb /opt/couchdb/etc/local.d/05-flohmarkt.ini
  13. chmod 640 /opt/couchdb/etc/local.d/05-flohmarkt.ini
  14. ynh_script_progression --message="Starting couchdb..." --weight=4
  15. flohmarkt_ynh_start_couchdb
  16. else
  17. ynh_script_progression --message="CouchDB configuration file already exists." --weight=1
  18. fi
  19. # restore couchdb from json
  20. ynh_script_progression --message="Importing couchdb from json backup..." --weight=8
  21. flohmarkt_ynh_restore_couchdb
  22. # RESTORE THE APP MAIN DIR
  23. ynh_script_progression --message="Restoring the app main directory..." --weight=10
  24. ynh_restore_file --origin_path="$flohmarkt_install"
  25. # RESTORE THE DATA DIRECTORY
  26. ynh_script_progression --message="Restoring the data directory..." --weight=1
  27. ynh_restore_file --origin_path="$flohmarkt_data_dir" --not_mandatory
  28. mkdir -p $data_dir
  29. # restore logfiles
  30. # independent of the question whether one wants the logfiles in a backup (as you can
  31. # see I decided I wanted them for the time being) it is important to create the log
  32. # directory and file so that the systemd.service can redirect STDOUT to the file.
  33. # If the logfile(or maybe just -directory?) is missing the service will not start
  34. # on a fresh install, because directory and/or file do not exist.
  35. ynh_script_progression --message="Restoring log directory and logfiles..." --weight=1
  36. ynh_restore_file --origin_path="$flohmarkt_log_dir" --not_mandatory
  37. mkdir -p -m755 "$flohmarkt_log_dir"
  38. touch "$flohmarkt_logfile"
  39. # logfile contains possibly the secret setup URL
  40. chmod 640 "$flohmarkt_logfile"
  41. # RESTORE FAIL2BAN CONFIGURATION
  42. ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=2
  43. ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf"
  44. ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf"
  45. ynh_systemd_action --action=restart --service_name=fail2ban
  46. # RESTORE THE NGINX CONFIGURATION
  47. ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1
  48. ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
  49. # RESTORE THE LOGROTATE CONFIGURATION
  50. ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1
  51. ynh_restore_file --origin_path="/etc/logrotate.d/$app"
  52. # restore flohmarkt systemd service and integrate service into yunohost
  53. ynh_script_progression --message="Restoring flohmarkt.service and integrating service into YunoHost..." --weight=1
  54. ynh_restore_file --origin_path="/etc/systemd/system/$flohmarkt_filename.service"
  55. ynh_systemd_action --action=enable --service_name=$flohmarkt_filename
  56. yunohost service add $flohmarkt_filename --description="A decentral federated small advertisement platform" --log="$flohmarkt_logfile"
  57. flohmarkt_ynh_start_service
  58. # RELOAD NGINX
  59. ynh_script_progression --message="Reloading NGINX web server..." --weight=1
  60. ynh_systemd_action --service_name=nginx --action=reload
  61. # create symlinks
  62. flohmarkt_ynh_create_symlinks
  63. ynh_script_progression --message="Restoration completed for $app" --last