reset_default_config 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. # RETRIEVE ARGUMENTS
  11. #=================================================
  12. app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
  13. final_path=$(ynh_app_setting_get $app final_path)
  14. encrypt=$(ynh_app_setting_get $app encrypt)
  15. core_backup=$(ynh_app_setting_get $app core_backup)
  16. apps_backup=$(ynh_app_setting_get $app apps_backup)
  17. #=================================================
  18. # SORT OUT THE CONFIG FILE TO HANDLE
  19. #=================================================
  20. file="$1"
  21. if [ "$file" = "Backup_list.conf" ]; then
  22. config_file="$final_path/Backup_list.conf"
  23. fi
  24. #=================================================
  25. # SPECIFIC ACTION
  26. #=================================================
  27. # RESET THE CONFIG FILE
  28. #=================================================
  29. # Verify the checksum and backup the file if it's different
  30. ynh_backup_if_checksum_is_different "$config_file"
  31. if [ "$file" = "Backup_list.conf" ]
  32. then
  33. # Get the default file and overwrite the current config
  34. cp "$final_path/Backup_list.conf.default" "$config_file"
  35. # Recreate the default config
  36. backup_dir="/home/yunohost.app/${app}/backup"
  37. enc_backup_dir="/home/yunohost.app/${app}/encrypted_backup"
  38. ynh_replace_string "^backup_dir=.*" "backup_dir=$backup_dir" "$config_file"
  39. ynh_replace_string "^enc_backup_dir=.*" "enc_backup_dir=$enc_backup_dir" "$config_file"
  40. if [ $encrypt -eq 1 ]
  41. then
  42. encrypt=true
  43. passkey="$final_path/passkey"
  44. else
  45. encrypt=false
  46. passkey=na
  47. fi
  48. ynh_replace_string "^encrypt=.*" "encrypt=$encrypt" "$config_file"
  49. ynh_replace_string "^cryptpass=.*" "cryptpass=$passkey" "$config_file"
  50. if [ $core_backup -eq 1 ]
  51. then
  52. core_backup=true
  53. else
  54. core_backup=false
  55. fi
  56. ynh_replace_string "^ynh_core_backup=.*" "ynh_core_backup=$core_backup" "$config_file"
  57. if [ $apps_backup -eq 1 ]
  58. then
  59. # Add all current applications to the backup
  60. while read backup_app
  61. do
  62. ynh_replace_string "^ynh_app_backup=$" "ynh_app_backup=$backup_app\n&" "$config_file"
  63. done <<< "$(yunohost app list -i | grep id: | sed 's/.*id: //')"
  64. fi
  65. fi
  66. # Calculate and store the config file checksum into the app settings
  67. ynh_store_file_checksum "$config_file"