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 <dl6er@dl6er.de>
This commit is contained in:
DL6ER 2017-10-07 17:29:47 +02:00
parent 7875df0d6b
commit 114f84c948
No known key found for this signature in database
GPG key ID: 00135ACBD90B28DD

View file

@ -49,7 +49,8 @@ Options:
-nr, --noreload Update ${type}list without refreshing dnsmasq -nr, --noreload Update ${type}list without refreshing dnsmasq
-q, --quiet Make output less verbose -q, --quiet Make output less verbose
-h, --help Show this help dialog -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 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 "^((-|_)*[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 validDomain=$(grep -P "^[^\.]{1,63}(\.[^\.]{1,63})*$" <<< "${validDomain}") # Length of each label
fi fi
if [[ -n "${validDomain}" ]]; then if [[ -n "${validDomain}" ]]; then
domList=("${domList[@]}" ${validDomain}) domList=("${domList[@]}" ${validDomain})
else else
@ -223,6 +224,12 @@ Displaylist() {
exit 0; exit 0;
} }
NukeList() {
if [[ -f "${listMain}" ]]; then
echo "" > "${listMain}"
fi
}
for var in "$@"; do for var in "$@"; do
case "${var}" in case "${var}" in
"-w" | "whitelist" ) listMain="${whitelist}"; listAlt="${blacklist}";; "-w" | "whitelist" ) listMain="${whitelist}"; listAlt="${blacklist}";;
@ -234,6 +241,7 @@ for var in "$@"; do
"-q" | "--quiet" ) verbose=false;; "-q" | "--quiet" ) verbose=false;;
"-h" | "--help" ) helpFunc;; "-h" | "--help" ) helpFunc;;
"-l" | "--list" ) Displaylist;; "-l" | "--list" ) Displaylist;;
"--nuke" ) NukeList;;
* ) HandleOther "${var}";; * ) HandleOther "${var}";;
esac esac
done done