mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 02:42:58 +00:00
Touch files before addKey or addOrEditKeyValPair
Signed-off-by: Christian König <ckoenig@posteo.de>
This commit is contained in:
parent
2fd5b944ad
commit
67385b7ed4
2 changed files with 6 additions and 3 deletions
|
@ -31,6 +31,9 @@ addOrEditKeyValPair() {
|
||||||
local key="${2}"
|
local key="${2}"
|
||||||
local value="${3}"
|
local value="${3}"
|
||||||
|
|
||||||
|
# touch file to prevent grep error if file does not exist yet
|
||||||
|
touch "${file}"
|
||||||
|
|
||||||
if grep -q "^${key}=" "${file}"; then
|
if grep -q "^${key}=" "${file}"; then
|
||||||
# Key already exists in file, modify the value
|
# Key already exists in file, modify the value
|
||||||
sed -i "/^${key}=/c\\${key}=${value}" "${file}"
|
sed -i "/^${key}=/c\\${key}=${value}" "${file}"
|
||||||
|
@ -51,6 +54,9 @@ addKey(){
|
||||||
local file="${1}"
|
local file="${1}"
|
||||||
local key="${2}"
|
local key="${2}"
|
||||||
|
|
||||||
|
# touch file to prevent grep error if file does not exist yet
|
||||||
|
touch "${file}"
|
||||||
|
|
||||||
if ! grep -q "^${key}" "${file}"; then
|
if ! grep -q "^${key}" "${file}"; then
|
||||||
# Key does not exist, add it.
|
# Key does not exist, add it.
|
||||||
echo "${key}" >> "${file}"
|
echo "${key}" >> "${file}"
|
||||||
|
|
|
@ -1785,9 +1785,6 @@ create_pihole_user() {
|
||||||
finalExports() {
|
finalExports() {
|
||||||
# set or update the variables in the file
|
# set or update the variables in the file
|
||||||
|
|
||||||
# create the file if it does not exist
|
|
||||||
touch "${setupVars}"
|
|
||||||
|
|
||||||
addOrEditKeyValPair "${setupVars}" "PIHOLE_INTERFACE" "${PIHOLE_INTERFACE}"
|
addOrEditKeyValPair "${setupVars}" "PIHOLE_INTERFACE" "${PIHOLE_INTERFACE}"
|
||||||
addOrEditKeyValPair "${setupVars}" "PIHOLE_DNS_1" "${PIHOLE_DNS_1}"
|
addOrEditKeyValPair "${setupVars}" "PIHOLE_DNS_1" "${PIHOLE_DNS_1}"
|
||||||
addOrEditKeyValPair "${setupVars}" "PIHOLE_DNS_2" "${PIHOLE_DNS_2}"
|
addOrEditKeyValPair "${setupVars}" "PIHOLE_DNS_2" "${PIHOLE_DNS_2}"
|
||||||
|
|
Loading…
Reference in a new issue