From 3b229489c2f4aca05637eef674d5e8c116dbf373 Mon Sep 17 00:00:00 2001 From: Ludovic Rousseau Date: Fri, 13 Apr 2018 09:19:31 +0200 Subject: [PATCH 1/4] Fix regex to find DBFILE= from configuration file The regex ^\s^.DBFILE\s*=\s* does not work to match "DBFILE=" I don't know what the second '^' is used for. With the change I now have the results: DBFILE=/foo/bar -> /foo/bar DBFILE=/foo/bar -> /foo/bar # DBFILE=/foo/bar -> /etc/pihole/pihole-FTL.db xDBFILE=/foo/bar -> /etc/pihole/pihole-FTL.db Signed-off-by: Ludovic Rousseau --- advanced/Scripts/piholeLogFlush.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeLogFlush.sh b/advanced/Scripts/piholeLogFlush.sh index 5fd9832e..ffc9e0f5 100755 --- a/advanced/Scripts/piholeLogFlush.sh +++ b/advanced/Scripts/piholeLogFlush.sh @@ -16,7 +16,7 @@ source ${colfile} # Constructed to return nothing when # a) the setting is not present in the config file, or # b) the setting is commented out (e.g. "#DBFILE=...") -DBFILE="$(sed -n -e 's/^\s^.DBFILE\s*=\s*//p' /etc/pihole/pihole-FTL.conf)" +DBFILE="$(sed -n -e 's/^\s*DBFILE\s*=\s*//p' /etc/pihole/pihole-FTL.conf)" # Test for empty string. Use standard path in this case. if [ -z "$DBFILE" ]; then DBFILE="/etc/pihole/pihole-FTL.db" From d8f85a898130453e4f4ee9f0924d33c3c450dfbc Mon Sep 17 00:00:00 2001 From: Ludovic Rousseau Date: Fri, 13 Apr 2018 11:08:02 +0200 Subject: [PATCH 2/4] Avoid a "No such file or directory" error Check the file /etc/pihole/pihole-FTL.conf exists before trying to use it. without the patch I get, each day, in my logs: sed: can't read /etc/pihole/pihole-FTL.conf: No such file or directory I use a variable FTLconf to not repeat the file name twice. Signed-off-by: Ludovic Rousseau --- advanced/Scripts/piholeLogFlush.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeLogFlush.sh b/advanced/Scripts/piholeLogFlush.sh index ffc9e0f5..9777b613 100755 --- a/advanced/Scripts/piholeLogFlush.sh +++ b/advanced/Scripts/piholeLogFlush.sh @@ -16,7 +16,8 @@ source ${colfile} # Constructed to return nothing when # a) the setting is not present in the config file, or # b) the setting is commented out (e.g. "#DBFILE=...") -DBFILE="$(sed -n -e 's/^\s*DBFILE\s*=\s*//p' /etc/pihole/pihole-FTL.conf)" +FTLconf="/etc/pihole/pihole-FTL.conf" +[ -e "$FTLconf" ] && DBFILE="$(sed -n -e 's/^\s*DBFILE\s*=\s*//p' $FTLconf)" # Test for empty string. Use standard path in this case. if [ -z "$DBFILE" ]; then DBFILE="/etc/pihole/pihole-FTL.db" From 9b3531f634ba59e0d71b25e2ceda1abbf291acf8 Mon Sep 17 00:00:00 2001 From: Ludovic Rousseau Date: Fri, 13 Apr 2018 11:48:34 +0200 Subject: [PATCH 3/4] Fix stylistic issue Expand variable using ${FTLconf} Signed-off-by: Ludovic Rousseau --- advanced/Scripts/piholeLogFlush.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeLogFlush.sh b/advanced/Scripts/piholeLogFlush.sh index 9777b613..be2ca20d 100755 --- a/advanced/Scripts/piholeLogFlush.sh +++ b/advanced/Scripts/piholeLogFlush.sh @@ -17,7 +17,7 @@ source ${colfile} # a) the setting is not present in the config file, or # b) the setting is commented out (e.g. "#DBFILE=...") FTLconf="/etc/pihole/pihole-FTL.conf" -[ -e "$FTLconf" ] && DBFILE="$(sed -n -e 's/^\s*DBFILE\s*=\s*//p' $FTLconf)" +[ -e "$FTLconf" ] && DBFILE="$(sed -n -e 's/^\s*DBFILE\s*=\s*//p' ${FTLconf})" # Test for empty string. Use standard path in this case. if [ -z "$DBFILE" ]; then DBFILE="/etc/pihole/pihole-FTL.db" From 7edab27e53fbe005c542d996bb40a2a54505f5fb Mon Sep 17 00:00:00 2001 From: Ludovic Rousseau Date: Fri, 13 Apr 2018 12:19:55 +0200 Subject: [PATCH 4/4] Stylistic change to use an explicit if/then/fi Signed-off-by: Ludovic Rousseau --- advanced/Scripts/piholeLogFlush.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeLogFlush.sh b/advanced/Scripts/piholeLogFlush.sh index be2ca20d..44af77a6 100755 --- a/advanced/Scripts/piholeLogFlush.sh +++ b/advanced/Scripts/piholeLogFlush.sh @@ -17,7 +17,9 @@ source ${colfile} # a) the setting is not present in the config file, or # b) the setting is commented out (e.g. "#DBFILE=...") FTLconf="/etc/pihole/pihole-FTL.conf" -[ -e "$FTLconf" ] && DBFILE="$(sed -n -e 's/^\s*DBFILE\s*=\s*//p' ${FTLconf})" +if [ -e "$FTLconf" ]; then + DBFILE="$(sed -n -e 's/^\s*DBFILE\s*=\s*//p' ${FTLconf})" +fi # Test for empty string. Use standard path in this case. if [ -z "$DBFILE" ]; then DBFILE="/etc/pihole/pihole-FTL.db"