reset_default_config 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. elif [ "$file" = "01-pihole.conf" ]; then
  28. config_file="/etc/dnsmasq.d/01-pihole.conf"
  29. fi
  30. #=================================================
  31. # SPECIFIC ACTION
  32. #=================================================
  33. # RESET THE CONFIG FILE
  34. #=================================================
  35. ynh_script_progression --message="Resetting the config file $config_file..." --weight=9
  36. # Verify the checksum and backup the file if it's different
  37. ynh_backup_if_checksum_is_different --file="$config_file"
  38. main_iface=$(ip route | grep --max-count=1 default | awk '{print $5;}')
  39. if [ "$file" = "setupVars.conf" ]
  40. then
  41. # Recreate the default config
  42. # Trouve l'interface réseau par défaut
  43. echo "PIHOLE_INTERFACE=$main_iface" > "$config_file"
  44. echo "IPV4_ADDRESS=127.0.0.1" >> "$config_file"
  45. echo "IPV6_ADDRESS=::1" >> "$config_file"
  46. echo "PIHOLE_DNS_1=" >> "$config_file"
  47. echo "PIHOLE_DNS_2=" >> "$config_file"
  48. if [ $query_logging -eq 1 ]; then
  49. query_logging=true
  50. else
  51. query_logging=false
  52. fi
  53. echo "QUERY_LOGGING=$query_logging" >> "$config_file"
  54. echo "INSTALL_WEB=true" >> "$config_file"
  55. elif [ "$file" = "pihole-FTL.conf" ]
  56. then
  57. # Get the default file and overwrite the current config
  58. cp /etc/yunohost/apps/$app/conf/pihole-FTL.conf "$config_file"
  59. ynh_script_progression --message="Restarting Pi-Hole..." --weight=2
  60. # Restart pihole-FTL
  61. ynh_systemd_action --action=restart --service_name=pihole-FTL
  62. elif [ "$file" = "01-pihole.conf" ]
  63. then
  64. cp "$pihole_local_repo/advanced/01-pihole.conf" $config_file
  65. # Use dns from /etc/resolv.dnsmasq.conf
  66. ynh_replace_string --match_string="@DNS1@" --replace_string="" --target_file=$config_file
  67. ynh_replace_string --match_string="@DNS2@" --replace_string="" --target_file=$config_file
  68. ynh_replace_string --match_string="^no-resolv" --replace_string="#no-resolv" --target_file=$config_file
  69. ynh_replace_string --match_string="@INT@" --replace_string="$main_iface" --target_file=$config_file
  70. if [ "$query_logging" = "true" ]; then
  71. ynh_replace_string --match_string="^#log-queries" --replace_string="log-queries" --target_file=$config_file
  72. else
  73. ynh_replace_string --match_string="^log-queries" --replace_string="#log-queries" --target_file=$config_file
  74. fi
  75. # Fix a too recent option for our dnsmasq version.
  76. ynh_replace_string --match_string="log-queries=extra" --replace_string="log-queries" --target_file=$config_file
  77. # To prevent any conflict with the original dnsmasq config, comment cache-size in the original config.
  78. ynh_replace_string --match_string="^cache-size=" --replace_string="#pihole# cache-size=" --target_file=/etc/dnsmasq.conf
  79. fi
  80. # Calculate and store the config file checksum into the app settings
  81. ynh_store_file_checksum --file="$config_file"
  82. #=================================================
  83. # END OF SCRIPT
  84. #=================================================
  85. ynh_script_progression --message="Execution completed" --last