restore 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/bash
  2. source ../settings/scripts/_common.sh
  3. source /usr/share/yunohost/helpers
  4. ##
  5. ## 1. - 4. order matters!
  6. ##
  7. # 1. restore couchdb directory
  8. # uncritical, good to have
  9. ynh_script_progression --message="Restoring couchdb directory..." --weight=1
  10. ynh_restore_file --origin_path="/var/lib/couchdb"
  11. # 2. restore the apps settings
  12. # they contain variables needed to install couchdb (see below)
  13. ynh_script_progression --message="Restoring flohmarkts settings..." --weight=1
  14. ynh_restore_file --origin_path="/etc/yunohost/apps/$app"
  15. # 3. get variables from settings.yaml for couchdb
  16. ynh_script_progression --message="Restoring settings for couchdb install..." --weight=1
  17. # export app=$YNH_APP_INSTANCE_NAME
  18. # export couchdb_magic_cookie=$(ynh_app_setting_get $app couchdb_magic_cookie)
  19. # export password_couchdb_admin=$(ynh_app_setting_get $app password_couchdb_admin)
  20. # export password_couchdb_admin=$(ynh_app_setting_get $app password_couchdb_admin)
  21. # @@ debug
  22. env
  23. # 4. reinstall couchdb
  24. ynh_script_progression --message="Reinstalling couchdb..." --weight=40
  25. echo "\
  26. couchdb couchdb/mode select standalone
  27. couchdb couchdb/mode seen true
  28. couchdb couchdb/bindaddress string 127.0.0.1
  29. couchdb couchdb/bindaddress seen true
  30. couchdb couchdb/cookie string $couchdb_magic_cookie
  31. couchdb couchdb/adminpass password $password_couchdb_admin
  32. couchdb couchdb/adminpass seen true
  33. couchdb couchdb/adminpass_again password $password_couchdb_admin
  34. couchdb couchdb/adminpass_again seen true" | debconf-set-selections
  35. DEBIAN_FRONTEND=noninteractive # apt-get install -y --force-yes couchdb
  36. ynh_install_extra_app_dependencies \
  37. --repo="deb https://apache.jfrog.io/artifactory/couchdb-deb/ $(lsb_release -c -s) main" \
  38. --key="https://couchdb.apache.org/repo/keys.asc" \
  39. --package="couchdb"
  40. # stop couchdb
  41. systemctl stop couchdb
  42. # add couchdb configuration
  43. ynh_script_progression --message="Adding a configuration file..." --weight=2
  44. ynh_restore_file --origin_path="/opt/couchdb/etc/local.d/05-flohmarkt.ini"
  45. chown root:couchdb /opt/couchdb/etc/local.d/05-flohmarkt.ini
  46. chmod 640 /opt/couchdb/etc/local.d/05-flohmarkt.ini
  47. # start couchdb
  48. systemctl start couchdb
  49. systemctl status couchdb
  50. # RESTORE THE APP MAIN DIR
  51. ynh_script_progression --message="Restoring the app main directory..." --weight=10
  52. ynh_restore_file --origin_path="$install_dir"
  53. # RESTORE THE DATA DIRECTORY
  54. ynh_script_progression --message="Restoring the data directory..." --weight=1
  55. ynh_restore_file --origin_path="$data_dir" --not_mandatory
  56. mkdir -p $data_dir
  57. # RESTORE FAIL2BAN CONFIGURATION
  58. ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=2
  59. ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf"
  60. ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf"
  61. ynh_systemd_action --action=restart --service_name=fail2ban
  62. # RESTORE THE NGINX CONFIGURATION
  63. ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1
  64. ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
  65. # RESTORE THE LOGROTATE CONFIGURATION
  66. ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1
  67. ynh_restore_file --origin_path="/etc/logrotate.d/$app"
  68. # INTEGRATE SERVICE IN YUNOHOST
  69. ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
  70. yunohost service add $app --description="A decentral federated small advertisement platform" --log="/var/log/$app/$app.log"
  71. # RELOAD NGINX
  72. ynh_script_progression --message="Reloading NGINX web server..." --weight=1
  73. ynh_systemd_action --service_name=nginx --action=reload
  74. ynh_script_progression --message="Restoration completed for $app" --last