#!/usr/bin/env bash # Verify pihole version (run pihole -v) and send a notfication to Gotify italic="\033[3m" underline="\033[4m" ita_under="\033[3;4m" bgd="\033[1;4;31m" red="\033[1;31m" green="\033[1;32m" bold="\033[1m" box="\033[1;41m" reset="\033[0m" command -v pihole >/dev/null 2>&1 || { echo -e "${bold}pihole${reset} is not installed. Aborting..." >&2; exit 1; } curl -Is https://www.apple.com | head -1 | grep 200 1>/dev/null if [[ $? -eq 1 ]]; then echo -e "\n${red}No Internet connection !${reset}" echo -e "Exit !" exit 1 fi dotenv () { set -a # shellcheck disable=SC1091 [ -f ".env" ] && . ".env" || echo -e "${red}\nNo .env file found ! No token for gotify.${reset}" set +a } dotenv gotify_server="https://gotify.photos-nas.ovh" host=$(hostname) available=false msg= infos= echo -e "${box}Find Pi-hole update on $host${reset}\n" upd=$(pihole -v) #upd=$(cat 'update_pihole.txt') printf " \e[1m%-10s \e[1m%-10s \e[1m%-10s \n" "Pi-hole" "Current" "Last" while IFS= read -r line; do app=$(echo "${line}" | awk '{print $1}') current=$(echo "${line}" | awk '{print $4}') last=$(echo "${line}" | awk '{print $6}' | sed 's/.$//') if [ "$current" != "$last" ]; then printf " \e[1;31m%-10s\e[0m \e[1;31m%-10s\e[0m \e[1;31m%-10s\e[0m \n" "${app}" "${current}" "${last}" msg+="**${app}: current:${current} last:${last}**\n" available=true infos+="https://github.com/pi-hole/${app}/releases/tag/${last}\n" else printf " \e[1;32m%-10s\e[0m \e[1;32m%-10s\e[0m \e[1;32m%-10s\e[0m \n" "${app}" "${current}" "${last}" msg+="${app}: current:${current} last:${last}\n" fi done <<< "$upd" echo -e "\n$infos" if [ "$available" = true ];then if [ ! -t 0 ]; then # "I'm on a TTY, this is interactive." a=$(echo -e "\nPlease run ${italic}pihole -up${reset} to update ! (y/n)") read -p "$a" choice if [ "$choice" == "y" ] || [ "$choice" == "Y" ]; then pihole -up fi else echo -e "Sending notification to $gotify_server ..." TITLE="Pi-hole on $host update" MESSAGE="**A new version of Pi-hole is available:**\n\n $msg\n\n $infos\n\n Please run *pihole -up* on $host to update !" PRIORITY=8 URL="$gotify_server/message?token=$token&?format=markdown" curl -s -S --output /dev/null --data '{"message": "'"${MESSAGE}"'", "title": "'"${TITLE}"'", "priority":'"${PRIORITY}"', "extras": {"client::display": {"contentType": "text/markdown"}}}' -H 'Content-Type: application/json' "$URL" fi else echo -e "\nNo available update !" fi