reset_default_app 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC STARTING
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. # Load common variables for all scripts.
  8. source scripts/_common.sh
  9. source /usr/share/yunohost/helpers
  10. #=================================================
  11. # MANAGE SCRIPT FAILURE
  12. #=================================================
  13. ynh_clean_setup () {
  14. # Clean installation remaining that are not handle by the remove script.
  15. ynh_clean_check_starting
  16. }
  17. # Exit if an error occurs during the execution of the script
  18. ynh_abort_if_errors
  19. #=================================================
  20. # RETRIEVE ARGUMENTS
  21. #=================================================
  22. app=$YNH_APP_INSTANCE_NAME
  23. final_path=$(ynh_app_setting_get --app=$app --key=final_path)
  24. frequency="$(ynh_app_setting_get --app=$app --key=frequency)"
  25. #=================================================
  26. # DOWNLOAD, CHECK AND UNPACK SOURCE
  27. #=================================================
  28. ynh_script_progression --message="Resetting source files..." --time --weight=1
  29. # Download, check integrity, uncompress and patch the source from app.src
  30. (cd scripts; YNH_CWD=$PWD ynh_setup_source --dest_dir="$final_path")
  31. #=================================================
  32. # RECREATE DIRECTORY
  33. #=================================================
  34. backup_dir="/home/yunohost.app/${app}/backup"
  35. mkdir -p "$backup_dir"
  36. #=================================================
  37. # UPDATE THE CRON FILE
  38. #=================================================
  39. ynh_script_progression --message="Updating the cron file..."
  40. # Verify the checksum and backup the file if it's different
  41. ynh_backup_if_checksum_is_different --file="/etc/cron.d/$app"
  42. (cd scripts; cp ../conf/cron /etc/cron.d/$app)
  43. ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file=/etc/cron.d/$app
  44. ynh_replace_string --match_string="__APP__" --replace_string=$app --target_file=/etc/cron.d/$app
  45. if [ "$frequency" = "Daily" ]; then
  46. cron_freq="0 2 * * *"
  47. run_freq="every day"
  48. elif [ "$frequency" = "Each 3 days" ]; then
  49. cron_freq="0 2 */3 * *"
  50. run_freq="each 3 days"
  51. elif [ "$frequency" = "Weekly" ]; then
  52. cron_freq="0 2 * * 0"
  53. run_freq="once a week on sunday"
  54. elif [ "$frequency" = "Biweekly" ]; then
  55. cron_freq="0 2 * * 0/2"
  56. run_freq="one sunday out of two"
  57. else # Monthly
  58. cron_freq="0 2 1 * *"
  59. run_freq="once a month on the first sunday"
  60. fi
  61. ynh_replace_string --match_string="__FREQUENCY__" --replace_string="$cron_freq" --target_file=/etc/cron.d/$app
  62. # Recalculate and store the config file checksum into the app settings
  63. ynh_store_file_checksum --file="/etc/cron.d/$app"
  64. #=================================================
  65. # RECONFIGURE ARCHIVIST
  66. #=================================================
  67. ynh_script_progression --message="Reconfiguring archivist..." --time --weight=1
  68. yunohost app action run $app reset_default_config
  69. #=================================================
  70. # SETUP LOGROTATE
  71. #=================================================
  72. ynh_script_progression --message="Resetting logrotate configuration..." --time --weight=1
  73. # Use logrotate to manage app-specific logfile(s)
  74. ynh_use_logrotate --non-append
  75. #=================================================
  76. # SECURE FILES AND DIRECTORIES
  77. #=================================================
  78. # Set permissions on app files
  79. chown -R root: $final_path
  80. #=================================================
  81. # END OF SCRIPT
  82. #=================================================
  83. ynh_script_progression --message="Execution completed" --time --last