2
0

install 6.1 KB

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