Skip to content

Commit

Permalink
Merge pull request #27 from Andr3Carvalh0/feature/version
Browse files Browse the repository at this point in the history
Adds 'v' flag to display the currents tool version
  • Loading branch information
yubiuser authored May 16, 2021
2 parents aa55d24 + 84e72b1 commit 3be034f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This script tries to provide you with a bunch of information that enables you to
---
**The script outputs**

- the number of adlists (and how many are enabled)
- the number of adlists (and how many are enabled)
- the number of unique domains in your gravity.db
- the number of blocked domains as reported by pihole ('blocking status == blocked by gravity' or blocking status == blocked by gravity+blocked during CNAME inspection) and how often those domains have been blocked ('hits')
- the number of covered domains and how often those would have been blocked ('hits')
Expand Down Expand Up @@ -63,8 +63,9 @@ options:
-t [Num] Show top blocked domains. [Num] defines the number to show.
-s [total/domains/hits/unique] Set sorting order to total domains, domains covered, hits covered or unique covered domains DESC. (Default sorting: id ASC)
-u Show covered unique domains
-a Run in 'automatic mode'. No user input is requiered at all, assuming default choice would be to leave everything untouched.
-a Run in 'automatic mode'. No user input is required at all, assuming default choice would be to leave everything untouched.
-r Analyse regex as well. Depending on the amount of domains and regex this might take a while.
-v Display pihole_adlist_tool's version.
-h Show this help dialog
```
Expand Down
31 changes: 29 additions & 2 deletions pihole_adlist_tool
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
PIHOLE_ADLIST_TOOL_VERSION="2.5.0"

# define path to pihole's databases and temporary database
TEMP_DB="/tmp/temp.db"
Expand Down Expand Up @@ -75,6 +76,22 @@ declare -a all_domains
CURRENT_DOMAIN=
REGEX_ID=

# version message
print_version() {
echo "Pihole Adlist Tool v${PIHOLE_ADLIST_TOOL_VERSION}"
}

# fetches latest version
fetch_remote_version() {
local remote_version="$(
curl --silent https://api.github.com/repos/yubiuser/pihole_adlist_tool/releases/latest |
grep '"tag_name":' |
awk -F \" '{print $4}'
)"
# returns the latest version tag(eg: 2.4.0).
echo "$remote_version"
}

# help message
print_help() {
echo
Expand All @@ -94,6 +111,8 @@ print_help() {
to leave everything untouched.
-r Analyse regex as well. Depending on the amount of domains and regex this might take a while.
-v Display pihole_adlist_tool's version.
-h Show this help dialog.
"
Expand Down Expand Up @@ -194,14 +213,16 @@ SUDO_SQLITE=$(declare -f sqlite)
trap cleanup_on_trap INT

# getopts flags and assing arguments to variables
while getopts 'd:t:s:uarh' flag; do
while getopts 'd:t:s:uarvh' flag; do
case "${flag}" in
d) DAYS_REQUESTED="${OPTARG}" ;;
t) TOP="${OPTARG}" ;;
s) SORT="${OPTARG}" ;;
u) UNIQUE=1 ;;
a) AUTOMATIC_MODE=1 ;;
r) REGEX_MODE=1 ;;
v) print_version
exit 0 ;;
h) print_help
exit 0 ;;
*) print_help
Expand Down Expand Up @@ -333,6 +354,12 @@ if [ "$REGEX_MODE" -eq 1 ];
echo -e " [i] REGEX_MODE: Disabled"
fi

# verify if there is an update available
remote_version=$(fetch_remote_version)
if [ -n "$remote_version" -a "$remote_version" != "$PIHOLE_ADLIST_TOOL_VERSION" ]; then
echo -e " [i] There is an update available: $remote_version"
fi

echo -e "\n ++++++++++++++++++++++\n\n"
}

Expand All @@ -343,7 +370,7 @@ echo -e "\n ++++++++++++++++++++++\n\n"

echo
echo
echo " ${bold}*** Pihole Adlist Tool ***${normal}"
echo " ${bold}*** Pihole Adlist Tool $PIHOLE_ADLIST_TOOL_VERSION ***${normal}"
echo

warm_up
Expand Down

0 comments on commit 3be034f

Please sign in to comment.