install 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/bash
  2. #=================================================
  3. # IMPORT GENERIC HELPERS
  4. #=================================================
  5. source _common.sh
  6. source /usr/share/yunohost/helpers
  7. #=================================================
  8. # INITIALIZE AND STORE SETTINGS
  9. #=================================================
  10. if [ "$encrypt" -eq 1 ] && [ -z "$encryption_pwd" ]; then
  11. ynh_die "encryption_pwd can't be empty if you choose to enable encryption."
  12. fi
  13. # Not saved as settings by default
  14. ynh_app_setting_set --key="encryption_pwd" --value="$encryption_pwd"
  15. _set_frequencies
  16. ynh_app_setting_set --key=overwrite_cron --value=1
  17. #=================================================
  18. # DOWNLOAD, CHECK AND UNPACK SOURCE
  19. #=================================================
  20. ynh_script_progression "Setting up source files..."
  21. # Download, check integrity, uncompress and patch the source from app.src
  22. ynh_setup_source --dest_dir="$install_dir"
  23. #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "root:root" "$install_dir"
  24. chown -R "root:root" "$data_dir"
  25. #=================================================
  26. # CONFIGURE ARCHIVIST
  27. #=================================================
  28. ynh_script_progression "Configuring Archivist..."
  29. if [ "$encrypt" -eq 1 ]; then
  30. encrypt=true
  31. passkey="$install_dir/passkey"
  32. echo "$encryption_pwd" > "$passkey"
  33. chmod 400 "$passkey"
  34. else
  35. encrypt=false
  36. passkey=na
  37. fi
  38. if [ "$core_backup" -eq 1 ]; then
  39. core_backup=true
  40. else
  41. core_backup=false
  42. fi
  43. config_file="$install_dir/Backup_list.conf"
  44. cp "$install_dir/Backup_list.conf.default" "$config_file"
  45. ynh_replace --file="$config_file" --match="^backup_dir=.*" --replace="backup_dir=$data_dir/backup"
  46. ynh_replace --file="$config_file" --match="^enc_backup_dir=.*" --replace="enc_backup_dir=$data_dir/encrypted_backup"
  47. ynh_replace --file="$config_file" --match="^encrypt=.*" --replace="encrypt=$encrypt"
  48. ynh_replace --file="$config_file" --match="^cryptpass=.*" --replace="cryptpass=$passkey"
  49. ynh_replace --file="$config_file" --match="^ynh_core_backup=.*" --replace="ynh_core_backup=$core_backup"
  50. if [ $apps_backup -eq 1 ]; then
  51. # Add all current applications to the backup
  52. while read -r backup_app; do
  53. ynh_replace --file="$config_file" --match="^ynh_app_backup=$" --replace="ynh_app_backup=$backup_app\n&"
  54. done <<< "$(yunohost app list | grep 'id:' | sed 's/.*id: //')"
  55. fi
  56. # Calculate and store the config file checksum into the app settings
  57. ynh_store_file_checksum "$config_file"
  58. #=================================================
  59. # SYSTEM CONFIGURATION
  60. #=================================================
  61. ynh_script_progression "Adding system configurations related to $app..."
  62. # Use logrotate to manage application logfile(s)
  63. ynh_config_add_logrotate
  64. # Add Cron configuration file
  65. ynh_config_add --template="archivist.cron" --destination="/etc/cron.d/$app"
  66. #=================================================
  67. # END OF SCRIPT
  68. #=================================================
  69. ynh_script_progression "Installation of $app completed"