2
0

reset_default_config 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC STARTING
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. source scripts/_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
  16. #=================================================
  17. app=$YNH_APP_INSTANCE_NAME
  18. final_path=$(ynh_app_setting_get --app=$app --key=final_path)
  19. encrypt=$(ynh_app_setting_get --app=$app --key=encrypt)
  20. core_backup=$(ynh_app_setting_get --app=$app --key=core_backup)
  21. apps_backup=$(ynh_app_setting_get --app=$app --key=apps_backup)
  22. #=================================================
  23. # SORT OUT THE CONFIG FILE TO HANDLE
  24. #=================================================
  25. file="$1"
  26. if [ "$file" = "Backup_list.conf" ]; then
  27. config_file="$final_path/Backup_list.conf"
  28. fi
  29. #=================================================
  30. # SPECIFIC ACTION
  31. #=================================================
  32. # RESET THE CONFIG FILE
  33. #=================================================
  34. ynh_script_progression --message="Reseting the config file $file"
  35. # Verify the checksum and backup the file if it's different
  36. ynh_backup_if_checksum_is_different --file="$config_file"
  37. if [ "$file" = "Backup_list.conf" ]
  38. then
  39. # Get the default file and overwrite the current config
  40. cp "$final_path/Backup_list.conf.default" "$config_file"
  41. # Recreate the default config
  42. backup_dir="/home/yunohost.app/${app}/backup"
  43. enc_backup_dir="/home/yunohost.app/${app}/encrypted_backup"
  44. ynh_replace_string --match_string="^backup_dir=.*" --replace_string="backup_dir=$backup_dir" --target_file="$config_file"
  45. ynh_replace_string --match_string="^enc_backup_dir=.*" --replace_string="enc_backup_dir=$enc_backup_dir" --target_file="$config_file"
  46. if [ $encrypt -eq 1 ]
  47. then
  48. encrypt=true
  49. passkey="$final_path/passkey"
  50. else
  51. encrypt=false
  52. passkey=na
  53. fi
  54. ynh_replace_string --match_string="^encrypt=.*" --replace_string="encrypt=$encrypt" --target_file="$config_file"
  55. ynh_replace_string --match_string="^cryptpass=.*" --replace_string="cryptpass=$passkey" --target_file="$config_file"
  56. if [ $core_backup -eq 1 ]
  57. then
  58. core_backup=true
  59. else
  60. core_backup=false
  61. fi
  62. ynh_replace_string --match_string="^ynh_core_backup=.*" --replace_string="ynh_core_backup=$core_backup" --target_file="$config_file"
  63. if [ $apps_backup -eq 1 ]
  64. then
  65. # Add all current applications to the backup
  66. while read backup_app
  67. do
  68. ynh_replace_string --match_string="^ynh_app_backup=$" --replace_string="ynh_app_backup=$backup_app\n&" --target_file="$config_file"
  69. done <<< "$(yunohost app list -i | grep id: | sed 's/.*id: //')"
  70. fi
  71. fi
  72. # Calculate and store the config file checksum into the app settings
  73. ynh_store_file_checksum --file="$config_file"
  74. #=================================================
  75. # END OF SCRIPT
  76. #=================================================
  77. ynh_script_progression --message="Execution completed" --last