From 114f84c948b08693bea934e822c1c4c2956e29b3 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 7 Oct 2017 17:29:47 +0200 Subject: [PATCH 1/3] Add --nuke option to list.sh that can be used e.g. by Teleporter to empty out lists before importing new content Signed-off-by: DL6ER --- advanced/Scripts/list.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh index a3f3261a..98d5c399 100755 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -49,7 +49,8 @@ Options: -nr, --noreload Update ${type}list without refreshing dnsmasq -q, --quiet Make output less verbose -h, --help Show this help dialog - -l, --list Display all your ${type}listed domains" + -l, --list Display all your ${type}listed domains + --nuke Removes all entries in a list" exit 0 } @@ -70,7 +71,7 @@ HandleOther() { validDomain=$(grep -P "^((-|_)*[a-z\d]((-|_)*[a-z\d])*(-|_)*)(\.(-|_)*([a-z\d]((-|_)*[a-z\d])*))*$" <<< "${domain}") # Valid chars check validDomain=$(grep -P "^[^\.]{1,63}(\.[^\.]{1,63})*$" <<< "${validDomain}") # Length of each label fi - + if [[ -n "${validDomain}" ]]; then domList=("${domList[@]}" ${validDomain}) else @@ -223,6 +224,12 @@ Displaylist() { exit 0; } +NukeList() { + if [[ -f "${listMain}" ]]; then + echo "" > "${listMain}" + fi +} + for var in "$@"; do case "${var}" in "-w" | "whitelist" ) listMain="${whitelist}"; listAlt="${blacklist}";; @@ -234,6 +241,7 @@ for var in "$@"; do "-q" | "--quiet" ) verbose=false;; "-h" | "--help" ) helpFunc;; "-l" | "--list" ) Displaylist;; + "--nuke" ) NukeList;; * ) HandleOther "${var}";; esac done From f22b83d379d729cf7c6c21723f2712570d3cbc34 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 7 Oct 2017 17:46:40 +0200 Subject: [PATCH 2/3] Create a backup before emptying the list Signed-off-by: DL6ER --- advanced/Scripts/list.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh index 98d5c399..a8c3a604 100755 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -226,6 +226,9 @@ Displaylist() { NukeList() { if [[ -f "${listMain}" ]]; then + # Back up original list + cp "${listMain}" "${listMain}.bck" + # Empty out file echo "" > "${listMain}" fi } From 70ad656af0eaffb9dce7233e638428aae65be11e Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 7 Oct 2017 22:04:14 +0200 Subject: [PATCH 3/3] Save backup as ".bck~" to prevent reading of the file by dnsmasq Signed-off-by: DL6ER --- advanced/Scripts/list.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh index a8c3a604..9ddfe8f3 100755 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -227,7 +227,7 @@ Displaylist() { NukeList() { if [[ -f "${listMain}" ]]; then # Back up original list - cp "${listMain}" "${listMain}.bck" + cp "${listMain}" "${listMain}.bck~" # Empty out file echo "" > "${listMain}" fi