upgrade 7.0 KB

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