upgrade 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. encrypt=$(ynh_app_setting_get $app encrypt)
  21. core_backup=$(ynh_app_setting_get $app core_backup)
  22. apps_backup=$(ynh_app_setting_get $app apps_backup)
  23. overwrite_cron=$(ynh_app_setting_get $app overwrite_cron)
  24. #=================================================
  25. # CHECK VERSION
  26. #=================================================
  27. upgrade_type=$(ynh_check_app_version_changed)
  28. #=================================================
  29. # ENSURE DOWNWARD COMPATIBILITY
  30. #=================================================
  31. # If encrypt doesn't exist, create it
  32. if [ -z "$encrypt" ]; then
  33. encrypt="$(grep "^encrypt=" "$final_path/Backup_list.conf" | cut -d= -f2)"
  34. if [ "$encrypt" = true ]; then
  35. encrypt=1
  36. else
  37. encrypt=0
  38. fi
  39. ynh_app_setting_set $app encrypt $encrypt
  40. fi
  41. # If core_backup doesn't exist, create it
  42. if [ -z "$core_backup" ]; then
  43. core_backup="$(grep "^ynh_core_backup=" "$final_path/Backup_list.conf" | cut -d= -f2)"
  44. ynh_app_setting_set $app core_backup $core_backup
  45. fi
  46. # If apps_backup doesn't exist, create it
  47. if [ -z "$apps_backup" ]; then
  48. apps_backup="$(grep --count --max-count=1 "^ynh_app_backup=" "$final_path/Backup_list.conf")"
  49. ynh_app_setting_set $app apps_backup $apps_backup
  50. fi
  51. # If overwrite_cron doesn't exist, create it
  52. if [ -z "$overwrite_cron" ]; then
  53. overwrite_cron=1
  54. ynh_app_setting_set $app overwrite_cron $overwrite_cron
  55. fi
  56. #=================================================
  57. # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  58. #=================================================
  59. # Backup the current version of the app
  60. ynh_backup_before_upgrade
  61. ynh_clean_setup () {
  62. # restore it if the upgrade fails
  63. ynh_restore_upgradebackup
  64. }
  65. # Exit if an error occurs during the execution of the script
  66. ynh_abort_if_errors
  67. #=================================================
  68. # STANDARD UPGRADE STEPS
  69. #=================================================
  70. # DOWNLOAD, CHECK AND UNPACK SOURCE
  71. #=================================================
  72. if [ "$upgrade_type" == "UPGRADE_APP" ]
  73. then
  74. # Download, check integrity, uncompress and patch the source from app.src
  75. ynh_setup_source "$final_path"
  76. fi
  77. #=================================================
  78. # SPECIFIC UPGRADE
  79. #=================================================
  80. # STRETCH COMPATIBILITY
  81. #=================================================
  82. if is_stretch
  83. then
  84. ynh_replace_string "yunohost backup create --ignore-apps" "yunohost backup create" "$final_path/archivist.sh"
  85. ynh_replace_string "yunohost backup create --ignore-system" "yunohost backup create" "$final_path/archivist.sh"
  86. fi
  87. #=================================================
  88. # UPDATE THE CRON FILE
  89. #=================================================
  90. # Overwrite the cron file only if it's allowed
  91. if [ $overwrite_cron -eq 1 ]
  92. then
  93. # Verify the checksum and backup the file if it's different
  94. ynh_backup_if_checksum_is_different "/etc/cron.d/$app"
  95. cp ../conf/cron /etc/cron.d/$app
  96. ynh_replace_string "__FINALPATH__" "$final_path" /etc/cron.d/$app
  97. ynh_replace_string "__APP__" "$app" /etc/cron.d/$app
  98. if [ "$frequency" = "Daily" ]; then
  99. cron_freq="0 2 * * *"
  100. elif [ "$frequency" = "Each 3 days" ]; then
  101. cron_freq="0 2 */3 * *"
  102. elif [ "$frequency" = "Weekly" ]; then
  103. cron_freq="0 2 * * 0"
  104. elif [ "$frequency" = "Biweekly" ]; then
  105. cron_freq="0 2 * * 0/2"
  106. else # Monthly
  107. cron_freq="0 2 1 * *"
  108. fi
  109. ynh_replace_string "__FREQUENCY__" "$cron_freq" /etc/cron.d/$app
  110. # Recalculate and store the config file checksum into the app settings
  111. ynh_store_file_checksum "/etc/cron.d/$app"
  112. fi
  113. #=================================================
  114. # SETUP LOGROTATE
  115. #=================================================
  116. # Use logrotate to manage app-specific logfile(s)
  117. ynh_use_logrotate --non-append
  118. #=================================================
  119. # GENERIC FINALIZATION
  120. #=================================================
  121. # SECURE FILES AND DIRECTORIES
  122. #=================================================
  123. # Set right permissions for curl installation
  124. chown -R root: $final_path