Une tentative de paquetage d'Invidious pour YunoHost
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
4.4KB

  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC START
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
  8. source ../settings/scripts/_common.sh
  9. source /usr/share/yunohost/helpers
  10. #=================================================
  11. # MANAGE SCRIPT FAILURE
  12. #=================================================
  13. ynh_clean_setup () {
  14. #### Remove this function if there's nothing to clean before calling the remove script.
  15. true
  16. }
  17. # Exit if an error occurs during the execution of the script
  18. ynh_abort_if_errors
  19. #=================================================
  20. # LOAD SETTINGS
  21. #=================================================
  22. ynh_print_info "Loading settings..."
  23. app=$YNH_APP_INSTANCE_NAME
  24. domain=$(ynh_app_setting_get $app domain)
  25. path_url=$(ynh_app_setting_get $app path)
  26. final_path=$(ynh_app_setting_get $app final_path)
  27. db_name=$(ynh_app_setting_get $app db_name)
  28. #=================================================
  29. # CHECK IF THE APP CAN BE RESTORED
  30. #=================================================
  31. ynh_print_info "Validating restoration parameters..."
  32. ynh_webpath_available $domain $path_url \
  33. || ynh_die "Path not available: ${domain}${path_url}"
  34. test ! -d $final_path \
  35. || ynh_die "There is already a directory: $final_path "
  36. #=================================================
  37. # STANDARD RESTORATION STEPS
  38. #=================================================
  39. # RESTORE THE NGINX CONFIGURATION
  40. #=================================================
  41. ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
  42. #=================================================
  43. # RESTORE THE APP MAIN DIR
  44. #=================================================
  45. ynh_print_info "Restoring the app main directory..."
  46. ynh_restore_file "$final_path"
  47. #=================================================
  48. # RECREATE THE DEDICATED USER
  49. #=================================================
  50. ynh_print_info "Recreating the dedicated system user..."
  51. # Create the dedicated user (if not existing)
  52. ynh_system_user_create $app
  53. #=================================================
  54. # RESTORE USER RIGHTS
  55. #=================================================
  56. # Restore permissions on app files
  57. chown -R root: $final_path
  58. #=================================================
  59. # RESTORE THE PHP-FPM CONFIGURATION
  60. #=================================================
  61. ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf"
  62. #=================================================
  63. # SPECIFIC RESTORATION
  64. #=================================================
  65. # REINSTALL DEPENDENCIES
  66. #=================================================
  67. ynh_print_info "Reinstalling dependencies..."
  68. # Define and install dependencies
  69. ynh_install_app_dependencies $pkg_dependencies
  70. #=================================================
  71. # RESTORE THE MYSQL DATABASE
  72. #=================================================
  73. ynh_print_info "Restoring the MySQL database..."
  74. db_pwd=$(ynh_app_setting_get $app mysqlpwd)
  75. ynh_mysql_setup_db $db_name $db_name $db_pwd
  76. ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
  77. #=================================================
  78. # RESTORE SYSTEMD
  79. #=================================================
  80. ynh_print_info "Restoring the systemd configuration..."
  81. ynh_restore_file "/etc/systemd/system/$app.service"
  82. systemctl enable $app.service
  83. #=================================================
  84. # ADVERTISE SERVICE IN ADMIN PANEL
  85. #=================================================
  86. yunohost service add $app --log "/var/log/$app/$app.log"
  87. #=================================================
  88. # RESTORE THE CRON FILE
  89. #=================================================
  90. ynh_restore_file "/etc/cron.d/$app"
  91. #=================================================
  92. # RESTORE THE LOGROTATE CONFIGURATION
  93. #=================================================
  94. ynh_restore_file "/etc/logrotate.d/$app"
  95. #=================================================
  96. # GENERIC FINALIZATION
  97. #=================================================
  98. # RELOAD NGINX AND PHP-FPM
  99. #=================================================
  100. ynh_print_info "Reloading nginx web server and php-fpm..."
  101. systemctl reload php7.0-fpm
  102. systemctl reload nginx
  103. #=================================================
  104. # END OF SCRIPT
  105. #=================================================
  106. ynh_print_info "Restoration completed for $app"