reset_default_config 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/bash
  2. #=================================================
  3. # IMPORT GENERIC HELPERS
  4. #=================================================
  5. source scripts/_common.sh
  6. source /usr/share/yunohost/helpers
  7. #=================================================
  8. # SORT OUT THE CONFIG FILE TO HANDLE
  9. #=================================================
  10. file="$1"
  11. if [ "$file" = "Backup_list.conf" ]; then
  12. config_file="$install_dir/Backup_list.conf"
  13. fi
  14. #=================================================
  15. # RESET THE CONFIG FILE
  16. #=================================================
  17. ynh_script_progression --message="Reseting the config file $file"
  18. # Verify the checksum and backup the file if it's different
  19. ynh_backup_if_checksum_is_different --file="$config_file"
  20. if [ "$file" = "Backup_list.conf" ]; then
  21. if [ "$encrypt" -eq 1 ]; then
  22. encrypt=true
  23. passkey="$install_dir/passkey"
  24. echo "$encryption_pwd" > "$passkey"
  25. chmod 400 "$passkey"
  26. else
  27. encrypt=false
  28. passkey=na
  29. fi
  30. if [ "$core_backup" -eq 1 ]; then
  31. core_backup=true
  32. else
  33. core_backup=false
  34. fi
  35. config_file="$install_dir/Backup_list.conf"
  36. cp "$install_dir/Backup_list.conf.default" "$config_file"
  37. ynh_replace_string --target_file="$config_file" --match_string="^backup_dir=.*" --replace_string="backup_dir=$data_dir/backup"
  38. ynh_replace_string --target_file="$config_file" --match_string="^enc_backup_dir=.*" --replace_string="enc_backup_dir=$data_dir/encrypted_backup"
  39. ynh_replace_string --target_file="$config_file" --match_string="^encrypt=.*" --replace_string="encrypt=$encrypt"
  40. ynh_replace_string --target_file="$config_file" --match_string="^cryptpass=.*" --replace_string="cryptpass=$passkey"
  41. ynh_replace_string --target_file="$config_file" --match_string="^ynh_core_backup=.*" --replace_string="ynh_core_backup=$core_backup"
  42. if [ $apps_backup -eq 1 ]; then
  43. # Add all current applications to the backup
  44. while read -r backup_app; do
  45. ynh_replace_string --target_file="$config_file" --match_string="^ynh_app_backup=$" --replace_string="ynh_app_backup=$backup_app\n&"
  46. done <<< "$(yunohost app list | grep 'id:' | sed 's/.*id: //')"
  47. fi
  48. fi
  49. # Calculate and store the config file checksum into the app settings
  50. ynh_store_file_checksum --file="$config_file"
  51. #=================================================
  52. # END OF SCRIPT
  53. #=================================================
  54. ynh_script_progression --message="Execution completed" --last