reset_default_config 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. query_logging=$(ynh_app_setting_get $app query_logging)
  14. #=================================================
  15. # SORT OUT THE CONFIG FILE TO HANDLE
  16. #=================================================
  17. file="$1"
  18. if [ "$file" = "setupVars.conf" ]; then
  19. config_file="/etc/pihole/setupVars.conf"
  20. elif [ "$file" = "pihole-FTL.conf" ]; then
  21. config_file="/etc/pihole/pihole-FTL.conf"
  22. fi
  23. #=================================================
  24. # SPECIFIC ACTION
  25. #=================================================
  26. # RESET THE CONFIG FILE
  27. #=================================================
  28. # Verify the checksum and backup the file if it's different
  29. ynh_backup_if_checksum_is_different "$config_file"
  30. if [ "$file" = "setupVars.conf" ]
  31. then
  32. # Recreate the default config
  33. # Trouve l'interface réseau par défaut
  34. main_iface=$(ip route | grep default | awk '{print $5;}')
  35. echo "PIHOLE_INTERFACE=$main_iface" > "$config_file"
  36. echo "IPV4_ADDRESS=127.0.0.1" >> "$config_file"
  37. echo "IPV6_ADDRESS=" >> "$config_file"
  38. echo "PIHOLE_DNS_1=" >> "$config_file"
  39. echo "PIHOLE_DNS_2=" >> "$config_file"
  40. if [ $query_logging -eq 1 ]; then
  41. query_logging=true
  42. else
  43. query_logging=false
  44. fi
  45. echo "QUERY_LOGGING=$query_logging" >> "$config_file"
  46. echo "INSTALL_WEB=true" >> "$config_file"
  47. elif [ "$file" = "pihole-FTL.conf" ]
  48. then
  49. # Get the default file and overwrite the current config
  50. cp /etc/yunohost/apps/$app/conf/pihole-FTL.conf "$config_file"
  51. # Restart pihole-FTL
  52. ynh_system_reload --service_name=pihole-FTL --action=restart
  53. fi
  54. # Calculate and store the config file checksum into the app settings
  55. ynh_store_file_checksum "$config_file"