mirror of
https://github.com/pi-hole/pi-hole.git
synced 2025-04-23 07:40:15 +00:00
Proof of concept usage of a utility script file for splitting out some commonly used code into an easily sourceable file
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
parent
1dd9d55d82
commit
bdc101ab09
15 changed files with 58 additions and 25 deletions
23
advanced/Scripts/utils.sh
Executable file
23
advanced/Scripts/utils.sh
Executable file
|
@ -0,0 +1,23 @@
|
|||
# Basic Housekeeping rules
|
||||
# - Functions must be self contained
|
||||
# - Functions must be added in alphabetical order
|
||||
|
||||
#######################
|
||||
# Takes three arguments key, value, and file.
|
||||
# Checks the target file for the existence of the key
|
||||
# - If it exists, it changes the value
|
||||
# - If it does not exist, it adds the value
|
||||
#
|
||||
# Example usage:
|
||||
# addOrEditKeyValuePair "BLOCKING_ENABLED" "true" "/etc/pihole/setupVars.conf"
|
||||
#######################
|
||||
addOrEditKeyValPair() {
|
||||
local key="${1}"
|
||||
local value="${2}"
|
||||
local file="${3}"
|
||||
if grep -q "^${key}=" "${file}"; then
|
||||
sed -i "/^${key}=/c\\${key}=${value}" "${file}"
|
||||
else
|
||||
echo "${key}=${value}" >> "${file}"
|
||||
fi
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue