2
0

reset_default_config 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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=$app --key=final_path)
  14. encrypt=$(ynh_app_setting_get --app=$app --key=encrypt)
  15. core_backup=$(ynh_app_setting_get --app=$app --key=core_backup)
  16. apps_backup=$(ynh_app_setting_get --app=$app --key=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. ynh_script_progression --message="Reseting the config file $file"
  30. # Verify the checksum and backup the file if it's different
  31. ynh_backup_if_checksum_is_different --file="$config_file"
  32. if [ "$file" = "Backup_list.conf" ]
  33. then
  34. # Get the default file and overwrite the current config
  35. cp "$final_path/Backup_list.conf.default" "$config_file"
  36. # Recreate the default config
  37. backup_dir="/home/yunohost.app/${app}/backup"
  38. enc_backup_dir="/home/yunohost.app/${app}/encrypted_backup"
  39. ynh_replace_string --match_string="^backup_dir=.*" --replace_string="backup_dir=$backup_dir" --target_file="$config_file"
  40. ynh_replace_string --match_string="^enc_backup_dir=.*" --replace_string="enc_backup_dir=$enc_backup_dir" --target_file="$config_file"
  41. if [ $encrypt -eq 1 ]
  42. then
  43. encrypt=true
  44. passkey="$final_path/passkey"
  45. else
  46. encrypt=false
  47. passkey=na
  48. fi
  49. ynh_replace_string --match_string="^encrypt=.*" --replace_string="encrypt=$encrypt" --target_file="$config_file"
  50. ynh_replace_string --match_string="^cryptpass=.*" --replace_string="cryptpass=$passkey" --target_file="$config_file"
  51. if [ $core_backup -eq 1 ]
  52. then
  53. core_backup=true
  54. else
  55. core_backup=false
  56. fi
  57. ynh_replace_string --match_string="^ynh_core_backup=.*" --replace_string="ynh_core_backup=$core_backup" --target_file="$config_file"
  58. if [ $apps_backup -eq 1 ]
  59. then
  60. # Add all current applications to the backup
  61. while read backup_app
  62. do
  63. ynh_replace_string --match_string="^ynh_app_backup=$" --replace_string="ynh_app_backup=$backup_app\n&" --target_file="$config_file"
  64. done <<< "$(yunohost app list -i | grep id: | sed 's/.*id: //')"
  65. fi
  66. fi
  67. # Calculate and store the config file checksum into the app settings
  68. ynh_store_file_checksum --file="$config_file"
  69. #=================================================
  70. # END OF SCRIPT
  71. #=================================================
  72. ynh_script_progression --message="Execution completed" --last