install 7.4 KB

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