Skip to content

Commit

Permalink
Merge pull request #238 from pi-hole/tweak_version_control
Browse files Browse the repository at this point in the history
Improve PADD version comparison
  • Loading branch information
yubiuser committed Jul 18, 2022
2 parents d74f60d + e7dab3f commit 14632f1
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions padd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ GetVersionInformation() {
core_version=$(pihole -v -p | awk '{print $4}' | tr -d '[:alpha:]')
core_version_latest=$(pihole -v -p | awk '{print $(NF)}' | tr -d ')')

# if core_version is something else then x.xx set it to N/A
if ! echo "${core_version}" | grep -qE '^[0-9]+([.][0-9]+)?$' || [ "${core_version_latest}" = "ERROR" ]; then
# if core_version is something else then x.xx or x.xx.xxx set it to N/A
if ! echo "${core_version}" | grep -qE '^[0-9]+([.][0-9]+){1,2}$' || [ "${core_version_latest}" = "ERROR" ]; then
core_version="N/A"
core_version_heatmap=${yellow_text}
else
Expand All @@ -495,8 +495,8 @@ GetVersionInformation() {
web_version=$(pihole -v -a | awk '{print $4}' | tr -d '[:alpha:]')
web_version_latest=$(pihole -v -a | awk '{print $(NF)}' | tr -d ')')

# if web_version is something else then x.xx set it to N/A
if ! echo "${web_version}" | grep -qE '^[0-9]+([.][0-9]+)?$' || [ "${web_version_latest}" = "ERROR" ]; then
# if web_version is something else then x.xx or x.xx.xxx set it to N/A
if ! echo "${web_version}" | grep -qE '^[0-9]+([.][0-9]+){1,2}$' || [ "${web_version_latest}" = "ERROR" ]; then
web_version="N/A"
web_version_heatmap=${yellow_text}
else
Expand All @@ -522,8 +522,8 @@ GetVersionInformation() {
ftl_version=$(pihole -v -f | awk '{print $4}' | tr -d '[:alpha:]')
ftl_version_latest=$(pihole -v -f | awk '{print $(NF)}' | tr -d ')')

# if ftl_version is something else then x.xx set it to N/A
if ! echo "${ftl_version}" | grep -qE '^[0-9]+([.][0-9]+)?$' || [ "${ftl_version_latest}" = "ERROR" ]; then
# if ftl_version is something else then x.xx or x.xx.xxx set it to N/A
if ! echo "${ftl_version}" | grep -qE '^[0-9]+([.][0-9]+){1,2}$' || [ "${ftl_version_latest}" = "ERROR" ]; then
ftl_version="N/A"
ftl_version_heatmap=${yellow_text}
else
Expand All @@ -543,17 +543,22 @@ GetVersionInformation() {
# PADD version information...
padd_version_latest="$(curl --silent https://api.github.com/repos/pi-hole/PADD/releases/latest | grep '"tag_name":' | awk -F \" '{print $4}')"
# is PADD up-to-date?
if [ "${padd_version_latest}" = "" ]; then
if [ -z "${padd_version_latest}" ]; then
padd_version_heatmap=${yellow_text}
else
if [ "${padd_version}" != "${padd_version_latest}" ]; then
padd_version_latest_converted="$(VersionConverter "${padd_version_latest}")"
padd_version_converted=$(VersionConverter "${padd_version}")

if [ "${padd_version_converted}" -lt "${padd_version_latest_converted}" ]; then
padd_out_of_date_flag="true"
padd_version_heatmap=${red_text}
else
# local and remote PADD version match or local is newer
padd_version_heatmap=${green_text}
fi
fi


# was any portion of Pi-hole out-of-date?
# yes, pi-hole is out of date
if [ "${out_of_date_flag}" = "true" ]; then
Expand Down Expand Up @@ -992,6 +997,12 @@ CheckConnectivity() {
fi
}

# converts a given version string e.g. v3.7.1 to 3007001000 to allow for easier comparison of multi digit version numbers
# credits https://apple.stackexchange.com/a/123408
VersionConverter() {
echo "$@" | tr -d '[:alpha:]' | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }';
}

########################################## MAIN FUNCTIONS ##########################################

OutputJSON() {
Expand Down

0 comments on commit 14632f1

Please sign in to comment.