install 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC START
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. # Load common variables for all scripts.
  8. source _common.sh
  9. source /usr/share/yunohost/helpers
  10. #=================================================
  11. # MANAGE SCRIPT FAILURE
  12. #=================================================
  13. # Exit if an error occurs during the execution of the script
  14. ynh_abort_if_errors
  15. #=================================================
  16. # RETRIEVE ARGUMENTS FROM THE MANIFEST
  17. #=================================================
  18. encrypt=$YNH_APP_ARG_ENCRYPT
  19. ynh_print_OFF; encryption_pwd=$YNH_APP_ARG_ENCRYPTION_PWD; ynh_print_ON
  20. core_backup=$YNH_APP_ARG_CORE_BACKUP
  21. apps_backup=$YNH_APP_ARG_APPS_BACKUP
  22. frequency="$YNH_APP_ARG_FREQUENCY"
  23. app=$YNH_APP_INSTANCE_NAME
  24. #=================================================
  25. # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
  26. #=================================================
  27. ynh_script_progression --message="Validating installation parameters..."
  28. final_path=/opt/yunohost/$app
  29. test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
  30. if [ $encrypt -eq 1 ]; then
  31. ynh_print_OFF
  32. test -n "$encryption_pwd" || ynh_die --message="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_script_progression --message="Storing installation settings..." --weight=3
  39. ynh_app_setting_set --app=$app --key=frequency --value="$frequency"
  40. ynh_app_setting_set --app=$app --key=encrypt --value="$encrypt"
  41. ynh_app_setting_set --app=$app --key=core_backup --value="$core_backup"
  42. ynh_app_setting_set --app=$app --key=apps_backup --value="$apps_backup"
  43. ynh_app_setting_set --app=$app --key=overwrite_cron --value=1
  44. ynh_app_setting_set --app=$app --key=admin_mail_html --value=1
  45. #=================================================
  46. # STANDARD MODIFICATIONS
  47. #=================================================
  48. # INSTALL DEPENDENCIES
  49. #=================================================
  50. ynh_script_progression --message="Installing dependencies..." --weight=15
  51. # Valid the fucking debconf message
  52. # To find this, install the package, install also debconf-utils
  53. # Then use `debconf-get-selections | grep package`
  54. echo "encfs encfs/security-information boolean true" | debconf-set-selections
  55. ynh_install_app_dependencies $app_depencencies
  56. #=================================================
  57. # DOWNLOAD, CHECK AND UNPACK SOURCE
  58. #=================================================
  59. ynh_script_progression --message="Setting up source files..." --weight=3
  60. ynh_app_setting_set --app=$app --key=final_path --value=$final_path
  61. # Download, check integrity, uncompress and patch the source from app.src
  62. ynh_setup_source --dest_dir="$final_path"
  63. #=================================================
  64. # SPECIFIC SETUP
  65. #=================================================
  66. # CREATE THE BACKUP DIRECTORY
  67. #=================================================
  68. backup_dir="/home/yunohost.app/${app}/backup"
  69. enc_backup_dir="/home/yunohost.app/${app}/encrypted_backup"
  70. mkdir -p "$backup_dir"
  71. #=================================================
  72. # CONFIGURE ARCHIVIST
  73. #=================================================
  74. ynh_script_progression --message="Configuring Archivist..." --weight=2
  75. config_file="$final_path/Backup_list.conf"
  76. cp "$final_path/Backup_list.conf.default" "$config_file"
  77. ynh_replace_string --match_string="^backup_dir=.*" --replace_string="backup_dir=$backup_dir" --target_file="$config_file"
  78. ynh_replace_string --match_string="^enc_backup_dir=.*" --replace_string="enc_backup_dir=$enc_backup_dir" --target_file="$config_file"
  79. if [ $encrypt -eq 1 ]
  80. then
  81. encrypt=true
  82. passkey="$final_path/passkey"
  83. ynh_print_OFF; echo "$encryption_pwd" > "$passkey"; ynh_print_ON
  84. chmod 400 "$passkey"
  85. else
  86. encrypt=false
  87. passkey=na
  88. fi
  89. ynh_replace_string --match_string="^encrypt=.*" --replace_string="encrypt=$encrypt" --target_file="$config_file"
  90. ynh_replace_string --match_string="^cryptpass=.*" --replace_string="cryptpass=$passkey" --target_file="$config_file"
  91. if [ $core_backup -eq 1 ]
  92. then
  93. core_backup=true
  94. else
  95. core_backup=false
  96. fi
  97. ynh_replace_string --match_string="^ynh_core_backup=.*" --replace_string="ynh_core_backup=$core_backup" --target_file="$config_file"
  98. if [ $apps_backup -eq 1 ]
  99. then
  100. # Add all current applications to the backup
  101. while read backup_app
  102. do
  103. ynh_replace_string --match_string="^ynh_app_backup=$" --replace_string="ynh_app_backup=$backup_app\n&" --target_file="$config_file"
  104. done <<< "$(yunohost app list | grep 'id:' | sed 's/.*id: //')"
  105. fi
  106. # Calculate and store the config file checksum into the app settings
  107. ynh_store_file_checksum --file="$config_file"
  108. #=================================================
  109. # SET THE CRON FILE
  110. #=================================================
  111. ynh_script_progression --message="Configuring the cron file..."
  112. cp ../conf/cron /etc/cron.d/$app
  113. ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file=/etc/cron.d/$app
  114. ynh_replace_string --match_string="__APP__" --replace_string=$app --target_file=/etc/cron.d/$app
  115. if [ "$frequency" = "Daily" ]; then
  116. cron_freq="0 2 * * *"
  117. run_freq="every day"
  118. elif [ "$frequency" = "Each 3 days" ]; then
  119. cron_freq="0 2 */3 * *"
  120. run_freq="each 3 days"
  121. elif [ "$frequency" = "Weekly" ]; then
  122. cron_freq="0 2 * * 0"
  123. run_freq="once a week on sunday"
  124. elif [ "$frequency" = "Biweekly" ]; then
  125. cron_freq="0 2 * * 0/2"
  126. run_freq="one sunday out of two"
  127. else # Monthly
  128. cron_freq="0 2 1 * *"
  129. run_freq="once a month on the first sunday"
  130. fi
  131. ynh_replace_string --match_string="__FREQUENCY__" --replace_string="$cron_freq" --target_file=/etc/cron.d/$app
  132. # Calculate and store the config file checksum into the app settings
  133. ynh_store_file_checksum --file="/etc/cron.d/$app"
  134. #=================================================
  135. # GENERIC FINALIZATION
  136. #=================================================
  137. # SECURE FILES AND DIRECTORIES
  138. #=================================================
  139. # Set permissions to app files
  140. chown -R root: $final_path
  141. #=================================================
  142. # SETUP LOGROTATE
  143. #=================================================
  144. ynh_script_progression --message="Configuring log rotation..."
  145. mkdir -p /var/log/$app
  146. # Use logrotate to manage application logfile(s)
  147. ynh_use_logrotate
  148. #=================================================
  149. # PRINT INFORMATION
  150. #=================================================
  151. Informations="
  152. 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 --message="$Informations"
  155. #=================================================
  156. # SEND A README FOR THE ADMIN
  157. #=================================================
  158. if [ "$encrypt" = "true" ]
  159. then
  160. encrypt_message="Your password for encryption is '$encryption_pwd'
  161. "
  162. else
  163. encrypt_message=""
  164. fi
  165. # Get main domain and buid the url of the admin panel of the app.
  166. admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
  167. echo "${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 __URL_TAG1__documentation__URL_TAG2__https://github.com/maniackcrudelis/archivist/blob/master/Configuration.md__URL_TAG3__ about the configuration of archivist for more information.
  171. You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__.
  172. 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__.
  173. 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
  174. ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=install
  175. #=================================================
  176. # END OF SCRIPT
  177. #=================================================
  178. ynh_script_progression --message="Installation of $app completed" --last