Skip to content

Commit

Permalink
Better Version Checking and Splash Screen
Browse files Browse the repository at this point in the history
Major
- Added 'tr -d' to strip out letters from version numbers for version
comparisons
- Changed GetPiholeVersionInformation function to GetVersionInformation
- Added in version check for Chronometer2 version
- Added "splash screen" when Chronometer2 starts

Minor
- Cleaned up some printf/echo set (shellchecked)
- Cleaned up some quoting in string variables
- Updated logo (smaller, includes Chronometer2 version)
- Added latest blocked domain to stats section
  • Loading branch information
jpmck committed Jun 17, 2017
1 parent 0e2c5ce commit 6e07920
Showing 1 changed file with 92 additions and 42 deletions.
134 changes: 92 additions & 42 deletions chronometer2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
# Addresses Issue 5: https://github.com/jpmck/chronometer2/issues/5 ... I think...
export LC_ALL=C.UTF-8

chronometer2Version="v1.1.0"

# SOURCES
piLog="/var/log/pihole.log"
gravity="/etc/pihole/gravity.list"
chronometer2Version="1.2.0"

# COLORS
blueColor=$(tput setaf 6)
greenColor=$(tput setaf 2)
magentaColor=$(tput setaf 5)
redColor=$(tput setaf 1)
resetColor=$(tput setaf 7)
yellowColor=$(tput setaf 3)
Expand Down Expand Up @@ -68,12 +65,12 @@ GetSystemInformation() {

# Convert CPU temperature to correct unit
if [ "${TEMPERATUREUNIT}" == "F" ]; then
temperature=$(printf %.1f $(echo "scale=4; ${cpu}*9/5000+32" | bc))°F
temperature=$(printf %.1f "$(echo "scale=4; ${cpu}*9/5000+32" | bc)")°F
elif [ "${TEMPERATUREUNIT}" == "K" ]; then
temperature=$(printf %.1f $(echo "scale=4; (${cpu}/1000+273.15)" | bc))°K
temperature=$(printf %.1f "$(echo "scale=4; (${cpu}/1000+273.15)" | bc)")°K
# Addresses Issue 1: https://github.com/jpmck/chronometer2/issues/1
else
temperature=$(printf %.1f $(echo "scale=4; ${cpu}/1000" | bc))°C
temperature=$(printf %.1f "$(echo "scale=4; ${cpu}/1000" | bc)")°C
fi

# CPU load and heatmap calculations
Expand All @@ -86,7 +83,7 @@ GetSystemInformation() {
cpuLoad15=$(cat /proc/loadavg | awk '{print $3}')
cpuLoad15Heatmap=$(CPUHeatmapGenerator ${cpuLoad15} ${numProc})

cpuPercent=$(printf %.1f $(echo "scale=4; (${cpuLoad1}/${numProc})*100" | bc))
cpuPercent=$(printf %.1f "$(echo "scale=4; (${cpuLoad1}/${numProc})*100" | bc)")

# Memory use
memoryUsedPercent=$(free | awk '/Mem/ {printf "%.1f",($2-$4-$6-$7)/$2 * 100}')
Expand Down Expand Up @@ -118,7 +115,7 @@ GetNetworkInformation() {
# Is Pi-Hole acting as the DHCP server?
if [[ "${DHCP_ACTIVE}" == "true" ]]; then
dhcpStatus="Enabled"
dhcpInfo=" Range: "${DHCP_START}" - "${DHCP_END}
dhcpInfo=" Range: ${DHCP_START} - ${DHCP_END}"
dhcpHeatmap=${greenColor}

# Is DHCP handling IPv6?
Expand All @@ -138,7 +135,7 @@ GetNetworkInformation() {
DHCP_ROUTER=$(/sbin/ip route | awk '/default/ { print $3 }')
fi

dhcpInfo=" Router: "${DHCP_ROUTER}
dhcpInfo=" Router: ${DHCP_ROUTER}"
dhcpHeatmap=${redColor}

dhcpIPv6Status="N/A"
Expand Down Expand Up @@ -183,7 +180,7 @@ GetPiholeInformation() {
fi
}

GetPiholeVersionInformation() {
GetVersionInformation() {
# Check if version status has been saved
if [ -e "piHoleVersion" ]; then
# the file exits, use it
Expand All @@ -198,9 +195,10 @@ GetPiholeVersionInformation() {

# what are the latest available versions?
# TODO: update if necessary if added to pihole
piholeVersionLatest=$(pihole -v -p -l)
webVersionLatest=$(pihole -v -a -l)
ftlVersionLatest=$(curl -sI https://github.com/pi-hole/FTL/releases/latest | grep 'Location' | awk -F '/' '{print $NF}' | tr -d '\r\n')
piholeVersionLatest=$(pihole -v -p -l | tr -d "[:alpha:]")
webVersionLatest=$(pihole -v -a -l | tr -d "[:alpha:]")
ftlVersionLatest=$(curl -sI https://github.com/pi-hole/FTL/releases/latest | grep 'Location' | awk -F '/' '{print $NF}' | tr -d '\r\n[:alpha:]')
chronometer2VersionLatest=$(curl -sI https://github.com/jpmck/chronometer2/releases/latest | grep 'Location' | awk -F '/' '{print $NF}' | tr -d '\r\n[:alpha:]')

# check if everything is up-to-date...
# is core up-to-date?
Expand All @@ -227,15 +225,33 @@ GetPiholeVersionInformation() {
ftlVersionHeatmap=${resetColor}
fi

# was anything out-of-date?
# is chronometer2 up-to-date?
if [[ "${chronometer2Version}" != "${chronometer2VersionLatest}" ]]; then
chronometer2OutOfDateFlag="true"
chronometer2VersionHeatmap=${redColor}
else
chronometer2VersionHeatmap=${resetColor}
fi

# was any portion of Pi-hole out-of-date?
# yes, pi-hole is out of date
if [[ "${outOfDateFlag}" == "true" ]]; then
versionStatus="Pi-hole is out-of-date!"
versionHeatmap=${redColor}
else
versionStatus="Pi-hole is up-to-date!"
versionHeatmap=${greenColor}
# but is chronometer2 out-of-date?
if [[ "${chronometer2OutOfDateFlag}" == "true" ]]; then
versionStatus="Chronometer2 is out-of-date!"
versionHeatmap=${redColor}
# else, everything is good!
else
versionStatus="Pi-hole is up-to-date!"
versionHeatmap=${greenColor}
fi
fi



# write it all to the file
echo "lastCheck="${today} > ./piHoleVersion

Expand All @@ -248,6 +264,9 @@ GetPiholeVersionInformation() {
echo "ftlVersion="$ftlVersion >> ./piHoleVersion
echo "ftlVersionHeatmap="$ftlVersionHeatmap >> ./piHoleVersion

echo "chronometer2Version="$chronometer2Version >> ./piHoleVersion
echo "chronometer2VersionHeatmap="$chronometer2VersionHeatmap >> ./piHoleVersion

echo "versionStatus="\"$versionStatus\" >> ./piHoleVersion
echo "versionHeatmap="$versionHeatmap >> ./piHoleVersion

Expand All @@ -256,14 +275,15 @@ GetPiholeVersionInformation() {
# else the file dosn't exist
else
# We're using...
piholeVersion=$(pihole -v -p -c)
webVersion=$(pihole -v -a -c)
ftlVersion=$(/usr/bin/pihole-FTL version)
piholeVersion=$(pihole -v -p -c | tr -d "[:alpha:]")
webVersion=$(pihole -v -a -c | tr -d "[:alpha:]")
ftlVersion=$(/usr/bin/pihole-FTL version | tr -d "[:alpha:]")

echo "lastCheck=0" > ./piHoleVersion
echo "piholeVersion="$piholeVersion >> ./piHoleVersion
echo "webVersion="$webVersion >> ./piHoleVersion
echo "ftlVersion="$ftlVersion >> ./piHoleVersion
echo "chronometer2Version="$chronometer2Version >> ./piHoleVersion

# there's a file now
# will check on next display
Expand All @@ -277,22 +297,22 @@ outputDHCPInformation() {
}

outputJSON() {
# CalcQueriesToday
# CalcblockedToday
# CalcPercentBlockedToday
# CalcBlockedDomains
#
# printf '{"domains_being_blocked":"%s","dns_queries_today":"%s","ads_blocked_today":"%s","ads_percentage_today":"%s"}\n' "$blockedDomainsTotal" "$queriesToday" "$blockedToday" "$percentBlockedToday"

GetSummaryInformatioon
echo "{\"domains_being_blocked\":${domains_being_blocked_raw},\"dns_queries_today\":${dns_queries_today_raw},\"ads_blocked_today\":${ads_blocked_today_raw},\"ads_percentage_today\":${ads_percentage_today_raw}}"
}

outputLogo() {
echo " ___ _ _ _"
echo -e "| _ (_)___| |_ ___| |___ ${versionHeatmap}${versionStatus}"
echo "| _/ |___| ' \/ _ \ / -_)${resetColor} Pi-hole Core ${piholeVersionHeatmap}${piholeVersion}${resetColor}"
echo "|_| |_| |_||_\___/_\___|${resetColor} (Web ${webVersionHeatmap}${webVersion}${resetColor}, FTL ${ftlVersionHeatmap}${ftlVersion}${resetColor})"
echo -e "${redColor}.${yellowColor}-${greenColor}.${blueColor}. ${greenColor}. ${magentaColor}. ${versionHeatmap}${versionStatus}${resetColor}"

echo -e "${yellowColor}|${greenColor}-${blueColor}'${magentaColor}. ${yellowColor}- ${blueColor}|${magentaColor}-${redColor}. ${greenColor}.${blueColor}-${magentaColor}.${redColor}| ${greenColor}.${blueColor}-${magentaColor}, ${resetColor}Pi-hole ${piholeVersionHeatmap}v${piholeVersion}${resetColor}, Web ${webVersionHeatmap}v${webVersion}${resetColor}, FTL ${ftlVersionHeatmap}v${ftlVersion}${resetColor}"

echo -e "${greenColor}' ${redColor}' ${magentaColor}' ${yellowColor}'${greenColor}-${blueColor}\`${magentaColor}-${redColor}'${yellowColor}'${greenColor}-${blueColor}\`${magentaColor}'${redColor}- ${resetColor}Chronometer2 ${chronometer2VersionHeatmap}v${chronometer2Version}${resetColor}"


# echo " ___ _ _ _"
# echo -e "| _ (_)___| |_ ___| |___ ${versionHeatmap}${versionStatus}"
# echo "| _/ |___| ' \/ _ \ / -_)${resetColor} Pi-hole Core ${piholeVersionHeatmap}v${piholeVersion}${resetColor}"
# echo "|_| |_| |_||_\___/_\___|${resetColor} (Web ${webVersionHeatmap}v${webVersion}${resetColor}, FTL ${ftlVersionHeatmap}v${ftlVersion}${resetColor})"
echo ""
}

Expand All @@ -313,7 +333,7 @@ outputPiholeStats() {
echo "STATS ======================================================"
printf " %-10s%0.0f\n" "Blocking:" "${domains_being_blocked}"
printf " %-10s%-19s%-10s%-19s\n" "Queries:" "${dns_queries_today}" "Pi-holed:" "${ads_blocked_today} (${ads_percentage_today}%)"
# printf " %-10s%-19s%-10s%-19s\n" "DNS 1:" "${PIHOLE_DNS_1}" "DNS 2:" "${PIHOLE_DNS_2}"
printf " %-10s%-39s\n" "Latest:" "${domain}"
}

outputSystemInformation() {
Expand All @@ -322,7 +342,7 @@ outputSystemInformation() {
printf " %-10s%-19s\n" "Uptime:" "${systemUptime}"
printf " %-10s${tempHeatMap}%-19s${resetColor}" "CPU Temp:" "${temperature}"
printf " %-10s${cpuLoad1Heatmap}%-4s${resetColor}, ${cpuLoad5Heatmap}%-4s${resetColor}, ${cpuLoad15Heatmap}%-4s${resetColor}\n" "CPU Load:" "${cpuLoad1}" "${cpuLoad5}" "${cpuLoad15}"
printf " %-10s%-19s%-10s${cpuLoad1Heatmap}%-19s${resetColor}\n" "Memory:" "${memoryUsedPercent}%" "CPU Load:" "${cpuPercent}%"
printf " %-10s%-19s%-10s${cpuLoad1Heatmap}%-19s${resetColor}" "Memory:" "${memoryUsedPercent}%" "CPU Load:" "${cpuPercent}%"
}

normalChrono() {
Expand All @@ -342,17 +362,11 @@ normalChrono() {
outputDHCPInformation
outputSystemInformation

#Do Our Calculations
# CalcQueriesToday
# CalcblockedToday
# CalcPercentBlockedToday
# CalcBlockedDomains

# Get our information
GetSystemInformation
GetPiholeInformation
GetNetworkInformation
GetPiholeVersionInformation
GetVersionInformation

sleep 5
done
Expand All @@ -373,16 +387,52 @@ EOM
}

if [[ $# = 0 ]]; then
clear

# Nice logo
echo -e " ${yellowColor}.${greenColor}-${blueColor}. . ,${magentaColor}-${redColor}."
echo -e "${yellowColor}( ${magentaColor}|${redColor}-${yellowColor}. ${blueColor}.${magentaColor}-${redColor}.${yellowColor}.${greenColor}-${blueColor}.${magentaColor}.${redColor}-${yellowColor}.${greenColor}.${blueColor}-${magentaColor}.${redColor}.${yellowColor}-${greenColor}.${blueColor}-${magentaColor}.${redColor}.${yellowColor}-${greenColor},${blueColor}-${magentaColor}|${redColor}-${yellowColor}.${greenColor}-${blueColor},${magentaColor}.${redColor}-${yellowColor}. ${redColor}/"
echo -e " ${blueColor}\`${magentaColor}-${redColor}' ${greenColor}'${blueColor}-${magentaColor}' ${greenColor}\`${blueColor}-${magentaColor}'${redColor}' ${greenColor}'${blueColor}\`${magentaColor}-${redColor}'${yellowColor}' ${blueColor}' ${redColor}'${yellowColor}\`${greenColor}'${blueColor}- ${redColor}'${yellowColor}-${greenColor}\`${blueColor}'${magentaColor}-${redColor}' ${redColor}'${yellowColor}-${greenColor}-${resetColor}"
echo ""

# Get Our Config Values
. /etc/pihole/setupVars.conf

echo "START UP===================================================="
echo "- Checking for Chronometer2 version file..."
if [ -e "piHoleVersion" ]; then
echo " - Chronometer2 version file found... deleting."
rm piHoleVersion
else
echo " - Chronometer2 version file not found."
fi

# Get our information for the first time
echo "- Gathering system information..."
GetSystemInformation
echo "- Gathering Pi-hole information..."
GetPiholeInformation
echo "- Gathering network information..."
GetNetworkInformation
GetPiholeVersionInformation
echo "- Gathering version information..."
GetVersionInformation
echo " - Pi-hole Core v$piholeVersion"
echo " - Web Admin v$webVersion"
echo " - FTL v$ftlVersion"
echo " - Chronometer2 v$chronometer2Version"
echo "- Checking for update information..."
GetVersionInformation
echo " - $versionStatus"
echo ""
printf "Chronometer2 will start in "

for i in 5 4 3 2 1
do
printf " $i..."
sleep 1
done

printf " now!"
# Run Chronometer2
normalChrono
fi
Expand Down

0 comments on commit 6e07920

Please sign in to comment.