install 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. 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. test -n "$encryption_pwd" || ynh_die "encryption_pwd can't be empty if you choose to enable encryption."
  30. fi
  31. #=================================================
  32. # STORE SETTINGS FROM MANIFEST
  33. #=================================================
  34. ynh_app_setting_set $app frequency $frequency
  35. #=================================================
  36. # STANDARD MODIFICATIONS
  37. #=================================================
  38. # INSTALL DEPENDENCIES
  39. #=================================================
  40. # Valid the fucking debconf message
  41. # To find this, install the package, install also debconf-utils
  42. # Then use `debconf-get-selections | grep package`
  43. echo "encfs encfs/security-information boolean true" | debconf-set-selections
  44. ynh_install_app_dependencies rsync encfs sshpass
  45. #=================================================
  46. # DOWNLOAD, CHECK AND UNPACK SOURCE
  47. #=================================================
  48. ynh_app_setting_set $app final_path $final_path
  49. # Download, check integrity, uncompress and patch the source from app.src
  50. ynh_setup_source "$final_path"
  51. #=================================================
  52. # SPECIFIC SETUP
  53. #=================================================
  54. # CREATE THE BACKUP DIRECTORY
  55. #=================================================
  56. backup_dir="/home/yunohost.app/${app}_backup"
  57. enc_backup_dir="/home/yunohost.app/${app}_encrypted_backup"
  58. mkdir -p "$backup_dir"
  59. #=================================================
  60. # CONFIGURE ARCHIVIST
  61. #=================================================
  62. config_file="$final_path/Backup_list.conf"
  63. cp "$final_path/Backup_list.conf.default" "$config_file"
  64. ynh_replace_string "^backup_dir=.*" "backup_dir=$backup_dir" "$config_file"
  65. ynh_replace_string "^enc_backup_dir=.*" "enc_backup_dir=$enc_backup_dir" "$config_file"
  66. if [ $encrypt -eq 1 ]
  67. then
  68. encrypt=true
  69. passkey="$final_path/passkey"
  70. echo "$encryption_pwd" > "$passkey"
  71. chmod 400 "$passkey"
  72. else
  73. encrypt=false
  74. passkey=na
  75. fi
  76. ynh_replace_string "^encrypt=.*" "encrypt=$encrypt" "$config_file"
  77. ynh_replace_string "^cryptpass=.*" "cryptpass=$passkey" "$config_file"
  78. if [ $core_backup -eq 1 ]
  79. then
  80. core_backup=true
  81. else
  82. core_backup=false
  83. fi
  84. ynh_replace_string "^ynh_core_backup=.*" "ynh_core_backup=$core_backup" "$config_file"
  85. if [ $apps_backup -eq 1 ]
  86. then
  87. # Add all current applications to the backup
  88. while read backup_app
  89. do
  90. ynh_replace_string "^ynh_app_backup=$" "ynh_app_backup=$backup_app\n&" "$config_file"
  91. done <<< "$(yunohost app list -i | grep id: | sed 's/.*id: //')"
  92. fi
  93. #=================================================
  94. # SET THE CRON FILE
  95. #=================================================
  96. cp ../conf/cron /etc/cron.d/$app
  97. ynh_replace_string "__FINALPATH__" "$final_path" /etc/cron.d/$app
  98. ynh_replace_string "__APP__" "$app" /etc/cron.d/$app
  99. if [ "$frequency" = "Daily" ]; then
  100. cron_freq="0 0 * * *"
  101. elif [ "$frequency" = "Each 3 days" ]; then
  102. cron_freq="0 0 */3 * *"
  103. elif [ "$frequency" = "Weekly" ]; then
  104. cron_freq="0 0 * * 0"
  105. elif [ "$frequency" = "Biweekly" ]; then
  106. cron_freq="0 0 * * 0/2"
  107. else # Monthly
  108. cron_freq="0 0 1 * *"
  109. fi
  110. ynh_replace_string "__FREQUENCY__" "$cron_freq" /etc/cron.d/$app
  111. # Calculate and store the config file checksum into the app settings
  112. ynh_store_file_checksum "/etc/cron.d/$app"
  113. #=================================================
  114. # GENERIC FINALIZATION
  115. #=================================================
  116. # SECURE FILES AND DIRECTORIES
  117. #=================================================
  118. # Set permissions to app files
  119. chown -R root: $final_path
  120. #=================================================
  121. # SETUP LOGROTATE
  122. #=================================================
  123. mkdir -p /var/log/$app
  124. # Use logrotate to manage application logfile(s)
  125. ynh_use_logrotate
  126. #=================================================
  127. # PRINT INFORMATIONS
  128. #=================================================
  129. WARNING echo -e "\nTo add recipients or to modify the files or apps to backup,
  130. please have a look to the config file $config_file."