Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve PADD version comparison #238

Merged
merged 4 commits into from
Jul 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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...
yubiuser marked this conversation as resolved.
Show resolved Hide resolved
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