reset_default_config 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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=$app --key=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. ynh_script_progression --message="Resetting the config file $config_file..." --weight=9
  29. # Verify the checksum and backup the file if it's different
  30. ynh_backup_if_checksum_is_different --file="$config_file"
  31. if [ "$file" = "setupVars.conf" ]
  32. then
  33. # Recreate the default config
  34. # Trouve l'interface réseau par défaut
  35. main_iface=$(ip route | grep --max-count=1 default | awk '{print $5;}')
  36. echo "PIHOLE_INTERFACE=$main_iface" > "$config_file"
  37. echo "IPV4_ADDRESS=127.0.0.1" >> "$config_file"
  38. echo "IPV6_ADDRESS=::1" >> "$config_file"
  39. echo "PIHOLE_DNS_1=" >> "$config_file"
  40. echo "PIHOLE_DNS_2=" >> "$config_file"
  41. if [ $query_logging -eq 1 ]; then
  42. query_logging=true
  43. else
  44. query_logging=false
  45. fi
  46. echo "QUERY_LOGGING=$query_logging" >> "$config_file"
  47. echo "INSTALL_WEB=true" >> "$config_file"
  48. elif [ "$file" = "pihole-FTL.conf" ]
  49. then
  50. # Get the default file and overwrite the current config
  51. cp /etc/yunohost/apps/$app/conf/pihole-FTL.conf "$config_file"
  52. ynh_script_progression --message="Restarting PiHole..." --weight=2
  53. # Restart pihole-FTL
  54. ynh_systemd_action --action=restart --service_name=pihole-FTL
  55. fi
  56. # Calculate and store the config file checksum into the app settings
  57. ynh_store_file_checksum --file="$config_file"
  58. #=================================================
  59. # END OF SCRIPT
  60. #=================================================
  61. ynh_script_progression --message="Execution completed" --last