Sign Up
Log In
Sign Up
Username:
*
Email:
*
Password:
*
Password confirmation:
*
or
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
Web
pi-hole
config.pihole.rb
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File config.pihole.rb of Package pi-hole
#!/usr/bin/ruby require "fileutils" sysconfig_file = "/etc/sysconfig/pihole" dnsmasq_file = "/etc/dnsmasq.d/01-pihole.conf" setupvars_file = "/etc/pihole/setupVars.conf" lines = File.readlines sysconfig_file regex = /^(?<variable>\w+)=(?<value>[\w\:\.\d\s]+)$/ pihole_interface = nil pihole_ipv4 = nil pihole_ipv6 = nil pihole_dns_1 = nil pihole_dns_2 = nil lines.each do |line| line.strip! next if line[0] == "#" match = line.match regex next if match.nil? case match[:variable] when "PIHOLE_INTERFACE" pihole_interface = match[:value] when "PIHOLE_IPV4" pihole_ipv4 = match[:value] when "PIHOLE_IPV6" pihole_ipv6 = match[:value] when "PIHOLE_DNS_1" pihole_dns_1 = match[:value] when "PIHOLE_DNS_2" pihole_dns_2 = match[:value] else puts "Unrecognized variable #{match[:variable]}" exit 1 end end content = File.read(dnsmasq_file) content.gsub!(/^interface=.*$/, "interface=#{pihole_interface}") content.gsub!(/^server=.*\nserver=.*$/, "server=#{pihole_dns_1}\nserver=#{pihole_dns_2}") File.open("#{dnsmasq_file}.temp", "w") do |file| file.puts content end FileUtils.mv "#{dnsmasq_file}.temp", dnsmasq_file content = File.read(setupvars_file) content.gsub!(/^PIHOLE_INTERFACE=.*$/, "PIHOLE_INTERFACE=#{pihole_interface}") content.gsub!(/^IPV4_ADDRESS=.*$/, "IPV4_ADDRESS=#{pihole_ipv4}") content.gsub!(/^IPV6_ADDRESS=.*$/, "IPV6_ADDRESS=#{pihole_ipv6}") content.gsub!(/^PIHOLE_DNS_1=.*$/, "PIHOLE_DNS_1=#{pihole_dns_1}") content.gsub!(/^PIHOLE_DNS_2=.*$/, "PIHOLE_DNS_2=#{pihole_dns_2}") File.open("#{setupvars_file}.temp", "w") do |file| file.puts content end FileUtils.mv "#{setupvars_file}.temp", setupvars_file `systemctl reload pihole-ftl`
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Contact
Support
@OBShq
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor