From 2fd5b944ad4294d7894ff93a23f18db6baa12e2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 3 Nov 2022 22:01:37 +0100 Subject: [PATCH 1/2] Touch setupVars before writing to it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- automated install/basic-install.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 8edd4936..ea7052f3 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1785,6 +1785,9 @@ create_pihole_user() { finalExports() { # 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_DNS_1" "${PIHOLE_DNS_1}" addOrEditKeyValPair "${setupVars}" "PIHOLE_DNS_2" "${PIHOLE_DNS_2}" From 67385b7ed43a2c68bc851b3329c72c838849beea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 9 Nov 2022 21:25:09 +0100 Subject: [PATCH 2/2] Touch files before addKey or addOrEditKeyValPair MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/utils.sh | 6 ++++++ automated install/basic-install.sh | 3 --- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/utils.sh b/advanced/Scripts/utils.sh index 1174fa62..37516472 100755 --- a/advanced/Scripts/utils.sh +++ b/advanced/Scripts/utils.sh @@ -31,6 +31,9 @@ addOrEditKeyValPair() { local key="${2}" local value="${3}" + # touch file to prevent grep error if file does not exist yet + touch "${file}" + if grep -q "^${key}=" "${file}"; then # Key already exists in file, modify the value sed -i "/^${key}=/c\\${key}=${value}" "${file}" @@ -51,6 +54,9 @@ addKey(){ local file="${1}" local key="${2}" + # touch file to prevent grep error if file does not exist yet + touch "${file}" + if ! grep -q "^${key}" "${file}"; then # Key does not exist, add it. echo "${key}" >> "${file}" diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index ea7052f3..8edd4936 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1785,9 +1785,6 @@ create_pihole_user() { finalExports() { # 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_DNS_1" "${PIHOLE_DNS_1}" addOrEditKeyValPair "${setupVars}" "PIHOLE_DNS_2" "${PIHOLE_DNS_2}"