reset_default_config 2.7 KB

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