2
0

reset_default_app 3.6 KB

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