reset_default_config 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. query_logging=$(ynh_app_setting_get --app=$app --key=query_logging)
  19. #=================================================
  20. # SORT OUT THE CONFIG FILE TO HANDLE
  21. #=================================================
  22. file="$1"
  23. if [ "$file" = "setupVars.conf" ]; then
  24. config_file="/etc/pihole/setupVars.conf"
  25. elif [ "$file" = "pihole-FTL.conf" ]; then
  26. config_file="/etc/pihole/pihole-FTL.conf"
  27. fi
  28. #=================================================
  29. # SPECIFIC ACTION
  30. #=================================================
  31. # RESET THE CONFIG FILE
  32. #=================================================
  33. ynh_script_progression --message="Resetting the config file $config_file..." --weight=9
  34. # Verify the checksum and backup the file if it's different
  35. ynh_backup_if_checksum_is_different --file="$config_file"
  36. main_iface=$(ip route | grep --max-count=1 default | awk '{print $5;}')
  37. if [ "$file" = "setupVars.conf" ]
  38. then
  39. # Recreate the default config
  40. # Trouve l'interface réseau par défaut
  41. echo "PIHOLE_INTERFACE=$main_iface" > "$config_file"
  42. echo "IPV4_ADDRESS=127.0.0.1" >> "$config_file"
  43. echo "IPV6_ADDRESS=::1" >> "$config_file"
  44. echo "PIHOLE_DNS_1=" >> "$config_file"
  45. echo "PIHOLE_DNS_2=" >> "$config_file"
  46. if [ $query_logging -eq 1 ]; then
  47. query_logging=true
  48. else
  49. query_logging=false
  50. fi
  51. echo "QUERY_LOGGING=$query_logging" >> "$config_file"
  52. echo "INSTALL_WEB=true" >> "$config_file"
  53. elif [ "$file" = "pihole-FTL.conf" ]
  54. then
  55. # Get the default file and overwrite the current config
  56. port=$(ynh_app_setting_get --app=$app --key=port)
  57. ynh_add_config --template="/etc/yunohost/apps/$app/conf/pihole-FTL.conf" --destination="$config_file"
  58. ynh_script_progression --message="Restarting Pi-Hole..." --weight=2
  59. # Restart pihole-FTL
  60. ynh_systemd_action --action=restart --service_name=pihole-FTL
  61. fi
  62. # Calculate and store the config file checksum into the app settings
  63. ynh_store_file_checksum --file="$config_file"
  64. #=================================================
  65. # END OF SCRIPT
  66. #=================================================
  67. ynh_script_progression --message="Execution completed" --last