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