2
0

upgrade 4.6 KB

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