mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-12-26 14:50:17 +00:00
Remove no-longer-needed utils (#5826)
This commit is contained in:
commit
eb4b6ecf25
2 changed files with 0 additions and 102 deletions
|
@ -25,7 +25,6 @@
|
||||||
#
|
#
|
||||||
# Example usage:
|
# Example usage:
|
||||||
# addOrEditKeyValPair "/etc/pihole/setupVars.conf" "BLOCKING_ENABLED" "true"
|
# addOrEditKeyValPair "/etc/pihole/setupVars.conf" "BLOCKING_ENABLED" "true"
|
||||||
# TODO: We miight not actually need this function in v6
|
|
||||||
#######################
|
#######################
|
||||||
addOrEditKeyValPair() {
|
addOrEditKeyValPair() {
|
||||||
local file="${1}"
|
local file="${1}"
|
||||||
|
@ -44,43 +43,6 @@ addOrEditKeyValPair() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
#######################
|
|
||||||
# Takes two arguments: file, and key.
|
|
||||||
# Adds a key to target file
|
|
||||||
#
|
|
||||||
# Example usage:
|
|
||||||
# addKey "/etc/dnsmasq.d/01-pihole.conf" "log-queries"
|
|
||||||
#######################
|
|
||||||
addKey(){
|
|
||||||
local file="${1}"
|
|
||||||
local key="${2}"
|
|
||||||
|
|
||||||
# touch file to prevent grep error if file does not exist yet
|
|
||||||
touch "${file}"
|
|
||||||
|
|
||||||
# Match key against entire line, using both anchors. We assume
|
|
||||||
# that the file's keys never have bounding whitespace. Anchors
|
|
||||||
# are necessary to ensure the key is considered absent when it
|
|
||||||
# is a substring of another key present in the file.
|
|
||||||
if ! grep -q "^${key}$" "${file}"; then
|
|
||||||
# Key does not exist, add it.
|
|
||||||
echo "${key}" >> "${file}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
#######################
|
|
||||||
# Takes two arguments: file, and key.
|
|
||||||
# Deletes a key or key/value pair from target file
|
|
||||||
#
|
|
||||||
# Example usage:
|
|
||||||
# removeKey "/etc/pihole/setupVars.conf" "PIHOLE_DNS_1"
|
|
||||||
#######################
|
|
||||||
removeKey() {
|
|
||||||
local file="${1}"
|
|
||||||
local key="${2}"
|
|
||||||
sed -i "/^${key}/d" "${file}"
|
|
||||||
}
|
|
||||||
|
|
||||||
#######################
|
#######################
|
||||||
# returns FTL's PID based on the content of the pihole-FTL.pid file
|
# returns FTL's PID based on the content of the pihole-FTL.pid file
|
||||||
#
|
#
|
||||||
|
|
|
@ -18,70 +18,6 @@ def test_key_val_replacement_works(host):
|
||||||
assert expected_stdout == output.stdout
|
assert expected_stdout == output.stdout
|
||||||
|
|
||||||
|
|
||||||
def test_key_addition_works(host):
|
|
||||||
"""Confirms addKey adds a key (no value) to a file without duplicating it"""
|
|
||||||
host.run(
|
|
||||||
"""
|
|
||||||
source /opt/pihole/utils.sh
|
|
||||||
addKey "./testoutput" "KEY_ONE"
|
|
||||||
addKey "./testoutput" "KEY_ONE"
|
|
||||||
addKey "./testoutput" "KEY_TWO"
|
|
||||||
addKey "./testoutput" "KEY_TWO"
|
|
||||||
addKey "./testoutput" "KEY_THREE"
|
|
||||||
addKey "./testoutput" "KEY_THREE"
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
output = host.run(
|
|
||||||
"""
|
|
||||||
cat ./testoutput
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
expected_stdout = "KEY_ONE\nKEY_TWO\nKEY_THREE\n"
|
|
||||||
assert expected_stdout == output.stdout
|
|
||||||
|
|
||||||
|
|
||||||
def test_key_addition_substr(host):
|
|
||||||
"""Confirms addKey adds substring keys (no value) to a file"""
|
|
||||||
host.run(
|
|
||||||
"""
|
|
||||||
source /opt/pihole/utils.sh
|
|
||||||
addKey "./testoutput" "KEY_ONE"
|
|
||||||
addKey "./testoutput" "KEY_O"
|
|
||||||
addKey "./testoutput" "KEY_TWO"
|
|
||||||
addKey "./testoutput" "Y_TWO"
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
output = host.run(
|
|
||||||
"""
|
|
||||||
cat ./testoutput
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
expected_stdout = "KEY_ONE\nKEY_O\nKEY_TWO\nY_TWO\n"
|
|
||||||
assert expected_stdout == output.stdout
|
|
||||||
|
|
||||||
|
|
||||||
def test_key_removal_works(host):
|
|
||||||
"""Confirms removeKey removes a key or key/value pair"""
|
|
||||||
host.run(
|
|
||||||
"""
|
|
||||||
source /opt/pihole/utils.sh
|
|
||||||
addOrEditKeyValPair "./testoutput" "KEY_ONE" "value1"
|
|
||||||
addOrEditKeyValPair "./testoutput" "KEY_TWO" "value2"
|
|
||||||
addOrEditKeyValPair "./testoutput" "KEY_THREE" "value3"
|
|
||||||
addKey "./testoutput" "KEY_FOUR"
|
|
||||||
removeKey "./testoutput" "KEY_TWO"
|
|
||||||
removeKey "./testoutput" "KEY_FOUR"
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
output = host.run(
|
|
||||||
"""
|
|
||||||
cat ./testoutput
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
expected_stdout = "KEY_ONE=value1\nKEY_THREE=value3\n"
|
|
||||||
assert expected_stdout == output.stdout
|
|
||||||
|
|
||||||
|
|
||||||
def test_getFTLPID_default(host):
|
def test_getFTLPID_default(host):
|
||||||
"""Confirms getFTLPID returns the default value if FTL is not running"""
|
"""Confirms getFTLPID returns the default value if FTL is not running"""
|
||||||
output = host.run(
|
output = host.run(
|
||||||
|
|
Loading…
Reference in a new issue