2
0

install 7.6 KB

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