Address review comments

Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
Adam Warner 2022-04-04 22:02:26 +01:00
parent 7fa8cdd03e
commit 4d31d5ee11
No known key found for this signature in database
GPG Key ID: 872950F3ECF2B173
4 changed files with 10 additions and 10 deletions

View File

@ -56,11 +56,11 @@ addOrEditKeyValPair() {
# Deletes a key from target file # Deletes a key from target file
# #
# Example usage: # Example usage:
# removeKey "PIHOLE_DNS_1" "/etc/pihole/setupVars.conf" # removeKey "/etc/pihole/setupVars.conf" "PIHOLE_DNS_1"
####################### #######################
removeKey() { removeKey() {
local key="${1}" local file="${1}"
local file="${2}" local key="${2}"
sed -i "/^${key}/d" "${file}" sed -i "/^${key}/d" "${file}"
} }

View File

@ -60,7 +60,7 @@ add_setting() {
} }
delete_setting() { delete_setting() {
removeKey "${1}" "${setupVars}" removeKey "${setupVars}" "${1}"
} }
change_setting() { change_setting() {
@ -72,7 +72,7 @@ addFTLsetting() {
} }
deleteFTLsetting() { deleteFTLsetting() {
removeKey "${1}" "${FTLconf}" removeKey "${FTLconf}" "${1}"
} }
changeFTLsetting() { changeFTLsetting() {
@ -84,7 +84,7 @@ add_dnsmasq_setting() {
} }
delete_dnsmasq_setting() { delete_dnsmasq_setting() {
removeKey "${1}" "${dnsmasqconfig}" removeKey "${dnsmasqconfig}" "${1}"
} }
SetTemperatureUnit() { SetTemperatureUnit() {

4
pihole
View File

@ -260,7 +260,7 @@ Options:
exit 0 exit 0
elif [[ "${1}" == "off" ]]; then elif [[ "${1}" == "off" ]]; then
# Disable logging # Disable logging
sed -i 's/^log-queries/#log-queries/' /etc/dnsmasq.d/01-pihole.conf addOrEditKeyValPair /etc/dnsmasq.d/01-pihole.conf "log-queries"
addOrEditKeyValPair "${setupVars}" "QUERY_LOGGING" "false" addOrEditKeyValPair "${setupVars}" "QUERY_LOGGING" "false"
if [[ "${2}" != "noflush" ]]; then if [[ "${2}" != "noflush" ]]; then
# Flush logs # Flush logs
@ -270,7 +270,7 @@ Options:
local str="Logging has been disabled!" local str="Logging has been disabled!"
elif [[ "${1}" == "on" ]]; then elif [[ "${1}" == "on" ]]; then
# Enable logging # Enable logging
sed -i 's/^#log-queries/log-queries/' /etc/dnsmasq.d/01-pihole.conf removeKey /etc/dnsmasq.d/01-pihole.conf "log-queries"
addOrEditKeyValPair "${setupVars}" "QUERY_LOGGING" "true" addOrEditKeyValPair "${setupVars}" "QUERY_LOGGING" "true"
echo -e " ${INFO} Enabling logging..." echo -e " ${INFO} Enabling logging..."
local str="Logging has been enabled!" local str="Logging has been enabled!"

View File

@ -17,13 +17,13 @@ def test_key_val_replacement_works(host):
def test_key_val_removal_works(host): def test_key_val_removal_works(host):
''' Confirms addOrEditKeyValPair provides the expected output ''' ''' Confirms removeKey provides the expected output '''
host.run(''' host.run('''
source /opt/pihole/utils.sh source /opt/pihole/utils.sh
addOrEditKeyValPair "./testoutput" "KEY_ONE" "value1" addOrEditKeyValPair "./testoutput" "KEY_ONE" "value1"
addOrEditKeyValPair "./testoutput" "KEY_TWO" "value2" addOrEditKeyValPair "./testoutput" "KEY_TWO" "value2"
addOrEditKeyValPair "./testoutput" "KEY_THREE" "value3" addOrEditKeyValPair "./testoutput" "KEY_THREE" "value3"
removeKey "KEY_TWO" "./testoutput" removeKey "./testoutput" "KEY_TWO"
''') ''')
output = host.run(''' output = host.run('''
cat ./testoutput cat ./testoutput