From 4c853defb25d9e51b82ed8aa9fdbf9d9834dea2d Mon Sep 17 00:00:00 2001 From: Promofaux Date: Tue, 25 Oct 2016 22:27:35 +0100 Subject: [PATCH] add if traps to check for existence of whitelist.txt / blacklist.txt --- gravity.sh | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/gravity.sh b/gravity.sh index 03aafabb..f524e587 100755 --- a/gravity.sh +++ b/gravity.sh @@ -187,12 +187,16 @@ gravity_Schwarzchild() { gravity_Blacklist() { # Append blacklist entries if they exist - numBlacklisted=$(wc -l < "${blacklistFile}") - plural=; [[ "$numBlacklisted" != "1" ]] && plural=s + if [[ -f "${blacklistFile}" ]]; then + numBlacklisted=$(wc -l < "${blacklistFile}") + plural=; [[ "$numBlacklisted" != "1" ]] && plural=s + echo -n "::: BlackListing $numBlacklisted domain${plural}..." + cat ${blacklistFile} >> ${piholeDir}/${eventHorizon} + echo " done!" + else + echo "::: Nothing to blacklist!" + fi - echo -n "::: BlackListing $numBlacklisted domain${plural}..." - cat ${blacklistFile} >> ${piholeDir}/${eventHorizon} - echo " done!" } gravity_Whitelist() { @@ -209,15 +213,19 @@ gravity_Whitelist() { done echo " done!" - # Ensure adlist domains are in whitelist.txt + # Ensure adlist domains are in whitelist.txt ${whitelistScript} -nr -q "${urls[@]}" > /dev/null - # Remove anything in whitelist.txt from the Event Horizon - numWhitelisted=$(wc -l < "${whitelistFile}") - plural=; [[ "$numWhitelisted" != "1" ]] && plural=s - echo -n "::: Whitelisting $numWhitelisted domain${plural}..." - grep -F -x -v -f ${whitelistFile} ${piholeDir}/${preEventHorizon} > ${piholeDir}/${eventHorizon} - echo " done!" + if [[ -f "${whitelistFile}" ]]; then + # Remove anything in whitelist.txt from the Event Horizon + numWhitelisted=$(wc -l < "${whitelistFile}") + plural=; [[ "$numWhitelisted" != "1" ]] && plural=s + echo -n "::: Whitelisting $numWhitelisted domain${plural}..." + grep -F -x -v -f ${whitelistFile} ${piholeDir}/${preEventHorizon} > ${piholeDir}/${eventHorizon} + echo " done!" + else + echo "::: Nothing to whitelist!" + fi } gravity_unique() {