upgrade 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. ynh_script_progression --message="Load settings" --weight=3
  15. app=$YNH_APP_INSTANCE_NAME
  16. final_path=$(ynh_app_setting_get $app final_path)
  17. frequency="$(ynh_app_setting_get $app frequency)"
  18. encrypt=$(ynh_app_setting_get $app encrypt)
  19. core_backup=$(ynh_app_setting_get $app core_backup)
  20. apps_backup=$(ynh_app_setting_get $app apps_backup)
  21. overwrite_cron=$(ynh_app_setting_get $app overwrite_cron)
  22. #=================================================
  23. # CHECK VERSION
  24. #=================================================
  25. upgrade_type=$(ynh_check_app_version_changed)
  26. #=================================================
  27. # ENSURE DOWNWARD COMPATIBILITY
  28. #=================================================
  29. ynh_script_progression --message="Ensure downward compatibility"
  30. # If encrypt doesn't exist, create it
  31. if [ -z "$encrypt" ]; then
  32. encrypt="$(grep "^encrypt=" "$final_path/Backup_list.conf" | cut -d= -f2)"
  33. if [ "$encrypt" = true ]; then
  34. encrypt=1
  35. else
  36. encrypt=0
  37. fi
  38. ynh_app_setting_set $app encrypt $encrypt
  39. fi
  40. # If core_backup doesn't exist, create it
  41. if [ -z "$core_backup" ]; then
  42. core_backup="$(grep "^ynh_core_backup=" "$final_path/Backup_list.conf" | cut -d= -f2)"
  43. ynh_app_setting_set $app core_backup $core_backup
  44. fi
  45. # If apps_backup doesn't exist, create it
  46. if [ -z "$apps_backup" ]; then
  47. apps_backup="$(grep --count --max-count=1 "^ynh_app_backup=" "$final_path/Backup_list.conf")"
  48. ynh_app_setting_set $app apps_backup $apps_backup
  49. fi
  50. # If overwrite_cron doesn't exist, create it
  51. if [ -z "$overwrite_cron" ]; then
  52. overwrite_cron=1
  53. ynh_app_setting_set $app overwrite_cron $overwrite_cron
  54. fi
  55. admin_mail_html=$(ynh_app_setting_get $app admin_mail_html)
  56. # If admin_mail_html doesn't exist, create it
  57. if [ -z "$admin_mail_html" ]; then
  58. admin_mail_html=1
  59. ynh_app_setting_set $app admin_mail_html $admin_mail_html
  60. fi
  61. #=================================================
  62. # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  63. #=================================================
  64. ynh_script_progression --message="Backup the app before upgrading" --weight=2
  65. # Backup the current version of the app
  66. ynh_backup_before_upgrade
  67. ynh_clean_setup () {
  68. # restore it if the upgrade fails
  69. ynh_restore_upgradebackup
  70. }
  71. # Exit if an error occurs during the execution of the script
  72. ynh_abort_if_errors
  73. #=================================================
  74. # STANDARD UPGRADE STEPS
  75. #=================================================
  76. # DOWNLOAD, CHECK AND UNPACK SOURCE
  77. #=================================================
  78. if [ "$upgrade_type" == "UPGRADE_APP" ]
  79. then
  80. ynh_script_progression --message="Download, check and unpack source" --weight=2
  81. # Download, check integrity, uncompress and patch the source from app.src
  82. ynh_setup_source "$final_path"
  83. fi
  84. #=================================================
  85. # UPGRADE DEPENDENCIES
  86. #=================================================
  87. ynh_script_progression --message="Upgrade dependencies" --weight=8
  88. ynh_install_app_dependencies $app_depencencies
  89. #=================================================
  90. # SPECIFIC UPGRADE
  91. #=================================================
  92. # STRETCH COMPATIBILITY
  93. #=================================================
  94. if is_stretch
  95. then
  96. ynh_replace_string "yunohost backup create --ignore-apps" "yunohost backup create" "$final_path/archivist.sh"
  97. ynh_replace_string "yunohost backup create --ignore-system" "yunohost backup create" "$final_path/archivist.sh"
  98. fi
  99. #=================================================
  100. # UPDATE THE CRON FILE
  101. #=================================================
  102. ynh_script_progression --message="Update the cron file"
  103. # Overwrite the cron file only if it's allowed
  104. if [ $overwrite_cron -eq 1 ]
  105. then
  106. # Verify the checksum and backup the file if it's different
  107. ynh_backup_if_checksum_is_different "/etc/cron.d/$app"
  108. cp ../conf/cron /etc/cron.d/$app
  109. ynh_replace_string "__FINALPATH__" "$final_path" /etc/cron.d/$app
  110. ynh_replace_string "__APP__" "$app" /etc/cron.d/$app
  111. if [ "$frequency" = "Daily" ]; then
  112. cron_freq="0 2 * * *"
  113. run_freq="every day"
  114. elif [ "$frequency" = "Each 3 days" ]; then
  115. cron_freq="0 2 */3 * *"
  116. run_freq="each 3 days"
  117. elif [ "$frequency" = "Weekly" ]; then
  118. cron_freq="0 2 * * 0"
  119. run_freq="once a week on sunday"
  120. elif [ "$frequency" = "Biweekly" ]; then
  121. cron_freq="0 2 * * 0/2"
  122. run_freq="one sunday out of two"
  123. else # Monthly
  124. cron_freq="0 2 1 * *"
  125. run_freq="once a month on the first sunday"
  126. fi
  127. ynh_replace_string "__FREQUENCY__" "$cron_freq" /etc/cron.d/$app
  128. # Recalculate and store the config file checksum into the app settings
  129. ynh_store_file_checksum "/etc/cron.d/$app"
  130. fi
  131. #=================================================
  132. # SETUP LOGROTATE
  133. #=================================================
  134. ynh_script_progression --message="Reconfigure logrotate"
  135. # Use logrotate to manage app-specific logfile(s)
  136. ynh_use_logrotate --non-append
  137. #=================================================
  138. # GENERIC FINALIZATION
  139. #=================================================
  140. # SECURE FILES AND DIRECTORIES
  141. #=================================================
  142. # Set permissions on app files
  143. chown -R root: $final_path
  144. #=================================================
  145. # SEND A README FOR THE ADMIN
  146. #=================================================
  147. # Get main domain and buid the url of the admin panel of the app.
  148. admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
  149. # Build the changelog
  150. ynh_app_changelog || true
  151. echo "Archivist is going to run $run_freq.
  152. If you want to change the frequency, have a look to the file /etc/cron.d/$app.
  153. Please read the __URL_TAG1__documentation__URL_TAG2__https://github.com/maniackcrudelis/archivist/blob/master/Configuration.md__URL_TAG3__ about the configuration of archivist for more information.
  154. You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__.
  155. You can also find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__.
  156. If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/archivist_ynh__URL_TAG3__.
  157. ---
  158. Changelog since your last upgrade:
  159. $(cat changelog)" > mail_to_send
  160. ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type="upgrade"
  161. #=================================================
  162. # END OF SCRIPT
  163. #=================================================
  164. ynh_script_progression --message="Upgrade completed" --last