update_pihole.sh
-fonction send_gotify_notification() -fonction send_pushover_notification() -bugfix export PATH="/usr/local/bin:$PATH" pour avoir pihole par cron.
This commit is contained in:
74
update_pihole.sh
Executable file → Normal file
74
update_pihole.sh
Executable file → Normal file
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Verify pihole version (run pihole -v) and send a notfication to Gotify
|
# Verify pihole version (run pihole -v) and send a notfication to Gotify
|
||||||
|
|
||||||
@@ -12,6 +12,9 @@ bold="\033[1m"
|
|||||||
box="\033[1;41m"
|
box="\033[1;41m"
|
||||||
reset="\033[0m"
|
reset="\033[0m"
|
||||||
|
|
||||||
|
export PATH="/usr/local/bin:$PATH"
|
||||||
|
# run by cron $PATH=/usr/bin:/bin
|
||||||
|
|
||||||
command -v pihole >/dev/null 2>&1 || { echo -e "${bold}pihole${reset} is not installed. Aborting..." >&2; exit 1; }
|
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
|
curl -Is https://www.apple.com | head -1 | grep 200 1>/dev/null
|
||||||
@@ -21,6 +24,14 @@ if [[ $? -eq 1 ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
host=$(hostname)
|
||||||
|
available=false
|
||||||
|
msg_md=
|
||||||
|
msg_html=
|
||||||
|
infos=
|
||||||
|
# Choose the notification
|
||||||
|
notif="pushover"
|
||||||
|
|
||||||
dotenv () {
|
dotenv () {
|
||||||
set -a
|
set -a
|
||||||
# shellcheck disable=SC1091
|
# shellcheck disable=SC1091
|
||||||
@@ -30,11 +41,38 @@ dotenv () {
|
|||||||
|
|
||||||
dotenv
|
dotenv
|
||||||
|
|
||||||
gotify_server="https://gotify.photos-nas.ovh"
|
send_gotify_notification() {
|
||||||
host=$(hostname)
|
now=$(date +"%d-%m-%Y %T")
|
||||||
available=false
|
gotify_server="https://gotify.maboiteverte.fr"
|
||||||
msg=
|
TITLE="Pi-hole on $host update"
|
||||||
infos=
|
MESSAGE="**A new version of Pi-hole is available:**\n\n $msg_md\n\n $infos\n\n Please run *pihole -up* on $host to update !"
|
||||||
|
PRIORITY=8
|
||||||
|
URL="$gotify_server/message?token=$token_gotify&?format=markdown"
|
||||||
|
|
||||||
|
echo -e "Sending notification to $gotify_server ..."
|
||||||
|
# -S, --show-error Show error even when -s is used
|
||||||
|
# -s, --silent Silent mode
|
||||||
|
# -v Verbose
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
[ $? -eq 0 ] && echo -e "${greenbold}Gotify notification sent successfully !${reset}" || echo -e "${redbold}error sending Gotify notification !${reset}"
|
||||||
|
}
|
||||||
|
|
||||||
|
send_pushover_notification() {
|
||||||
|
echo -e "Sending Pushover notification ..."
|
||||||
|
curl -s -F "token=$BASH_APP" \
|
||||||
|
-F "user=$USER_KEY" \
|
||||||
|
-F "title=$1" \
|
||||||
|
-F priority=2 \
|
||||||
|
-F html=1 \
|
||||||
|
-F retry=60 \
|
||||||
|
-F expire=86400 \
|
||||||
|
-F "message=$2" https://api.pushover.net/1/messages.json
|
||||||
|
|
||||||
|
[ $? -eq 0 ] && echo -e "${greenbold}Pushover notification sent successfully !${reset}" || echo -e "${redbold}error sending Pushover notification !${reset}"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
echo -e "${box}Find Pi-hole update on $host${reset}\n"
|
echo -e "${box}Find Pi-hole update on $host${reset}\n"
|
||||||
|
|
||||||
@@ -51,21 +89,23 @@ while IFS= read -r line; do
|
|||||||
|
|
||||||
if [ "$current" != "$last" ]; then
|
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}"
|
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"
|
msg_md+="**${app}: current:${current} last:${last}**\n"
|
||||||
|
msg_html+="${app}: current:${current} last:${last}<br />"
|
||||||
available=true
|
available=true
|
||||||
infos+="https://github.com/pi-hole/${app}/releases/tag/${last}\n"
|
infos+="https://github.com/pi-hole/${app}/releases/tag/${last}\n"
|
||||||
else
|
else
|
||||||
printf " \e[1;32m%-10s\e[0m \e[1;32m%-10s\e[0m \e[1;32m%-10s\e[0m \n" "${app}" "${current}" "${last}"
|
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"
|
msg_md+="${app}: current:${current} last:${last}\n"
|
||||||
|
msg_html+="${app}: current:${current} last:${last}<br />"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done <<< "$upd"
|
done <<< "$upd"
|
||||||
|
|
||||||
echo -e "\n$infos"
|
echo -e "\n$infos"
|
||||||
|
|
||||||
if [ "$available" = true ];then
|
if [ ! "$available" = true ];then
|
||||||
|
|
||||||
if [ ! -t 0 ]; then
|
if [ -t 0 ]; then
|
||||||
# "I'm on a TTY, this is interactive."
|
# "I'm on a TTY, this is interactive."
|
||||||
a=$(echo -e "\nPlease run ${italic}pihole -up${reset} to update ! (y/n)")
|
a=$(echo -e "\nPlease run ${italic}pihole -up${reset} to update ! (y/n)")
|
||||||
read -p "$a" choice
|
read -p "$a" choice
|
||||||
@@ -74,13 +114,13 @@ if [ "$available" = true ];then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
echo -e "Sending notification to $gotify_server ..."
|
# Run by cron
|
||||||
TITLE="Pi-hole on $host update"
|
if [ "$notif" == "gotify" ];then
|
||||||
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 !"
|
send_gotify_notification
|
||||||
PRIORITY=8
|
elif [ "$notif" == "pushover" ];then
|
||||||
URL="$gotify_server/message?token=$token&?format=markdown"
|
send_pushover_notification "A new version of Pi-hole is available" "$msg_html <br /> $infos <br /> Please run <b>pihole -up</b> on $host to update"
|
||||||
|
#pushover -a "bash" -m "A new version of Pi-hole is available: <br /> $msg_html <br /> $infos <br /> Please run <b>pihole -up</b> on $host to update" -p 2 -f 1
|
||||||
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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user