install 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. #=================================================
  47. # STANDARD MODIFICATIONS
  48. #=================================================
  49. # INSTALL DEPENDENCIES
  50. #=================================================
  51. ynh_script_progression --message="Install dependencies" --weight=15
  52. # Valid the fucking debconf message
  53. # To find this, install the package, install also debconf-utils
  54. # Then use `debconf-get-selections | grep package`
  55. echo "encfs encfs/security-information boolean true" | debconf-set-selections
  56. ynh_install_app_dependencies $app_depencencies
  57. #=================================================
  58. # DOWNLOAD, CHECK AND UNPACK SOURCE
  59. #=================================================
  60. ynh_script_progression --message="Download, check and unpack source" --weight=3
  61. ynh_app_setting_set $app final_path $final_path
  62. # Download, check integrity, uncompress and patch the source from app.src
  63. ynh_setup_source "$final_path"
  64. #=================================================
  65. # SPECIFIC SETUP
  66. #=================================================
  67. # CREATE THE BACKUP DIRECTORY
  68. #=================================================
  69. backup_dir="/home/yunohost.app/${app}/backup"
  70. enc_backup_dir="/home/yunohost.app/${app}/encrypted_backup"
  71. mkdir -p "$backup_dir"
  72. #=================================================
  73. # CONFIGURE ARCHIVIST
  74. #=================================================
  75. ynh_script_progression --message="Configure Archivist" --weight=2
  76. config_file="$final_path/Backup_list.conf"
  77. cp "$final_path/Backup_list.conf.default" "$config_file"
  78. ynh_replace_string "^backup_dir=.*" "backup_dir=$backup_dir" "$config_file"
  79. ynh_replace_string "^enc_backup_dir=.*" "enc_backup_dir=$enc_backup_dir" "$config_file"
  80. if [ $encrypt -eq 1 ]
  81. then
  82. encrypt=true
  83. passkey="$final_path/passkey"
  84. ynh_print_OFF; echo "$encryption_pwd" > "$passkey"; ynh_print_ON
  85. chmod 400 "$passkey"
  86. else
  87. encrypt=false
  88. passkey=na
  89. fi
  90. ynh_replace_string "^encrypt=.*" "encrypt=$encrypt" "$config_file"
  91. ynh_replace_string "^cryptpass=.*" "cryptpass=$passkey" "$config_file"
  92. if [ $core_backup -eq 1 ]
  93. then
  94. core_backup=true
  95. else
  96. core_backup=false
  97. fi
  98. ynh_replace_string "^ynh_core_backup=.*" "ynh_core_backup=$core_backup" "$config_file"
  99. if [ $apps_backup -eq 1 ]
  100. then
  101. # Add all current applications to the backup
  102. while read backup_app
  103. do
  104. ynh_replace_string "^ynh_app_backup=$" "ynh_app_backup=$backup_app\n&" "$config_file"
  105. done <<< "$(yunohost app list -i | grep id: | sed 's/.*id: //')"
  106. fi
  107. # Calculate and store the config file checksum into the app settings
  108. ynh_store_file_checksum "$config_file"
  109. #=================================================
  110. # STRETCH COMPATIBILITY
  111. #=================================================
  112. if is_stretch
  113. then
  114. ynh_replace_string "yunohost backup create --ignore-apps" "yunohost backup create" "$final_path/archivist.sh"
  115. ynh_replace_string "yunohost backup create --ignore-system" "yunohost backup create" "$final_path/archivist.sh"
  116. fi
  117. #=================================================
  118. # SET THE CRON FILE
  119. #=================================================
  120. ynh_script_progression --message="Set the cron file"
  121. cp ../conf/cron /etc/cron.d/$app
  122. ynh_replace_string "__FINALPATH__" "$final_path" /etc/cron.d/$app
  123. ynh_replace_string "__APP__" "$app" /etc/cron.d/$app
  124. if [ "$frequency" = "Daily" ]; then
  125. cron_freq="0 2 * * *"
  126. run_freq="every day"
  127. elif [ "$frequency" = "Each 3 days" ]; then
  128. cron_freq="0 2 */3 * *"
  129. run_freq="each 3 days"
  130. elif [ "$frequency" = "Weekly" ]; then
  131. cron_freq="0 2 * * 0"
  132. run_freq="once a week on sunday"
  133. elif [ "$frequency" = "Biweekly" ]; then
  134. cron_freq="0 2 * * 0/2"
  135. run_freq="one sunday out of two"
  136. else # Monthly
  137. cron_freq="0 2 1 * *"
  138. run_freq="once a month on the first sunday"
  139. fi
  140. ynh_replace_string "__FREQUENCY__" "$cron_freq" /etc/cron.d/$app
  141. # Calculate and store the config file checksum into the app settings
  142. ynh_store_file_checksum "/etc/cron.d/$app"
  143. #=================================================
  144. # GENERIC FINALIZATION
  145. #=================================================
  146. # SECURE FILES AND DIRECTORIES
  147. #=================================================
  148. # Set permissions to app files
  149. chown -R root: $final_path
  150. #=================================================
  151. # SETUP LOGROTATE
  152. #=================================================
  153. ynh_script_progression --message="Configure logrotate"
  154. mkdir -p /var/log/$app
  155. # Use logrotate to manage application logfile(s)
  156. ynh_use_logrotate
  157. #=================================================
  158. # PRINT INFORMATION
  159. #=================================================
  160. Informations="To add recipients or to modify the files or apps to backup,
  161. please have a look to the config file $config_file"
  162. ynh_print_info "
  163. $Informations" >&2
  164. #=================================================
  165. # SEND A README FOR THE ADMIN
  166. #=================================================
  167. ynh_print_OFF
  168. if [ "$encrypt" = "true" ]
  169. then
  170. encrypt_message="Your password for encryption is '$encryption_pwd'
  171. "
  172. else
  173. encrypt_message=""
  174. fi
  175. # Get main domain and buid the url of the admin panel of the app.
  176. admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
  177. message="${encrypt_message}Archivist is going to run $run_freq.
  178. If you want to change the frequency, have a look to the file /etc/cron.d/$app.
  179. $Informations
  180. Please read the documentation (https://github.com/maniackcrudelis/archivist/blob/master/Configuration.md) about the configuration of archivist for more information.
  181. You can configure this app easily by using the experimental config-panel feature: $admin_panel/config-panel.
  182. You can also find some specific actions for this app by using the experimental action feature: $admin_panel/actions.
  183. If you're facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/archivist_ynh"
  184. ynh_send_readme_to_admin --app_message="$message" --recipients="root" --type="install"
  185. ynh_print_ON
  186. #=================================================
  187. # END OF SCRIPT
  188. #=================================================
  189. ynh_script_progression --message="Installation completed" --last