2
0

install 6.8 KB

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