mirror of
https://github.com/pi-hole/pi-hole
synced 2024-12-22 06:48:07 +00:00
Add bash / cron based update checker for Pi-hole
This commit is contained in:
parent
2c33c64fae
commit
6ca47dc3b3
70
advanced/Scripts/updatecheck.sh
Executable file
70
advanced/Scripts/updatecheck.sh
Executable file
@ -0,0 +1,70 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Pi-hole: A black hole for Internet advertisements
|
||||||
|
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
||||||
|
# Network-wide ad blocking via your own hardware.
|
||||||
|
#
|
||||||
|
# Checks for updates via GitHub
|
||||||
|
#
|
||||||
|
# This file is copyright under the latest version of the EUPL.
|
||||||
|
# Please see LICENSE file for your rights under this license.
|
||||||
|
|
||||||
|
# Credit: https://stackoverflow.com/a/46324904
|
||||||
|
function json_extract() {
|
||||||
|
local key=$1
|
||||||
|
local json=$2
|
||||||
|
|
||||||
|
local string_regex='"([^"\]|\\.)*"'
|
||||||
|
local number_regex='-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?'
|
||||||
|
local value_regex="${string_regex}|${number_regex}|true|false|null"
|
||||||
|
local pair_regex="\"${key}\"[[:space:]]*:[[:space:]]*(${value_regex})"
|
||||||
|
|
||||||
|
if [[ ${json} =~ ${pair_regex} ]]; then
|
||||||
|
echo $(sed 's/^"\|"$//g' <<< "${BASH_REMATCH[1]}")
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
GITHUB_CORE_VERSION="$(json_extract tag_name "$(curl -q 'https://api.github.com/repos/pi-hole/pi-hole/releases/latest' 2> /dev/null)")"
|
||||||
|
GITHUB_WEB_VERSION="$(json_extract tag_name "$(curl -q 'https://api.github.com/repos/pi-hole/AdminLTE/releases/latest' 2> /dev/null)")"
|
||||||
|
GITHUB_FTL_VERSION="$(json_extract tag_name "$(curl -q 'https://api.github.com/repos/pi-hole/FTL/releases/latest' 2> /dev/null)")"
|
||||||
|
|
||||||
|
echo "${GITHUB_CORE_VERSION} ${GITHUB_WEB_VERSION} ${GITHUB_FTL_VERSION}" > "/etc/pihole/GitHubVersions"
|
||||||
|
|
||||||
|
function get_local_branch() {
|
||||||
|
# Return active branch
|
||||||
|
local directory
|
||||||
|
directory="${1}"
|
||||||
|
local output
|
||||||
|
|
||||||
|
cd "${directory}" || return 1
|
||||||
|
# Store STDERR as STDOUT variable
|
||||||
|
output=$( { git rev-parse --abbrev-ref HEAD; } 2>&1 )
|
||||||
|
echo "$output"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
CORE_BRANCH="$(get_local_branch /etc/.pihole)"
|
||||||
|
WEB_BRANCH="$(get_local_branch /var/www/html/admin)"
|
||||||
|
FTL_BRANCH="$(pihole-FTL tag)"
|
||||||
|
|
||||||
|
echo "${CORE_BRANCH} ${WEB_BRANCH} ${FTL_BRANCH}" > "/etc/pihole/localbranches"
|
||||||
|
|
||||||
|
function get_local_version() {
|
||||||
|
# Return active branch
|
||||||
|
local directory
|
||||||
|
directory="${1}"
|
||||||
|
local output
|
||||||
|
|
||||||
|
cd "${directory}" || return 1
|
||||||
|
# Store STDERR as STDOUT variable
|
||||||
|
output=$( { git describe --long --dirty --tags; } 2>&1 )
|
||||||
|
echo "$output"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
CORE_VERSION="$(get_local_version /etc/.pihole)"
|
||||||
|
WEB_VERSION="$(get_local_version /var/www/html/admin)"
|
||||||
|
FTL_VERSION="$(pihole-FTL version)"
|
||||||
|
|
||||||
|
echo "${CORE_VERSION} ${WEB_VERSION} ${FTL_VERSION}" > "/etc/pihole/localversions"
|
@ -28,3 +28,6 @@
|
|||||||
00 00 * * * root PATH="$PATH:/usr/local/bin/" pihole flush once quiet
|
00 00 * * * root PATH="$PATH:/usr/local/bin/" pihole flush once quiet
|
||||||
|
|
||||||
@reboot root /usr/sbin/logrotate /etc/pihole/logrotate
|
@reboot root /usr/sbin/logrotate /etc/pihole/logrotate
|
||||||
|
|
||||||
|
# Pi-hole: Grab remote version and branch every 10 minutes
|
||||||
|
*/10 * * * * root PATH="$PATH:/usr/local/bin/" pihole updatechecker
|
||||||
|
10
pihole
10
pihole
@ -200,7 +200,7 @@ Options:
|
|||||||
|
|
||||||
# Scan Wildcards
|
# Scan Wildcards
|
||||||
if [[ -e "${wildcardlist}" ]]; then
|
if [[ -e "${wildcardlist}" ]]; then
|
||||||
# Determine all subdomains, domain and TLDs
|
# Determine all subdomains, domain and TLDs
|
||||||
mapfile -t wildcards <<< "$(processWildcards "${domainQuery}")"
|
mapfile -t wildcards <<< "$(processWildcards "${domainQuery}")"
|
||||||
|
|
||||||
for match in "${wildcards[@]}"; do
|
for match in "${wildcards[@]}"; do
|
||||||
@ -483,7 +483,7 @@ statusFunc() {
|
|||||||
|
|
||||||
# Determine if Pi-hole's addn-hosts configs are commented out
|
# Determine if Pi-hole's addn-hosts configs are commented out
|
||||||
addnConfigs=$(grep -i "addn-hosts=/" /etc/dnsmasq.d/01-pihole.conf)
|
addnConfigs=$(grep -i "addn-hosts=/" /etc/dnsmasq.d/01-pihole.conf)
|
||||||
|
|
||||||
if [[ "${addnConfigs}" =~ "#" ]]; then
|
if [[ "${addnConfigs}" =~ "#" ]]; then
|
||||||
# A config is commented out
|
# A config is commented out
|
||||||
case "${1}" in
|
case "${1}" in
|
||||||
@ -579,6 +579,11 @@ tricorderFunc() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateCheckFunc() {
|
||||||
|
"${PI_HOLE_SCRIPT_DIR}"/updatecheck.sh "$@"
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
helpFunc() {
|
helpFunc() {
|
||||||
echo "Usage: pihole [options]
|
echo "Usage: pihole [options]
|
||||||
Example: 'pihole -w -h'
|
Example: 'pihole -w -h'
|
||||||
@ -650,5 +655,6 @@ case "${1}" in
|
|||||||
"-t" | "tail" ) tailFunc;;
|
"-t" | "tail" ) tailFunc;;
|
||||||
"checkout" ) piholeCheckoutFunc "$@";;
|
"checkout" ) piholeCheckoutFunc "$@";;
|
||||||
"tricorder" ) tricorderFunc;;
|
"tricorder" ) tricorderFunc;;
|
||||||
|
"updatechecker" ) updateCheckFunc;;
|
||||||
* ) helpFunc;;
|
* ) helpFunc;;
|
||||||
esac
|
esac
|
||||||
|
Loading…
Reference in New Issue
Block a user