Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0cb49accf7 | |||
| 1e220cd809 | |||
| 09042d0eb2 | |||
| ed2cee734e |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
.env
|
.env
|
||||||
.envrc
|
.envrc
|
||||||
|
.DS_Store
|
||||||
35
lan.list
35
lan.list
@@ -1,43 +1,70 @@
|
|||||||
192.168.2.1 asus.photos-nas.ovh asus
|
192.168.2.1 asus.photos-nas.ovh asus
|
||||||
192.168.2.1 www.asusrouter.com et12
|
192.168.2.1 www.asusrouter.com et12
|
||||||
|
192.168.2.57 adventurelog.photos-nas.ovh adventurelog
|
||||||
|
192.168.2.57 adventurelogapi.photos-nas.ovh adventurelogapi
|
||||||
192.168.2.57 airdrop.photos-nas.ovh airdrop
|
192.168.2.57 airdrop.photos-nas.ovh airdrop
|
||||||
|
192.168.2.57 bearlytics.photos-nas.ovh bearlytics
|
||||||
|
192.168.2.57 birdnet.photos-nas.ovh birdnet
|
||||||
192.168.2.57 books.photos-nas.ovh books
|
192.168.2.57 books.photos-nas.ovh books
|
||||||
192.168.2.57 change.photos-nas.ovh changedetection
|
192.168.2.57 change.photos-nas.ovh changedetection
|
||||||
|
192.168.2.57 checkcle.photos-nas.ovh checkcle
|
||||||
192.168.2.57 chibisafe.photos-nas.ovh chibisafe
|
192.168.2.57 chibisafe.photos-nas.ovh chibisafe
|
||||||
192.168.2.57 dcommander.photos-nas.ovh dcommander
|
192.168.2.57 compose.photos-nas.ovh compose
|
||||||
|
192.168.2.57 diun.photos-nas.ovh diun
|
||||||
192.168.2.57 dockge.photos-nas.ovh dockge
|
192.168.2.57 dockge.photos-nas.ovh dockge
|
||||||
192.168.2.57 docspell.photos-nas.ovh docspell
|
192.168.2.57 dockpeek.photos-nas.ovh dockpeek
|
||||||
192.168.2.57 dozzle.photos-nas.ovh dozzle
|
192.168.2.57 dozzle.photos-nas.ovh dozzle
|
||||||
192.168.2.57 ds923.photos-nas.ovh dsm
|
192.168.2.57 ds923.photos-nas.ovh dsm
|
||||||
|
192.168.2.57 freshrss.photos-nas.ovh freshrss
|
||||||
|
192.168.2.57 ftp.photos-nas.ovh ftp
|
||||||
192.168.2.57 git.photos-nas.ovh git
|
192.168.2.57 git.photos-nas.ovh git
|
||||||
192.168.2.57 glances.photos-nas.ovh glances
|
192.168.2.57 glances.photos-nas.ovh glances
|
||||||
192.168.2.57 gokapi.photos-nas.ovh gokapi
|
192.168.2.57 gokapi.photos-nas.ovh gokapi
|
||||||
192.168.2.57 gotify.photos-nas.ovh gotify
|
192.168.2.57 gotify.photos-nas.ovh gotify
|
||||||
|
192.168.2.57 hoarder.photos-nas.ovh hoarder
|
||||||
192.168.2.57 igotify.photos-nas.ovh gotify-api
|
192.168.2.57 igotify.photos-nas.ovh gotify-api
|
||||||
192.168.2.57 immich.photos-nas.ovh immich
|
192.168.2.57 immich.photos-nas.ovh immich
|
||||||
192.168.2.57 invidious.photos-nas.ovh invidious
|
192.168.2.57 invidious.photos-nas.ovh invidious
|
||||||
192.168.2.57 it-tools.photos-nas.ovh it-tools
|
192.168.2.57 it-tools.photos-nas.ovh it-tools
|
||||||
|
192.168.2.57 linkwarden.photos-nas.ovh linkwarden
|
||||||
|
192.168.2.57 lunalytics.photos-nas.ovh lunalytics
|
||||||
192.168.2.57 maloja.photos-nas.ovh maloja
|
192.168.2.57 maloja.photos-nas.ovh maloja
|
||||||
192.168.2.57 maps-server.photos-nas.ovh maps-server
|
192.168.2.57 maps-server.photos-nas.ovh maps-server
|
||||||
192.168.2.57 maps.photos-nas.ovh maps
|
192.168.2.57 maps.photos-nas.ovh maps
|
||||||
|
192.168.2.57 materialious.photos-nas.ovh materialious
|
||||||
|
192.168.2.57 mealie.photos-nas.ovh mealie
|
||||||
192.168.2.57 menu.photos-nas.ovh heimdall
|
192.168.2.57 menu.photos-nas.ovh heimdall
|
||||||
|
192.168.2.57 metube.photos-nas.ovh metube
|
||||||
192.168.2.57 navidrome.photos-nas.ovh navidrome
|
192.168.2.57 navidrome.photos-nas.ovh navidrome
|
||||||
192.168.2.57 nextcloud.photos-nas.ovh nextcloud
|
192.168.2.57 nextcloud.photos-nas.ovh nextcloud
|
||||||
|
192.168.2.57 nmap.photos-nas.ovh nmap
|
||||||
|
192.168.2.57 ntfy.photos-nas.ovh ntfy
|
||||||
|
192.168.2.57 omnitools.photos-nas.ovh omnitools
|
||||||
192.168.2.57 paperlessngx.photos-nas.ovh paperlessngx
|
192.168.2.57 paperlessngx.photos-nas.ovh paperlessngx
|
||||||
192.168.2.57 pastebin.photos-nas.ovh pastebin
|
192.168.2.57 pastebin.photos-nas.ovh pastebin
|
||||||
192.168.2.57 photos.photos-nas.ovh photos
|
192.168.2.57 photos.photos-nas.ovh photos
|
||||||
|
192.168.2.57 pinchflat.photos-nas.ovh pinchflat
|
||||||
192.168.2.57 pingvin.photos-nas.ovh pingvin
|
192.168.2.57 pingvin.photos-nas.ovh pingvin
|
||||||
|
192.168.2.57 piped.photos-nas.ovh piped
|
||||||
|
192.168.2.57 pipedapi.photos-nas.ovh pipedapi
|
||||||
|
192.168.2.57 pipedproxy.photos-nas.ovh pipedproxy
|
||||||
|
192.168.2.57 portracker.photos-nas.ovh portracker
|
||||||
192.168.2.57 psitransfer.photos-nas.ovh psitransfer
|
192.168.2.57 psitransfer.photos-nas.ovh psitransfer
|
||||||
|
192.168.2.57 rustpad.photos-nas.ovh rustpad
|
||||||
192.168.2.57 seafile.photos-nas.ovh seafile
|
192.168.2.57 seafile.photos-nas.ovh seafile
|
||||||
192.168.2.57 search.photos-nas.ovh searxng
|
192.168.2.57 search.photos-nas.ovh searxng
|
||||||
192.168.2.57 send.photos-nas.ovh send
|
192.168.2.57 send.photos-nas.ovh send
|
||||||
|
192.168.2.57 shiori.photos-nas.ovh shiori
|
||||||
|
192.168.2.57 slink.photos-nas.ovh slink
|
||||||
192.168.2.57 snippet.photos-nas.ovh snippet
|
192.168.2.57 snippet.photos-nas.ovh snippet
|
||||||
192.168.2.57 syno-dashboard.photos-nas.ovh syno-dashboard
|
|
||||||
192.168.2.57 tautulli.photos-nas.ovh tautulli
|
192.168.2.57 tautulli.photos-nas.ovh tautulli
|
||||||
192.168.2.57 test.photos-nas.ovh test
|
192.168.2.57 test.photos-nas.ovh test
|
||||||
|
192.168.2.57 trip.photos-nas.ovh trip
|
||||||
192.168.2.57 tube.photos-nas.ovh tube
|
192.168.2.57 tube.photos-nas.ovh tube
|
||||||
192.168.2.57 uptime.photos-nas.ovh uptime-kuma
|
|
||||||
192.168.2.57 vault.photos-nas.ovh vaultwarten
|
192.168.2.57 vault.photos-nas.ovh vaultwarten
|
||||||
|
192.168.2.57 whoogle.photos-nas.ovh whoogle
|
||||||
|
192.168.2.57 wud.photos-nas.ovh wud
|
||||||
192.168.2.57 yacy.photos-nas.ovh yacy
|
192.168.2.57 yacy.photos-nas.ovh yacy
|
||||||
|
192.168.2.57 ytweb.photos-nas.ovh ytweb
|
||||||
192.168.2.116 pihole1.photos-nas.ovh dietpi1
|
192.168.2.116 pihole1.photos-nas.ovh dietpi1
|
||||||
192.168.2.216 pihole2.photos-nas.ovh dietpi2
|
192.168.2.216 pihole2.photos-nas.ovh dietpi2
|
||||||
|
|||||||
@@ -1,54 +1,79 @@
|
|||||||
|
adventurelog
|
||||||
|
adventurelogapi
|
||||||
airdrop
|
airdrop
|
||||||
asus
|
asus
|
||||||
|
bearlytics
|
||||||
|
birdnet
|
||||||
books
|
books
|
||||||
change
|
change
|
||||||
|
checkcle
|
||||||
chibisafe
|
chibisafe
|
||||||
dcommander
|
compose
|
||||||
|
diun
|
||||||
dockge
|
dockge
|
||||||
docspell
|
dockpeek
|
||||||
dozzle
|
dozzle
|
||||||
drive
|
drive
|
||||||
ds916
|
ds916
|
||||||
ds923
|
ds923
|
||||||
files
|
files
|
||||||
|
freshrss
|
||||||
|
ftp
|
||||||
git
|
git
|
||||||
gitea
|
gitea
|
||||||
glances
|
glances
|
||||||
gokapi
|
gokapi
|
||||||
gotify
|
gotify
|
||||||
|
hoarder
|
||||||
home-assistant
|
home-assistant
|
||||||
homebridge
|
homebridge
|
||||||
igotify
|
igotify
|
||||||
immich
|
immich
|
||||||
invidious
|
invidious
|
||||||
it-tools
|
it-tools
|
||||||
|
lunalytics
|
||||||
|
linkwarden
|
||||||
maloja
|
maloja
|
||||||
maps-server
|
maps-server
|
||||||
maps
|
maps
|
||||||
|
materialious
|
||||||
|
mealie
|
||||||
menu
|
menu
|
||||||
|
metube
|
||||||
musiiic
|
musiiic
|
||||||
navidrome
|
navidrome
|
||||||
nextcloud
|
nextcloud
|
||||||
notif
|
nmap
|
||||||
|
ntfy
|
||||||
|
omnitools
|
||||||
paperlessngx
|
paperlessngx
|
||||||
pastebin
|
pastebin
|
||||||
photos
|
photos
|
||||||
pihole1
|
pihole1
|
||||||
pihole2
|
pihole2
|
||||||
|
pinchflat
|
||||||
pingvin
|
pingvin
|
||||||
|
piped
|
||||||
|
pipedapi
|
||||||
|
pipedproxy
|
||||||
portainer
|
portainer
|
||||||
|
portracker
|
||||||
psitransfer
|
psitransfer
|
||||||
|
rustpad
|
||||||
seafile
|
seafile
|
||||||
search
|
search
|
||||||
send
|
send
|
||||||
|
shiori
|
||||||
|
slink
|
||||||
snippet
|
snippet
|
||||||
syno-dashboard
|
|
||||||
tautulli
|
tautulli
|
||||||
test
|
test
|
||||||
|
trip
|
||||||
tube
|
tube
|
||||||
tunes
|
tunes
|
||||||
uptime
|
|
||||||
vault
|
vault
|
||||||
wg
|
wg
|
||||||
|
whoogle
|
||||||
|
wud
|
||||||
yacy
|
yacy
|
||||||
yatch
|
ytweb
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Sync_pihole_lan.sh synchronise the /etc/pihole/lan.list file with your Subdomains
|
# Sync_pihole_lan.sh synchronise the /etc/pihole/lan.list file with your Subdomains
|
||||||
# v2.0
|
# v4.0 synchro avec la zone photos-nas.ovh sur OVH via l'API
|
||||||
|
|
||||||
|
# 1. liste principale des sous-domaines => subdomains.photos-nas.ovh.txt
|
||||||
|
# 2. sauvegarde des lan.list de chaque pihole => lan.list.1 et lan.list.2
|
||||||
|
# 3. lan.list à jour que l'on copie sur chaque pihole
|
||||||
|
# 4. on récupère via l'API la list des CNAME sur la zone photos-nas.ovh => zone.photos-nas.ovh
|
||||||
|
# 5. on ajoute ou supprime les CNAME sur la zone photos-nas.ovh
|
||||||
|
|
||||||
italic="\033[3m"
|
italic="\033[3m"
|
||||||
underline="\033[4m"
|
underline="\033[4m"
|
||||||
@@ -20,15 +26,26 @@ reset="\033[0m"
|
|||||||
|
|
||||||
absent=()
|
absent=()
|
||||||
delete=()
|
delete=()
|
||||||
|
extra=()
|
||||||
domain=".photos-nas.ovh"
|
domain=".photos-nas.ovh"
|
||||||
not_required=("drive" "files" "gitea" "home-assistant" "homebridge" "portainer" "tunes" "wg" "yatch")
|
not_required=("drive" "files" "gitea" "home-assistant" "homebridge" "portainer" "tunes" "wg" "www")
|
||||||
not_used=("ds916" "musiiic" "notif")
|
not_used=("ds916" "musiiic" "notif")
|
||||||
|
|
||||||
pihole1=192.168.2.116
|
pihole1=192.168.2.116
|
||||||
pihole2=192.168.2.216
|
pihole2=192.168.2.216
|
||||||
|
|
||||||
echo -e "${greenbold}Sync_pihole_lan.sh synchronise the /etc/pihole/lan.list file with your Subdomains ...${reset}\n"
|
ScriptPath="$(readlink -f "$0")" # /Users/bruno/Documents/Scripts/bashbirds/bashbirds.sh
|
||||||
|
ScriptWorkDir="$(dirname "$ScriptPath")" # /Users/bruno/Documents/Scripts/bashbirds
|
||||||
|
|
||||||
|
echo -e "${greenbold}Sync_pihole_lan.sh synchronise the /etc/pihole/lan.list file with your Subdomains ...${reset}\n"
|
||||||
|
echo -e " For Pihole 6:"
|
||||||
|
echo -e " - edit Pihole preferences (nano /etc/pihole/pihole.toml)"
|
||||||
|
echo -e " - set etc_dnsmasq_d = true ### CHANGED, default = false"
|
||||||
|
echo
|
||||||
|
echo
|
||||||
|
|
||||||
|
: << 'COMMENTS'
|
||||||
|
COMMENTS
|
||||||
cat < /dev/null > /dev/tcp/1.1.1.1/53
|
cat < /dev/null > /dev/tcp/1.1.1.1/53
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
echo -e "\n${red}No Internet connection !${reset}"
|
echo -e "\n${red}No Internet connection !${reset}"
|
||||||
@@ -39,45 +56,49 @@ fi
|
|||||||
|
|
||||||
echo -e "${bold}Backup ${italic}lan.list...${reset}"
|
echo -e "${bold}Backup ${italic}lan.list...${reset}"
|
||||||
|
|
||||||
# Sauvegarde du /etc/pihole/lan.list de chaque pihole vers lan.list.1 et lan.list.2
|
# 1. Sauvegarde du /etc/pihole/lan.list de chaque pihole vers lan.list.1 et lan.list.2
|
||||||
ping -q -c1 "$pihole1" &>/dev/null && ssh -p51322 root@"$pihole1" "cat /etc/pihole/lan.list" > lan.list.1 || echo -e "\n${red}Pihole1 is unreachable !'${reset}"
|
ping -q -c1 "$pihole1" &>/dev/null && ssh -p51322 root@"$pihole1" "cat /etc/pihole/lan.list" > $ScriptWorkDir/lan.list.1 || echo -e "\n${red}Pihole1 is unreachable !'${reset}"
|
||||||
ping -q -c1 "$pihole2" &>/dev/null && ssh -p51522 root@"$pihole2" "cat /etc/pihole/lan.list" > lan.list.2 || echo -e "${red}Pihole2 is unreachable !'${reset}"
|
ping -q -c1 "$pihole2" &>/dev/null && ssh -p51522 root@"$pihole2" "cat /etc/pihole/lan.list" > $ScriptWorkDir/lan.list.2 || echo -e "${red}Pihole2 is unreachable !'${reset}"
|
||||||
|
|
||||||
|
|
||||||
# Si un lan.list.bak existe, on l'archive
|
# Si un lan.list.bak existe, on l'archive
|
||||||
if [ -f lan.list.bak ]; then
|
if [ -f "$ScriptWorkDir/lan.list.bak" ]; then
|
||||||
cp lan.list.bak /tmp/lan.list
|
cp "$ScriptWorkDir/lan.list.bak" /tmp/lan.list
|
||||||
bzip2 /tmp/lan.list # lan.list.bz2
|
bzip2 /tmp/lan.list # lan.list.bz2
|
||||||
mv /tmp/lan.list.bz2 .
|
mv /tmp/lan.list.bz2 .
|
||||||
fi
|
fi
|
||||||
# On backup le lan.list vers lan.list.bak (sinon lan.list.1 devient lan.list)
|
# On backup le lan.list vers lan.list.bak (sinon lan.list.1 devient lan.list)
|
||||||
if [ -f lan.list ]; then
|
if [ -f $ScriptWorkDir/lan.list ]; then
|
||||||
cp lan.list lan.list.bak
|
cp $ScriptWorkDir/lan.list $ScriptWorkDir/lan.list.bak
|
||||||
elif [ -f lan.list.1 ]; then
|
elif [ -f $ScriptWorkDir/lan.list.1 ]; then
|
||||||
cp lan.list.1 lan.list
|
cp $ScriptWorkDir/lan.list.1 $ScriptWorkDir/lan.list
|
||||||
elif [ -f lan.list.2 ]; then
|
elif [ -f $ScriptWorkDir/lan.list.2 ]; then
|
||||||
cp lan.list.2 lan.list
|
cp $ScriptWorkDir/lan.list.2 $ScriptWorkDir/lan.list
|
||||||
else
|
else
|
||||||
echo "Error ! No lan.list file !"
|
echo "Error ! No lan.list file !"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
nb_dynhost=$(awk 'END { print NR }' lan.list)
|
|
||||||
|
|
||||||
|
nb_dynhost=$(awk 'END { print NR }' $ScriptWorkDir/lan.list)
|
||||||
echo -e "\n$nb_dynhost dynhost found in lan.list !"
|
echo -e "\n$nb_dynhost dynhost found in lan.list !"
|
||||||
|
|
||||||
|
|
||||||
# Suppression des 'not_required' et 'not_used' dans le lan.list
|
# 2. Suppression des 'not_required' et 'not_used' dans le lan.list
|
||||||
|
|
||||||
echo -e "${bold}\nFind extra dynhost in ${italic}lan.list...${reset}"
|
echo -e "${bold}\nFind not_used and not_required dynhost in ${italic}lan.list...${reset}"
|
||||||
|
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
|
|
||||||
ndd=$(echo "${line}" | awk '{print $2}' | awk -F"." '{print $1}')
|
ndd=$(echo "${line}" | awk '{print $2}' | awk -F"." '{print $1}')
|
||||||
if [[ " ${not_required[*]} " =~ " $ndd " ]] || [[ " ${not_used[*]} " =~ " $ndd " ]]; then
|
if [[ " ${not_required[*]} " =~ " $ndd " ]] || [[ " ${not_used[*]} " =~ " $ndd " ]]; then
|
||||||
|
if [[ ! "$line" == *asusrouter* ]]; then
|
||||||
delete+=(${ndd})
|
delete+=(${ndd})
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
done < lan.list
|
done < $ScriptWorkDir/lan.list
|
||||||
|
|
||||||
if [ ${#delete[@]} -ge 1 ]; then
|
if [ ${#delete[@]} -ge 1 ]; then
|
||||||
|
|
||||||
@@ -98,22 +119,21 @@ if [ ${#delete[@]} -ge 1 ]; then
|
|||||||
echo "$nb_dynhost dynhost found in lan.list !"
|
echo "$nb_dynhost dynhost found in lan.list !"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "None"
|
echo -e "${green}None !${reset}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Ajout des DynHOST de OVH (Zones DNS) dans les 2 lan.list (pihole1 & pihole2)
|
# 3. Recherche des sous-domaines manquants dans lan.list (d'après subdomains.photos-nas.ovh.txt)
|
||||||
# Zones DNS -> photos-nas.ovh -> Historique des zones
|
|
||||||
|
|
||||||
echo -e "${bold}\nFind missing dynhost in ${italic}lan.list...${reset}"
|
echo -e "${bold}\nFind missing dynhost in ${italic}lan.list...${reset}"
|
||||||
|
|
||||||
#dynhost_list=$(cat photos-nas.ovh_dns_data.txt | grep "60 IN A" | sed '1d')
|
#dynhost_list=$(cat photos-nas.ovh_dns_data.txt | grep "60 IN A" | sed '1d')
|
||||||
dynhost_list=$(cat subdomains.photos-nas.ovh.txt)
|
dynhost_list=$(cat $ScriptWorkDir/subdomains.photos-nas.ovh.txt)
|
||||||
|
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
|
|
||||||
dynhost=$(echo "${line}" | awk '{print $1}')
|
dynhost=$(echo "${line}" | awk '{print $1}')
|
||||||
grep -q $dynhost lan.list
|
grep -q $dynhost $ScriptWorkDir/lan.list
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
if [[ ! " ${not_required[*]} " =~ " $dynhost " ]] && [[ ! " ${not_used[*]} " =~ " $dynhost " ]]; then
|
if [[ ! " ${not_required[*]} " =~ " $dynhost " ]] && [[ ! " ${not_used[*]} " =~ " $dynhost " ]]; then
|
||||||
absent+=(${dynhost})
|
absent+=(${dynhost})
|
||||||
@@ -143,37 +163,78 @@ if [ ${#absent[@]} -ge 1 ]; then
|
|||||||
cat /tmp/temp_file.list
|
cat /tmp/temp_file.list
|
||||||
|
|
||||||
# On ajoute le /tmp/temp_file.list au lan.list
|
# On ajoute le /tmp/temp_file.list au lan.list
|
||||||
cat /tmp/temp_file.list >> lan.list
|
cat /tmp/temp_file.list >> $ScriptWorkDir/lan.list
|
||||||
# On trie le lan.list
|
# On trie le lan.list
|
||||||
cat lan.list | sort -k2 > lan.list.sorted
|
cat $ScriptWorkDir/lan.list | sort -k2 > $ScriptWorkDir/lan.list.sorted
|
||||||
mv lan.list.sorted lan.list
|
mv $ScriptWorkDir/lan.list.sorted $ScriptWorkDir/lan.list
|
||||||
|
|
||||||
else
|
else
|
||||||
echo -e "${green}No new dynhost !${reset}"
|
echo -e "${green}No new dynhost !${reset}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# 4. Recherche des sous-domaines supplementaires dans lan.list (d'après subdomains.photos-nas.ovh.txt)
|
||||||
|
|
||||||
|
echo -e "${bold}\nRemove extra dynhost in ${italic}lan.list...${reset}"
|
||||||
|
|
||||||
|
lan_list=$(cat $ScriptWorkDir/lan.list)
|
||||||
|
|
||||||
|
while IFS= read -r line; do
|
||||||
|
|
||||||
|
dynhost=$(echo "${line}" | awk '{print $2}' | awk -F"." '{print $1}')
|
||||||
|
|
||||||
|
grep -q $dynhost $ScriptWorkDir/subdomains.photos-nas.ovh.txt
|
||||||
|
if [ ! $? != 0 ]; then
|
||||||
|
echo "${line}" >> /tmp/extra.txt
|
||||||
|
else
|
||||||
|
extra+=(${dynhost})
|
||||||
|
fi
|
||||||
|
if [[ "$dynhost" == *www* ]]; then
|
||||||
|
echo "${line}" >> /tmp/extra.txt
|
||||||
|
|
||||||
|
#extra=( "${extra[@]/$dynhost}" )
|
||||||
|
# on supprime www et on reconstruit le tableau
|
||||||
|
new_array=()
|
||||||
|
for value in "${extra[@]}"
|
||||||
|
do
|
||||||
|
[[ $value != $dynhost ]] && new_array+=("$value")
|
||||||
|
done
|
||||||
|
extra=("${new_array[@]}")
|
||||||
|
unset new_array
|
||||||
|
fi
|
||||||
|
|
||||||
|
done <<< "$lan_list"
|
||||||
|
|
||||||
|
if [ ${#extra[@]} -ge 1 ]; then
|
||||||
|
echo "${extra[@]}"
|
||||||
|
else
|
||||||
|
echo -e "${green}No extra dynhost !${reset}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cp /tmp/extra.txt $ScriptWorkDir/lan.list
|
||||||
|
[ -f /tmp/extra.txt ] && rm /tmp/extra.txt
|
||||||
|
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo -e "${bold}Display ${italic}lan.list. Please verify IP and subdomains.${reset}"
|
echo -e "${bold}Display ${italic}lan.list. Please verify IP and subdomains.${reset}"
|
||||||
cat lan.list
|
cat $ScriptWorkDir/lan.list
|
||||||
|
|
||||||
|
nb_dynhost=$(awk 'END { print NR }' $ScriptWorkDir/lan.list)
|
||||||
nb_dynhost=$(awk 'END { print NR }' lan.list)
|
|
||||||
echo -e "$nb_dynhost dynhost !\n"
|
echo -e "$nb_dynhost dynhost !\n"
|
||||||
|
|
||||||
# Do you want to modify lan.list ?
|
# Do you want to modify lan.list ?
|
||||||
a=$(echo -e "Do you want to edit ${italic}lan.list${reset} ? (y/n)")
|
a=$(echo -e "Do you want to edit ${italic}lan.list${reset} ? (y/n)")
|
||||||
read -p "$a" choice
|
read -p "$a" choice
|
||||||
if [ "$choice" == "y" ] || [ "$choice" == "Y" ]; then
|
if [ "$choice" == "y" ] || [ "$choice" == "Y" ]; then
|
||||||
nano -l lan.list
|
nano -l $ScriptWorkDir/lan.list
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# On exporte lan.list vers chaque /etc/pihole/lan.list (pihole1 et pihole2)
|
# 4. On exporte lan.list vers chaque /etc/pihole/lan.list (pihole1 et pihole2)
|
||||||
|
|
||||||
: << 'COMMENTS'
|
: << 'COMMENTS2'
|
||||||
echo "toto"
|
echo "toto"
|
||||||
COMMENTS
|
COMMENTS2
|
||||||
|
|
||||||
b=$(echo -e "Do you want to export ${italic}lan.list${reset} to ${bold}pihole1${reset} ($pihole1) and ${bold}pihole2${reset} ($pihole2) ? (y/n)")
|
b=$(echo -e "Do you want to export ${italic}lan.list${reset} to ${bold}pihole1${reset} ($pihole1) and ${bold}pihole2${reset} ($pihole2) ? (y/n)")
|
||||||
read -p "$b" choice
|
read -p "$b" choice
|
||||||
@@ -181,12 +242,16 @@ if [ "$choice" == "y" ] || [ "$choice" == "Y" ]; then
|
|||||||
|
|
||||||
if ping -q -c1 "$pihole1" &>/dev/null; then
|
if ping -q -c1 "$pihole1" &>/dev/null; then
|
||||||
echo "Export to pihole1..."
|
echo "Export to pihole1..."
|
||||||
cat lan.list | ssh -p51322 root@"$pihole1" 'cat > /etc/pihole/lan.list'
|
cat $ScriptWorkDir/lan.list | ssh -p51322 root@"$pihole1" 'cat > /etc/pihole/lan.list'
|
||||||
[ $? != 0 ] && echo -e "${red}Error during transfer to pihole1 ($pihole1)${reset}" || echo -e "${green}Ok${reset}"
|
[ $? != 0 ] && echo -e "${red}Error during transfer to pihole1 ($pihole1)${reset}" || echo -e "${green}Ok${reset}"
|
||||||
|
|
||||||
echo "Restarting dns on pihole1..."
|
# pihole 5
|
||||||
ssh -p51322 root@"$pihole1" 'pihole restartdns'
|
#echo "Restarting dns on pihole1..."
|
||||||
[ $? != 0 ] && echo -e "${red}Error during restarting dns on pihole1 ($pihole1)${reset}" || echo -e "${green}Ok${reset}"
|
#ssh -p51322 root@"$pihole1" 'pihole restartdns'
|
||||||
|
# pihole 6
|
||||||
|
echo "Update the lists and flush the cache without restarting the DNS server on pihole1..."
|
||||||
|
ssh -p51322 root@"$pihole1" 'pihole reloaddns'
|
||||||
|
[ $? != 0 ] && echo -e "${red}Error during reloading dns on pihole1 ($pihole1)${reset}" || echo -e "${green}Ok${reset}"
|
||||||
else
|
else
|
||||||
echo -e "\n${red}Pihole1 is unreachable !'${reset}"
|
echo -e "\n${red}Pihole1 is unreachable !'${reset}"
|
||||||
fi
|
fi
|
||||||
@@ -194,22 +259,227 @@ if [ "$choice" == "y" ] || [ "$choice" == "Y" ]; then
|
|||||||
|
|
||||||
if ping -q -c1 "$pihole2" &>/dev/null; then
|
if ping -q -c1 "$pihole2" &>/dev/null; then
|
||||||
echo "Export to pihole2..."
|
echo "Export to pihole2..."
|
||||||
cat lan.list | ssh -p51522 root@"$pihole2" 'cat > /etc/pihole/lan.list'
|
cat $ScriptWorkDir/lan.list | ssh -p51522 root@"$pihole2" 'cat > /etc/pihole/lan.list'
|
||||||
[ $? != 0 ] && echo -e "${red}Error during transfer to pihole2 ($pihole2)${reset}" || echo -e "${green}Ok${reset}"
|
[ $? != 0 ] && echo -e "${red}Error during transfer to pihole2 ($pihole2)${reset}" || echo -e "${green}Ok${reset}"
|
||||||
|
|
||||||
echo "Restarting dns on pihole2..."
|
# pihole 5
|
||||||
ssh -p51522 root@"$pihole2" 'pihole restartdns'
|
#echo "Restarting dns on pihole2..."
|
||||||
[ $? != 0 ] && echo -e "${red}Error during restarting dns on pihole2 ($pihole2)${reset}" || echo -e "${green}Ok${reset}"
|
#ssh -p51522 root@"$pihole2" 'pihole restartdns'
|
||||||
|
# pihole 6
|
||||||
|
echo "Update the lists and flush the cache without restarting the DNS server on pihole2..."
|
||||||
|
ssh -p51522 root@"$pihole2" 'pihole reloaddns'
|
||||||
|
[ $? != 0 ] && echo -e "${red}Error during reloading dns on pihole2 ($pihole2)${reset}" || echo -e "${green}Ok${reset}"
|
||||||
else
|
else
|
||||||
echo -e "n${red}Pihole2 is unreachable !'${reset}"
|
echo -e "\n${red}Pihole2 is unreachable !'${reset}"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo -e "OK, let's continue..."
|
echo -e "OK, let's continue..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# On supprime les fichiers temporaires
|
|
||||||
|
|
||||||
|
# 5. On compare la liste principale des sous-domaines subdomains.photos-nas.ovh.txt avec la zone photos-nas.ovh sur ovh (via l'API)
|
||||||
|
|
||||||
|
# On récupère la zone photos-nas.ovh depuis ovh
|
||||||
|
# a) Zones DNS -> photos-nas.ovh -> Historique des zones => photos-nas.ovh_dns_data.txt
|
||||||
|
# b) API OVH -> liste des CNAME de la zone photos-nas.ovh => zone.photos-nas.ovh
|
||||||
|
|
||||||
|
HTTP_QUERY="https://api.ovh.com/1.0/domain"
|
||||||
|
TIME=$(curl -s https://api.ovh.com/1.0/auth/time)
|
||||||
|
|
||||||
|
ZONE_FILE="zone.photos-nas.ovh"
|
||||||
|
ZONE="photos-nas.ovh"
|
||||||
|
|
||||||
|
source $ScriptWorkDir/ovh_secrets.txt
|
||||||
|
|
||||||
|
export_zone() {
|
||||||
|
HTTP_METHOD="GET"
|
||||||
|
HTTP_BODY=""
|
||||||
|
HTTP_QUERY="https://eu.api.ovh.com/v1/domain/zone/$ZONE/export"
|
||||||
|
|
||||||
|
CLEAR_SIGN="$OVH_APP_SECRET+$OVH_CONSUMER_KEY+$HTTP_METHOD+$HTTP_QUERY+$HTTP_BODY+$TIME"
|
||||||
|
SIG='$1$'$(echo -n $CLEAR_SIGN | openssl dgst -sha1 | sed -e 's/^.* //')
|
||||||
|
|
||||||
|
curl --silent -X $HTTP_METHOD -H "Content-Type:application/json;charset=utf-8" -H "X-Ovh-Application:$OVH_APP_KEY" -H "X-Ovh-Timestamp:$TIME" -H "X-Ovh-Signature:$SIG" -H "X-Ovh-Consumer:$OVH_CONSUMER_KEY" --data "$HTTP_BODY" $HTTP_QUERY | sed 's/\\n/\n/g' | sed 's/\"//g' | grep 'CNAME'> $ZONE_FILE
|
||||||
|
#curl --silent -X $HTTP_METHOD -H "Content-Type:application/json;charset=utf-8" -H "X-Ovh-Application:$OVH_APP_KEY" -H "X-Ovh-Timestamp:$TIME" -H "X-Ovh-Signature:$SIG" -H "X-Ovh-Consumer:$OVH_CONSUMER_KEY" --data "$HTTP_BODY" $HTTP_QUERY | sed 's/\\n/\n/g' | grep 'CNAME'
|
||||||
|
# |sed 's/,//g' |sed 's/\\n/\'$'\n''/g'
|
||||||
|
# | sed 's/\\n/\n/g'
|
||||||
|
#echo $?
|
||||||
|
if [ $? == 0 ]; then
|
||||||
|
echo -e "File ${italic}$ZONE_FILE${reset} have been created from OVH $ZONE zone !"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
remove_cname() {
|
||||||
|
record=""
|
||||||
|
|
||||||
|
HTTP_METHOD="GET"
|
||||||
|
HTTP_BODY=""
|
||||||
|
HTTP_QUERY="https://eu.api.ovh.com/v1/domain/zone/$ZONE/record?fieldType=CNAME&subDomain=$1"
|
||||||
|
|
||||||
|
CLEAR_SIGN="$OVH_APP_SECRET+$OVH_CONSUMER_KEY+$HTTP_METHOD+$HTTP_QUERY+$HTTP_BODY+$TIME"
|
||||||
|
SIG='$1$'$(echo -n $CLEAR_SIGN | openssl dgst -sha1 | sed -e 's/^.* //')
|
||||||
|
|
||||||
|
record=$(curl --silent -X $HTTP_METHOD -H "Content-Type:application/json;charset=utf-8" -H "X-Ovh-Application:$OVH_APP_KEY" -H "X-Ovh-Timestamp:$TIME" -H "X-Ovh-Signature:$SIG" -H "X-Ovh-Consumer:$OVH_CONSUMER_KEY" --data "$HTTP_BODY" $HTTP_QUERY | sed 's/.//;s/.$//')
|
||||||
|
#echo $? # 0
|
||||||
|
if [ $? == 0 ] && [ -n "$record" ]; then
|
||||||
|
echo "Record number for CNAME $1 is $record !"
|
||||||
|
|
||||||
|
HTTP_METHOD="DELETE"
|
||||||
|
HTTP_BODY=""
|
||||||
|
HTTP_QUERY="https://eu.api.ovh.com/v1/domain/zone/$ZONE/record/$record"
|
||||||
|
|
||||||
|
CLEAR_SIGN="$OVH_APP_SECRET+$OVH_CONSUMER_KEY+$HTTP_METHOD+$HTTP_QUERY+$HTTP_BODY+$TIME"
|
||||||
|
SIG='$1$'$(echo -n $CLEAR_SIGN | openssl dgst -sha1 | sed -e 's/^.* //')
|
||||||
|
|
||||||
|
curl --silent -X $HTTP_METHOD -H "Content-Type:application/json;charset=utf-8" -H "X-Ovh-Application:$OVH_APP_KEY" -H "X-Ovh-Timestamp:$TIME" -H "X-Ovh-Signature:$SIG" -H "X-Ovh-Consumer:$OVH_CONSUMER_KEY" --data "$HTTP_BODY" $HTTP_QUERY
|
||||||
|
#echo $? # 0
|
||||||
|
if [ $? == 0 ]; then
|
||||||
|
echo "CNAME $1 have been successfully deleted !"
|
||||||
|
else
|
||||||
|
echo "Error while deleting CNAME $1 !"
|
||||||
|
fi
|
||||||
|
|
||||||
|
else
|
||||||
|
echo "No record number found for CNAME $1 !"
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
add_cname() {
|
||||||
|
HTTP_METHOD="POST"
|
||||||
|
HTTP_BODY="{\"fieldType\": \"CNAME\",\"subDomain\": \"$1\",\"target\": \"photos-nas.ovh.\",\"ttl\": 0}"
|
||||||
|
HTTP_QUERY="https://eu.api.ovh.com/v1/domain/zone/$ZONE/record"
|
||||||
|
|
||||||
|
CLEAR_SIGN="$OVH_APP_SECRET+$OVH_CONSUMER_KEY+$HTTP_METHOD+$HTTP_QUERY+$HTTP_BODY+$TIME"
|
||||||
|
SIG='$1$'$(echo -n $CLEAR_SIGN | openssl dgst -sha1 | sed -e 's/^.* //')
|
||||||
|
|
||||||
|
curl --silent -X $HTTP_METHOD -H "Content-Type:application/json;charset=utf-8" -H "X-Ovh-Application:$OVH_APP_KEY" -H "X-Ovh-Timestamp:$TIME" -H "X-Ovh-Signature:$SIG" -H "X-Ovh-Consumer:$OVH_CONSUMER_KEY" --data "$HTTP_BODY" $HTTP_QUERY
|
||||||
|
#echo $? # null
|
||||||
|
if [ $? == 0 ]; then
|
||||||
|
echo "CNAME $1 have been successfully added !"
|
||||||
|
else
|
||||||
|
echo "Error adding CNAME $1 !"
|
||||||
|
fi
|
||||||
|
|
||||||
|
HTTP_BODY=""
|
||||||
|
HTTP_QUERY="https://eu.api.ovh.com/v1/domain/zone/$ZONE/refresh"
|
||||||
|
|
||||||
|
CLEAR_SIGN="$OVH_APP_SECRET+$OVH_CONSUMER_KEY+$HTTP_METHOD+$HTTP_QUERY+$HTTP_BODY+$TIME"
|
||||||
|
SIG='$1$'$(echo -n $CLEAR_SIGN | openssl dgst -sha1 | sed -e 's/^.* //')
|
||||||
|
|
||||||
|
curl --silent -X $HTTP_METHOD -H "Content-Type:application/json;charset=utf-8" -H "X-Ovh-Application:$OVH_APP_KEY" -H "X-Ovh-Timestamp:$TIME" -H "X-Ovh-Signature:$SIG" -H "X-Ovh-Consumer:$OVH_CONSUMER_KEY" --data "$HTTP_BODY" $HTTP_QUERY
|
||||||
|
#echo $? # 0
|
||||||
|
if [ $? == 0 ]; then
|
||||||
|
echo "Zone $ZONE have been successfully refresh !"
|
||||||
|
else
|
||||||
|
echo "Error while refreshing zone $ZONE !"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
echo -e "${bold}\nGet extra CNAME records list from zone ${italic}$ZONE${reset} (API OVH)..."
|
||||||
|
|
||||||
|
export_zone
|
||||||
|
|
||||||
|
#ovh_cname_list=$(cat photos-nas.ovh_dns_data.txt | grep "CNAME" | sed '1d')
|
||||||
|
|
||||||
|
|
||||||
|
ovh_cname_list=$(cat $ScriptWorkDir/$ZONE_FILE)
|
||||||
|
subdomains_list=$(cat $ScriptWorkDir/subdomains.photos-nas.ovh.txt)
|
||||||
|
extra_ovh=()
|
||||||
|
absent_ovh=()
|
||||||
|
|
||||||
|
echo -e "${bold}\nFind extra CNAME records in zone ${italic}$ZONE${reset}..."
|
||||||
|
|
||||||
|
while IFS= read -r line; do
|
||||||
|
|
||||||
|
dynhost=$(echo "${line}" | awk '{print $1}')
|
||||||
|
grep -q $dynhost $ScriptWorkDir/subdomains.photos-nas.ovh.txt
|
||||||
|
|
||||||
|
if [ $? != 0 ]; then
|
||||||
|
if [[ ! " ${not_required[*]} " =~ " $dynhost " ]] && [[ ! " ${not_used[*]} " =~ " $dynhost " ]]; then
|
||||||
|
#echo "$dynhost présent sur ovh"
|
||||||
|
extra_ovh+=(${dynhost})
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 55 sur ovh
|
||||||
|
# 54 sur subdomains.photos-nas.ovh.txt
|
||||||
|
# 43 sur lan.list
|
||||||
|
|
||||||
|
done <<< "$ovh_cname_list"
|
||||||
|
|
||||||
|
if [ ${#extra_ovh[@]} -ge 1 ]; then
|
||||||
|
|
||||||
|
echo -e "${red}To delete: ${extra_ovh[@]}${reset}"
|
||||||
|
|
||||||
|
for val in ${!extra_ovh[@]}
|
||||||
|
do
|
||||||
|
value="${extra_ovh[$val]}"
|
||||||
|
|
||||||
|
b=$(echo -e "Do you want to delete ${red}$value${reset} CNAME in OVH zone ${italic}$ZONE${reset} ? (y/n)")
|
||||||
|
read -p "$b" choice
|
||||||
|
if [ "$choice" == "y" ] || [ "$choice" == "Y" ]; then
|
||||||
|
remove_cname "$value"
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
#nb_dynhost=$(awk 'END { print NR }' lan.list)
|
||||||
|
#echo "$nb_dynhost dynhost found in lan.list !"
|
||||||
|
#fi
|
||||||
|
else
|
||||||
|
echo "None"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${bold}\nFind missing CNAME records in zone ${italic}$ZONE${reset}..."
|
||||||
|
|
||||||
|
while IFS= read -r line; do
|
||||||
|
|
||||||
|
dynhost=$(echo "${line}" | awk '{print $1}')
|
||||||
|
grep -q $dynhost $ScriptWorkDir/zone.photos-nas.ovh
|
||||||
|
|
||||||
|
if [ $? != 0 ]; then
|
||||||
|
if [[ ! " ${not_required[*]} " =~ " $dynhost " ]] && [[ ! " ${not_used[*]} " =~ " $dynhost " ]]; then
|
||||||
|
#echo "$dynhost absent sur ovh"
|
||||||
|
absent_ovh+=(${dynhost})
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
done <<< "$subdomains_list"
|
||||||
|
|
||||||
|
if [ ${#absent_ovh[@]} -ge 1 ]; then
|
||||||
|
|
||||||
|
echo -e "${red}To add: ${absent_ovh[@]}${reset}"
|
||||||
|
|
||||||
|
|
||||||
|
for val in ${!absent_ovh[@]}
|
||||||
|
do
|
||||||
|
value="${absent_ovh[$val]}"
|
||||||
|
|
||||||
|
b=$(echo -e "Do you want to add ${red}$value${reset} CNAME in OVH zone ${italic}$ZONE${reset} ? (y/n)")
|
||||||
|
read -p "$b" choice
|
||||||
|
if [ "$choice" == "y" ] || [ "$choice" == "Y" ]; then
|
||||||
|
echo "$value"
|
||||||
|
add_cname "$value"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
#nb_dynhost=$(awk 'END { print NR }' lan.list)
|
||||||
|
#echo "$nb_dynhost dynhost found in lan.list !"
|
||||||
|
|
||||||
|
else
|
||||||
|
echo "None"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# 6. On supprime les fichiers temporaires
|
||||||
[ -f /tmp/temp_file.list ] && rm /tmp/temp_file.list
|
[ -f /tmp/temp_file.list ] && rm /tmp/temp_file.list
|
||||||
[ -f lan.list.sorted ] && rm lan.list.sorted
|
[ -f $ScriptWorkDir/lan.list.sorted ] && rm $ScriptWorkDir/lan.list.sorted
|
||||||
|
|
||||||
|
|
||||||
|
# 7. fin
|
||||||
|
|
||||||
|
echo -e "\n${greenbold}Fin !${reset}"
|
||||||
|
|
||||||
# https://www.nas-forum.com/forum/topic/80160-multiples-dynhost-ovh/#comment-1319505612
|
# https://www.nas-forum.com/forum/topic/80160-multiples-dynhost-ovh/#comment-1319505612
|
||||||
|
|
||||||
|
|||||||
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