install 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. # RETRIEVE ARGUMENTS FROM THE MANIFEST
  18. #=================================================
  19. ynh_script_progression --message="Retrieve arguments from the manifest"
  20. encrypt=$YNH_APP_ARG_ENCRYPT
  21. ynh_print_OFF; encryption_pwd=$YNH_APP_ARG_ENCRYPTION_PWD; ynh_print_ON
  22. core_backup=$YNH_APP_ARG_CORE_BACKUP
  23. apps_backup=$YNH_APP_ARG_APPS_BACKUP
  24. frequency="$YNH_APP_ARG_FREQUENCY"
  25. app=$YNH_APP_INSTANCE_NAME
  26. #=================================================
  27. # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
  28. #=================================================
  29. ynh_script_progression --message="Check if the app can be installed"
  30. final_path=/opt/yunohost/$app
  31. test ! -e "$final_path" || ynh_die "This path already contains a folder"
  32. if [ $encrypt -eq 1 ]; then
  33. ynh_print_OFF
  34. test -n "$encryption_pwd" || ynh_die "encryption_pwd can't be empty if you choose to enable encryption."
  35. ynh_print_ON
  36. fi
  37. #=================================================
  38. # STORE SETTINGS FROM MANIFEST
  39. #=================================================
  40. ynh_script_progression --message="Store settings from manifest" --weight=3
  41. ynh_app_setting_set $app frequency "$frequency"
  42. ynh_app_setting_set $app encrypt "$encrypt"
  43. ynh_app_setting_set $app core_backup "$core_backup"
  44. ynh_app_setting_set $app apps_backup "$apps_backup"
  45. ynh_app_setting_set $app overwrite_cron "1"
  46. ynh_app_setting_set $app admin_mail_html "1"
  47. #=================================================
  48. # STANDARD MODIFICATIONS
  49. #=================================================
  50. # INSTALL DEPENDENCIES
  51. #=================================================
  52. ynh_script_progression --message="Install dependencies" --weight=15
  53. # Valid the fucking debconf message
  54. # To find this, install the package, install also debconf-utils
  55. # Then use `debconf-get-selections | grep package`
  56. echo "encfs encfs/security-information boolean true" | debconf-set-selections
  57. ynh_install_app_dependencies $app_depencencies
  58. #=================================================
  59. # DOWNLOAD, CHECK AND UNPACK SOURCE
  60. #=================================================
  61. ynh_script_progression --message="Download, check and unpack source" --weight=3
  62. ynh_app_setting_set $app final_path $final_path
  63. # Download, check integrity, uncompress and patch the source from app.src
  64. ynh_setup_source "$final_path"
  65. #=================================================
  66. # SPECIFIC SETUP
  67. #=================================================
  68. # CREATE THE BACKUP DIRECTORY
  69. #=================================================
  70. backup_dir="/home/yunohost.app/${app}/backup"
  71. enc_backup_dir="/home/yunohost.app/${app}/encrypted_backup"
  72. mkdir -p "$backup_dir"
  73. #=================================================
  74. # CONFIGURE ARCHIVIST
  75. #=================================================
  76. ynh_script_progression --message="Configure Archivist" --weight=2
  77. config_file="$final_path/Backup_list.conf"
  78. cp "$final_path/Backup_list.conf.default" "$config_file"
  79. ynh_replace_string "^backup_dir=.*" "backup_dir=$backup_dir" "$config_file"
  80. ynh_replace_string "^enc_backup_dir=.*" "enc_backup_dir=$enc_backup_dir" "$config_file"
  81. if [ $encrypt -eq 1 ]
  82. then
  83. encrypt=true
  84. passkey="$final_path/passkey"
  85. ynh_print_OFF; echo "$encryption_pwd" > "$passkey"; ynh_print_ON
  86. chmod 400 "$passkey"
  87. else
  88. encrypt=false
  89. passkey=na
  90. fi
  91. ynh_replace_string "^encrypt=.*" "encrypt=$encrypt" "$config_file"
  92. ynh_replace_string "^cryptpass=.*" "cryptpass=$passkey" "$config_file"
  93. if [ $core_backup -eq 1 ]
  94. then
  95. core_backup=true
  96. else
  97. core_backup=false
  98. fi
  99. ynh_replace_string "^ynh_core_backup=.*" "ynh_core_backup=$core_backup" "$config_file"
  100. if [ $apps_backup -eq 1 ]
  101. then
  102. # Add all current applications to the backup
  103. while read backup_app
  104. do
  105. ynh_replace_string "^ynh_app_backup=$" "ynh_app_backup=$backup_app\n&" "$config_file"
  106. done <<< "$(yunohost app list -i | grep id: | sed 's/.*id: //')"
  107. fi
  108. # Calculate and store the config file checksum into the app settings
  109. ynh_store_file_checksum "$config_file"
  110. #=================================================
  111. # STRETCH COMPATIBILITY
  112. #=================================================
  113. if is_stretch
  114. then
  115. ynh_replace_string "yunohost backup create --ignore-apps" "yunohost backup create" "$final_path/archivist.sh"
  116. ynh_replace_string "yunohost backup create --ignore-system" "yunohost backup create" "$final_path/archivist.sh"
  117. fi
  118. #=================================================
  119. # SET THE CRON FILE
  120. #=================================================
  121. ynh_script_progression --message="Set the cron file"
  122. cp ../conf/cron /etc/cron.d/$app
  123. ynh_replace_string "__FINALPATH__" "$final_path" /etc/cron.d/$app
  124. ynh_replace_string "__APP__" "$app" /etc/cron.d/$app
  125. if [ "$frequency" = "Daily" ]; then
  126. cron_freq="0 2 * * *"
  127. run_freq="every day"
  128. elif [ "$frequency" = "Each 3 days" ]; then
  129. cron_freq="0 2 */3 * *"
  130. run_freq="each 3 days"
  131. elif [ "$frequency" = "Weekly" ]; then
  132. cron_freq="0 2 * * 0"
  133. run_freq="once a week on sunday"
  134. elif [ "$frequency" = "Biweekly" ]; then
  135. cron_freq="0 2 * * 0/2"
  136. run_freq="one sunday out of two"
  137. else # Monthly
  138. cron_freq="0 2 1 * *"
  139. run_freq="once a month on the first sunday"
  140. fi
  141. ynh_replace_string "__FREQUENCY__" "$cron_freq" /etc/cron.d/$app
  142. # Calculate and store the config file checksum into the app settings
  143. ynh_store_file_checksum "/etc/cron.d/$app"
  144. #=================================================
  145. # GENERIC FINALIZATION
  146. #=================================================
  147. # SECURE FILES AND DIRECTORIES
  148. #=================================================
  149. # Set permissions to app files
  150. chown -R root: $final_path
  151. #=================================================
  152. # SETUP LOGROTATE
  153. #=================================================
  154. ynh_script_progression --message="Configure logrotate"
  155. mkdir -p /var/log/$app
  156. # Use logrotate to manage application logfile(s)
  157. ynh_use_logrotate
  158. #=================================================
  159. # PRINT INFORMATION
  160. #=================================================
  161. Informations="To add recipients or to modify the files or apps to backup,
  162. please have a look to the config file $config_file"
  163. ynh_print_info "
  164. $Informations" >&2
  165. #=================================================
  166. # SEND A README FOR THE ADMIN
  167. #=================================================
  168. if [ "$encrypt" = "true" ]
  169. then
  170. ynh_print_OFF
  171. encrypt_message="Your password for encryption is '$encryption_pwd'
  172. "
  173. ynh_print_ON
  174. else
  175. encrypt_message=""
  176. fi
  177. # Get main domain and buid the url of the admin panel of the app.
  178. admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
  179. ynh_print_OFF
  180. echo "${encrypt_message}Archivist is going to run $run_freq.
  181. If you want to change the frequency, have a look to the file /etc/cron.d/$app.
  182. $Informations
  183. 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.
  184. You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__.
  185. 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__.
  186. 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__." > mail_to_send
  187. ynh_print_ON
  188. ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type="install"
  189. #=================================================
  190. # END OF SCRIPT
  191. #=================================================
  192. ynh_script_progression --message="Installation completed" --last