upgrade 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. upgrade_type=$(ynh_check_app_version_changed)
  24. #=================================================
  25. # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  26. #=================================================
  27. # Backup the current version of the app
  28. ynh_backup_before_upgrade
  29. ynh_clean_setup () {
  30. # restore it if the upgrade fails
  31. ynh_restore_upgradebackup
  32. }
  33. # Exit if an error occurs during the execution of the script
  34. ynh_abort_if_errors
  35. #=================================================
  36. # STANDARD UPGRADE STEPS
  37. #=================================================
  38. # DOWNLOAD, CHECK AND UNPACK SOURCE
  39. #=================================================
  40. if [ "$upgrade_type" == "UPGRADE_APP" ]
  41. then
  42. # Download, check integrity, uncompress and patch the source from app.src
  43. ynh_setup_source "$final_path"
  44. fi
  45. #=================================================
  46. # SPECIFIC UPGRADE
  47. #=================================================
  48. # UPDATE THE CRON FILE
  49. #=================================================
  50. # Verify the checksum and backup the file if it's different
  51. ynh_backup_if_checksum_is_different "/etc/cron.d/$app"
  52. cp ../conf/cron /etc/cron.d/$app
  53. ynh_replace_string "__FINALPATH__" "$final_path" /etc/cron.d/$app
  54. ynh_replace_string "__APP__" "$app" /etc/cron.d/$app
  55. if [ "$frequency" = "Daily" ]; then
  56. cron_freq="0 2 * * *"
  57. elif [ "$frequency" = "Each 3 days" ]; then
  58. cron_freq="0 2 */3 * *"
  59. elif [ "$frequency" = "Weekly" ]; then
  60. cron_freq="0 2 * * 0"
  61. elif [ "$frequency" = "Biweekly" ]; then
  62. cron_freq="0 2 * * 0/2"
  63. else # Monthly
  64. cron_freq="0 2 1 * *"
  65. fi
  66. ynh_replace_string "__FREQUENCY__" "$cron_freq" /etc/cron.d/$app
  67. # Recalculate and store the config file checksum into the app settings
  68. ynh_store_file_checksum "/etc/cron.d/$app"
  69. #=================================================
  70. # SETUP LOGROTATE
  71. #=================================================
  72. # Use logrotate to manage app-specific logfile(s)
  73. ynh_use_logrotate --non-append
  74. #=================================================
  75. # GENERIC FINALIZATION
  76. #=================================================
  77. # SECURE FILES AND DIRECTORIES
  78. #=================================================
  79. # Set right permissions for curl installation
  80. chown -R root: $final_path