upgrade 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC START
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. source _common.sh
  8. source /usr/share/yunohost/helpers
  9. #=================================================
  10. # MANAGE SCRIPT FAILURE
  11. #=================================================
  12. # Exit if an error occurs during the execution of the script
  13. ynh_abort_if_errors
  14. #=================================================
  15. # LOAD SETTINGS
  16. #=================================================
  17. app=$YNH_APP_INSTANCE_NAME
  18. final_path=$(ynh_app_setting_get $app final_path)
  19. frequency="$(ynh_app_setting_get $app frequency)"
  20. #=================================================
  21. # CHECK VERSION
  22. #=================================================
  23. ynh_abort_if_up_to_date
  24. #=================================================
  25. # STANDARD UPGRADE STEPS
  26. #=================================================
  27. # DOWNLOAD, CHECK AND UNPACK SOURCE
  28. #=================================================
  29. # Download, check integrity, uncompress and patch the source from app.src
  30. ynh_setup_source "$final_path"
  31. #=================================================
  32. # SPECIFIC UPGRADE
  33. #=================================================
  34. # UPDATE THE CRON FILE
  35. #=================================================
  36. # Verify the checksum and backup the file if it's different
  37. ynh_backup_if_checksum_is_different "/etc/cron.d/$app"
  38. cp ../conf/cron /etc/cron.d/$app
  39. ynh_replace_string "__FINALPATH__" "$final_path" /etc/cron.d/$app
  40. ynh_replace_string "__APP__" "$app" /etc/cron.d/$app
  41. if [ "$frequency" = "Daily" ]; then
  42. cron_freq="0 2 * * *"
  43. elif [ "$frequency" = "Each 3 days" ]; then
  44. cron_freq="0 2 */3 * *"
  45. elif [ "$frequency" = "Weekly" ]; then
  46. cron_freq="0 2 * * 0"
  47. elif [ "$frequency" = "Biweekly" ]; then
  48. cron_freq="0 2 * * 0/2"
  49. else # Monthly
  50. cron_freq="0 2 1 * *"
  51. fi
  52. ynh_replace_string "__FREQUENCY__" "$cron_freq" /etc/cron.d/$app
  53. # Recalculate and store the config file checksum into the app settings
  54. ynh_store_file_checksum "/etc/cron.d/$app"
  55. #=================================================
  56. # SETUP LOGROTATE
  57. #=================================================
  58. # Use logrotate to manage app-specific logfile(s)
  59. ynh_use_logrotate --non-append
  60. #=================================================
  61. # GENERIC FINALIZATION
  62. #=================================================
  63. # SECURE FILES AND DIRECTORIES
  64. #=================================================
  65. # Set right permissions for curl installation
  66. chown -R root: $final_path