2
0

upgrade 4.8 KB

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